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
''' | |
Usage: viz.py INPUT.csv [template.html] > OUTPUT.xhtml | |
''' | |
import re | |
import math | |
import logging | |
import datetime | |
import operator | |
from tornado import template |
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
.s@\(\d\+\)@\=(submatch(1) + 17)@ | |
Search for numbers and replace them with results of expressions involving them. submatch(1) is \1 (groups in regexes) |
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
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 | |
# } |
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
RED="\[\033[01;31m\]" | |
GREEN="\[\033[01;32m\]" | |
COLOR_NONE="\[\033[0m\]" | |
function ruby_version { | |
if [[ -f ~/.rvm/bin/rvm-prompt ]]; then | |
local system=$(~/.rvm/bin/rvm-prompt s) | |
local interp=$(~/.rvm/bin/rvm-prompt i) | |
if [[ ! -n $system ]]; then | |
# Don't show interpreter if it's just MRI |
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
rvm use ree-1.8.7-2010.02@global | |
rvm gemset create rails2310 | |
gem install rails -v=2.3.10 |
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
def tip(msg); puts; puts msg; puts "-"*100; end | |
# | |
# 30 Ruby 1.9 Tips, Tricks & Features: | |
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/ | |
# | |
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2" | |
tip "Ruby 1.9 supports named captures in regular expressions!" |
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
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 } |
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
git remote prune origin - to remove a deleted remote branch. | |
git rebase -i - interactive rebase with options to pick, squash, discard and reorder commits. | |
git update-index --assume-unchanged | |
Undoing a merge: | |
$ git pull $REMOTE $BRANCH | |
# uh oh, that wasn't right | |
$ git reset --hard ORIG_HEAD | |
# all is right with the world |
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
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 |
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 3 no longer auto loads the lib folder. We can make it auto load the lib folder by putting it in config/application.rb like thus: config.autoload_paths += %W(#{config.root}/lib) | |
All strings are HTML escaped by default in Rails 3. Need to call html_safe on strings which we know are sure to be safe to display the HTML properly. | |
Reserved words: "config", "process" | |
Specifying RailsEnv in Apache configuration (vhost/httpd.conf etc) for Passenger 3.0.0 does not work in Rails 3. Changing that to RakeEnv does the trick. This was fixed in Passenger 3.0.1. | |
To add the default integer primary key to a table which was created with :id => false setting, we can do add_column :table_name, :id, :primary_key |