Skip to content

Instantly share code, notes, and snippets.

cd ~/Code/repo/ && watch -c 'ls .git/index.lock 2>/dev/null || git status --short'
@vrinek
vrinek / gist:1382849
Created November 21, 2011 14:55
Convert Ruby Regexp to JavaScript RegExp
class Regexp
def to_javascript
Regexp.new(inspect.sub('\\A','^').sub('\\Z','$').sub('\\z','$').sub(/^\//,'').sub(/\/[a-z]*$/,'').gsub(/\(\?#.+\)/, '').gsub(/\(\?-\w+:/,'('), self.options).inspect
end
end
ruby ../cleanup_gist/merged_branches.rb > ../cleanup_gist/table.txt && cat ../cleanup_gist/table.txt
@vrinek
vrinek / gist:1219113
Created September 15, 2011 12:30
finds focused specs (good for a git hook)
git grep -n ':focus *=> *true' -- $(ruby -e 'puts `ls -d spec/*`.split("\n").reject{|f| f == "spec/spec_helper.rb"}')
@vrinek
vrinek / gist:1188161
Created September 2, 2011 08:15
wikileaks decryption key
Gw0whe$PfehwH{W%$%0sfwFGOENqi24yHSFP{NKFwekqzcxGPAEGMq32pfewkjnwrHN}#%Fwedqkdg?WM43\hgwr#$JhowdnwqQELFDWmenhwREWKwqeq$
@vrinek
vrinek / gist:1034044
Created June 19, 2011 10:27
New installation of RVM on a vanilla OSX Snow Leopard
#!/bin/bash
# checks for GCC (installed from Xcode)
if [ "$(which gcc)" = "" ]; then
echo "You don't have Xcode installed. Please install it from http://developer.apple.com/"
exit 0
fi
# checks for git
if [ "$(which git)" = "" ]; then
@vrinek
vrinek / gist:990771
Created May 25, 2011 10:46
find out how a file has changed when you get a conflict in "rebase master"
git log -p --color $(git merge-base master branch)...master path/to/file.rb
def all_controller_actions(controller)
(controller.ancestors[1, controller.ancestors.index(ApplicationController)] + [Object]).inject(controller.new.methods) do |methods, ancestor|
methods -= ancestor.new.methods unless ancestor.class == Module
methods
end.reject{|m| m =~ /^_/}.sort.map(&:to_sym)
end
$$('a[data-remote=true]').each(function(a){
a.onclick = function(){
href = a.getAttribute('href');
url = href.split('?')[0];
params = href.split('?')[1];
newParam = encodeURI(eval(a.getAttribute('data-with')));
if(params){
params = params.split('&');
# used for paginations (Model.paginate :page => page_from_params)
# it just makes the WillPaginate::InvalidPage errors go away
def page_from_params
(p = params[:page].to_i) > 0 ? p : 1
end