Update routes.

This commit is contained in:
Rico Sta. Cruz 2012-03-16 14:29:12 +08:00
parent be8b53eada
commit e70b296c78
37 changed files with 4283 additions and 0 deletions

View File

@ -0,0 +1,78 @@
# Installing
wget "http://kohanaphp.com/download?modules%5Bauth%5D=Auth&languages%5Ben_US%5D=en_US&format=zip" -O k.zip &&\
unzip -q k.zip && rm k.zip &&\
mv Kohana_*/* . && rm -rf Kohana_* &&\
rm -f "Kohana License.html" &&\
# htaccess
cat example.htaccess | sed 's/RewriteBase .*/RewriteBase \//g' > .htaccess && rm example.htaccess &&\
echo Done! Go and edit application/config/config.php and change the site stuff.
# Public HTML
mkdir -p public_html &&\
mv index.html public_html &&\
mv .htaccess public_html &&\
echo Done. Now edit index.html's paths
Git ignore
(echo \*.swo; echo \*.swp; echo .DS_Store; echo Thumbs.db; echo \*~; echo application/logs; echo application/cache ) > .gitignore &&\
# Database
$config['default'] = array
(
'benchmark' => TRUE,
'persistent' => FALSE,
'connection' => array
(
'type' => 'mysql',
'user' => 'leet', // set to db user name
'pass' => 'l33t', // set to db user password
'host' => 'localhost',
'port' => FALSE,
'socket' => FALSE,
'database' => 'leetdb' // set to db name
),
'character_set' => 'utf8',
'table_prefix' => '',
'object' => TRUE,
'cache' => FALSE,
'escape' => TRUE
);
// ORM model
class Post_Model extends ORM {
protected $has_one = array('user'); // has_many, belong_to, has_one, has_and_belongs_to_many
}
// ORM
$post = ORM::factory('post', 1);
$post->name = "Post name";
$post->save();
foreach ($post->categories as $category)
{
echo $category->name;
}
// Find (returns even if no row is found)
$o = ORM::factory('article')->find(1);
$o = ORM::factory('article')->where('title', $title)->find();
if (!$o->loaded) { die('Not found'); }
echo $o->title;
// Find_all
$o = ORM::factory('article')->find_all();
foreach ($o as $article) { echo $article->title; }
// ->$saved
// ->$changed[]
// ->$object_name (Blog_Post_Model => "blog_post")
// ->$primary_key ('id')
// ->$primary_val ('username') - more userfriendly identifier
// ->$table_name
// ->$ignored_columns = array('whatever')
// ->$table_columns = array('id', 'username')
// ->$sorting = array('last_login' => 'desc') -- default sorting
//

104
_output/Etc/Rails_2.ctxt Normal file
View File

@ -0,0 +1,104 @@
# Debug
logger.debug "xx"
# Controller stuff
class MyController < ApplicationController::Base
controller.response.body
# Filters
before_filter :require_login # Looks for require_login method
before_filter MyFilter # Looks for MyFilter class
before_filter { |ct| head(400) if ct.params["stop_action"] }
around_filter :catch_exceptions
after_filter :xx
layout "admin_area" # Looks for the view file
layout "admin_area", :except => [ :rss, :whatever ]
layout :foo # Looks for private function foo
private
def whatever ...
class MyFilter
def self.filter(controller, &block)
# Model
belongs_to :user
validates_presence_of :user
default_scope :order => 'id DESC'
named_scope :today, :conditions = "created_at x"
named_scope :today, lambda {{ :conditions = [ "created_at between ? and ?", 1.hour.ago.utc, 300.seconds.ago.utc ] }}
# Then you can call feed.today
# Controller methods
render :action => 'help', :layout => 'help'
render :text => 'so and so'
render :status => :created, :location => post_url(post) # With HTTP headers
redirect_to :action => 'index'
render :partial => 'product', :collection => @products, :as => :item, :spacer_template => "product_ruler"
return head(:method_not_allowed)
head :created, :location => '...'
url_for :controller => 'posts', :action => 'recent'
location = request.env["SERVER_ADDR"]
# For views
auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS Feed"})
javascript_include_tag "foo"
stylesheet_link_tag
image_tag
# Ruby stuff!
# Defining a class method (not a typo)
Fixnum.instance_eval { def ten; 10; end }
Fixnum.ten # => 10
# Defining an instance method
Fixnum.class_eval { def number; self; end }
7.number #=> 7
# Multiple arguments, send()
class Klass
def hello(*args); "Hello " + args.join(' '); end
end
Klass.new.send :hello, "gentle", "readers"
def can(*args)
yield if can?(*args)
end
# can(x) {...} => if can?(x) {...}
# Struct
class Foo < Struct.new(:name, :email)
end
j = Foo.new("Jason", "jason@bateman.com")
j.name = "Hi"
print j.name
# Struct
class Foo < Struct.new(:name, :email)
end
j = Foo.new("Jason", "jason@bateman.com")
j.name = "Hi"
print j.name
# Method missing
def method_missing(method_name, *arguments)
if method_name.to_s[-1,1] == "?"
self == method_name.to_s[0..-2]
# Rails logger
Rails.logger.info("...")
# To string
:hello_there.to_s

9
_output/Rakefile Normal file
View File

@ -0,0 +1,9 @@
desc "Build"
task :build do
system "proton build"
end
desc "Deploy"
task :deploy => :build do
system "git update-ghpages rstacruz/cheatsheets -i _output"
end

208
_output/bash.html Normal file
View File

