An incomplete cheatsheet for rails 3. Things are added as they are required.
# http://guides.rubyonrails.org/active_record_validations_callbacks.html
class SomeClass < ActiveRecord::Base
# length
# controller | |
def proc_csv | |
import = Import.find(params[:id]) | |
if import.load_csv | |
flash[:notice] = "woo" | |
redirect_to some_url | |
else | |
flash[:error] = "ohoh" | |
end | |
end |
#!/usr/bin/env ruby | |
require "nokogiri" | |
require "open-uri" | |
def download(url, output_file) | |
exit unless system("wget -c #{url} --load-cookies=cookies.txt -O #{output_file}") | |
end | |
def download_pages |
require 'rubygems' | |
require 'nokogiri' | |
require 'net/http' | |
require 'openssl' | |
require 'open-uri' | |
class Net::HTTP | |
alias_method :origConnect, :connect | |
def connect |
#!/usr/bin/ruby | |
require 'rss' | |
# Usage | |
# $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/ | |
# episodes.rss | |
# OR | |
# $ ./railscasts.rb | |
p 'Downloading rss index' |
Install Python
$ brew install readline sqlite gdbm
$ brew install python --universal --framework
$ python --version
Python 2.7
Symlinks...
# /etc/init.d/nginx | |
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 |
# PATH ------------------------------------------------------------ | |
export PATH="/usr/local/bin:/usr/local/Cellar/ruby/1.9.2-p180/bin/:/usr/local/sbin:~/bin/:$PATH" | |
# Add Bash Completion --------------------------------------------- | |
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
fi | |
# Add Bash Completion support for Brew ---------------------------- | |
source `brew --prefix`/Library/Contributions/brew_bash_completion.sh |
00:58 /p/tmp> jruby bm.rb | |
Rehearsal ------------------------------------------------ | |
inject(fold) 2.898000 0.000000 2.898000 ( 2.821000) | |
Hash+map 2.412000 0.000000 2.412000 ( 2.412000) | |
--------------------------------------- total: 5.310000sec | |
user system total real | |
inject(fold) 2.477000 0.000000 2.477000 ( 2.477000) | |
Hash+map 2.292000 0.000000 2.292000 ( 2.292000) |
<html> | |
<head> | |
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> | |
<script language="javascript" type="text/javascript" src="http://localhost/arbor/lib/arbor.js" ></script> | |
<script language="javascript" type="text/javascript" src="http://localhost/arbor/demos/_/graphics.js" ></script> | |
<script language="javascript" type="text/javascript" src="http://localhost/arbor/demos/halfviz/src/renderer.js" ></script> | |
</head> | |
<body> | |
<canvas id="viewport" width="800" height="600"></canvas> | |
<script language="javascript" type="text/javascript"> |