From 74c9c2179605fa1aecafc1c16572464ab781dd2b Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Fri, 16 Jan 2015 12:02:16 +0800 Subject: [PATCH] gc Update --- bootstrap.md | 3 ++ capybara.md | 23 +++++++++--- ffmpeg.md | 8 ++-- js-date.md | 63 +++++++++++++++++++++++++++++++ rails-i18n.md | 13 +++++-- rails-migrations.md | 25 ++++++------ rails-models.md | 79 +++++++++++++++++++------------------- sed.md | 11 ++++++ travis-gh-pages.md | 56 +++++++++++++++++++++++++++ unite.md | 22 ----------- vim-unite.md | 36 ++++++++++++++++++ vim.md | 84 +++++++---------------------------------- vimscript.md | 92 +++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 356 insertions(+), 159 deletions(-) create mode 100644 js-date.md create mode 100644 travis-gh-pages.md delete mode 100644 unite.md create mode 100644 vim-unite.md create mode 100644 vimscript.md diff --git a/bootstrap.md b/bootstrap.md index 13838cff7..eaa139888 100644 --- a/bootstrap.md +++ b/bootstrap.md @@ -57,6 +57,9 @@ Max: .modal-content .modal-header %h4.modal-title hello + %button.close{type: 'button', data: { dismiss: 'modal' }} + %span{'aria-hidden' => true}!= "×" + %span.sr-only Close .modal-body ... .modal-footer diff --git a/capybara.md b/capybara.md index 80ebd1d13..a7e5d40f9 100644 --- a/capybara.md +++ b/capybara.md @@ -15,14 +15,25 @@ layout: default ## Interacting with forms - attach_file - fill_in 'First Name', :with => 'John' - check - uncheck - choose - select + attach_file 'Image', '/path/to/image.jpg' + fill_in 'First Name', with: 'John' + + check 'A checkbox' + uncheck 'A checkbox' + + choose 'A radio button' + + select 'Option', from: 'Select box' unselect +## Limiting + + within '.classname' do + click '...' + end + + within_fieldset :id do ... end + ## Querying Takes a CSS selector (or XPath if you're into that). diff --git a/ffmpeg.md b/ffmpeg.md index 9c3c9773a..ae44a3d05 100644 --- a/ffmpeg.md +++ b/ffmpeg.md @@ -35,13 +35,13 @@ layout: default ### To web # no audio - ffmpeg -i input.mov -vcodec h264 -acodec null -strict -2 output.mp4 - ffmpeg -i input.mov -vcodec libvpx -acodec null output.webm + ffmpeg -i input.mov -vcodec h264 -an -strict -2 output.mp4 + ffmpeg -i input.mov -vcodec libvpx -an output.webm ffmpeg -i input.mov -vcodec h264 -acodec aac -strict -2 output.mp4 ffmpeg -i input.mov -vcodec libvpx -acodec libvorbis output.webm diff --git a/js-date.md b/js-date.md new file mode 100644 index 000000000..c4e0bef11 --- /dev/null +++ b/js-date.md @@ -0,0 +1,63 @@ +--- +title: JavaScript Date +layout: default +--- + +### Constructor + +```js +new Date() +new Date(1419785527580) +new Date("December 17, 1995 03:24:00") +new Date("2013-03-01T01:10:00") +new Date(2014, 2, 1, 13, 0, 59, 0) + // year month* day hour minute sec milli + // * = zero-indexed +``` + +### Getters + +```js +.getDate() //=> 1..31 +.getDay() //=> 0..6 (sun..sat) +.getFullYear() //=> 2014 +.getMonth() //=> 0..11 + +.getHours() +.getMinutes() +.getSeconds() +.getMilliseconds() + +.getTime() //=> ms since epoch +.getTimezoneOffset() +``` + +### Conversion + +```js +.toString() //=> "Mon Dec 29 2014 00:58:28 GMT+0800 (PHT)" +.toTimeString() //=> "00:58:46 GMT+0800 (PHT)" +.toUTCString() //=> ""Sun, 28 Dec 2014 16:58:59 GMT" + +.toDateString() //=> "Thu Jan 10 2013" +.toISOString() //=> "2013-01-09T16:00:00.000Z" +.toLocaleString() //=> "12/29/2014, 12:57:31 AM" +.toLocaleTimeString() //=> "12:57:31 AM" +``` +### Setters + +```js +.setDate() +.setFullYear() +.setHours() +// ...etc; see getters +``` + +### UTC getters + +```js +.getUTCDate() +.getUTCDay() +.getUTCMonth() +// ...etc; see getters +``` diff --git a/rails-i18n.md b/rails-i18n.md index b08403fee..e9ed1215d 100644 --- a/rails-i18n.md +++ b/rails-i18n.md @@ -38,7 +38,16 @@ layout: default ### ActiveRecord - activerecord.attributes.user.name + activerecord: + attributes: + user: + name: "Name" + errors: + models: + venue: + attributes: + name: + blank: "Please enter a name." t 'blank', scope: activerecord.errors.models.[model_name].attributes.[attribute_name] @@ -51,8 +60,6 @@ layout: default create: "Create a %{model}" update: "Update %{model}" - activerecord.errors.models.venue.attributes.name.blank = "Please enter a name." - confirmation - :confirmation acceptance - :accepted presence - :blank diff --git a/rails-migrations.md b/rails-migrations.md index d152b672b..9d49f7f59 100644 --- a/rails-migrations.md +++ b/rails-migrations.md @@ -12,7 +12,7 @@ layout: default $ rake db:migrate -### Migrations +### Creating tables create_table :users do |t| t.string :name @@ -40,13 +40,24 @@ layout: default ### Operations + add_column :users, :first_name, :string + remove_column :users, :first_name, :string + + change_column :users, :first_name, :text + change_column :users, :first_name, :text + + change_column_default :users, :admin, nil + change_column_null :users, :email, true # adds NOT NULL constraint + create_table change_table drop_table + add_column change_column rename_column remove_column + add_index remove_index @@ -72,20 +83,10 @@ layout: default # Can have different types t.references :category, polymorphic: true -### Add/remove columns +### Auto-Add/remove columns $ 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 - ### Indices # Simple diff --git a/rails-models.md b/rails-models.md index f074eb38e..9f0773fb6 100644 --- a/rails-models.md +++ b/rails-models.md @@ -124,59 +124,51 @@ Validation class Person < ActiveRecord::Base - # Non empty -   validates :name, :presence => true +   validates :name, presence: true - # Checkboxes -   validates :terms_of_service, :acceptance => true +   validates :terms, acceptance: true + + validates :email, confirmation: true + + validates :slug, uniqueness: true + validates :slug, uniqueness: { case_sensitive: false } + validates :holiday, uniqueness: { scope: :year, :message => "only once a year" } + + validates :code, format: /regex/ + validates :code, format: { with: /regex/ } + + validates :name, length: { minimum: 2 } + validates :bio, length: { maximum: 500 } + validates :password, length: { in => 6..20 } + validates :number, length: { is => 6 } + + validates :gender, inclusion: %w(male female) + validates :gender, inclusion: { in: %w(male female) } + validates :lol, exclusion: %w(xyz) + + validates :points, numericality: true + validates :played, numericality: { only_integer: true } # Validate the associated records to ensure they're valid as well   has_many :books   validates_associated :books - # Confirmation (like passwords) - validates :email, :confirmation => true - - # Unique - validates :slug, :uniqueness => true - validates :slug, :uniqueness => { :case_sensitive => false } - validates :holiday, :uniqueness => { :scope => :year, :message => "only once a year" } - - # 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 } + 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" } # Multiple - validates :login, :email, :presence => true + validates :login, :email, presence: true # Conditional - validates :description, :presence => true, :if => :published? - validates :description, :presence => true, :if => lambda { |obj| .. } + validates :description, presence: true, if: :published? + validates :description, presence: true, if: lambda { |obj| .. } - # On - validates :title, :presence => true, :on => :save # :save | :create | :update + validates :title, presence: true, on: :save # :save | :create | :update end ### Custom validations @@ -239,6 +231,11 @@ API Student.joins(:schools).where(:schools => { :type => 'public' }) Student.joins(:schools).where('schools.type' => 'public' ) +### Where interpolation + + where("name = ?", "John") + where(["name = :name", { name: "John" }]) + ### Serialize class User < ActiveRecord::Base diff --git a/sed.md b/sed.md index 0e00b54bd..5bb9af437 100644 --- a/sed.md +++ b/sed.md @@ -15,3 +15,14 @@ To do in place replacements `-i ''` is required (GNU/sed is different) To do in place replacements use `-i` without arg sed -i -e 's/foo/bar/' example.md + +### Yes + + +Print until a certain line is met + + sed '/begin api/q' + +Print everything after a given line + + sed -n '/end api/,$p' diff --git a/travis-gh-pages.md b/travis-gh-pages.md new file mode 100644 index 000000000..eb1c1e5e1 --- /dev/null +++ b/travis-gh-pages.md @@ -0,0 +1,56 @@ +--- +title: Travis: deploy gh-pages +layout: default +--- + +Taken from https://medium.com/@nthgergo/publishing-gh-pages-with-travis-ci-53a8270e87db + +### Create an OAuth token and encrypt it + +Use https://github.com/settings/tokens/new + +```sh +# via node +npm install travis-encrypt -g +travis-encrypt -r user/repo GH_TOKEN=[the token here] + +# via ruby +gem install travis +travis encrypt -r user/repo GH_TOKEN=[the token here] +``` + +### Make it run the deploy script on deploy + +``` + # .travis.yml +script: + - bash ./scripts/deploy-to-gh-pages.sh +env: + global: + - GH_REF: "github.com/user/repo.git" + - secure: "nlnXJW/imf/w..." +``` + +### Write deployer + +Create the file `scripts/deploy-to-gh-pages.sh` + +``` +#!/bin/bash +# See https://medium.com/@nthgergo/publishing-gh-pages-with-travis-ci-53a8270e87db + +if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "master" ]; then exit 0; fi +rm -rf out || exit 0 +mkdir out + +# build +node build.js + +# deploy +( cd out + git init + git add . + git commit -m "Deploy to Github Pages" --author "Travis CI " + git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:gh-pages > /dev/null 2>&1 +) +``` diff --git a/unite.md b/unite.md deleted file mode 100644 index d9f18702d..000000000 --- a/unite.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Unite -layout: default ---- - -### Usage - - :Unite file - :Unite file_rec/async:! - :Unite tag - :Unite buffer - -### Options - -- `-start-insert` -- `-no-quit` -- `-winheight=10` -- `-quick-match` - select by pressing asdf keys -- `-winwidth=40` - use with vertical -- `-no-split` - open in current buffer -- `-auto-preview` - great for outline -- `-vertical` - open as sidebar diff --git a/vim-unite.md b/vim-unite.md new file mode 100644 index 000000000..b0e427bf0 --- /dev/null +++ b/vim-unite.md @@ -0,0 +1,36 @@ +--- +title: Vim-Unite +layout: default +--- + +### Usage + + :Unite file + :Unite file_rec/async:! + :Unite tag + :Unite buffer + +### Sources + +- `file/new` +- `file/async` +- `file_rec/async` +- `file_rec/git` +- `buffer` +- `buffer_tab` (current tab only) +- `tab` +- `register` +- `bookmark` +- `source` + +### Options + +- `-start-insert` +- `-no-quit` +- `-winheight=10` +- `-quick-match` - select by pressing asdf keys +- `-winwidth=40` - use with vertical +- `-no-split` - open in current buffer +- `-auto-preview` - great for outline +- `-vertical` - open as sidebar +- `-here` - in this buffer diff --git a/vim.md b/vim.md index 0e361a97f..7a5c9547f 100644 --- a/vim.md +++ b/vim.md @@ -59,18 +59,26 @@ Folds zx # Update +Jumping +------- + + ^O # Go back to previous location + ^I # Go forward + Misc ---- . # repeat last command ]p # paste under the current indentation level - C-o # Go back to previous location - C-i # Go forward - C-t # Go back to last tag - zz # Center this line +Counters +-------- + + ^A # increment number + ^X # decrement + Windows ------- @@ -81,6 +89,7 @@ Tags ^] # Jump to definition g] # See all definitions + C-t # Go back to last tag ^O ^I # Back/forward :tselect Classname # Find definitions of Classname @@ -97,70 +106,3 @@ Marks ### Calculator (Insert mode) =128/2 - -### Highlights - - hi Comment - term=bold,underline - gui=bold - ctermfg=4 - guifg=#80a0ff - -### Filetype detection - - augroup filetypedetect - au! BufNewFile,BufRead *.json setf javascript - augroup END - - au Filetype markdown setlocal spell - -### Conceal - - set conceallevel=2 - syn match newLine "
" conceal cchar=} - hi newLine guifg=green - -### Region conceal - - syn region inBold concealends matchgroup=bTag start="" end="" - hi inBold gui=bold - hi bTag guifg=blue - -### Syntax - - syn match :name ":regex" :flags - - syn region Comment start="/\*" end="\*/" - syn region String start=+"+ end=+"+ skip=+\\"+ - - syn cluster :name contains=:n1,:n2,:n3... - - flags: - keepend - oneline - nextgroup= - contains= - contained - - hi def link markdownH1 htmlH1 - -### Mapping - - nnoremap - vmap - ... - -Components: - - [nvixso](nore)map - ^ ^ - | don't recurse - | - normal, visual, insert, eX mode, select, operator-pending - -Arguments: - -- `` - only in current buffer -- `` - no echo -- `` - diff --git a/vimscript.md b/vimscript.md new file mode 100644 index 000000000..6a08e8727 --- /dev/null +++ b/vimscript.md @@ -0,0 +1,92 @@ +--- +title: vimscript +layout: default +--- + +Mapping +------- + + nnoremap + vmap + ... + +Components: + + [nvixso](nore)map + ^ ^ + | don't recurse + | + normal, visual, insert, eX mode, select, operator-pending + +Arguments: + +- `` - only in current buffer +- `` - no echo +- `` + +Stuff +----- + + let var = "hello" + echo "var = " . var + +Functions +--------- + + has("feature") " :h feature-list + executable("python") + globpath(&rtp, "syntax/c.vim") + + if getchar() == "\" + endif + + exe "vsplit" + +Syntax +------ + +### Highlights + + hi Comment + term=bold,underline + gui=bold + ctermfg=4 + guifg=#80a0ff + +### Filetype detection + + augroup filetypedetect + au! BufNewFile,BufRead *.json setf javascript + augroup END + + au Filetype markdown setlocal spell + +### Conceal + + set conceallevel=2 + syn match newLine "
" conceal cchar=} + hi newLine guifg=green + +### Region conceal + + syn region inBold concealends matchgroup=bTag start="" end="" + hi inBold gui=bold + hi bTag guifg=blue + +### Syntax + + syn match :name ":regex" :flags + + syn region Comment start="/\*" end="\*/" + syn region String start=+"+ end=+"+ skip=+\\"+ + + syn cluster :name contains=:n1,:n2,:n3... + + flags: + keepend + oneline + nextgroup= + contains= + contained + + hi def link markdownH1 htmlH1