This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh -NC user@host -L 8000:127.0.0.1:3306 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert to integer: 12, 0x03 | |
# raise an error if the string contains something other that a valid number | |
n = Integer(string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list which application listen on which port: | |
lsof -nPi | grep LISTEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh -p 2451 [email protected] 'sudo dd if=/dev/xenvg/box | gzip -c' | gzip -d | dd of=/dev/sda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| ... } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
OlderNewer