@ -0,0 +1,208 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Bash</h1>
<h3>String substitutions by patterns</h3>
<pre><code>STR=/path/to/foo.c
echo ${STR%.c} #=&gt; &quot;/path/to/foo&quot;
echo ${STR%.c}.o #=&gt; &quot;/path/to/foo.o&quot;
echo ${STR##*.} #=&gt; &quot;c&quot; (extension)
BASE=${SRC##*/} #=&gt; &quot;foo.c&quot; (basepath)
DIR=${SRC%$BASE} #=&gt; &quot;/path/to&quot;
</code></pre>
<h3>Substitutions by regex</h3>
<pre><code>echo ${STR/hi/hello} # Replace first match
echo ${STR//hi/hello} # Replace all matches
echo ${STR/#hi/hello} # ^hi
echo ${STR/%hi/hello} # hi$
echo &quot;${STR:0:3}&quot; # .substr(0, 3) -- position, length
echo &quot;${STR:-3:3}&quot; # Negative position = from the right
echo ${#line} # Length of $line
[ -z &quot;$CC&quot; ] &amp;&amp; CC=gcc # CC ||= &quot;gcc&quot; assignment
${CC:=gcc} # $CC || &quot;gcc&quot;
</code></pre>
<h3>Loops</h3>
<pre><code>for i in /etc/rc.*; do
echo $i
end
</code></pre>
<h2>Functions</h2>
<h3>Defining functions</h3>
<pre><code>myfunc() { ... }
fuction myfunc { ... }
fuction myfunc() { ... }
</code></pre>
<h3>Returning strings</h3>
<pre><code>myfunc() {
local myresult='some value'
echo $myresult
}
result=$(myfunc)
</code></pre>
<h3>Errors</h3>
<pre><code>myfunc() { return 1; }
</code></pre>
<h3>Arguments</h3>
<pre><code>$# # Number of arguments
$* # All args
$1 # First argument
</code></pre>
<h2>Ifs - files</h2>
<pre><code># File conditions
if [ -a FILE ]; then # -e exists -d directory -f file
fi # -r readable -w writeable -x executable
# -h symlink -s size &gt; 0
# File comparisons
if [ FILE1 -nt FILE2 ] # -nt 1 more recent than 2
# -ot 2 more recent than 1
# -ef same files
</code></pre>
<h2>Ifs</h2>
<pre><code># String
if [ -z STRING ] # empty?
if [ -n STRING ] # not empty?
# Numeric
if [ $? -eq 0 ] # -eq -ne -lt -le -gt -ge
# $? is exit status by the way
# Etc
if [ -o noclobber ] # if OPTIONNAME is enabled
if [ ! EXPR ] # not
if [ ONE -a TWO ] # and
if [ ONE -o TWO ] # or
# Regex
if [[ &quot;A&quot; =~ &quot;.&quot; ]]
</code></pre>
<h3>Numeric comparisons</h3>
<pre><code>if $(( $a &lt; $b ))
</code></pre>
<h3>Unset variables</h3>
<p>Assume <code>$FOO</code> is not set. Doing <em>this</em> will result in <em>that</em>:</p>
<pre><code>${FOO:-word} # Returns word
${FOO:+word} # Returns empty, or word if set
${FOO:=word} # Sets parameter to word, returns word
${FOO:?message} # Echoes message and exits
${FOO=word} # : is optional in all of the above
</code></pre>
<h2>Numeric calculations</h2>
<pre><code>$((RANDOM%=200)) # Random number 0..200
$((a + 200)) # $ is optional
</code></pre>
<h2>Arrays</h2>
<pre><code>Fruits[0]=&quot;Apple&quot;
Fruits[1]=&quot;Banana&quot;
Fruits[2]=&quot;Orange&quot;
# Declaring using declare -a
declare -a Fruits=('Apple' 'Banana' 'Orange')
echo ${Fruits[0]} # Element #0
echo ${Fruits[@]} # All elements, space-separated
echo ${#Fruits[@]} # Number of elements
echo ${#Fruits} # String length of the 1st element
echo ${#Fruits[3]} # String length of the Nth element
echo ${Fruits[@]:3:2} # Range (from position 3, length 2)
Fruits=(&quot;${Fruits[@]}&quot; &quot;Watermelon&quot;) # Push
Fruits=( ${Fruits[@]/Ap*/} ) # Remove by regex match
unset Fruits[2] # Remove one item
Fruits=(&quot;${Fruits[@]}&quot;) # Duplicate
Fruits=(&quot;${Fruits[@]}&quot; &quot;${Veggies[@]}&quot;) # Concatenate
lines=(`cat &quot;logfile&quot;`) # Read from file
</code></pre>
<h2>Misc crap</h2>
<pre><code>command -V cd #=&gt; &quot;cd is a function/alias/whatever&quot;
</code></pre>
<h3>Options</h3>
<pre><code>set -o noclobber # Avoid overlay files (echo &quot;hi&quot; &gt; foo)
set -o errexit # Used to exit upon error, avoiding cascading errors
set -o pipefail # Unveils hidden failures
set -o nounset # Exposes unset variables
</code></pre>
<h3>Glob options</h3>
<pre><code>set -o nullglob # Non-matching globs are removed ('*.foo' =&gt; '')
set -o failglob # Non-matching globs throw errors
set -o nocaseglob # Case insensitive globs
set -o dotglob # Wildcards match dotfiles (&quot;*.sh&quot; =&gt; &quot;.foo.sh&quot;)
set -o globstar # Allow ** for recursive matches ('lib/**/*.rb' =&gt; 'lib/a/b/c.rb')
</code></pre>
<p>set GLOBIGNORE as a colon-separated list of patterns to be removed from glob
matches.</p>
<h3>Trap errors</h3>
<pre><code>trap 'echo Error at about $LINENO' ERR
</code></pre>
<p>or</p>
<pre><code>traperr() {
echo &quot;ERROR: ${BASH_SOURCE[1]} at about ${BASH_LINENO[0]}&quot;
}
set -o errtrace
trap traperr ERR
</code></pre>
<h2>References</h2>
<ul>
<li> http://wiki.bash-hackers.org/</li>
</ul>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

50
_output/brew.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Brew</h1>
<p>Nice Homebrew packages:</p>
<ul>
<li><code>tig</code> - Git &quot;GUI&quot; for the console</li>
<li><code>mysql</code></li>
<li><code>postgresql</code></li>
<li><code>fmdiff</code> - Adaptor to use Apple's FileMerge as <code>diff</code> (<code>git config --global merge-tool fmdiff</code>)</li>
<li><code>cmus</code> - Curses-based music player</li>
<li><code>cclive</code> - Video downloader</li>
</ul>
<p>Not from brew:</p>
<ul>
<li><code>DiffMerge</code> - nice free merge tool for OSX</li>
</ul>
<h2>Tmux</h2>
<p>Install a more-recent version that supports tmux -C</p>
<pre><code>brew install https://github.com/adamv/homebrew-alt/raw/master/other/tmux-iterm2.rb
</code></pre>
<p>Install the wrapper for stuff to enable OSX clipboard to work</p>
<pre><code>brew install reattach-to-user-namespace --wrap-pbcopy-and-pbpaste
</code></pre>
<p>Make sure that your VIM alias uses it</p>
<pre><code>alias vim=&quot;reattach-to-user-namespace /Application/MacVim/Contents/MacOS/Vim&quot;
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

112
_output/capybara.html Normal file
View File

@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Capybara</h1>
<h2>Navigating</h2>
<pre><code>visit articles_path
</code></pre>
<h2>Clicking links and buttons</h2>
<pre><code>click 'Link Text'
click_button
click_link
</code></pre>
<h2>Interacting with forms</h2>
<pre><code>attach_file
fill_in 'First Name', :with =&gt; 'John'
check
uncheck
choose
select
unselect
</code></pre>
<h2>Querying</h2>
<p>Takes a CSS selector (or XPath if you're into that).
Translates nicely into RSpec matchers:</p>
<pre><code>page.should have_no_button(&quot;Save&quot;)
</code></pre>
<p>Use should have<em>no</em>* versions with RSpec matchers b/c
should_not doesn't wait for a timeout from the driver</p>
<pre><code>page.has_content?
page.has_css?
page.has_no_content?
page.has_no_css?
page.has_no_xpath?
page.has_xpath?
page.has_link?
page.has_no_link?
page.has_button?(&quot;Update&quot;)
page.has_no_button?
page.has_field?
page.has_no_field?
page.has_checked_field?
page.has_unchecked_field?
page.has_no_table?
page.has_table?
page.has_select?
page.has_no_select?
</code></pre>
<h2>Finding</h2>
<pre><code>find
find_button
find_by_id
find_field
find_link
locate
</code></pre>
<h2>Scoping</h2>
<pre><code>within
within_fieldset
within_table
within_frame
scope_to
</code></pre>
<h2>Scripting</h2>
<pre><code>execute_script
evaluate_script
</code></pre>
<h2>Debugging</h2>
<pre><code>save_and_open_page
</code></pre>
<h2>Miscellaneous</h2>
<pre><code>all
body
current_url
drag
field_labeled
source
wait_until
current_path
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

20
_output/cinema4d.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Cinema4d</h1>
<pre><code>E R T : Move/rotate/scale
P : snapping
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

148
_output/devise.html Normal file
View File

@ -0,0 +1,148 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Devise</h1>
<p><a href="https://github.com/plataformatec/devise">Devise</a> is a flexible authentication
gem.</p>
<h2>Installation</h2>
<p>Rails 3: Add the following to your Gemfile</p>
<pre><code>gem &quot;devise&quot;
gem &quot;hpricot&quot;
gem &quot;ruby_parser&quot;
</code></pre>
<p>Install devise in your project</p>
<pre><code>$ rails generate devise:install
</code></pre>
<p>Generate devise for your model</p>
<pre><code>$ rails generate devise MODEL
$ rake db:migrate
</code></pre>
<p>(Optional) Generate devise views</p>
<pre><code>$ rails generate devise:views
</code></pre>
<h2>Helpers</h2>
<pre><code>user_signed_in?
current_user
user_session
destroy_user_session_path (Logout)
new_user_session_path (Login)
edit_user_registration_path (Edit registration)
new_user_registration_path (Register new user)
</code></pre>
<h2>Controller stuff</h2>
<pre><code>before_filter :authenticate_user!
</code></pre>
<h2>Model</h2>
<h3>Model options</h3>
<pre><code>class User &lt; ActiveRecord::Base
devise :database_authenticatable,
:registerable,
:confirmable,
:recoverable,
:rememberable,
:trackable,
:validatable
end
</code></pre>
<h3>Migration helpers</h3>
<pre><code>create_table :users do |t|
t.database_authenticatable
t.confirmable
t.recoverable
t.rememberable
t.trackable
t.timestamps
end
</code></pre>
<h2>Routing</h2>
<h3>Authenticated and unauthenticated routes</h3>
<pre><code>unauthenticated do
root :to =&gt; 'home#index'
end
authenticated do
root :to =&gt; 'dashboard#index'
end
</code></pre>
<h3>As</h3>
<pre><code>as :user do
get 'sign_in', :to =&gt; 'devise/sessions#new'
end
</code></pre>
<h3>Devise_for magic</h3>
<pre><code>devise_for :users
# Session routes for Authenticatable (default)
new_user_session GET /users/sign_in {:controller=&gt;&quot;devise/sessions&quot;, :action=&gt;&quot;new&quot;}
user_session POST /users/sign_in {:controller=&gt;&quot;devise/sessions&quot;, :action=&gt;&quot;create&quot;}
destroy_user_session GET /users/sign_out {:controller=&gt;&quot;devise/sessions&quot;, :action=&gt;&quot;destroy&quot;}
# Password routes for Recoverable, if User model has :recoverable configured
new_user_password GET /users/password/new(.:format) {:controller=&gt;&quot;devise/passwords&quot;, :action=&gt;&quot;new&quot;}
edit_user_password GET /users/password/edit(.:format) {:controller=&gt;&quot;devise/passwords&quot;, :action=&gt;&quot;edit&quot;}
user_password PUT /users/password(.:format) {:controller=&gt;&quot;devise/passwords&quot;, :action=&gt;&quot;update&quot;}
POST /users/password(.:format) {:controller=&gt;&quot;devise/passwords&quot;, :action=&gt;&quot;create&quot;}
# Confirmation routes for Confirmable, if User model has :confirmable configured
new_user_confirmation GET /users/confirmation/new(.:format) {:controller=&gt;&quot;devise/confirmations&quot;, :action=&gt;&quot;new&quot;}
user_confirmation GET /users/confirmation(.:format) {:controller=&gt;&quot;devise/confirmations&quot;, :action=&gt;&quot;show&quot;}
POST /users/confirmation(.:format) {:controller=&gt;&quot;devise/confirmations&quot;, :action=&gt;&quot;create&quot;}
</code></pre>
<h3>Customizing devise_for</h3>
<pre><code>devise_for :users,
:path =&gt; &quot;usuarios&quot;,
:path_names =&gt; {
:sign_in =&gt; 'login',
:sign_out =&gt; 'logout',
:password =&gt; 'secret',
:confirmation =&gt; 'verification',
:unlock =&gt; 'unblock',
:registration =&gt; 'register',
:sign_up =&gt; 'cmon_let_me_in' }
</code></pre>
<h2>Test helpers</h2>
<pre><code>sign_in @user
sign_out @user
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

1293
_output/figlets.txt Normal file

File diff suppressed because it is too large Load Diff

39
_output/fitness.html Normal file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Fitness</h1>
<h3>Target heart rate</h3>
<pre><code>max heart rate = (220 - age)
</code></pre>
<p>&quot;The target heart rate method is a simple formula: take 220 and minus your age.
Then take that number and multiply it by .75 - .85, which will give you your
percentages of 75% -- 85% of your Max. HR.&quot;</p>
<p>http://www.bodybuilding.com/fun/mike1.htm</p>
<h3>Warmup sets</h3>
<ul>
<li>5 x Bar</li>
<li>5 x 60%</li>
<li>3 x 70%</li>
<li>2 x 80%</li>
<li>5 x 100% (work set)</li>
</ul>
<p>http://corw.in/warmup/</p>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

49
_output/heroku.html Normal file
View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Heroku</h1>
<h2>Create an app</h2>
<pre><code>heroku create sushi
</code></pre>
<h2>Custom domains</h2>
<pre><code>heroku addon:add custom_domains
heroku domains:add example.com
heroku domains:add www.example.com
</code></pre>
<h2>DNS records</h2>
<pre><code># Root domains
mydomain.com. (A)
=&gt; 75.101.163.44
=&gt; 75.101.145.87
=&gt; 174.129.212.2
# Subdomains
.mydomain.com. (CNAME)
=&gt; proxy.heroku.com
</code></pre>
<h2>Wildcard domains</h2>
<pre><code>heroku addons:add wildcard_domains
*.yourdomain.com =&gt; heroku.com
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

45
_output/html-css.html Normal file
View File

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Html-css</h1>
<h3>CSS - Selectors</h3>
<pre><code>.class {
}
</code></pre>
<h3>CSS - Font styling</h3>
<pre><code>font-family: Arial;
font-size: 12pt;
line-height: 150%;
color: #aa3322;
</code></pre>
<h3>CSS - Font styling</h3>
<pre><code>// Bold
font-weight: bold;
font-weight: normal;
// Italic
font-style: italic;
font-style: normal;
// Underline
text-decoration: underline;
text-decoration: none;
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

35
_output/html.html Normal file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>HTML</h1>
<h3>H5BP HTML tag</h3>
<pre><code>&lt;!--[if lt IE 7 ]&gt; &lt;html class=&quot;ie6&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 7 ]&gt; &lt;html class=&quot;ie7&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 8 ]&gt; &lt;html class=&quot;ie8&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if IE 9 ]&gt; &lt;html class=&quot;ie9&quot;&gt; &lt;![endif]--&gt;
&lt;!--[if (gt IE 9)|!(IE)]&gt;&lt;!--&gt; &lt;html class=&quot;&quot;&gt; &lt;!--&lt;![endif]--&gt;
</code></pre>
<h3>iPhone viewport</h3>
<pre><code>&lt;meta name=&quot;viewport&quot; content=&quot;width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;&quot;/&gt;
</code></pre>
<h3>Google jQuery</h3>
<pre><code>&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js&quot;&gt;&lt;/script&gt;
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

115
_output/index.html Normal file
View File

@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Cheat sheets</h1>
<ul class='pages'>
<li>
<a href='bash.html'>bash</a>
</li>
<li>
<a href='brew.html'>brew</a>
</li>
<li>
<a href='capybara.html'>capybara</a>
</li>
<li>
<a href='cinema4d.html'>cinema4d</a>
</li>
<li>
<a href='devise.html'>devise</a>
</li>
<li>
<a href='figlets.html'>figlets</a>
</li>
<li>
<a href='fitness.html'>fitness</a>
</li>
<li>
<a href='heroku.html'>heroku</a>
</li>
<li>
<a href='html-css.html'>html-css</a>
</li>
<li>
<a href='html.html'>html</a>
</li>
<li>
<a href='ios.html'>ios</a>
</li>
<li>
<a href='jquery.html'>jquery</a>
</li>
<li>
<a href='linux.html'>linux</a>
</li>
<li>
<a href='makefile.html'>makefile</a>
</li>
<li>
<a href='markdown.html'>markdown</a>
</li>
<li>
<a href='osx.html'>osx</a>
</li>
<li>
<a href='passenger.html'>passenger</a>
</li>
<li>
<a href='rails-models.html'>rails-models</a>
</li>
<li>
<a href='rails-plugins.html'>rails-plugins</a>
</li>
<li>
<a href='rails-routes.html'>rails-routes</a>
</li>
<li>
<a href='rails.html'>rails</a>
</li>
<li>
<a href='rdoc.html'>rdoc</a>
</li>
<li>
<a href='README.html'>README</a>
</li>
<li>
<a href='rst.html'>rst</a>
</li>
<li>
<a href='sequel.html'>sequel</a>
</li>
<li>
<a href='textile.html'>textile</a>
</li>
<li>
<a href='tig.html'>tig</a>
</li>
<li>
<a href='tmux.html'>tmux</a>
</li>
<li>
<a href='ubuntu.html'>ubuntu</a>
</li>
<li>
<a href='unicode.html'>unicode</a>
</li>
<li>
<a href='vim.html'>vim</a>
</li>
<li>
<a href='zsh.html'>zsh</a>
</li>
</ul>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

31
_output/ios.html Normal file
View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Ios</h1>
<p>Path to Installous downloads:</p>
<pre><code>/private/var/mobile/Documents/Installous/Downloads
</code></pre>
<p>Multiple Exchange accounts:</p>
<pre><code>scp root@iphone.local:/private/var/mobile/Library/Preferences/com.apple.accountsettings.plist .
</code></pre>
<p>Ringtone conversion using ffmpeg:</p>
<pre><code>ffmpeg -i foo.mp3 -ac 1 -ab 128000 -f mp4 -acodec libfaac -y target.m4r
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

66
_output/jquery.html Normal file
View File

@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>jQuery</h1>
<h3>Extending selectors</h3>
<pre><code>// $(&quot;:inline&quot;)
$.expr[':'].inline = function(a) {
return $(a).css('display') === 'inline';
};
</code></pre>
<h3>Extend CSS properties</h3>
<pre><code>$.cssHooks.someCSSProp = {
get: function(elem, computed, extra) {
},
set: function(elem, value) {
}
};
// Disable &quot;px&quot;
$.cssNumber[&quot;someCSSProp&quot;] = true;
</code></pre>
<h3>fn.animate() hooks</h3>
<pre><code>$.fn.step.someWhatever = function(fx) {
// ...
}
</code></pre>
<h3>Mobile events</h3>
<p>For support for <code>tap</code>, <code>swipe</code>, <code>swipeLeft</code>, et al, use
<a href="https://github.com/jquery/jquery-mobile/blob/master/js/jquery.mobile.event.js">jquery.mobile.event.js</a>. Be sure to set <code>$.support.touch</code> first.</p>
<p>To get <code>$.support.touch</code> (and family), use this from
<a href="https://github.com/jquery/jquery-mobile/blob/master/js/jquery.mobile.support.js">jquery.mobile.support.js</a>:</p>
<pre><code>$.extend($.support, {
orientation: &quot;orientation&quot; in window &amp;&amp; &quot;onorientationchange&quot; in window,
touch: &quot;ontouchend&quot; in document,
cssTransitions: &quot;WebKitTransitionEvent&quot; in window,
pushState: &quot;pushState&quot; in history &amp;&amp; &quot;replaceState&quot; in history,
mediaquery: $.mobile.media( &quot;only all&quot; ),
cssPseudoElement: !!propExists( &quot;content&quot; ),
touchOverflow: !!propExists( &quot;overflowScrolling&quot; ),
boxShadow: !!propExists( &quot;boxShadow&quot; ) &amp;&amp; !bb,
scrollTop: ( &quot;pageXOffset&quot; in window || &quot;scrollTop&quot; in document.documentElement || &quot;scrollTop&quot; in fakeBody[ 0 ] ) &amp;&amp; !webos &amp;&amp; !operamini,
dynamicBaseTag: baseTagTest()
});
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

21
_output/linux.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Linux</h1>
<h3>Mounting a RAM drive</h3>
<pre><code>$ mount -t tmpfs -o size=5G,nr_inodes=5k,mode=700 tmpfs /tmp
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

47
_output/makefile.html Normal file
View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Makefile</h1>
<h3>Safe assignment</h3>
<pre><code>prefix ?= /usr/local
</code></pre>
<h3>Cool stuff</h3>
<pre><code> gitdir ?= $(shell git --exec-path)
gitver ?= $(word 3,$(shell git --version))
</code></pre>
<h3>Substitutions</h3>
<pre><code> $(SOURCE:.cpp=.o)
$(patsubst %.cpp, %.c, $(SOURCES))
</code></pre>
<h3>Building files</h3>
<pre><code> %.o: %.c
ffmpeg -i $&lt; &gt; $@ # Input and output
foo $^
</code></pre>
<h3>Default task</h3>
<pre><code> default:
@echo &quot;hello.&quot;
@false
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

29
_output/markdown.html Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Markdown</h1>
<h2>Markdown</h2>
<pre><code># h1
### h3
[link](http://google.com)
[link][google]
[google]: http://google.com
![Image alt text](/path/to/img.jpg)
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

39
_output/osx.html Normal file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Osx</h1>
<h2>Locations of startup items</h2>
<pre><code>/System/Library/LaunchAgents/
/System/Library/LaunchDaemons/
/Library/LaunchAgents/
/Library/LaunchDaemons/
</code></pre>
<h2>Hide desktop icons</h2>
<pre><code>defaults write com.apple.finder CreateDesktop -bool false
killall Finder
</code></pre>
<h2>Auto-hide other windows on dock switch</h2>
<pre><code>defaults write com.apple.dock single-app -bool TRUE
killall Dock
defaults delete com.apple.dock single-app
killall Dock
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

25
_output/passenger.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Phusion Passenger</h1>
<pre><code>server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public; # &lt;--- be sure to point to 'public'!
passenger_enabled on;
autoindex on; # Show directory listings
}
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

324
_output/rails-models.html Normal file
View File

@ -0,0 +1,324 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Rails Models</h1>
<h3>Generating models</h3>
<pre><code>$ rails g model User
</code></pre>
<h3>Associations</h3>
<pre><code>belongs_to
has_one
has_many
has_many :through
has_one :through
has_and_belongs_to_many
belongs_to :author,
class_name: 'User',
dependent: :destroy // delete this
</code></pre>
<h3>Has many</h3>
<pre><code>belongs_to :parent, :foreign_key =&gt; 'parent_id' class_name: 'Folder'
has_many :folders, :foreign_key =&gt; 'parent_id', class_name: 'Folder'
has_many :comments, :order =&gt; &quot;posted_on&quot;
has_many :comments, :include =&gt; :author
has_many :people, :class_name =&gt; &quot;Person&quot;
has_many :people, :conditions =&gt; &quot;deleted = 0&quot;
has_many :tracks, :order =&gt; &quot;position&quot;
has_many :comments, :dependent =&gt; :nullify
has_many :comments, :dependent =&gt; :destroy
has_many :tags, :as =&gt; :taggable
has_many :reports, :readonly =&gt; true
has_many :subscribers, :through =&gt; :subscriptions, class_name: &quot;User&quot;, :source =&gt; :user
has_many :subscribers, :finder_sql =&gt;
'SELECT DISTINCT people.* ' +
'FROM people p, post_subscriptions ps ' +
'WHERE ps.post_id = #{id} AND ps.person_id = p.id ' +
'ORDER BY p.first_name'
</code></pre>
<h3>Many-to-many</h3>
<p>If you have a join model:</p>
<pre><code>class Programmer &lt; ActiveRecord::Base
has_many :assignments
has_many :projects, :through =&gt; :assignments
end
class Project &lt; ActiveRecord::Base
has_many :assignments
has_many :programmers, :through =&gt; :assignments
end
class Assignment
belongs_to :project
belongs_to :programmer
end
</code></pre>
<p>Or HABTM:</p>
<pre><code>has_and_belongs_to_many :projects
has_and_belongs_to_many :projects, :include =&gt; [ :milestones, :manager ]
has_and_belongs_to_many :nations, :class_name =&gt; &quot;Country&quot;
has_and_belongs_to_many :categories, :join_table =&gt; &quot;prods_cats&quot;
has_and_belongs_to_many :categories, :readonly =&gt; true
has_and_belongs_to_many :active_projects, :join_table =&gt; 'developers_projects', :delete_sql =&gt;
&quot;DELETE FROM developers_projects WHERE active=1 AND developer_id = #{id} AND project_id = #{record.id}&quot;
</code></pre>
<h3>Polymorphic associations</h3>
<pre><code>class Post
has_many :attachments, :as =&gt; :parent
end
class Image
belongs_to :parent, :polymorphic =&gt; true
end
</code></pre>
<p>And in migrations:</p>
<pre><code>create_table :images do
t.references :post, :polymorphic =&gt; true
end
</code></pre>
<h2>Migrations</h2>
<h3>Run migrations</h3>
<pre><code>$ rake db:migrate
</code></pre>
<h3>Migrations</h3>
<pre><code>create_table :users do |t|
t.string :name
t.text :description
t.primary_key :id
t.string
t.text
t.integer
t.float
t.decimal
t.datetime
t.timestamp
t.time
t.date
t.binary
t.boolean
end
options:
:null (boolean)
:limit (integer)
:default
:precision (integer)
:scale (integer)
</code></pre>
<h3>Tasks</h3>
<pre><code>create_table
change_table
drop_table
add_column
change_column
rename_column
remove_column
add_index
remove_index
</code></pre>
<h3>Associations</h3>
<pre><code>t.references :category # kinda same as t.integer :category_id
# Can have different types
t.references :category, polymorphic: true
</code></pre>
<h3>Add/remove columns</h3>
<pre><code>$ rails generate migration RemovePartNumberFromProducts part_number:string
class RemovePartNumberFromProducts &lt; ActiveRecord::Migration
def up
remove_column :products, :part_number
end
def down
add_column :products, :part_number, :string
end
end
</code></pre>
<h2>Validation</h2>
<pre><code>class Person &lt; ActiveRecord::Base
# Checkboxes
  validates :terms_of_service, :acceptance =&gt; true
# Validate associated records
  has_many :books
  validates_associated :books
# Confirmation (like passwords)
validates :email, :confirmation =&gt; true
# Format
validates :legacy_code, :format =&gt; {
:with =&gt; /\A[a-zA-Z]+\z/,
:message =&gt; &quot;Only letters allowed&quot;
}
# Length
validates :name, :length =&gt; { :minimum =&gt; 2 }
validates :bio, :length =&gt; { :maximum =&gt; 500 }
validates :password, :length =&gt; { :in =&gt; 6..20 }
validates :number, :length =&gt; { :is =&gt; 6 }
# Length (full enchalada)
validates :content, :length =&gt; {
:minimum =&gt; 300,
:maximum =&gt; 400,
:tokenizer =&gt; lambda { |str| str.scan(/\w+/) },
:too_short =&gt; &quot;must have at least %{count} words&quot;,
:too_long =&gt; &quot;must have at most %{count} words&quot;
}
end
# Numeric
validates :points, :numericality =&gt; true
validates :games_played, :numericality =&gt; { :only_integer =&gt; true }
# Non empty
  validates :name, :presence =&gt; true
# Multiple
validate :login, :email, :presence =&gt; true
end
</code></pre>
<h3>Custom validations</h3>
<pre><code>class Person &lt; ActiveRecord::Base
validate :foo_cant_be_nil
def foo_cant_be_nil
errors.add(:foo, 'cant be nil') if foo.nil?
end
end
</code></pre>
<h2>API</h2>
<pre><code>items = Model.find_by_email(email)
items = Model.where(first_name: &quot;Harvey&quot;)
item = Model.find(id)
item.serialize_hash
item.new_record?
item.create # Same an #new then #save
item.create! # Same as above, but raises an Exception
item.save
item.save! # Same as above, but raises an Exception
item.update
item.update_attributes
item.update_attributes!
item.valid?
item.invalid?
</code></pre>
<p>http://guides.rubyonrails.org/active<em>record</em>validations_callbacks.html</p>
<h3>Mass updates</h3>
<pre><code># Updates person id 15
Person.update 15, name: &quot;John&quot;, age: 24
Person.update [1,2], [{name: &quot;John&quot;}, {name: &quot;foo&quot;}]
</code></pre>
<h3>Joining</h3>
<pre><code>Student.joins(:schools).where(:schools =&gt; { :type =&gt; 'public' })
Student.joins(:schools).where('schools.type' =&gt; 'public' )
</code></pre>
<h3>Serialize</h3>
<pre><code>class User &lt; ActiveRecord::Base
serialize :preferences
end
user = User.create(:preferences =&gt; { &quot;background&quot; =&gt; &quot;black&quot;, &quot;display&quot; =&gt; large })
</code></pre>
<p>You can also specify a class option as the second parameter thatll raise an
exception if a serialized object is retrieved as a descendant of a class not in
the hierarchy.</p>
<pre><code>class User &lt; ActiveRecord::Base
serialize :preferences, Hash
end
user = User.create(:preferences =&gt; %w( one two three ))
User.find(user.id).preferences # raises SerializationTypeMismatch
</code></pre>
<h2>Overriding accessors</h2>
<pre><code>class Song &lt; ActiveRecord::Base
# Uses an integer of seconds to hold the length of the song
def length=(minutes)
write_attribute(:length, minutes.to_i * 60)
end
def length
read_attribute(:length) / 60
end
end
</code></pre>
<ul>
<li>http://api.rubyonrails.org/classes/ActiveRecord/Base.html</li>
</ul>
<h2>Callbacks</h2>
<pre><code>after_create
after_initialize
after_validation
after_save
after_commit
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

165
_output/rails-plugins.html Normal file
View File

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Rails-plugins</h1>
<h2>Generate a plugin</h2>
<p>Generate a Rails Engine plugin:</p>
<pre><code>rails plugin new myplugin --skip-bundle --full
</code></pre>
<h2>Initializers</h2>
<ul>
<li><a href="http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html">Rails::Railtie</a></li>
<li><a href="http://www.engineyard.com/blog/2010/extending-rails-3-with-railties/">EngineYard blog
post</a></li>
</ul>
<p>Subclass Railtie and provide an <code>initializer</code> method.</p>
<pre><code>module NewPlugin
class Railtie &lt; Rails::Railtie
initializer &quot;newplugin.initialize&quot; do |app|
# subscribe to all rails notifications: controllers, AR, etc.
ActiveSupport::Notifications.subscribe do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
puts &quot;Got notification: #{event.inspect}&quot;
end
end
end
end
</code></pre>
<h2>Custom routes</h2>
<ul>
<li><a href="http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper.html">ActionDispatch::Routing::Mapper</a></li>
</ul>
<p>To create custom <code>routes.rb</code> keywords:</p>
<pre><code># # routes.rb:
# myplugin_for x
#
class ActionDispatch::Routing
class Mapper
def myplugin_for(*x)
end
end
end
</code></pre>
<p>Example with a block:</p>
<pre><code># authenticated do
# resources :users
# end
#
def authenticated
constraint = lambda { |request| request... }
constraints(constraint) { yield }
end
</code></pre>
<h2>Custom generators</h2>
<ul>
<li><a href="http://guides.rubyonrails.org/generators.html">Guide: generators</a></li>
<li><a href="http://api.rubyonrails.org/classes/ActiveRecord/Generators/Base.html">ActiveRecord::Generators::Base</a></li>
</ul>
<h3>Basic</h3>
<pre><code># rails g initializer
# lib/generators/initializer_generator.rb
class InitializerGenerator &lt; Rails::Generators::Base
def create_initializer_file
create_file &quot;config/initializers/initializer.rb&quot;, &quot;# Add initialization content here&quot;
end
end
</code></pre>
<ul>
<li>Extend <code>Rails::Generators::Base</code>.</li>
<li>Each public method in the generator is executed when a generator is invoked. </li>
</ul>
<h3>Generating a generator</h3>
<pre><code>$ rails generate generator initializer
</code></pre>
<h3>NamedBase</h3>
<p>Use <code>NamedBase</code> instead if you want to take an argument. It will be available as
<code>file_name</code>.</p>
<pre><code>class InitializerGenerator &lt; Rails::Generators::Base
def lol
puts file_name
end
end
</code></pre>
<h3>More</h3>
<pre><code>class InitializerGenerator &lt; Rails::Generators::NamedBase
#
  source_root File.expand_path(&quot;../templates&quot;, __FILE__)
desc &quot;Description goes here.&quot;
end
</code></pre>
<h3>Generators lookup</h3>
<p>When invoking <code>rails g XXX</code>:</p>
<ul>
<li>[rails/]generators/XXX/XXX_generator.rb</li>
<li>[rails/]generators/XXX_generator.rb</li>
</ul>
<p>When invoking <code>rails g XXX:YYY</code>:</p>
<ul>
<li>[rails/]generators/XXX/YYY_generator.rb</li>
</ul>
<h2>ActiveModel 'acts as'</h2>
<pre><code># yaffle/lib/yaffle/acts_as_yaffle.rb
module Yaffle
module ActsAsYaffle
extend ActiveSupport::Concern
included do
end
module ClassMethods
def acts_as_yaffle(options = {})
# your code will go here
end
end
end
end
ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

198
_output/rails-routes.html Normal file
View File

@ -0,0 +1,198 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Rails-routes</h1>
<h2>mapping</h2>
<p><a href="http://guides.rubyonrails.org/routing.html">Guides/Routing</a></p>
<p><a href="Rhttp://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper.html">ActionDispatch::Routing::Mapper</a>
(See included modules)</p>
<h3>Multiple resources</h3>
<pre><code>resources :books
# PhotosController:
# index =&gt; GET /photos
# new =&gt; GET /photos/new
# create =&gt; POST /photos/new
# show =&gt; GET /photos/:id
# edit =&gt; GET /photos/:id/edit
# update =&gt; PUT /photos/:id
# delete =&gt; DELETE /photos/:id
#
# Helpers:
# new_book_path
# book_path(id)
# edit_book_path(id)
#
resources :photos do
member { get 'preview' } # /photo/1/preview
get 'preview', on: :member # (..same as the first)
collection { get 'search' } # /photos/search
end
</code></pre>
<h3>Single resource</h3>
<pre><code>resource :coder
# CodersController:
# new =&gt; GET /coder/new
# create =&gt; POST /coder/new
# show =&gt; GET /coder
# edit =&gt; GET /coder/edit
# update =&gt; PUT /coder
# delete =&gt; DELETE /coder
</code></pre>
<h3>Matching</h3>
<pre><code>match 'photo/:id' =&gt; 'photos#show' # /photo/what-is-it
match 'photo/:id', id: /[0-9]+/ # /photo/0192
match 'photo/:id' =&gt; 'photos#show', constraints: { id: /[0-9]+/ }
match 'photo/:id', via: :get
match 'photo/:id', via: [:get, :post]
match 'photo/*path' =&gt; 'photos#unknown' # /photo/what/ever
# params[:format] == 'jpg'
match 'photos/:id' =&gt; 'photos#show', :defaults =&gt; { :format =&gt; 'jpg' }
</code></pre>
<h3>Redirection</h3>
<pre><code>match '/stories' =&gt; redirect('/posts')
match '/stories/:name' =&gt; redirect('/posts/%{name}')
</code></pre>
<h3>Named</h3>
<pre><code># logout_path
match 'exit' =&gt; 'sessions#destroy', as: :logout
</code></pre>
<h3>Constraints</h3>
<pre><code>match '/', constraints: { subdomain: 'admin' }
# admin.site.com/admin/photos
namespace 'admin' do
constraints subdomain: 'admin' do
resources :photos
end
end
</code></pre>
<h3>Custom constraints</h3>
<pre><code>class BlacklistConstraint
def initialize
@ips = Blacklist.retrieve_ips
end
def matches?(request)
@ips.include?(request.remote_ip)
end
end
TwitterClone::Application.routes.draw do
match &quot;*path&quot; =&gt; &quot;blacklist#index&quot;,
:constraints =&gt; BlacklistConstraint.new
end
</code></pre>
<h3>Scopes</h3>
<pre><code>scope 'admin', constraints: { subdomain: 'admin' } do
resources ...
end
</code></pre>
<h3>Rack middleware</h3>
<pre><code># Yes, Sprockets is middleware
match '/application.js' =&gt; Sprockets
</code></pre>
<h3>Route helpers</h3>
<pre><code>projects_path # /projects
projects_url # http://site.com/projects
</code></pre>
<h3>Default help text</h3>
<pre><code># The priority is based upon order of creation:
# first created -&gt; highest priority.
# Sample of regular route:
match 'products/:id' =&gt; 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
match 'products/:id/purchase' =&gt; 'catalog#purchase', :as =&gt; :purchase
# This route can be invoked with purchase_url(:id =&gt; product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
resources :products
# Sample resource route with options:
resources :products do
member do
get 'short'
post 'toggle'
end
collection do
get 'sold'
end
end
# Sample resource route with sub-resources:
resources :products do
resources :comments, :sales
resource :seller
end
# Sample resource route with more complex sub-resources
resources :products do
resources :comments
resources :sales do
get 'recent', :on =&gt; :collection
end
end
# Sample resource route within a namespace:
namespace :admin do
# Directs /admin/products/* to Admin::ProductsController
# (app/controllers/admin/products_controller.rb)
resources :products
end
# You can have the root of your site routed with &quot;root&quot;
# just remember to delete public/index.html.
root :to =&gt; 'welcome#index'
# See how all your routes lay out with &quot;rake routes&quot;
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
match ':controller(/:action(/:id(.:format)))'
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

153
_output/rails.html Normal file
View File

@ -0,0 +1,153 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Rails</h1>
<h2>Helpers</h2>
<pre><code>class ApplicationController
helper_method :logged_in?
def logged_in?
&quot;Something&quot;
end
end
</code></pre>
<h3>CSS/JS packages</h3>
<pre><code>stylesheet_link_tag :monkey
javascript_link_tag :monkey
</code></pre>
<h3>Forms</h3>
<pre><code># http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
- form_for @person do |f|
= f.label :first_name
= f.label :first_name, &quot;First name&quot;
= f.text_field :first_name
= f.label :last_name&gt;
= f.text_field :last_name&gt;
- fields_for @person.permission do |fields|
= fields.checkbox :admin
-# name=&quot;person[admin]&quot;
- fields_for :person, @client do |fields|
= fields.checkbox :admin
= f.submit
# Also: check_box, email_field, fields_for
# file_field, hidden_field, label, number_field, password_field
# radio_button, range_field, search_field, telephonen_field,
# text_area, text_field, url_field
</code></pre>
<h2>Controllers</h2>
<p>http://apidock.com/rails/ActionController/Base</p>
<pre><code>class ProjectsController
layout 'project' # Actually defaults to `projects` based
# on the controller name
def save
end
def edit
end
end
</code></pre>
<h3>Before filter</h3>
<pre><code>class ApplicationController &lt; ActionController::Base
before_filter :validate, only: [:save, :edit]
before_filter :ensure_auth, except: [:logout]
before_filter :require_login
private
def require_login
unless logged_in?
flash[:error] = &quot;You must be logged in to access this section&quot;
redirect_to new_login_url # halts request cycle
end
end
end
</code></pre>
<h3>Default URL optinos</h3>
<pre><code>class ApplicationController &lt; ActionController::Base
# The options parameter is the hash passed in to 'url_for'
def default_url_options(options)
{:locale =&gt; I18n.locale}
end
end
</code></pre>
<h3>Hashes</h3>
<pre><code>session[:what]
flash[:notice] = &quot;Your session expired&quot;
params[:id]
</code></pre>
<h3>XML and JSON</h3>
<pre><code>class UsersController &lt; ApplicationController
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml =&gt; @users}
format.json { render :json =&gt; @users}
end
end
end
</code></pre>
<h3>Redirection</h3>
<pre><code>redirect_to action: 'show', id: @entry.id
redirect_to root_url # a path
</code></pre>
<h3>Render</h3>
<pre><code>render nothing: true
render template: 'products/show'
render action: 'something' # same as `file: 'my/something'`
# Renders the template only, does not execute
# the action
</code></pre>
<h2>Layouts</h2>
<pre><code># app/views/layouts/application.html.erb
&lt;%= content_for?(:content) ? yield :content : yield %&gt;
# app/views/layouts/news.html.erb
&lt;% content_for :content do %&gt;
...
&lt;% end %&gt;
&lt;% render template: :'layouts/application' %&gt;
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

43
_output/rdoc.html Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Rdoc</h1>
<h3>Basic RDoc format</h3>
<pre><code># Foo.
#
# @example
#
# y
# g
#
# @param [String] param_name The xx and xx.
#
# @see http://url.com
#
# @return [true] if so
#
# == Definition lists
#
# list:: hi.
# +foo+:: parameterized
#
# == Definition lists
# [foo] also
# [bar] like this
</code></pre>
<p>http://rdoc.rubyforge.org/RDoc/Markup.html</p>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

70
_output/rst.html Normal file
View File

@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>ReStructuredText</h1>
<h3>Comments</h3>
<pre><code>.. @theme 2010
.. include:: ../themes/2010/common.rst
.. contents::
.. |substitute| replace:: replacement name
</code></pre>
<h3>Headings</h3>
<pre><code>Heading
=======
.. class:: brief
Hello there. |substitute| **This is bold**
- Bullet list with a link_ (or `link with words`_)
- Yes
.. _link: http://link.org
</code></pre>
<h3>PDF page break</h3>
<pre><code>.. raw:: pdf
PageBreak oneColumn
</code></pre>
<h3>Link targets</h3>
<pre><code>Internal link target_.
.. _target:
This is where _target will end up in.
</code></pre>
<h3>Tables (?)</h3>
<pre><code>.. class:: hash-table
.. list-table::
* - :key:`Weekly work hours:`
- :val:`50 hours`
* - :key:`Cost per hour:`
- :val:`PhP 1,500/hour`
* - :key:`Weekly rate:`
- :val:`PhP 75,000/week`
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

412
_output/sequel.html Normal file
View File

@ -0,0 +1,412 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Sequel</h1>
<h1>Cheat Sheet </h1>
<h2>Open a database</h2>
<pre>
require 'rubygems'
require 'sequel'
DB = Sequel.sqlite('my_blog.db')
DB = Sequel.connect('postgres://user:password@localhost/my_db')
DB = Sequel.postgres('my_db', :user =&gt; 'user', :password =&gt; 'password', :host =&gt; 'localhost')
DB = Sequel.ado('mydb')
</pre>
<h2>Open an SQLite memory database</h2>
<p>
Without a filename argument, the sqlite adapter will setup a new sqlite
database in memory.
</p>
<pre>
DB = Sequel.sqlite
</pre>
<h2>Logging SQL statements</h2>
<pre>
require 'logger'
DB = Sequel.sqlite '', :loggers =&gt; [Logger.new($stdout)]
# or
DB.loggers &lt;&lt; Logger.new(...)
</pre>
<h2>Using raw SQL</h2>
<pre>
DB.run &quot;CREATE TABLE users (name VARCHAR(255) NOT NULL, age INT(3) NOT NULL)&quot;
dataset = DB[&quot;SELECT age FROM users WHERE name = ?&quot;, name]
dataset.map(:age)
DB.fetch(&quot;SELECT name FROM users&quot;) do |row|
p row[:name]
end
</pre>
<h2>Create a dataset</h2>
<pre>
dataset = DB[:items]
dataset = DB.from(:items)
</pre>
<h2>Most dataset methods are chainable</h2>
<pre>
dataset = DB[:managers].where(:salary =&gt; 5000..10000).order(:name, :department)
</pre>
<h2>Insert rows</h2>
<pre>
dataset.insert(:name =&gt; 'Sharon', :grade =&gt; 50)
</pre>
<h2>Retrieve rows</h2>
<pre>
dataset.each{|r| p r}
dataset.all # =&gt; [{...}, {...}, ...]
dataset.first # =&gt; {...}
</pre>
<h2>Update/Delete rows</h2>
<pre>
dataset.filter(~:active).delete
dataset.filter('price &lt; ?', 100).update(:active =&gt; true)
</pre>
<h2>Datasets are Enumerable</h2>
<pre>
dataset.map{|r| r[:name]}
dataset.map(:name) # same as above
dataset.inject(0){|sum, r| sum + r[:value]}
dataset.sum(:value) # same as above
</pre>
<h2>Filtering (see also doc/dataset_filtering.rdoc)</h2>
<h3>Equality</h3>
<pre>
dataset.filter(:name =&gt; 'abc')
dataset.filter('name = ?', 'abc')
</pre>
<h3>Inequality</h3>
<pre>
dataset.filter{value &gt; 100}
dataset.exclude{value &lt;= 100}
</pre>
<h3>Inclusion</h3>
<pre>
dataset.filter(:value =&gt; 50..100)
dataset.where{(value &gt;= 50) &amp; (value &lt;= 100)}
dataset.where('value IN ?', [50,75,100])
dataset.where(:value=&gt;[50,75,100])
dataset.where(:id=&gt;other_dataset.select(:other_id))
</pre>
<h3>Subselects as scalar values</h3>
<pre>
dataset.where('price &gt; (SELECT avg(price) + 100 FROM table)')
dataset.filter{price &gt; dataset.select(avg(price) + 100)}
</pre>
<h3>LIKE/Regexp</h3>
<pre>
DB[:items].filter(:name.like('AL%'))
DB[:items].filter(:name =&gt; /^AL/)
</pre>
<h3>AND/OR/NOT</h3>
<pre>
DB[:items].filter{(x &gt; 5) &amp; (y &gt; 10)}.sql
# SELECT * FROM items WHERE ((x &gt; 5) AND (y &gt; 10))
DB[:items].filter({:x =&gt; 1, :y =&gt; 2}.sql_or &amp; ~{:z =&gt; 3}).sql
# SELECT * FROM items WHERE (((x = 1) OR (y = 2)) AND (z != 3))
</pre>
<h3>Mathematical operators</h3>
<pre>
DB[:items].filter((:x + :y) &gt; :z).sql
# SELECT * FROM items WHERE ((x + y) &gt; z)
DB[:items].filter{price - 100 &lt; avg(price)}.sql
# SELECT * FROM items WHERE ((price - 100) &lt; avg(price))
</pre>
<h2>Ordering</h2>
<pre>
dataset.order(:kind)
dataset.reverse_order(:kind)
dataset.order(:kind.desc, :name)
</pre>
<h2>Limit/Offset</h2>
<pre>
dataset.limit(30) # LIMIT 30
dataset.limit(30, 10) # LIMIT 30 OFFSET 10
</pre>
<h2>Joins</h2>
<pre>
DB[:items].left_outer_join(:categories, :id =&gt; :category_id).sql
# SELECT * FROM items LEFT OUTER JOIN categories ON categories.id = items.category_id
DB[:items].join(:categories, :id =&gt; :category_id).join(:groups, :id =&gt; :items__group_id)
# SELECT * FROM items INNER JOIN categories ON categories.id = items.category_id INNER JOIN groups ON groups.id = items.group_id
</pre>
<p>
</p>
<h2>Aggregate functions methods</h2>
<pre>
dataset.count #=&gt; record count
dataset.max(:price)
dataset.min(:price)
dataset.avg(:price)
dataset.sum(:stock)
dataset.group_and_count(:category)
dataset.group(:category).select(:category, :AVG.sql_function(:price))
</pre>
<h2>SQL Functions / Literals</h2>
<pre>
dataset.update(:updated_at =&gt; :NOW.sql_function)
dataset.update(:updated_at =&gt; 'NOW()'.lit)
dataset.update(:updated_at =&gt; &quot;DateValue('1/1/2001')&quot;.lit)
dataset.update(:updated_at =&gt; :DateValue.sql_function('1/1/2001'))
</pre>
<h2>Schema Manipulation</h2>
<pre>
DB.create_table :items do
primary_key :id
String :name, :unique =&gt; true, :null =&gt; false
TrueClass :active, :default =&gt; true
foreign_key :category_id, :categories
DateTime :created_at
index :created_at
end
DB.drop_table :items
DB.create_table :test do
String :zipcode
enum :system, :elements =&gt; ['mac', 'linux', 'windows']
end
</pre>
<h2>Aliasing</h2>
<pre>
DB[:items].select(:name.as(:item_name))
DB[:items].select(:name___item_name)
DB[:items___items_table].select(:items_table__name___item_name)
# SELECT items_table.name AS item_name FROM items AS items_table
</pre>
<h2>Transactions</h2>
<pre>
DB.transaction do
dataset.insert(:first_name =&gt; 'Inigo', :last_name =&gt; 'Montoya')
dataset.insert(:first_name =&gt; 'Farm', :last_name =&gt; 'Boy')
end # Either both are inserted or neither are inserted
</pre>
<p>
Database#transaction is re-entrant:
</p>
<pre>
DB.transaction do # BEGIN issued only here
DB.transaction
dataset &lt;&lt; {:first_name =&gt; 'Inigo', :last_name =&gt; 'Montoya'}
end
end # COMMIT issued only here
</pre>
<p>
Transactions are aborted if an error is raised:
</p>
<pre>
DB.transaction do
raise &quot;some error occurred&quot;
end # ROLLBACK issued and the error is re-raised
</pre>
<p>
Transactions can also be aborted by raising Sequel::Rollback:
</p>
<pre>
DB.transaction do
raise(Sequel::Rollback) if something_bad_happened
end # ROLLBACK issued and no error raised
</pre>
<p>
Savepoints can be used if the database supports it:
</p>
<pre>
DB.transaction do
dataset &lt;&lt; {:first_name =&gt; 'Farm', :last_name =&gt; 'Boy'} # Inserted
DB.transaction(:savepoint=&gt;true) # This savepoint is rolled back
dataset &lt;&lt; {:first_name =&gt; 'Inigo', :last_name =&gt; 'Montoya'} # Not inserted
raise(Sequel::Rollback) if something_bad_happened
end
dataset &lt;&lt; {:first_name =&gt; 'Prince', :last_name =&gt; 'Humperdink'} # Inserted
end
</pre>
<h2>Miscellaneous:</h2>
<pre>
dataset.sql # &quot;SELECT * FROM items&quot;
dataset.delete_sql # &quot;DELETE FROM items&quot;
dataset.where(:name =&gt; 'sequel').exists # &quot;EXISTS ( SELECT * FROM items WHERE name = 'sequel' )&quot;
dataset.columns #=&gt; array of columns in the result set, does a SELECT
DB.schema(:items) =&gt; [[:id, {:type=&gt;:integer, ...}], [:name, {:type=&gt;:string, ...}], ...]
</pre>
<hr style="height: 10px"></hr><h2>Documents</h2>
<pre>
http://sequel.rubyforge.org/rdoc/files/doc/association_basics_rdoc.html
http://sequel.rubyforge.org/rdoc/classes/Sequel/Schema/Generator.html
http://sequel.rubyforge.org/rdoc/files/doc/validations_rdoc.html
http://sequel.rubyforge.org/rdoc/classes/Sequel/Model.html
</pre>
<h2>Alter table</h2>
<pre>
database.alter_table :deals do
add_column :name, String
drop_column :column_name
rename_column :from, :to
add_constraint :valid_name, :name.like('A%')
drop_constraint :constraint
add_full_text_index :body
add_spacial_index [columns]
add_index :price
drop_index :index
add_foreign_key :artist_id, :table
add_primary_key :id
add_unique_constraint [columns]
set_column_allow_null :foo, false
set_column_default :title, ''
set_column_type :price, 'char(10)'
end
</pre>
<h2>Model associations</h2>
<pre>
class Deal &lt; Sequel::Model
# Us (left) &lt;=&gt; Them (right)
many_to_many :images,
left_id: :deal_id,
right_id: :image_id,
join_table: :image_links
one_to_many :files,
key: :deal_id,
class: :DataFile,
many_to_one :parent, class: self
one_to_many :children, key: :parent_id, class: self
one_to_many :gold_albums, class: :Album do |ds|
ds.filter { copies_sold &gt; 50000 }
end
</pre>
<p>
Provided by many_to_many
</p>
<pre>
Deal[1].images
Deal[1].add_image
Deal[1].remove_image
Deal[1].remove_all_images
</pre>
<h2>Validations</h2>
<pre>
def validate
super
errors.add(:name, 'cannot be empty') if !name || name.empty?
validates_presence [:title, :site]
validates_unique :name
validates_format /\Ahttps?:\/\//, :website, :message=&gt;'is not a valid URL'
validates_includes %w(a b c), :type
validates_integer :rating
validates_numeric :number
validates_type String, [:title, :description]
validates_integer :rating if new?
# options: :message =&gt;, :allow_nil =&gt;, :allow_blank =&gt;,
# :allow_missing =&gt;,
validates_exact_length 17, :isbn
validates_min_length 3, :name
validates_max_length 100, :name
validates_length_range 3..100, :name
# Setter override
def filename=(name)
@values[:filename] = name
end
end
end
deal.errors
</pre>
<h2>Model stuff</h2>
<pre>
deal = Deal[1]
deal.changed_columns
deal.destory # Calls hooks
deal.delete # No hooks
deal.exists?
deal.new?
deal.hash # Only uniques
deal.keys #=&gt; [:id, :name]
deal.modified!
deal.modified?
deal.lock!
</pre>
<h2>Callbacks</h2>
<pre>
before_create
after_create
before_validation
after_validation
before_save
before_update
UPDATE QUERY
after_update
after_save
before_destroy
DELETE QUERY
after_destroy
</pre>
<h2>Schema</h2>
<pre>
class Deal &lt; Sequel::Model
set_schema do
primary_key :id
primary_key [:id, :title]
String :name, primary_key: true
String :title
Numeric :price
DateTime :expires
unique :whatever
check(:price) { num &gt; 0 }
foreign_key :artist_id
String :artist_name, key: :id
index :title
index [:artist_id, :name]
full_text_index :title
# String, Integer, Fixnum, Bignum, Float, Numeric, BigDecimal,
# Date, DateTime, Time, File, TrueClass, FalseClass
end
end
</pre>
<h2>Unrestrict primary key</h2>
<pre>
Category.create id: 'travel' # error
Category.unrestrict_primary_key
Category.create id: 'travel' # ok
</pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

1
_output/style.css Normal file
View File

@ -0,0 +1 @@
body{font-family:"pt sans",sans-serif;font-size:14px;line-height:1.5}html{background:#505060}body{width:800px;margin:20px auto;padding:20px;-moz-border-radius:2px;-webkit-border-radius:2px;-o-border-radius:2px;-ms-border-radius:2px;-khtml-border-radius:2px;border-radius:2px;-moz-box-shadow:0 2px 3px rgba(0,0,0,0.2);-webkit-box-shadow:0 2px 3px rgba(0,0,0,0.2);-o-box-shadow:0 2px 3px rgba(0,0,0,0.2);box-shadow:0 2px 3px rgba(0,0,0,0.2);background:#fafafa;color:#333}p,ul,ol,pre{margin:15px 0}h1,h2,h3,h4,h5,h6{margin:40px 0 15px 0}h1{font-family:georgia,serif;text-align:center;font-size:24pt;color:#aaa;font-style:italic;font-weight:normal;margin:10px 0;padding:10px 0;border-bottom:dotted 1px #ddd;border-top:dotted 1px #ddd}h2,h3{color:#88a;font-size:1.5em;border-bottom:solid 1px #ddd;padding-bottom:3px}h3{font-size:1.3em}pre,code{font-family:monaco,monospace;font-size:12px;color:#444}pre{line-height:1.6;background:#f7f7f2;padding:10px 35px;-moz-box-shadow:inset 0 0 5px rgba(0,0,0,0.1);-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,0.1);-o-box-shadow:inset 0 0 5px rgba(0,0,0,0.1);box-shadow:inset 0 0 5px rgba(0,0,0,0.1);overflow-x:auto;margin-left:-20px;margin-right:-20px}h2 + pre,h3 + pre{border-top:solid 2px #c0c0dd;margin-top:-16px}ul.pages,ul.pages li{margin:0;padding:0;list-style-type:none}ul.pages{overflow:hidden;margin:40px 0}ul.pages li{width:20%;float:left}ul.pages a{display:block;text-decoration:none;padding:2px 5px;-moz-border-radius:3px;-webkit-border-radius:3px;-o-border-radius:3px;-ms-border-radius:3px;-khtml-border-radius:3px;border-radius:3px}ul.pages a:hover{background:#eee}ul.pages li:first-letter{text-transform:uppercase}.str{color:#080}.kwd{color:#008}.com{color:#7bd;text-shadow:1px 1px 0 rgba(255,255,255,0.3)}.typ{color:#606}.lit{color:#066}.pun{color:#660}.pln{color:#000}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec{color:#606}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}@media print{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun{color:#440}.pln{color:#000}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}

83
_output/textile.html Normal file
View File

@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Textile</h1>
<h3>Pre blocks</h3>
<pre><code>&lt;pre&gt;
I am &lt;b&gt;very serious.&lt;/b&gt; -- this will get escaped.
&lt;/pre&gt;
</code></pre>
<h3>Line breaks</h3>
<pre><code>Line breaks.
Just break the lines.
</code></pre>
<h3>Entities</h3>
<pre><code>one(TM), two(R), three(C).
</code></pre>
<h3>Inlines</h3>
<pre><code>_em_ *strong* __bold-italic__. ??citation??.
@code@. -strikehtrough-. +insertion+.
%span%. %{color:red}formatting%.
&quot;Hypertext&quot;:index.html
&quot;Text link&quot;:link
[link]http://link.com
!image.jpg!
!image.jpg(title text)!
!image.jpg!:link.html
!&gt;right.jpg!
</code></pre>
<h3>Horizontal line</h3>
<pre><code>--
</code></pre>
<h3>Blocks</h3>
<pre><code>h1. Header 1
h2. Header 2
bq. Blockquote
p(classname). Class.
p(#id). ID.
</code></pre>
<h3>Lists</h3>
<pre><code>## ordered list
* unordered list
</code></pre>
<h3>Footnotes</h3>
<pre><code>Footnotes[1].
fn1. Something.
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

54
_output/tig.html Normal file
View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Tig</h1>
<h2>Tig shortcuts</h2>
<p>Invocation</p>
<pre><code>tig blame FILE
tig master # Show a branch
tig test..master # Show difference between two bracnhes
tig FILE # Show history of file
tig v0.0.3:README # Show contents of file in a specific revision
</code></pre>
<h2>All views</h2>
<ul>
<li><code>^N</code> - Next on parent view</li>
<li><code>^P</code> - Previous on parent view</li>
</ul>
<p><code>m</code> - Main view
* <code>D</code> - Toggle between date display modes
* <code>A</code> - Toggle between author display modes
* <code>C</code> - Cherry pick a commit</p>
<p><code>S</code> - Stage view</p>
<ul>
<li><code>u</code> - Stage/unstage file or chunk</li>
<li><code>!</code> - Revert file or chunk</li>
<li><code>C</code> - Commit</li>
<li><code>M</code> - Merge</li>
</ul>
<p><code>H</code> - Branch view</p>
<ul>
<li><code>i</code> - Change sort header</li>
</ul>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

73
_output/tmux.html Normal file
View File

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>tmux Terminal Multiplexer</h1>
<h3>Commands</h3>
<pre><code>$ tmux
-u # UTF8 mode
-S ~/.tmux.socket
$ tmux attach
</code></pre>
<h3>Help</h3>
<pre><code>C-b ?
</code></pre>
<h3>Scrolling</h3>
<pre><code>C-b [ # Enter scroll mode then press up and down
</code></pre>
<h3>Copy/paste</h3>
<pre><code>C-b [ # 1. Enter scroll mode first.
Space # 2. Start selecting and move around.
Enter # 3. Press enter to copy.
C-b ] # Paste
</code></pre>
<h3>Panes</h3>
<pre><code>C-b v # vert
C-b n # horiz
C-b hkjl # navigation
C-b HJKL # resize
C-b o # next window
C-b x # close pane
C-b { or } # move windows around
</code></pre>
<h3>Windows</h3>
<pre><code>C-b c # New window
C-b 1 # Go to window 1
</code></pre>
<h3>Detach/attach</h3>
<pre><code>C-b d # detatch
C-b ( ) # Switch through sessions
$ tmux attach
</code></pre>
<h3>Niceties</h3>
<pre><code>C-b t # Time
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

29
_output/ubuntu.html Normal file
View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>Ubuntu/Debian</h1>
<h3>Aptitude stuff</h3>
<pre><code>aptitude search mysql # Look for something
dpkg -S `which tsclient` # What package does it belong to?
dpkg -L aria2c # What does this package provide?
dpkg -i *.deb # Install a deb file
</code></pre>
<h3>Apt archives path</h3>
<pre><code>/var/cache/apt/archives
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

19
_output/unicode.txt Normal file
View File

@ -0,0 +1,19 @@
▲▼▶
⬅⬆⬇
◢ ◣ ◤ ◥
: «» XOR , (), [], •, ⌘, ⌥, ▲▼, ▸▹, ◇ XOR ◆, ◐◑◒◓ ◢ ◣ ◤ ◥, ★ ☆ , ♠♥♣♦, ⚐⚑, ✂
ࣾ home &#002302;
information &#008505;
♡ heart &#009825;
⚙ cog or gear &#009881;
⚿ key &#009919;
✉ envelope &#009993;
✎ pencil &#009998;
✓ check or tick mark &#010003;
❌ cross mark &#010060;
💬 speech balloon &#128172;

50
_output/vim.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>vim</h1>
<pre><code>. - repeat last command
]p - paste under the current indentation level
</code></pre>
<h2>Motions</h2>
<pre><code>vip - Select paragraph
vipipipip - Select more
ap - a paragraph
ip - inner paragraph
{a,i}p - Paragraph
{a,i}w - Word
{a,i}s - Sentence
ab - A block [(
aB - A block in [{
at - A XML tag block
a[ ( { &lt; - A [], (), or {} block
a' &quot; ` - A quoted string
</code></pre>
<p>Example:</p>
<pre><code>yip - Yank inner paragraph
yap - Yank paragraph (including newline)
</code></pre>
<h2>SCSS!</h2>
<pre><code>va{= - reindent block
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

36
_output/zsh.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<h1>ZSH</h1>
<h3>Stuff</h3>
<pre><code>!! Last command (sudo !!)
!* Last command's parameters (vim !*)
!^ Last command's first parameter
!$ Last command's last parameter
!?ls&lt;tab&gt; Command and params of last `ls` command (sudo !?mv&lt;tab&gt;)
!?ls?:*&lt;tab&gt; Params of last `ls` command
*(m0) Last modified today
*(m-4) Last modified &lt;4 days ago
</code></pre>
<h3>Change default shell</h3>
<pre><code>chsh -s `which zsh`
</code></pre>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script src="http://cachedcommons.org/cache/prettify/1.0.0/javascripts/prettify-min.js"></script>
<script>$("pre").addClass("prettyprint");</script>
<script>prettyPrint();</script>
</body>
</html>

View File

@ -55,6 +55,16 @@ mapping
# params[:format] == 'jpg' # params[:format] == 'jpg'
match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' } match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
### Get/post
`get` is the same as `match via: :get`.
get 'photo/:id' => 'photos#show'
# same as match 'photo/:id' => 'photos#show', via: :get
post 'photo/:id' => 'photos#update'
# same as match 'photo/:id' => 'photos#show', via: :post
### Redirection ### Redirection
match '/stories' => redirect('/posts') match '/stories' => redirect('/posts')