Skip to content

Instantly share code, notes, and snippets.

require 'benchmark'
module Kernel
alias old_require require
def require(path)
#unless caller.find { |caller_line| caller_line.match /dependencies\.rb/ }
# return old_require(path)
#end
@indirect
indirect / rc.sh
Created August 19, 2010 22:52
rails console alias for both 2 and 3
# Rails 2 and Rails 3 console
function rc {
if [ -e "./script/console" ]; then
./script/console $@
else
rails console $@
fi
}
@j-manu
j-manu / Tips
Created November 21, 2010 10:36
tips & tricks
Delete large number of files:
ls|xargs -L 1000 rm
--
Maintenace page for Rails
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/../tmp/stop.txt -f
@vijaydev
vijaydev / gist:713678
Created November 24, 2010 13:53
Unix/Linux
Use ssh-copy-id to install your public key in a remote machine's authorized_keys. Also takes care of the permissions of the remote user's .ssh and .ssh/authorized_keys.
ssh -t reachable_host ssh unreachable_host. Enables to connect to a host unreachable from current network but reachable from reachable_host's network.
To navigate to a directory, run a command and get back: (cd /to/dir && cmd_to_run)
To rip audio out of a video file: mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <out_file> <in_file>
Rsync: rsync --recursive -avz -e "ssh -p 2020" user@machine:/path dest
yours: current_user.projects.inject(0){|sum,p| sum+= (p.users.count-1); sum}
mine: current_user.projects.to_a.sum { |p| p.users.count -1 }
your_rails_app/script/runner
======
#!/usr/bin/env ruby
path_to_rails = File.dirname(File.expand_path(__FILE__))
exec("#{path_to_rails}/rails runner #{ARGV[0]}")
======
rvm use ree-1.8.7-2010.02@global
rvm gemset create rails2310
gem install rails -v=2.3.10
require 'net/http'
require 'json'
###
# Stupid simple class for uploading to imgur.
#
# client = Imgur2.new 'my imgur key'
# p File.open(ARGV[0], 'rb') { |f|
# client.upload f
# }
@vijaydev
vijaydev / Vim Tricks
Created April 27, 2011 12:51
Vim Tricks
.s@\(\d\+\)@\=(submatch(1) + 17)@
Search for numbers and replace them with results of expressions involving them. submatch(1) is \1 (groups in regexes)
@sanand0
sanand0 / viz.py
Created May 3, 2011 17:10
Utility functions for visualisations
'''
Usage: viz.py INPUT.csv [template.html] > OUTPUT.xhtml
'''
import re
import math
import logging
import datetime
import operator
from tornado import template