Thursday, July 8, 2010

Overwrite Inploy app servers' restart command

Inploy (http://github.com/dcrec1/inploy) is a rails deployment
solution. It comes with integration to restart 4 app servers:
* mongrel
* passenger
* thin
* unicorn

I needed a way to change how Inploy restarts passenger since our
passenger's restart file is at a different location.

I could've changed the command inside Inploy's passenger.rb but I
wanted to avoid that as there's good chance that someone in the future
won't know to re-apply the change when they upgrade Inploy.

So I needed a way to monkey patch Inploy's passenger module. My first
attempt was to create my version of the Passenger module and require
the file in rails' environment.rb. That was no good because Inploy's
update command does not seem to bootstrap the whole rails environment
so my override simply wasn't getting loaded.

I had to find another way in to load my module for the deployment
process. It turns out the solution I was looking for is in rake. Since
Inploy's update is just a rake task, I could create a passenger.rake
in Rails.root/lib/tasks and define my restart_server override inside
my custom passenger.rake.

Please let me know if there is a better / proper way to achieve what I
needed. Otherwise hope this helps someone else.

Wednesday, December 9, 2009

My shortcut to open any gem in TextMate with 1 command

Using the implementation from @peepcode's blog on shell method missing as a base.
I've added another action (code snippet below) to open a gem library in TextMate by typing in the name of the gem followed by ".mate".

when /^[A-Za-z0-9_\-\/]+\.mate$/
  # Open the gem in textmate
  # @example
  #   haml.mate
  gem_to_open = command.first.gsub(/\.mate$/, '')
  run "gem which #{gem_to_open} | tail -1 | xargs dirname | sed -e's/$/\\/../' | xargs mate"

Wednesday, November 25, 2009

Download sources jar from maven

We use Maven, when Maven downloads dependencies it doesn't download sources, which I rely on when learn and debug programs....
I was expecting, for what seem a simple thing to me, a flag that I can add in maven's settings files or an option to pass to mvn command.... but I couldn't find the solution (or anything close to it). Don't get me wrong, there are solutions out there, but I just feel it is too much hassle for the task.

So I wrote a little script that go thru my repo and downloads any jar that doesn't have its respective sources :p

Monday, November 23, 2009

ImageMagick and JPEG on OSX

I am not a fan of port or fink so I always install ImageMagick from source.
Recently I came across a problem where ImageMagick fails to identify JPEG's.
The error looks something like this
identify: no decode delegate for this image format

After some digging around it appears I need to install libjpeg and reinstall ImageMagick for JPEG support.
So I downloaded jpegsrc.v7.tar.gz and just run thru the standard configure, make & make install then reinstalled ImageMagick.
After the installation you should be able to see JPEG as one of the supported format via the command "identify -list format".
It should contain something like this.
JPEG* JPEG rw- Joint Photographic Experts Group JFIF format (70)


Tuesday, September 8, 2009

Mass erb to haml conversion

Do this in your application's root folder.

find . -name "*.erb" | while read f; do html2haml -r $f ${f%.erb}.haml; done;

Thursday, August 27, 2009

How to stop unix read command escape backslashes

If you want to pipe any output that has backslashes in it (or make 'read' take a string with backslashes) to the read command then you will need to stop the read command treating backslash as escape character by using read -r
e.g.
cleartool ls | while read -r file
do
# do something to file
done

Monday, August 24, 2009

Software design or code design

Software design

Generally high level, a.k.a.
  • architecture
  • infrastructure
    e.g. 3-tiers or client server, ejb or not

Code design

  • domain design
  • flow design
  • good code design means clean, maintainable code
  • code design issues are easier to fix than software design
The following extract from Domain Driven Design applies regardless the type of project (waterfall or agile).
Any technical person contributing to the model must spend some
time touching the code, whatever primary role he or she plays on
the project. Anyone responsible for changing code must learn to
express a model through the code. Every developer must be
involved in some level of discussion about the model and have
contact with domain experts. Those who contribute in different
ways must consciously engage those who touch the code in a
dynamic exchange of model ideas through the Ubiquitous
Language.
A solution consultant should touch the code (or at least know the code if they don't want to touch it).