Friday, April 13, 2012

Remove all Ruby Gems

To remove all gems from your system, this should work.


gem list | cut -d" " -f1 | xargs gem uninstall -aIx

On JRuby following works


gem list --no-versions | while read x; do sudo gem uninstall $x -a; done

Many a times you may run in to situation where you simply want to clean up all the gems installed. I found this article very helpful. Above command is copied from their. You can read detail on the site.

Wednesday, January 25, 2012

Git Reference card

Git create remote branch

To create a local branch
git branch branch_name
To switch/checkout local branch
git checkout branch_name
You can combine above two in one step instead
git checkout -b your_branch
Create remote branch (so that other co-workers/programmers/whoever can pull)
git push -u origin your_branch
Others can pull this by
git checkout origin/your_branch

View diff in GIT

What you will commit
git diff

diff between two branch
git diff master..branch_1
diff since last commit
git diff HEAD
This entry is a note to self for being amnesiac
.

Monday, November 28, 2011

Disqus(ted)

Great added Disqus to blog. Looks like I lost all old comments (of whatever few I had).

Tuesday, June 21, 2011

Monday, June 20, 2011

Install ruby using RVM

This is note to self, for installing ruby 1.8.7 using RVM. Other versions can be installed in same way "mostly". Just replace the version 1.8.7 with version intended

Verbose documentation about RVM installtion can be found at https://rvm.beginrescueend.com/rvm/install/

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >>

add above line in ~/.bashrc file in the end

rvm package install zlib
rvm package install openssl
rvm install 1.8.7--with-openssl-dir=$HOME/.rvm/usr
rvm use 1.8.7 --default

zlib and openssl is required in many cases.

Wednesday, June 08, 2011

Sinatra: memcached as session store

A simple route for using memcached as session store.

require 'rubygems'
require 'sinatra'

use Rack::Session::Memcache, :memcache_server => 'localhost:11211', :expire_after => 3600, :namespace => "sinatra.chandankumar.com"

get "/" do
"value = " << session[:value].inspect
end

get "/set" do
session[:value] = params[:value].inspect
redirect "/"
end

This would enable you to spawn multiple instances of (same) Sinatra app while sharing session store to achieve non sticky session. Helps scaling the front end.

Wednesday, June 01, 2011

Sinatra Ajax File Upload

Valums script at http://valums.com/ajax-upload/ works like a charm in sinatra route you would require something like

  get :upload do
render "/test/upload", :layout => false
end
post :upload do
logger.debug params
newf = File.open("public/post.jpg", "wb")
newf.write(request.body.read)
'{success:true}'
end