Posted: January 11th, 2012 | Author: Andrea | Filed under: resque, ruby, upstart | No Comments »
Resque is a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later. Resque works firing up a set number of workers than will coninuously look for job to be processed and will execute them following the rules defined when the workers are launched. You can have a single worker process any queue or having a single worker processing a single queue or even fire up more workers that will look forward to a single queue. Read more about resque.
A very important topic is to be sure that the workers are always available and that any time your application is deployed also the workers are restarted. This is crucial cause the worker load an instance of your application and will then process the jobs against this application instance. If you deploy a new version of your application but you do not restart your workers the jobs will be run on an outdated code version and this is clearly something you do not want! Read the rest of this entry »
Posted: November 3rd, 2011 | Author: Andrea | Filed under: git | No Comments »
I am now using git since more than a year as my primary scm. I tend to use it also against svn repo, I can so focusing on git becoming always more comfortable using it.
To be honest up to now my git use has always been quite basic, while projects I was working on never needed more that a master/develop/topic branches workflow. Recently I faced a more complex issue related to the necessary support for proper support branch that was going to diverge for a long time from the develop branch.
We have a develop branch where is done the job for new version 2.0 while we still have a stable branch where we support version 1.0. The issue comes from the fact that version 1.0 is not going to receive only simple hotfixes but will also be improved with new feature that need to be ported to version 2.0..
For the first month or so we still were able to merge the 2 branches but not they have diverged too much. Merge is not an option and so we had to find a new strategy.
Our goal was to carry all the changes made on a topic branch borned by the 2.0 branch into the same 2.0 and also to the 1.0 without merging 2.0 into 1.0. This can be solved cherry-picking any single commit from the topic branch to the 2.0 and then merge topic into 1.0. While this works fine we faced situations where the topic branch were actually getting too long and cherry picking many commits can be buggy and tricky.
Read the rest of this entry »
Posted: July 27th, 2011 | Author: Andrea | Filed under: ruby | No Comments »
Something very cool in ruby are mixins. As the word says mixin is a technique to mixed a module into a class using the statement “include”.
While including a module is a very large topic I focused on the opportunity to include module defined in the Ruby standard library into your class to take advantages of the methods and abilities that these modules provide.
The Comparable module in ruby define methods like < <= == > >= between? .
What if I want to achieve is making my class instances comparable so that I can ask to ruby if class_a > class_b. Read the rest of this entry »
Posted: July 2nd, 2011 | Author: Andrea | Filed under: ruby | Tags: ruby | No Comments »
Working on one of my first ruby gem I have started to learn more about ruby meta programming and ruby core language.
My gem needs a sort of singleton class that needs to be configured when the application starts. I have choosed to use a Module as singleton cause a ruby module cannot be initialized and so it just fits my needs.
I will then include the configured module into the model that will need it.
Read the rest of this entry »
Posted: June 11th, 2011 | Author: Andrea | Filed under: ruby | Tags: ruby | No Comments »
Playing with the ruby console I am wondering how I can read some input from the console.
Ruby ships with the method gets that makes easy to read console input. Just try the following code:
print "What is your name? "
$stdout.flush
name = gets
puts 'Hi ' + name + '!!!' + name
# => Hi andrea
# !!!
When the console asks for your name just type it. The ruby program will read the console input and will welcome you. You will note that a new line is added after that the variable name is printed out. This is the default behaviour of the gets function. Gets add a new line after any variable that memorize. If this is not desired you can call the method chomp on the gets result and the newline is suppressed.
Change your code as follows and the new line will not be printed anymore:
print "What is your name? "
$stdout.flush
name = gets.chomp
puts 'Hi ' + name + '!!!' + name
#=> Hi andrea!!!
Posted: June 5th, 2011 | Author: Andrea | Filed under: bundler, ruby | Tags: ruby | No Comments »
Since some months I have started to programm in Ruby and especially using the Rails framework. I have to say I find Rails so great that I realized, that after some months, that I can be quite productive knowing very little about Ruby itself. This tells you how powerfull can be a dsl written in Ruby and talks about the nice job Rails developers did but is not going to make me shine as a Ruby developer.
I have decided to step back and I am finally going to open a Programming Ruby book seriously. I will go throught my Ruby discovering writing here my tests and anything I will discover in my learning Ruby travel. This will help me to fix some concept in my mind and hopefully someone else will learn from my mistakes.
For the moment I discovered something about bundler I really didn’t know before and I ‘d like to share. I have just ended reading a post of Yehuda Katz about Bundler and Gems dependencies that really opened my eyes.
Something from Yehuda post:
Read the rest of this entry »
Posted: March 2nd, 2011 | Author: Andrea | Filed under: Uncategorized | Tags: Uncategorized | No Comments »
A couple of weeks ago I was reading a post from Raymond Camden that remembered me I completely forgot to add support to addevent() in Railo cfmap implementation. The blog post was quite interesting and showed a way to add streetview to a google map, generated by cfmap, using the Coldfusion.Map.addEvent function. Read the post here.
Of course code was not running in Railo due to the lack of the method in the Railo js library.
I made a patch and support was added in Railo 3.2.1.005/3.3.0.005.
So following the Ray example (all credits to Ray for the following code) you can run the following code in Railo and adding a streeview to your cfmap using the addEvent() function.
<script>
function init() {
ColdFusion.Map.addEvent("mainMap","click",function(overlay,overlaylnglt) {
address = arguments[arguments.length-1];
var loc = new GLatLng(address.lat(),address.lng());
panoramaOptions = { latlng:loc };
var myPano = new GStreetviewPanorama(document.getElementById("streetDiv"), panoramaOptions);
});
}
</script>
<cfmap centeraddress="Milano Italy" zoomlevel="15" name="mainMap"/>
<div id="streetDiv" style="width:500px;height:500px"></div>
<cfset ajaxOnLoad("init")>
Please note that in Railo js library are available both the Railo and Coldfusion namespaces so Railo.Map.addEvent() is equivalent as running Coldfusion.Map.addEvent().
Have fun!
Posted: February 13th, 2011 | Author: Andrea | Filed under: mongodb | No Comments »
A new update the the MongoDB Cache extension for Railo is on the extension provider.
Some bug was fixed and performance improved by a better tuning of the query that respects the cache expiration timeout. In my tests I could reach 400 interactions ( put and get of 400 items ) in in average time of 1200ms. Pretty awesome!!!!
Posted: January 24th, 2011 | Author: Andrea | Filed under: Uncategorized | 7 Comments »
I have just uploaded the Railo WebSockets Gateway Extension to the Railo preview extension provider.
This extension enables you to launch a server that is capable to manage messaging from HTML WebSockets.
The server runs on a dedicated port. Railo will receive notifications when a connection is opened, closed and any time a message is sent invoking a cfc listener class. The gateway can also being invoked via SendGatewayMessage so to allow your app to push message to all the connected clients.
While only few browsers natively support WebSockets up to now exists many libraries that mange the failover to flash sockets or other technologies like ajax long polling etc… WebSockets are a great way to implement messaging and data pushing using well known technologies like javascript. The gateway just makes it a breeze pushing data from your Railo application to any connected client.
You can find docs about the extension in the Railo wiki and some sample code cloning the following github repo https://github.com/andreacfm/websockets_example_apps.
Please post any feedback in the Railo Google Group and any bug in the Railo Jira bugtraker.
Posted: November 13th, 2010 | Author: Andrea | Filed under: mongodb, Uncategorized | 3 Comments »
I have uploaded yesterday a main update of the MongoDB Cache extension for Railo. See installation details here
I have improved the management of timespan and timeidle expiring using some incredible feature that MongoDB offers.
1) Any time you ask for a key the plugin attempts to delete it running a MongoDB query ( optimized using index on any relevant field ) and then fetch it. If key is still there means that is a still valid entry.
2) Any 20 seconds a clean process is runned so to keep the db more updated as possible and making the the flush operation on cacheGet() more efficient.
In my test this has improved speed of about 30% delegating more operation to the db itself.
The following code makes 2000 read/write operation in an average of 1500/1600 ms.
<cfset start = gettickcount()>
<cfloop from="1" to="1000" index="i">
<cfcache action="put" id="a#i#" value="#i#">
<cfcache action="get" id="a#i#" name="v">
<cfcache action="put" id="b#i#" value="#{value = i}#">
<cfcache action="get" id="b#i#" name="v">
</cfloop>
<cfset end = gettickcount()>
<cfoutput>#end - start# millis</cfoutput>
Amazing !!!!!