Skip to main content

Posts

ActionController::Live rails 4 Nginx passenger and redis

This is the most common setup for rails applications and most straightforward solution for SSE aka server side events.



In order to get SSE to work using redis we just use Ajax to respond to publish events based on json fields being present but you can even send a pure data payload:




Recent posts

:: Rails Cropping Demystified ::

Design choice:
Solution1
Carrierwave, S3, Fog, Jquery File Upload, Jcrop + RMagick / MiniMagick

Advantage Server Side:

Support for all browser versionsSingle stream file upload and can be coupled with resque for heavy loading.

OR

Solution2
S3,  Jquery File Upload, HTML5  cropping + CORS

Advantage client side and CORS Upload

More compute optimizedServer band-with as files are directly sent to S3Best suited to multiple file uploads.

Solution 1: Server side cropping
Setup:
Carrierwave has an excellent readme guide on how to install and setup these are the important bits:

GemFile:
gem 'carrierwave' gem "fog" gem "rmagick" Initializer carrierwave.rb (Constants as defined in config.yml)
CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS', # required :aws_access_key_id => APP_CONFIG['s3']['aws_access_key_id'], # required :aws_secret_…

Junit Tests OpenJPA and Websphere EJB3.0 + DB2 9.0

Junit Tests OpenJPA and Websphere EJB3.0 DB2

For those of us with IBM and their beau software aka tools.

Heres what i had to do to configure the websphere Enterprise container to fire JUnits to persist EJB’s over OpenJPA 1.2.3

You will have to Override persistence.xml file settings to start using JDBC over JTA.

Here’s a snippet from my Abstract Test Case class
Most interesting one is the TransactionMode which is correlated to using
prop.getProperty("jdbc.password")); configOverrides.put("openjpa.TransactionMode", "local");
Result:
Allows you to reuse a single persistence unit as Websphere has a bug wherein it would not allow multiple persistence Units to load together. Even worse a separate one for test also fails

Just one more thing
Remember to commit or close connections in the end so:

@After public void tearDown() throws Exception { entityTransaction.commit(); super.tearDown(); } Complete Abrstract Template
public abstract class AbstractTestCase e…

Predicates Java Pattern to save Database Queries

The apache commons CollectionUtils has a collection of very interesting methods to allow using Ruby style collection filtering, rejecting,collecting injecting ...

I found the select method quite useful to avoid multiple DB Queries with a DB similar predicate and syntactically clean.

Problem: I wish to append a List/Collection to my Bean based on some predicate (orgId="mcool").

Solution:
Use of Predicates:

Basic Example:BeanPropertyValueEqualsPredicate  predicate = new BeanPropertyValueEqualsPredicate("orgId", value);


BeanPropertyValueEqualsPredicate predicate = new BeanPropertyValueEqualsPredicate("orgId", value); Collection<Organisation> organisationCool = CollectionUtils.select(allOrgansations, predicate); allOrganisations above was fetched with a single sql select.

bean.setOrganisationsList(organisationCool );

Caution:  Needless to say but typically small datasets and only for cases where in memory selection is beneficial.



More about the Ruby …