Wednesday, December 9, 2009
My shortcut to open any gem in TextMate with 1 command
Wednesday, November 25, 2009
Download sources jar from maven
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
Tuesday, September 8, 2009
Mass erb to haml conversion
Thursday, August 27, 2009
How to stop unix read command escape backslashes
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
Any technical person contributing to the model must spend someA solution consultant should touch the code (or at least know the code if they don't want to touch it).
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.
Rails Rumble after thoughts
Building an application in 48 hrs is hard. Time flies when you are not prepared.
Here are some of the things that you want to touch on before the competition starts.
- application security / access - who has access to what
- model / resource routes - what models are required and how are they connected from browser / UI perspective
- fields & columns in models
- model validation / mandatory fields
For the initial first few models that you add to the application, the effort to add each one does not increases in linear fashion.
Because with each model, you need CRUD pages / functionality. Each additional page needs to be styled therefore more visual design required, also more thoughts required for workflow / navigation design.
Often we have to just implement some crude pages to test / visualise our app (particular for workflow) while our designer work thru the markup, which means we usually have to go back and cleanup those pages' markup to fit with the design.
Overall, it was exhausting but I learnt heaps of cool tricks this year building TechMeets.com.
Monday, August 17, 2009
Using google_ajax_library when offline.
How to use WinMerge as ClearCase compare & merge tool?
Tuesday, August 4, 2009
How to validate money amount in ActiveRecord?
Wednesday, April 29, 2009
How I installed ruby and run RoR on QNAP TS-219
Set LD_LIBRARY_PATH to be /opt/lib so libssl.so.0.9.8 and libcrypto.so.0.9.8 can be found. Alternatively symlink them to /usr/lib might work as well.
Install ruby & rubygems from source, using default options.
Then run this to install mysql gem.
gem install mysql -- --with-mysql-dir=/usr/local/mysql
Thursday, February 19, 2009
How do I automatically revert to local javascript when offline?
I decided I didn't want to have to bother with that so I implemented something that will check if I am connected online or not and make the appropriate javascript include calls.
The code looks like this:
- if Ping.pingecho("ajax.googleapis.com", 10, 80)
= google_jquery
- else
= javascript_include_tag 'jquery-1.2.6.min.js'
Monday, January 12, 2009
How to remove windows carriage return (^M) on Mac
Here are a couple of command that should do the job of removing those trailing ^M (carriage return) chars.
perl -pi -e's/\r//g' filename
sed -e's/^M//g' filename > newfile
To type ^M in Terminal do Ctrl+V then Ctrl+M.
Friday, January 9, 2009
Use ActiveRecord migration to manage database changes in Java projects
Make it easy to recreate another database with the same schema.
activerecord-jdbc-adapter gem
Resources:
http://www.ics.muni.cz/~makub/ruby/#c2
Steps:
jruby -S gem install --no-rdoc --no-ri activerecord-jdbc-adapter
Update: Thanks to Nick's blog, you no longer have to set GEM_PATH to get the gems required included by the base application.
How to do mass renaming of file extension
You want to rename all the .wiki files to be .textile instead.
Solution:
\ls -1 *.wiki | while read f; do mv $f ${f%.wiki}.textile; done
Easy way to backup codebase on USB key with git
$ git --version
git version 1.6.0.4
mkdir project.init and cd into it
git --bare init
In project codebase's directory
git init
git add .
git ci -m'first commit'
git remote add origin /path/to/project.git
git push origin master
Modify you local master to track remote by appending the following to your project's .git/config file:
[branch "master"]
remote = origin
merge = refs/heads/master
Then you can just do the following in the future to push new files to your USB.
git add .
git ci -m'update repos'
git push
$ git push origin master
Counting objects: 6669, done.
Compressing objects: 100% (6570/6570), done.
Writing objects: 100% (6669/6669), 7.90 MiB | 348 KiB/s, done.
Total 6669 (delta 4488), reused 0 (delta 0)
*** Project description file hasn't been set
error: hooks/update exited with error code 1
error: hook declined to update refs/heads/master
To /cygdrive/e/westpac/compass.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to '/cygdrive/e/project.git'
The above problem is caused by a hook script (.git/hooks/update).
Rename update to something like update.bak so it does not get executed solves the above problem.
Use jruby to dump DB schema to ruby
I have a database that rails doesn't have an easy way to connect to.
Solution:
Use jruby & JDBC
Requirements:
jruby
Resources:
http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/
Steps:
jruby -S gem install activerecord
jruby -S gem install activerecord-jdbc-adapter
Put the jdbc jar in Classpath for jruby. e.g. inside C:\work\tools\jruby-1.1.6\lib
Run this script:
require 'rubygems'
gem 'activerecord-jdbc-adapter'
require 'jdbc_adapter'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
:url => 'jdbc:sqlserver://localhost:1433;DatabaseName=FineosSixApp',
:username => 'username',
:password => 'password'
)
ActiveRecord::SchemaDumper.dump
To load the schema into say mysql
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => 'username',
:password => 'password',
:database => 'database'
)
load('schema.rb')
Future Improvements:
Instead of using jruby on command line, create an ant task that uses jruby.jar and do the same thing.
Basically integrating the schema dump into the build file.
It'll be useful to store the client code base along with schema that runs with the code base.