Update routes.
This commit is contained in:
parent
be8b53eada
commit
e70b296c78
|
@ -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
|
||||
|
||||
//
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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} #=> "/path/to/foo"
|
||||
echo ${STR%.c}.o #=> "/path/to/foo.o"
|
||||
echo ${STR##*.} #=> "c" (extension)
|
||||
|
||||
BASE=${SRC##*/} #=> "foo.c" (basepath)
|
||||
DIR=${SRC%$BASE} #=> "/path/to"
|
||||
</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 "${STR:0:3}" # .substr(0, 3) -- position, length
|
||||
echo "${STR:-3:3}" # Negative position = from the right
|
||||
|
||||
echo ${#line} # Length of $line
|
||||
|
||||
[ -z "$CC" ] && CC=gcc # CC ||= "gcc" assignment
|
||||
${CC:=gcc} # $CC || "gcc"
|
||||
</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 > 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 [[ "A" =~ "." ]]
|
||||
</code></pre>
|
||||
|
||||
<h3>Numeric comparisons</h3>
|
||||
|
||||
<pre><code>if $(( $a < $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]="Apple"
|
||||
Fruits[1]="Banana"
|
||||
Fruits[2]="Orange"
|
||||
|
||||
# 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=("${Fruits[@]}" "Watermelon") # Push
|
||||
Fruits=( ${Fruits[@]/Ap*/} ) # Remove by regex match
|
||||
unset Fruits[2] # Remove one item
|
||||
Fruits=("${Fruits[@]}") # Duplicate
|
||||
Fruits=("${Fruits[@]}" "${Veggies[@]}") # Concatenate
|
||||
lines=(`cat "logfile"`) # Read from file
|
||||
</code></pre>
|
||||
|
||||
<h2>Misc crap</h2>
|
||||
|
||||
<pre><code>command -V cd #=> "cd is a function/alias/whatever"
|
||||
</code></pre>
|
||||
|
||||
<h3>Options</h3>
|
||||
|
||||
<pre><code>set -o noclobber # Avoid overlay files (echo "hi" > 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' => '')
|
||||
set -o failglob # Non-matching globs throw errors
|
||||
set -o nocaseglob # Case insensitive globs
|
||||
set -o dotglob # Wildcards match dotfiles ("*.sh" => ".foo.sh")
|
||||
set -o globstar # Allow ** for recursive matches ('lib/**/*.rb' => '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 "ERROR: ${BASH_SOURCE[1]} at about ${BASH_LINENO[0]}"
|
||||
}
|
||||
|
||||
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>
|
|
@ -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 "GUI" 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="reattach-to-user-namespace /Application/MacVim/Contents/MacOS/Vim"
|
||||
</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>
|
|
@ -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 => '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("Save")
|
||||
</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?("Update")
|
||||
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>
|
|
@ -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>
|
|
@ -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 "devise"
|
||||
gem "hpricot"
|
||||
gem "ruby_parser"
|
||||
</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 < 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 => 'home#index'
|
||||
end
|
||||
|
||||
authenticated do
|
||||
root :to => 'dashboard#index'
|
||||
end
|
||||
</code></pre>
|
||||
|
||||
<h3>As</h3>
|
||||
|
||||
<pre><code>as :user do
|
||||
get 'sign_in', :to => '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=>"devise/sessions", :action=>"new"}
|
||||
user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
|
||||
destroy_user_session GET /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
|
||||
|
||||
# Password routes for Recoverable, if User model has :recoverable configured
|
||||
new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
|
||||
edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
|
||||
user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
|
||||
POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
|
||||
|
||||
# Confirmation routes for Confirmable, if User model has :confirmable configured
|
||||
new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
|
||||
user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
|
||||
POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
|
||||
</code></pre>
|
||||
|
||||
<h3>Customizing devise_for</h3>
|
||||
|
||||
<pre><code>devise_for :users,
|
||||
:path => "usuarios",
|
||||
:path_names => {
|
||||
:sign_in => 'login',
|
||||
:sign_out => 'logout',
|
||||
:password => 'secret',
|
||||
:confirmation => 'verification',
|
||||
:unlock => 'unblock',
|
||||
:registration => 'register',
|
||||
:sign_up => '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>
|
File diff suppressed because it is too large
Load Diff
|
@ -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>"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."</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>
|
|
@ -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)
|
||||
=> 75.101.163.44
|
||||
=> 75.101.145.87
|
||||
=> 174.129.212.2
|
||||
|
||||
# Subdomains
|
||||
.mydomain.com. (CNAME)
|
||||
=> proxy.heroku.com
|
||||
</code></pre>
|
||||
|
||||
<h2>Wildcard domains</h2>
|
||||
|
||||
<pre><code>heroku addons:add wildcard_domains
|
||||
|
||||
*.yourdomain.com => 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>
|
|
@ -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>
|
|
@ -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><!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
|
||||
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
|
||||
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
|
||||
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
|
||||
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
|
||||
</code></pre>
|
||||
|
||||
<h3>iPhone viewport</h3>
|
||||
|
||||
<pre><code><meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
|
||||
</code></pre>
|
||||
|
||||
<h3>Google jQuery</h3>
|
||||
|
||||
<pre><code><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
|
||||
</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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>// $(":inline")
|
||||
$.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 "px"
|
||||
$.cssNumber["someCSSProp"] = 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: "orientation" in window && "onorientationchange" in window,
|
||||
touch: "ontouchend" in document,
|
||||
cssTransitions: "WebKitTransitionEvent" in window,
|
||||
pushState: "pushState" in history && "replaceState" in history,
|
||||
mediaquery: $.mobile.media( "only all" ),
|
||||
cssPseudoElement: !!propExists( "content" ),
|
||||
touchOverflow: !!propExists( "overflowScrolling" ),
|
||||
boxShadow: !!propExists( "boxShadow" ) && !bb,
|
||||
scrollTop: ( "pageXOffset" in window || "scrollTop" in document.documentElement || "scrollTop" in fakeBody[ 0 ] ) && !webos && !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>
|
|
@ -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>
|
|
@ -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 $< > $@ # Input and output
|
||||
foo $^
|
||||
</code></pre>
|
||||
|
||||
<h3>Default task</h3>
|
||||
|
||||
<pre><code> default:
|
||||
@echo "hello."
|
||||
@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>
|
|
@ -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
|
||||
|
||||

|
||||
</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>
|
|
@ -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>
|
|
@ -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; # <--- 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>
|
|
@ -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 => 'parent_id' class_name: 'Folder'
|
||||
has_many :folders, :foreign_key => 'parent_id', class_name: 'Folder'
|
||||
|
||||
has_many :comments, :order => "posted_on"
|
||||
has_many :comments, :include => :author
|
||||
has_many :people, :class_name => "Person"
|
||||
has_many :people, :conditions => "deleted = 0"
|
||||
has_many :tracks, :order => "position"
|
||||
has_many :comments, :dependent => :nullify
|
||||
has_many :comments, :dependent => :destroy
|
||||
has_many :tags, :as => :taggable
|
||||
has_many :reports, :readonly => true
|
||||
has_many :subscribers, :through => :subscriptions, class_name: "User", :source => :user
|
||||
has_many :subscribers, :finder_sql =>
|
||||
'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 < ActiveRecord::Base
|
||||
has_many :assignments
|
||||
has_many :projects, :through => :assignments
|
||||
end
|
||||
|
||||
class Project < ActiveRecord::Base
|
||||
has_many :assignments
|
||||
has_many :programmers, :through => :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 => [ :milestones, :manager ]
|
||||
has_and_belongs_to_many :nations, :class_name => "Country"
|
||||
has_and_belongs_to_many :categories, :join_table => "prods_cats"
|
||||
has_and_belongs_to_many :categories, :readonly => true
|
||||
has_and_belongs_to_many :active_projects, :join_table => 'developers_projects', :delete_sql =>
|
||||
"DELETE FROM developers_projects WHERE active=1 AND developer_id = #{id} AND project_id = #{record.id}"
|
||||
</code></pre>
|
||||
|
||||
<h3>Polymorphic associations</h3>
|
||||
|
||||
<pre><code>class Post
|
||||
has_many :attachments, :as => :parent
|
||||
end
|
||||
|
||||
class Image
|
||||
belongs_to :parent, :polymorphic => true
|
||||
end
|
||||
</code></pre>
|
||||
|
||||
<p>And in migrations:</p>
|
||||
|
||||
<pre><code>create_table :images do
|
||||
t.references :post, :polymorphic => 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 < 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 < ActiveRecord::Base
|
||||
|
||||
# Checkboxes
|
||||
validates :terms_of_service, :acceptance => true
|
||||
|
||||
# Validate associated records
|
||||
has_many :books
|
||||
validates_associated :books
|
||||
|
||||
# Confirmation (like passwords)
|
||||
validates :email, :confirmation => true
|
||||
|
||||
# Format
|
||||
validates :legacy_code, :format => {
|
||||
:with => /\A[a-zA-Z]+\z/,
|
||||
:message => "Only letters allowed"
|
||||
}
|
||||
|
||||
# Length
|
||||
validates :name, :length => { :minimum => 2 }
|
||||
validates :bio, :length => { :maximum => 500 }
|
||||
validates :password, :length => { :in => 6..20 }
|
||||
validates :number, :length => { :is => 6 }
|
||||
|
||||
# Length (full enchalada)
|
||||
validates :content, :length => {
|
||||
:minimum => 300,
|
||||
:maximum => 400,
|
||||
:tokenizer => lambda { |str| str.scan(/\w+/) },
|
||||
:too_short => "must have at least %{count} words",
|
||||
:too_long => "must have at most %{count} words"
|
||||
}
|
||||
end
|
||||
|
||||
# Numeric
|
||||
validates :points, :numericality => true
|
||||
validates :games_played, :numericality => { :only_integer => true }
|
||||
|
||||
# Non empty
|
||||
validates :name, :presence => true
|
||||
|
||||
# Multiple
|
||||
validate :login, :email, :presence => true
|
||||
end
|
||||
</code></pre>
|
||||
|
||||
<h3>Custom validations</h3>
|
||||
|
||||
<pre><code>class Person < 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: "Harvey")
|
||||
|
||||
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: "John", age: 24
|
||||
Person.update [1,2], [{name: "John"}, {name: "foo"}]
|
||||
</code></pre>
|
||||
|
||||
<h3>Joining</h3>
|
||||
|
||||
<pre><code>Student.joins(:schools).where(:schools => { :type => 'public' })
|
||||
Student.joins(:schools).where('schools.type' => 'public' )
|
||||
</code></pre>
|
||||
|
||||
<h3>Serialize</h3>
|
||||
|
||||
<pre><code>class User < ActiveRecord::Base
|
||||
serialize :preferences
|
||||
end
|
||||
|
||||
user = User.create(:preferences => { "background" => "black", "display" => large })
|
||||
</code></pre>
|
||||
|
||||
<p>You can also specify a class option as the second parameter that’ll raise an
|
||||
exception if a serialized object is retrieved as a descendant of a class not in
|
||||
the hierarchy.</p>
|
||||
|
||||
<pre><code>class User < ActiveRecord::Base
|
||||
serialize :preferences, Hash
|
||||
end
|
||||
|
||||
user = User.create(:preferences => %w( one two three ))
|
||||
User.find(user.id).preferences # raises SerializationTypeMismatch
|
||||
</code></pre>
|
||||
|
||||
<h2>Overriding accessors</h2>
|
||||
|
||||
<pre><code>class Song < 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>
|
|
@ -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 < Rails::Railtie
|
||||
initializer "newplugin.initialize" do |app|
|
||||
|
||||
# subscribe to all rails notifications: controllers, AR, etc.
|
||||
ActiveSupport::Notifications.subscribe do |*args|
|
||||
event = ActiveSupport::Notifications::Event.new(*args)
|
||||
puts "Got notification: #{event.inspect}"
|
||||
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 < Rails::Generators::Base
|
||||
def create_initializer_file
|
||||
create_file "config/initializers/initializer.rb", "# Add initialization content here"
|
||||
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 < Rails::Generators::Base
|
||||
def lol
|
||||
puts file_name
|
||||
end
|
||||
end
|
||||
</code></pre>
|
||||
|
||||
<h3>More</h3>
|
||||
|
||||
<pre><code>class InitializerGenerator < Rails::Generators::NamedBase
|
||||
#
|
||||
source_root File.expand_path("../templates", __FILE__)
|
||||
desc "Description goes here."
|
||||
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>
|
|
@ -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 => GET /photos
|
||||
# new => GET /photos/new
|
||||
# create => POST /photos/new
|
||||
# show => GET /photos/:id
|
||||
# edit => GET /photos/:id/edit
|
||||
# update => PUT /photos/:id
|
||||
# delete => 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 => GET /coder/new
|
||||
# create => POST /coder/new
|
||||
# show => GET /coder
|
||||
# edit => GET /coder/edit
|
||||
# update => PUT /coder
|
||||
# delete => DELETE /coder
|
||||
</code></pre>
|
||||
|
||||
<h3>Matching</h3>
|
||||
|
||||
<pre><code>match 'photo/:id' => 'photos#show' # /photo/what-is-it
|
||||
match 'photo/:id', id: /[0-9]+/ # /photo/0192
|
||||
match 'photo/:id' => 'photos#show', constraints: { id: /[0-9]+/ }
|
||||
match 'photo/:id', via: :get
|
||||
match 'photo/:id', via: [:get, :post]
|
||||
|
||||
match 'photo/*path' => 'photos#unknown' # /photo/what/ever
|
||||
|
||||
# params[:format] == 'jpg'
|
||||
match 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
|
||||
</code></pre>
|
||||
|
||||
<h3>Redirection</h3>
|
||||
|
||||
<pre><code>match '/stories' => redirect('/posts')
|
||||
match '/stories/:name' => redirect('/posts/%{name}')
|
||||
</code></pre>
|
||||
|
||||
<h3>Named</h3>
|
||||
|
||||
<pre><code># logout_path
|
||||
match 'exit' => '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 "*path" => "blacklist#index",
|
||||
:constraints => 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' => 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 -> highest priority.
|
||||
|
||||
# Sample of regular route:
|
||||
match 'products/:id' => 'catalog#view'
|
||||
|
||||
# Keep in mind you can assign values other than :controller and :action
|
||||
|
||||
# Sample of named route:
|
||||
match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
||||
|
||||
# This route can be invoked with purchase_url(:id => 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 => :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 "root"
|
||||
# just remember to delete public/index.html.
|
||||
root :to => 'welcome#index'
|
||||
|
||||
# See how all your routes lay out with "rake routes"
|
||||
|
||||
# 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>
|
|
@ -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?
|
||||
"Something"
|
||||
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, "First name"
|
||||
= f.text_field :first_name
|
||||
|
||||
= f.label :last_name>
|
||||
= f.text_field :last_name>
|
||||
|
||||
- fields_for @person.permission do |fields|
|
||||
= fields.checkbox :admin
|
||||
|
||||
-# name="person[admin]"
|
||||
- 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 < 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] = "You must be logged in to access this section"
|
||||
redirect_to new_login_url # halts request cycle
|
||||
end
|
||||
end
|
||||
end
|
||||
</code></pre>
|
||||
|
||||
<h3>Default URL optinos</h3>
|
||||
|
||||
<pre><code>class ApplicationController < ActionController::Base
|
||||
# The options parameter is the hash passed in to 'url_for'
|
||||
def default_url_options(options)
|
||||
{:locale => I18n.locale}
|
||||
end
|
||||
end
|
||||
</code></pre>
|
||||
|
||||
<h3>Hashes</h3>
|
||||
|
||||
<pre><code>session[:what]
|
||||
flash[:notice] = "Your session expired"
|
||||
params[:id]
|
||||
</code></pre>
|
||||
|
||||
<h3>XML and JSON</h3>
|
||||
|
||||
<pre><code>class UsersController < ApplicationController
|
||||
def index
|
||||
@users = User.all
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @users}
|
||||
format.json { render :json => @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
|
||||
<%= content_for?(:content) ? yield :content : yield %>
|
||||
|
||||
# app/views/layouts/news.html.erb
|
||||
<% content_for :content do %>
|
||||
...
|
||||
<% end %>
|
||||
<% render template: :'layouts/application' %>
|
||||
</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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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 => 'user', :password => 'password', :host => '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 => [Logger.new($stdout)]
|
||||
# or
|
||||
DB.loggers << Logger.new(...)
|
||||
</pre>
|
||||
<h2>Using raw SQL</h2>
|
||||
<pre>
|
||||
DB.run "CREATE TABLE users (name VARCHAR(255) NOT NULL, age INT(3) NOT NULL)"
|
||||
dataset = DB["SELECT age FROM users WHERE name = ?", name]
|
||||
dataset.map(:age)
|
||||
DB.fetch("SELECT name FROM users") 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 => 5000..10000).order(:name, :department)
|
||||
</pre>
|
||||
<h2>Insert rows</h2>
|
||||
<pre>
|
||||
dataset.insert(:name => 'Sharon', :grade => 50)
|
||||
</pre>
|
||||
<h2>Retrieve rows</h2>
|
||||
<pre>
|
||||
dataset.each{|r| p r}
|
||||
dataset.all # => [{...}, {...}, ...]
|
||||
dataset.first # => {...}
|
||||
</pre>
|
||||
<h2>Update/Delete rows</h2>
|
||||
<pre>
|
||||
dataset.filter(~:active).delete
|
||||
dataset.filter('price < ?', 100).update(:active => 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 => 'abc')
|
||||
dataset.filter('name = ?', 'abc')
|
||||
</pre>
|
||||
<h3>Inequality</h3>
|
||||
<pre>
|
||||
dataset.filter{value > 100}
|
||||
dataset.exclude{value <= 100}
|
||||
</pre>
|
||||
<h3>Inclusion</h3>
|
||||
<pre>
|
||||
dataset.filter(:value => 50..100)
|
||||
dataset.where{(value >= 50) & (value <= 100)}
|
||||
|
||||
dataset.where('value IN ?', [50,75,100])
|
||||
dataset.where(:value=>[50,75,100])
|
||||
|
||||
dataset.where(:id=>other_dataset.select(:other_id))
|
||||
</pre>
|
||||
<h3>Subselects as scalar values</h3>
|
||||
<pre>
|
||||
dataset.where('price > (SELECT avg(price) + 100 FROM table)')
|
||||
dataset.filter{price > dataset.select(avg(price) + 100)}
|
||||
</pre>
|
||||
<h3>LIKE/Regexp</h3>
|
||||
<pre>
|
||||
DB[:items].filter(:name.like('AL%'))
|
||||
DB[:items].filter(:name => /^AL/)
|
||||
</pre>
|
||||
<h3>AND/OR/NOT</h3>
|
||||
<pre>
|
||||
DB[:items].filter{(x > 5) & (y > 10)}.sql
|
||||
# SELECT * FROM items WHERE ((x > 5) AND (y > 10))
|
||||
|
||||
DB[:items].filter({:x => 1, :y => 2}.sql_or & ~{:z => 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) > :z).sql
|
||||
# SELECT * FROM items WHERE ((x + y) > z)
|
||||
|
||||
DB[:items].filter{price - 100 < avg(price)}.sql
|
||||
# SELECT * FROM items WHERE ((price - 100) < 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 => :category_id).sql
|
||||
# SELECT * FROM items LEFT OUTER JOIN categories ON categories.id = items.category_id
|
||||
|
||||
DB[:items].join(:categories, :id => :category_id).join(:groups, :id => :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 #=> 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 => :NOW.sql_function)
|
||||
dataset.update(:updated_at => 'NOW()'.lit)
|
||||
|
||||
dataset.update(:updated_at => "DateValue('1/1/2001')".lit)
|
||||
dataset.update(:updated_at => :DateValue.sql_function('1/1/2001'))
|
||||
</pre>
|
||||
<h2>Schema Manipulation</h2>
|
||||
<pre>
|
||||
DB.create_table :items do
|
||||
primary_key :id
|
||||
String :name, :unique => true, :null => false
|
||||
TrueClass :active, :default => 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 => ['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 => 'Inigo', :last_name => 'Montoya')
|
||||
dataset.insert(:first_name => 'Farm', :last_name => '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 << {:first_name => 'Inigo', :last_name => 'Montoya'}
|
||||
end
|
||||
end # COMMIT issued only here
|
||||
</pre>
|
||||
<p>
|
||||
Transactions are aborted if an error is raised:
|
||||
</p>
|
||||
<pre>
|
||||
DB.transaction do
|
||||
raise "some error occurred"
|
||||
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 << {:first_name => 'Farm', :last_name => 'Boy'} # Inserted
|
||||
DB.transaction(:savepoint=>true) # This savepoint is rolled back
|
||||
dataset << {:first_name => 'Inigo', :last_name => 'Montoya'} # Not inserted
|
||||
raise(Sequel::Rollback) if something_bad_happened
|
||||
end
|
||||
dataset << {:first_name => 'Prince', :last_name => 'Humperdink'} # Inserted
|
||||
end
|
||||
</pre>
|
||||
<h2>Miscellaneous:</h2>
|
||||
<pre>
|
||||
dataset.sql # "SELECT * FROM items"
|
||||
dataset.delete_sql # "DELETE FROM items"
|
||||
dataset.where(:name => 'sequel').exists # "EXISTS ( SELECT * FROM items WHERE name = 'sequel' )"
|
||||
dataset.columns #=> array of columns in the result set, does a SELECT
|
||||
DB.schema(:items) => [[:id, {:type=>:integer, ...}], [:name, {:type=>: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 < Sequel::Model
|
||||
|
||||
# Us (left) <=> 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 > 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=>'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 =>, :allow_nil =>, :allow_blank =>,
|
||||
# :allow_missing =>,
|
||||
|
||||
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 #=> [: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 < 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 > 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>
|
|
@ -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}}
|
|
@ -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><pre>
|
||||
I am <b>very serious.</b> -- this will get escaped.
|
||||
</pre>
|
||||
</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%.
|
||||
"Hypertext":index.html
|
||||
"Text link":link
|
||||
|
||||
[link]http://link.com
|
||||
|
||||
!image.jpg!
|
||||
!image.jpg(title text)!
|
||||
!image.jpg!:link.html
|
||||
|
||||
!>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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,19 @@
|
|||
▲▼▶
|
||||
|
||||
⬅⬆⬇
|
||||
|
||||
◢ ◣ ◤ ◥
|
||||
|
||||
: «» XOR ‹›, (), [], •, ⌘, ⌥, ▲▼, ▸▹, ◇ XOR ◆, ◐◑◒◓ ◢ ◣ ◤ ◥, ★ ☆ , ♠♥♣♦, ⚐⚑, ✂
|
||||
|
||||
|
||||
ࣾ home ࣾ
|
||||
ℹ information ℹ
|
||||
♡ heart ♡
|
||||
⚙ cog or gear ⚙
|
||||
⚿ key ⚿
|
||||
✉ envelope ✉
|
||||
✎ pencil ✎
|
||||
✓ check or tick mark ✓
|
||||
❌ cross mark ❌
|
||||
💬 speech balloon 💬
|
|
@ -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[ ( { < - A [], (), or {} block
|
||||
a' " ` - 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>
|
|
@ -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<tab> Command and params of last `ls` command (sudo !?mv<tab>)
|
||||
!?ls?:*<tab> Params of last `ls` command
|
||||
|
||||
*(m0) Last modified today
|
||||
*(m-4) Last modified <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>
|
|
@ -55,6 +55,16 @@ mapping
|
|||
# params[: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
|
||||
|
||||
match '/stories' => redirect('/posts')
|
||||
|
|
Loading…
Reference in New Issue