Skip to content

Instantly share code, notes, and snippets.

View schmurfy's full-sized avatar
:octocat:

Julien Ammous schmurfy

:octocat:
View GitHub Profile
rails profiling
Installing ruby-prof
First install ruby-prof 0.6.1:
1 git clone git://github.com/jeremy/ruby-prof.git
2 cd ruby-prof/
3 rake gem
4 sudo gem install pkg/ruby-prof-0.6.1.gem
ssh -NC user@host -L 8000:127.0.0.1:3306
list which application listen on which port:
lsof -nPi | grep LISTEN
# convert to integer: 12, 0x03
# raise an error if the string contains something other that a valid number
n = Integer(string)
ssh -p 2451 ja@91.121.104.30 'sudo dd if=/dev/xenvg/box | gzip -c' | gzip -d | dd of=/dev/sda
detach subdirectory:
You want to clone your repository and then use git filter-branch to mark everything but the subdirectory you want in your new repo to be garbage-collected. To clone your local repository:
$ git clone --no-hardlinks /XYZ /ABC
The --no-hardlinks switch makes git use real file copies instead of hardlinking when cloning a local repository. The garbage collection and pruning actions will only work on blobs (file contents), not links.
Then just filter-branch and reset to exclude the other files, so they can be pruned:
@schmurfy
schmurfy / gist:194461
Created September 26, 2009 21:39 — forked from mtodd/gist:180398
Surround a heredoc with quotes and you can continue the code on the same line:
render :status => 404, :text => <<-'EOH' and return unless setup
article not found<br/>
I, as a server, have failed<br/>
https?
EOH
Quotes also give you more freedom/creativity with the terminal ID:
@schmurfy
schmurfy / ruby1.9.rb
Created February 28, 2010 18:18
Ruby 1.9 changes Quick Reference
# some nice ruby 1.9 additions
str = arr.map(&:firstname) # if arr is an array of user object (worked in ruby 1.8 with activesupport but now native in ruby 1.9)
# map, each, etc... returns an iterator object with a with_index method
arr.map.with_index {|element, i| ... }
arr.each.with_index {|element, i| ... }
# lambda can have default parameters
p = proc{|a, b = 3| ... }
@schmurfy
schmurfy / datamapper.rb
Created February 28, 2010 15:46
DataMapper Quick Reference
# some more: http://cheat.errtheblog.com/s/datamapper/
# results of first steps with datamapper and lack of documentation
# use a bigint unsigned column as primary key
property :id, Serial, :min => 0, :max => 2**32
# automagically create database from your model definitions (destructive !)
DataMapper.auto_migrates!
<Model>.auto_migrate!
# client
require 'zmq'
ctx = ZMQ::Context.new(1)
s = ctx.socket(ZMQ::REQ);
# max queue size
s.setsockopt(ZMQ::HWM, 100);
s.connect("tcp://127.0.0.1:7000");
msg = "msg_content"