parent
57561c5e08
commit
74c9c21796
|
@ -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
|
||||
|
|
23
capybara.md
23
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).
|
||||
|
|
|
@ -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
|
||||
|
||||
<video width="320" height="240" controls>
|
||||
<source src="movie.mp4"></source>
|
||||
<source src="movie.webm"></source>
|
||||
<source src="movie.mp4" type='video/mp4'></source>
|
||||
<source src="movie.webm" type='video/ogg'></source>
|
||||
</video>
|
||||
|
|
|
@ -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
|
||||
```
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
11
sed.md
11
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'
|
||||
|
|
|
@ -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 <nobody@nobody.org>"
|
||||
git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:gh-pages > /dev/null 2>&1
|
||||
)
|
||||
```
|
22
unite.md
22
unite.md
|
@ -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
|
|
@ -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
|
84
vim.md
84
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) <C-r>=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 "<br>" conceal cchar=}
|
||||
hi newLine guifg=green
|
||||
|
||||
### Region conceal
|
||||
|
||||
syn region inBold concealends matchgroup=bTag start="<b>" end="</b>"
|
||||
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:
|
||||
|
||||
- `<buffer>` - only in current buffer
|
||||
- `<silent>` - no echo
|
||||
- `<nowait>`
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
- `<buffer>` - only in current buffer
|
||||
- `<silent>` - no echo
|
||||
- `<nowait>`
|
||||
|
||||
Stuff
|
||||
-----
|
||||
|
||||
let var = "hello"
|
||||
echo "var = " . var
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
has("feature") " :h feature-list
|
||||
executable("python")
|
||||
globpath(&rtp, "syntax/c.vim")
|
||||
|
||||
if getchar() == "\<LeftMouse>"
|
||||
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 "<br>" conceal cchar=}
|
||||
hi newLine guifg=green
|
||||
|
||||
### Region conceal
|
||||
|
||||
syn region inBold concealends matchgroup=bTag start="<b>" end="</b>"
|
||||
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
|
Loading…
Reference in New Issue