Content formatting update (part 5) (#1969)
This commit is contained in:
parent
05890aa33d
commit
39a6c1a6ab
|
@ -3,6 +3,7 @@ title: Angular.js
|
|||
category: JavaScript libraries
|
||||
tags: [Archived]
|
||||
archived: This describes an older version of Angular.
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
|
|
21
ansible.md
21
ansible.md
|
@ -1,12 +1,18 @@
|
|||
---
|
||||
title: Ansible
|
||||
category: Ansible
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
{% raw %}
|
||||
|
||||
## Getting started
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
- <https://www.ansible.com/>
|
||||
|
||||
### Hosts
|
||||
|
||||
$ sudo mkdir /etc/ansible
|
||||
|
@ -20,7 +26,9 @@ category: Ansible
|
|||
|
||||
$ ansible-playbook playbook.yml
|
||||
|
||||
## Tasks
|
||||
## Playbook files
|
||||
|
||||
### Tasks
|
||||
|
||||
- hosts: all
|
||||
user: root
|
||||
|
@ -39,7 +47,7 @@ category: Ansible
|
|||
handlers:
|
||||
- include: db.yml user=timmy
|
||||
|
||||
## Handlers
|
||||
### Handlers
|
||||
|
||||
handlers:
|
||||
- name: start apache2
|
||||
|
@ -51,7 +59,7 @@ category: Ansible
|
|||
notify:
|
||||
- start apache2
|
||||
|
||||
## Vars
|
||||
### Vars
|
||||
|
||||
- host: lol
|
||||
vars_files:
|
||||
|
@ -63,7 +71,7 @@ category: Ansible
|
|||
file: state=directory path=${project_root}/home/.ssh/
|
||||
only_if: "$vm == 0"
|
||||
|
||||
## Roles
|
||||
### Roles
|
||||
|
||||
- host: xxx
|
||||
roles:
|
||||
|
@ -91,9 +99,4 @@ category: Ansible
|
|||
vars:
|
||||
local_home: "{{ lookup('env','HOME') }}"
|
||||
|
||||
## References
|
||||
|
||||
* [Intro](http://www.ansibleworks.com/docs/intro_configuration.html)
|
||||
* [Modules](http://www.ansibleworks.com/docs/modules.html)
|
||||
|
||||
{% endraw %}
|
||||
|
|
12
arel.md
12
arel.md
|
@ -1,8 +1,16 @@
|
|||
---
|
||||
title: Arel
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
Arel is an SQL abstraction library built into Ruby on Rails.
|
||||
|
||||
* <https://github.com/rails/arel>
|
||||
|
||||
### Tables
|
||||
|
||||
```rb
|
||||
|
@ -123,7 +131,3 @@ all_time = photos_with_credits.count
|
|||
this_month = photos_with_credits.where(photos[:created_at].gteq(Date.today.beginning_of_month))
|
||||
recent_photos = photos_with_credits.where(photos[:created_at].gteq(Date.today.beginning_of_month)).limit(5)
|
||||
```
|
||||
|
||||
## Reference
|
||||
|
||||
* <http://github.com/rails/arel>
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
---
|
||||
title: Caskroom index
|
||||
layout: 2017/sheet
|
||||
tags: [Archived]
|
||||
archived: This sheet may have outdated information.
|
||||
---
|
||||
|
||||
|
||||
# Caskroom
|
||||
|
||||
|
||||
#### A
|
||||
|
||||
|
|
12
circle.md
12
circle.md
|
@ -1,9 +1,15 @@
|
|||
---
|
||||
title: CircleCI
|
||||
category: Devops
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## circle.yml
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
- <https://circleci.com/docs/config-sample>
|
||||
|
||||
### circle.yml
|
||||
|
||||
* __machine__: adjusting the VM to your preferences and requirements
|
||||
* __checkout__: checking out and cloning your git repo
|
||||
|
@ -14,7 +20,7 @@ category: Devops
|
|||
|
||||
See: <https://circleci.com/docs/configuration>
|
||||
|
||||
## Sample
|
||||
### Sample
|
||||
|
||||
```yml
|
||||
## Customize the test machine
|
||||
|
@ -91,5 +97,3 @@ notify:
|
|||
# A list of hashes representing hooks. Only the url field is supported.
|
||||
- url: https://someurl.com/hooks/circle
|
||||
```
|
||||
|
||||
See: <https://circleci.com/docs/config-sample>
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
---
|
||||
title: Command line stuff
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## List (ls)
|
||||
{: .-three-column}
|
||||
|
||||
### Usage
|
||||
|
||||
ls [options] [paths]
|
||||
|
||||
|
@ -18,14 +22,12 @@ title: Command line stuff
|
|||
|---
|
||||
| `-F` | Add / after directories |
|
||||
| `-G` | Color |
|
||||
{:.shortcuts}
|
||||
|
||||
### Options
|
||||
|
||||
| `-R` | Recurse |
|
||||
| `-a` | Include hidden (dotfiles) |
|
||||
| `-A` | Include hidden (but not . and ..) |
|
||||
{:.shortcuts}
|
||||
|
||||
### Sorting
|
||||
|
||||
|
@ -39,11 +41,11 @@ title: Command line stuff
|
|||
| `-c` | sort by time status was changed |
|
||||
|---
|
||||
| `-h` | Human-readable size (3k) |
|
||||
{:.shortcuts}
|
||||
|
||||
<br>
|
||||
|
||||
## Tail
|
||||
{: .-three-column}
|
||||
|
||||
### Usage
|
||||
|
||||
tail [-F | -f | -r] [-bN | -cN | -nN] [file ...]
|
||||
|
||||
|
@ -52,7 +54,6 @@ title: Command line stuff
|
|||
| `-f` | follow |
|
||||
| `-F` | follow by filename (accounts for log rotation) |
|
||||
| `-r` | Reverse order |
|
||||
{:.shortcuts}
|
||||
|
||||
### Options
|
||||
|
||||
|
@ -60,11 +61,13 @@ title: Command line stuff
|
|||
| `-cN` | N bytes |
|
||||
| `-nN` | N lines |
|
||||
| `+N` | Start from line N |
|
||||
{:.shortcuts}
|
||||
|
||||
<br>
|
||||
|
||||
## Sudo
|
||||
{: .-three-column}
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
sudo [options] <command>
|
||||
|
@ -73,7 +76,6 @@ sudo [options] <command>
|
|||
### Listing
|
||||
|
||||
| `-l` | List allowed commands |
|
||||
{:.shortcuts}
|
||||
|
||||
### Options
|
||||
|
||||
|
@ -84,17 +86,14 @@ sudo [options] <command>
|
|||
| `-n` | Don't prompt for password |
|
||||
| `-P` | Preserve group vector |
|
||||
| `-S` | Read password from stdin |
|
||||
{:.shortcuts}
|
||||
|
||||
### File descriptors
|
||||
|
||||
| `-C fd` | Close all open file descriptors |
|
||||
{:.shortcuts}
|
||||
|
||||
### Prompt
|
||||
|
||||
| `-p prompt` | Custom prompt (-p "%p password:") |
|
||||
{:.shortcuts}
|
||||
|
||||
### Interactive
|
||||
|
||||
|
@ -105,38 +104,33 @@ sudo [options] <command>
|
|||
|----
|
||||
| `-u user` | run as this user |
|
||||
| `-g group` | run as this group |
|
||||
{:.shortcuts}
|
||||
|
||||
### Timestamp
|
||||
|
||||
| `-v` | revalidate timestamp for 5 mins |
|
||||
| `-k` | invalidate timestamp |
|
||||
| `-K` | just like -k |
|
||||
{:.shortcuts}
|
||||
|
||||
<br>
|
||||
|
||||
## wc (Word count)
|
||||
{: .-three-column}
|
||||
|
||||
### wc
|
||||
|
||||
```
|
||||
... | wc [options]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
| `-c` | Bytes |
|
||||
| `-l` | Lines |
|
||||
| `-m` | Characters (incl multi-byte) |
|
||||
| `-w` | Words |
|
||||
{:.shortcuts}
|
||||
|
||||
<br>
|
||||
|
||||
## Search-and-replace in all files
|
||||
|
||||
perl -p -i -e 's/hello/HELLO/g' **/*
|
||||
|
||||
<br>
|
||||
|
||||
## Grep
|
||||
{: .-three-column}
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
grep [options] [pattern] [file ...]
|
||||
|
@ -164,9 +158,15 @@ grep [options] [pattern] [file ...]
|
|||
| `-r, -R` | --recursive |
|
||||
| `-v` | --invert-match |
|
||||
| `-i` | --ignore-case |
|
||||
{:.shortcuts}
|
||||
|
||||
### Synonyms
|
||||
|
||||
egrep => grep -E
|
||||
fgrep => grep -F
|
||||
|
||||
## Other recipes
|
||||
{: .-three-column}
|
||||
|
||||
### Search-and-replace in all files
|
||||
|
||||
perl -p -i -e 's/hello/HELLO/g' **/*
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
---
|
||||
title: Commander.js
|
||||
category: JavaScript libraries
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
- <https://github.com/tj/commander.js/>
|
||||
|
||||
### Initialize
|
||||
|
||||
var cli = require('commander');
|
||||
|
|
20
devise.md
20
devise.md
|
@ -1,12 +1,17 @@
|
|||
---
|
||||
title: Devise
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
[Devise](https://github.com/plataformatec/devise) is a flexible authentication
|
||||
gem.
|
||||
|
||||
Installation
|
||||
------------
|
||||
- <https://github.com/plataformatec/devise>
|
||||
|
||||
### Installation
|
||||
|
||||
Rails 3: Add the following to your Gemfile
|
||||
|
||||
|
@ -27,8 +32,7 @@ Generate devise for your model
|
|||
|
||||
$ rails generate devise:views
|
||||
|
||||
Helpers
|
||||
-------
|
||||
### Helpers
|
||||
|
||||
user_signed_in?
|
||||
current_user
|
||||
|
@ -38,8 +42,7 @@ Helpers
|
|||
edit_user_registration_path (Edit registration)
|
||||
new_user_registration_path (Register new user)
|
||||
|
||||
Controller stuff
|
||||
----------------
|
||||
### Controller stuff
|
||||
|
||||
before_filter :authenticate_user!
|
||||
|
||||
|
@ -123,8 +126,11 @@ Routing
|
|||
Test helpers
|
||||
------------
|
||||
|
||||
### Test helpers
|
||||
|
||||
include Devise::TestHelpers
|
||||
https://github.com/plataformatec/devise/blob/1094ba65aac1d37713f2cba71f9edad76b5ca274/lib/devise/test_helpers.rb
|
||||
|
||||
sign_in @user
|
||||
sign_out @user
|
||||
|
||||
See: <https://github.com/plataformatec/devise/blob/1094ba65aac1d37713f2cba71f9edad76b5ca274/lib/devise/test_helpers.rb>
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
---
|
||||
title: Elixir metaprogramming
|
||||
category: Elixir
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## Kernel
|
||||
### Kernel
|
||||
|
||||
Most of these magic is defined in [Kernel.SpecialForms](http://devdocs.io/elixir/elixir/kernel.specialforms).
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
---
|
||||
title: Firefox
|
||||
layout: 2017/sheet
|
||||
tags: [Archived]
|
||||
archived: This sheet has not been updated with newer Firefox releases.
|
||||
---
|
||||
|
||||
### [Firefox 31](https://www.mozilla.org/en-US/firefox/31.0/releasenotes/) (July 2014)
|
||||
|
|
12
flux.md
12
flux.md
|
@ -1,9 +1,19 @@
|
|||
---
|
||||
title: Flux architecture
|
||||
category: React
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## Architecture
|
||||
## About
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
Flux is an architecture for building client-side web applications.
|
||||
|
||||
* [In-Depth Overview](https://facebook.github.io/flux/docs/in-depth-overview/) _(facebook.github.io)_
|
||||
|
||||
### Architecture
|
||||
|
||||
* __Dispatchers__ receive *actions* that get dispatched to its listeners.
|
||||
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
---
|
||||
title: Git tricks
|
||||
category: Git
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## Refs
|
||||
### Refs
|
||||
|
||||
HEAD^ # 1 commit before head
|
||||
HEAD^^ # 2 commits before head
|
||||
HEAD~5 # 5 commits before head
|
||||
|
||||
## Branches
|
||||
### Branches
|
||||
|
||||
# create a new branch
|
||||
git checkout -b $branchname
|
||||
|
@ -31,7 +32,7 @@ category: Git
|
|||
# go back to previous branch
|
||||
git checkout -
|
||||
|
||||
## Collaboration
|
||||
### Collaboration
|
||||
|
||||
# Rebase your changes on top of the remote master
|
||||
git pull --rebase upstream master
|
||||
|
@ -43,6 +44,8 @@ category: Git
|
|||
Submodules
|
||||
----------
|
||||
|
||||
### Submodules
|
||||
|
||||
# Import .gitmodules
|
||||
git submodule init
|
||||
|
||||
|
@ -70,6 +73,8 @@ Diff
|
|||
Log options
|
||||
-----------
|
||||
|
||||
### Options
|
||||
|
||||
--oneline
|
||||
e11e9f9 Commit message here
|
||||
|
||||
|
@ -131,13 +136,13 @@ Misc
|
|||
|
||||
git bisect reset # abort
|
||||
|
||||
## Searching
|
||||
### Searching
|
||||
|
||||
git log --grep="fixes things" # search in commit messages
|
||||
git log -S"window.alert" # search in code
|
||||
git log -G"foo.*" # search in code (regex)
|
||||
|
||||
## GPG Signing
|
||||
### GPG signing
|
||||
|
||||
git config set user.signingkey <GPG KEY ID> # Sets GPG key to use for signing
|
||||
|
||||
|
|
5
gulp.md
5
gulp.md
|
@ -1,8 +1,13 @@
|
|||
---
|
||||
title: Gulp
|
||||
category: JavaScript libraries
|
||||
layout: 2017/sheet
|
||||
tags: [Archived]
|
||||
archived: The information on this sheet may possibly be outdated.
|
||||
---
|
||||
|
||||
### Available plugins
|
||||
|
||||
* gulp-ruby-sass
|
||||
* gulp-autoprefixer
|
||||
* gulp-minify-css
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
---
|
||||
title: Ledger examples
|
||||
category: Ledger
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
Inspecting transactions:
|
||||
### Inspecting transactions
|
||||
|
||||
# show me expenses for october (--period)
|
||||
ledger r Expenses -p oct
|
||||
|
@ -21,7 +22,7 @@ Inspecting transactions:
|
|||
ledger r mastercard -p "january"
|
||||
ledger r mastercard -b 01/25 -e 01/31
|
||||
|
||||
Graphing:
|
||||
### Graphing
|
||||
|
||||
# Graph my bank account balance, monthly
|
||||
ledger r Savings -M
|
||||
|
@ -32,14 +33,14 @@ Graphing:
|
|||
# ...what's the average per month?
|
||||
ledger r Expenses -M -n --average
|
||||
|
||||
Simple:
|
||||
### Simple
|
||||
|
||||
# what did I do yesterday?
|
||||
# ..list transactions on this day
|
||||
ledger r -p 01/26
|
||||
ledger r -p yesterday
|
||||
|
||||
Switches:
|
||||
### Switches
|
||||
|
||||
# what's everything I got in USD? (--exchange)
|
||||
ledger b Assets -X USD
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
---
|
||||
title: Ledger format
|
||||
category: Ledger
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### Example
|
||||
```
|
||||
2015/01/01 Pay rent
|
||||
Assets:Savings -$300
|
||||
|
@ -32,6 +34,9 @@ Flags:
|
|||
```
|
||||
|
||||
## Accounts
|
||||
|
||||
### Accounts
|
||||
|
||||
Only relevant with `--strict` or `--pedantic`
|
||||
|
||||
```
|
||||
|
@ -47,6 +52,8 @@ account Expenses:Food
|
|||
|
||||
## Others
|
||||
|
||||
### Others
|
||||
|
||||
```
|
||||
D $1,000.00 ; set default commodity
|
||||
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
---
|
||||
title: Ledger periods
|
||||
category: Ledger
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
- <https://ledger-cli.org/3.0/doc/ledger3.html#Period-Expressions>
|
||||
|
||||
### Usage
|
||||
|
||||
[INTERVAL] [BEGIN] [END]
|
||||
|
||||
Interval:
|
||||
#### Intervals
|
||||
|
||||
every day
|
||||
every week
|
||||
|
@ -25,17 +33,17 @@ Interval:
|
|||
quarterly
|
||||
yearly
|
||||
|
||||
Begin:
|
||||
#### Begin
|
||||
|
||||
from <SPEC>
|
||||
since <SPEC>
|
||||
|
||||
The end time can be either of:
|
||||
#### End
|
||||
|
||||
to <SPEC>
|
||||
until <SPEC>
|
||||
|
||||
Spec:
|
||||
### Spec
|
||||
|
||||
2004
|
||||
2004/10
|
||||
|
@ -47,8 +55,6 @@ Spec:
|
|||
next week
|
||||
last week
|
||||
|
||||
Examples:
|
||||
### Examples
|
||||
|
||||
$ ledger r -p "since last month"
|
||||
|
||||
See: http://ledger-cli.org/3.0/doc/ledger3.html#Period-Expressions
|
||||
|
|
|
@ -4,6 +4,10 @@ category: Ledger
|
|||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
|
||||
- <https://ledger-cli.org/3.0/doc/ledger3.html#Complex-expressions>
|
||||
|
||||
### Query characters
|
||||
|
||||
| Query | Description |
|
||||
|
@ -23,8 +27,3 @@ layout: 2017/sheet
|
|||
ledger r @taco
|
||||
ledger r comment =~ /landline/
|
||||
```
|
||||
|
||||
## References
|
||||
{: .-one-column}
|
||||
|
||||
- <http://ledger-cli.org/3.0/doc/ledger3.html#Complex-expressions>
|
||||
|
|
52
lua.md
52
lua.md
|
@ -1,14 +1,22 @@
|
|||
---
|
||||
title: Lua
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## Comments
|
||||
## Basic examples
|
||||
|
||||
### References
|
||||
|
||||
- <https://www.lua.org/pil/13.html>
|
||||
- <http://lua-users.org/wiki/ObjectOrientedProgramming>
|
||||
|
||||
### Comments
|
||||
|
||||
-- comment
|
||||
--[[ Multiline
|
||||
comment ]]
|
||||
|
||||
## Invoking functions
|
||||
### Invoking functions
|
||||
|
||||
print()
|
||||
print("Hi")
|
||||
|
@ -21,7 +29,7 @@ title: Lua
|
|||
f{x=10, y=20} <--> f({x=10, y=20})
|
||||
type{} <--> type({})
|
||||
|
||||
## Tables / arrays
|
||||
### Tables / arrays
|
||||
|
||||
t = {}
|
||||
t = { a = 1, b = 2 }
|
||||
|
@ -35,7 +43,7 @@ title: Lua
|
|||
print(array[2]) -- "b" (one-indexed)
|
||||
print(#array) -- 4 (length)
|
||||
|
||||
## Loops
|
||||
### Loops
|
||||
|
||||
while condition do
|
||||
end
|
||||
|
@ -57,7 +65,7 @@ title: Lua
|
|||
if condition then break end
|
||||
end
|
||||
|
||||
## Conditionals
|
||||
### Conditionals
|
||||
|
||||
if condition then
|
||||
print("yes")
|
||||
|
@ -67,12 +75,12 @@ title: Lua
|
|||
print("no")
|
||||
end
|
||||
|
||||
## Variables
|
||||
### Variables
|
||||
|
||||
local x = 2
|
||||
two, four = 2, 4
|
||||
|
||||
## Functions
|
||||
### Functions
|
||||
|
||||
function myFunction()
|
||||
return 1
|
||||
|
@ -100,7 +108,7 @@ title: Lua
|
|||
|
||||
doAction('write', "Shirley", "Abed")
|
||||
|
||||
## Lookups
|
||||
### Lookups
|
||||
|
||||
mytable = { x = 2, y = function() .. end }
|
||||
|
||||
|
@ -118,8 +126,9 @@ title: Lua
|
|||
function X:y(z) .. end
|
||||
function X.y(self, z) .. end
|
||||
|
||||
## Metatables
|
||||
## More concepts
|
||||
|
||||
### Metatables
|
||||
|
||||
mt = {}
|
||||
|
||||
|
@ -136,7 +145,7 @@ title: Lua
|
|||
|
||||
print(myobject)
|
||||
|
||||
## Classes
|
||||
### Classes
|
||||
|
||||
Account = {}
|
||||
|
||||
|
@ -161,7 +170,7 @@ title: Lua
|
|||
a = Account:new(9000)
|
||||
a:withdraw(200) -- method call
|
||||
|
||||
## Constants
|
||||
### Constants
|
||||
|
||||
nil
|
||||
false
|
||||
|
@ -169,6 +178,8 @@ title: Lua
|
|||
|
||||
## Operators (and their metatable names)
|
||||
|
||||
### Relational
|
||||
|
||||
-- Relational (binary)
|
||||
-- __eq __lt __gt __le __ge
|
||||
== < > <= >=
|
||||
|
@ -182,12 +193,15 @@ title: Lua
|
|||
-- __unm (unary minus)
|
||||
-
|
||||
|
||||
### Logic
|
||||
|
||||
-- Logic (and/or)
|
||||
nil and false --> nil
|
||||
false and nil --> false
|
||||
0 and 20 --> 20
|
||||
10 and 20 --> 20
|
||||
|
||||
### Tables
|
||||
|
||||
-- Length
|
||||
-- __len(array)
|
||||
|
@ -209,8 +223,9 @@ title: Lua
|
|||
-- Call
|
||||
-- __call(func, ...)
|
||||
|
||||
## API
|
||||
|
||||
## API: Global functions [(ref)](http://lua.gts-stolberg.de/en/Basis.php)
|
||||
### API: Global Functions
|
||||
|
||||
dofile("hello.lua")
|
||||
loadfile("hello.lua")
|
||||
|
@ -233,7 +248,7 @@ title: Lua
|
|||
tonumber("34")
|
||||
tonumber("8f", 16)
|
||||
|
||||
## API: Strings
|
||||
### API: Strings
|
||||
|
||||
'string'..'concatenation'
|
||||
|
||||
|
@ -258,7 +273,7 @@ title: Lua
|
|||
s:byte()
|
||||
s:format()
|
||||
|
||||
## API: Tables
|
||||
### API: Tables
|
||||
|
||||
table.foreach(t, function(row) ... end)
|
||||
table.setn
|
||||
|
@ -269,7 +284,7 @@ title: Lua
|
|||
table.sort
|
||||
table.remove(t, 4)
|
||||
|
||||
## API: Math [(ref)](http://lua-users.org/wiki/MathLibraryTutorial)
|
||||
### API: Math
|
||||
|
||||
math.abs math.acos math.asin math.atan math.atan2
|
||||
math.ceil math.cos math.cosh math.deg math.exp
|
||||
|
@ -281,7 +296,7 @@ title: Lua
|
|||
math.sqrt(144)
|
||||
math
|
||||
|
||||
## API: Misc
|
||||
### API: Misc
|
||||
|
||||
io.output(io.open("file.txt", "w"))
|
||||
io.write(x)
|
||||
|
@ -293,8 +308,3 @@ title: Lua
|
|||
file:read()
|
||||
file:lines()
|
||||
file:close()
|
||||
|
||||
## Reference
|
||||
|
||||
https://www.lua.org/pil/13.html
|
||||
http://lua-users.org/wiki/ObjectOrientedProgramming
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
---
|
||||
title: Make for assets
|
||||
hljs_languages: [makefile]
|
||||
layout: 2017/sheet
|
||||
tags: [Archived]
|
||||
archived: This sheet may be listing practices that are outdated.
|
||||
---
|
||||
|
||||
## Basic compiling
|
||||
### Basic compiling
|
||||
|
||||
```makefile
|
||||
bin := ./node_modules/.bin
|
||||
|
@ -14,7 +16,7 @@ build/%.js: src/%.coffee
|
|||
@$(bin)/coffee < $^ > $@
|
||||
```
|
||||
|
||||
## Stylus + Autoprefixer
|
||||
### Stylus + Autoprefixer
|
||||
|
||||
bin := ./node_modules/.bin
|
||||
stylus := $(bin)/stylus
|
||||
|
@ -28,18 +30,18 @@ build/%.js: src/%.coffee
|
|||
%.css: %.styl $(styl_files)
|
||||
@$(stylus) $< | $(autoprefixer) -b "> 1%" > $@
|
||||
|
||||
## Hint
|
||||
### Hint
|
||||
|
||||
hint:
|
||||
$(js_files)
|
||||
|
||||
## Watching
|
||||
### Watching
|
||||
|
||||
watch:
|
||||
@echo "... watching for changes"
|
||||
@while true; do make -s; sleep 1; done
|
||||
|
||||
## Browserify
|
||||
### Browserify
|
||||
|
||||
js_files := $(shell find web/ -name "*.js")
|
||||
|
||||
|
|
24
makefile.md
24
makefile.md
|
@ -5,7 +5,7 @@ layout: 2017/sheet
|
|||
category: CLI
|
||||
---
|
||||
|
||||
## Var assignment
|
||||
### Var assignment
|
||||
|
||||
```makefile
|
||||
foo = "bar"
|
||||
|
@ -19,7 +19,7 @@ foo != echo fooo # exec shell command and assign to foo
|
|||
|
||||
`=` expressions are only evaluated when they're being used.
|
||||
|
||||
## Magic variables
|
||||
### Magic variables
|
||||
|
||||
```makefile
|
||||
out.o: src.c src.h
|
||||
|
@ -38,7 +38,7 @@ also:
|
|||
$(@D) # target directory
|
||||
```
|
||||
|
||||
## Command prefixes
|
||||
### Command prefixes
|
||||
|
||||
| Prefix | Description |
|
||||
| ------ | ------------------------------------------- |
|
||||
|
@ -54,14 +54,14 @@ build:
|
|||
-include .depend
|
||||
```
|
||||
|
||||
## Find files
|
||||
### Find files
|
||||
|
||||
```makefile
|
||||
js_files := $(wildcard test/*.js)
|
||||
all_files := $(shell find images -name "*")
|
||||
```
|
||||
|
||||
## Substitutions
|
||||
### Substitutions
|
||||
|
||||
```makefile
|
||||
file = $(SOURCE:.cpp=.o) # foo.cpp => foo.o
|
||||
|
@ -71,7 +71,7 @@ outputs = $(patsubst %.c, %.o, $(wildcard *.c))
|
|||
assets = $(patsubst images/%, assets/%, $(wildcard images/*))
|
||||
```
|
||||
|
||||
## More functions
|
||||
### More functions
|
||||
|
||||
```makefile
|
||||
$(strip $(string_var))
|
||||
|
@ -80,7 +80,7 @@ $(filter %.less, $(files))
|
|||
$(filter-out %.less, $(files))
|
||||
```
|
||||
|
||||
## Building files
|
||||
### Building files
|
||||
|
||||
```makefile
|
||||
%.o: %.c
|
||||
|
@ -88,13 +88,13 @@ $(filter-out %.less, $(files))
|
|||
foo $^
|
||||
```
|
||||
|
||||
## Includes
|
||||
### Includes
|
||||
|
||||
```makefile
|
||||
-include foo.make
|
||||
```
|
||||
|
||||
## Options
|
||||
### Options
|
||||
|
||||
```sh
|
||||
make
|
||||
|
@ -104,7 +104,7 @@ make
|
|||
-j, --jobs=N # parallel processing
|
||||
```
|
||||
|
||||
## Conditionals
|
||||
### Conditionals
|
||||
|
||||
```makefile
|
||||
foo: $(objects)
|
||||
|
@ -115,14 +115,14 @@ else
|
|||
endif
|
||||
```
|
||||
|
||||
## Recursive
|
||||
### Recursive
|
||||
|
||||
```makefile
|
||||
deploy:
|
||||
$(MAKE) deploy2
|
||||
```
|
||||
|
||||
## Further reading
|
||||
### Further reading
|
||||
|
||||
- [isaacs's Makefile](https://gist.github.com/isaacs/62a2d1825d04437c6f08)
|
||||
- [Your Makefiles are wrong](https://tech.davis-hansson.com/p/make/)
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
---
|
||||
title: Mocha HTML
|
||||
category: JavaScript libraries
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
|
||||
This is a mocha template that loads js/css from cdn.
|
||||
|
||||
### Template
|
||||
|
||||
```html
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
title: Mocha.js TDD interface
|
||||
category: JavaScript libraries
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### TDD
|
||||
|
|
|
@ -4,11 +4,6 @@ category: Node.js
|
|||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
- <https://nodejs.org>
|
||||
|
||||
### Globals
|
||||
|
||||
__filename
|
||||
|
@ -34,7 +29,7 @@ layout: 2017/sheet
|
|||
|
||||
process.stdout.write(util.inspect(objekt, false, Infinity, true) + '\n');
|
||||
|
||||
## Spawn - passthru the in/out
|
||||
### Spawn - passthru the in/out
|
||||
|
||||
var spawn = require('child_process').spawn;
|
||||
var proc = spawn(bin, argv, { stdio: 'inherit' });
|
||||
|
|
10
nopt.md
10
nopt.md
|
@ -1,8 +1,16 @@
|
|||
---
|
||||
title: Nopt
|
||||
category: JavaScript libraries
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### About
|
||||
{: .-intro}
|
||||
|
||||
- <https://www.npmjs.org/package/nopt>
|
||||
|
||||
### Example
|
||||
|
||||
```js
|
||||
var args = require('nopt')({
|
||||
foo: [String, null],
|
||||
|
@ -46,5 +54,3 @@ if (args.version) {
|
|||
process.exit(0);
|
||||
}
|
||||
```
|
||||
|
||||
https://www.npmjs.org/package/nopt
|
||||
|
|
10
parsimmon.md
10
parsimmon.md
|
@ -1,8 +1,10 @@
|
|||
---
|
||||
title: Parsimmon
|
||||
category: JavaScript libraries
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### Basic usage
|
||||
```js
|
||||
const P = require('parsimmon')
|
||||
|
||||
|
@ -11,7 +13,7 @@ P.regexp(/[a-z]+/)
|
|||
//=> { status: true, value: ['hello'] }
|
||||
```
|
||||
|
||||
## Atoms
|
||||
### Atoms
|
||||
|
||||
```js
|
||||
P.regexp(/[a-z]+/)
|
||||
|
@ -23,7 +25,7 @@ P.optWhitespace
|
|||
P.eof
|
||||
```
|
||||
|
||||
## Combinators
|
||||
### Combinators
|
||||
|
||||
```js
|
||||
P.seq(a, b, c) // sequence of these
|
||||
|
@ -41,13 +43,13 @@ a.atMost(10)
|
|||
a.atLeast(10)
|
||||
```
|
||||
|
||||
## Formatting
|
||||
### Formatting
|
||||
|
||||
```js
|
||||
P.seq(P.number, P.oneOf('+-*/'), P.number)
|
||||
.map(([left, oper, right]) => ({ oper, left, right }))
|
||||
```
|
||||
|
||||
## Reference
|
||||
### Reference
|
||||
|
||||
- <https://github.com/jneen/parsimmon/blob/master/API.md>
|
||||
|
|
|
@ -2,18 +2,23 @@
|
|||
title: "Phoenix: Ecto models"
|
||||
category: Elixir
|
||||
deprecated: true
|
||||
layout: 2017/sheet
|
||||
tags: [Archived]
|
||||
archived: This is for Phoenix 1.2 and below. [Phoenix 1.3 has a new API.](./phoenix-ecto@1.3).
|
||||
---
|
||||
|
||||
This is for Phoenix 1.2 and below. [Phoenix 1.3 has a new API.](phoenix-ecto@1.3.html).
|
||||
### About
|
||||
|
||||
## Generating
|
||||
This is for Phoenix 1.2 and below. [Phoenix 1.3 has a new API.](./phoenix-ecto@1.3).
|
||||
|
||||
### Generating
|
||||
|
||||
```
|
||||
$ mix phoenix.gen.html Profile profiles email:string age:integer
|
||||
$ mix phoenix.gen.html User users email:string hashed_password:string
|
||||
```
|
||||
|
||||
## Schema
|
||||
### Schema
|
||||
|
||||
```elixir
|
||||
defmodule User do
|
||||
|
@ -30,7 +35,7 @@ defmodule User do
|
|||
end
|
||||
```
|
||||
|
||||
## Changesets
|
||||
### Changesets
|
||||
|
||||
```elixir
|
||||
def changeset(user, params \\ :empty) do
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
---
|
||||
title: PostgreSQL
|
||||
category: Databases
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
Replace anything within `<placeholder>` accordingly
|
||||
|
||||
### Console
|
||||
|
||||
$ psql #logs in to default database & default user
|
||||
$ sudo -u <rolename:postgres> psql #logs in with a particular user
|
||||
|
||||
Replace anything within `<placeholder>` accordingly
|
||||
|
||||
### Commands
|
||||
|
||||
* Show roles: `\du`
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
---
|
||||
title: Projectionist
|
||||
category: Vim
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### Basic usage
|
||||
|
||||
```json
|
||||
/* .projectionist.vim */
|
||||
|
@ -16,7 +18,7 @@ category: Vim
|
|||
}
|
||||
```
|
||||
|
||||
## Available options
|
||||
### Available options
|
||||
|
||||
```js
|
||||
{
|
||||
|
@ -35,7 +37,7 @@ category: Vim
|
|||
}
|
||||
```
|
||||
|
||||
## Commands
|
||||
### Commands
|
||||
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
|
@ -53,8 +55,7 @@ category: Vim
|
|||
| `:Lcd` | cd to root using :lcd |
|
||||
|---------|-------------|
|
||||
| `:ProjectDo {cmd}` | run command in root |
|
||||
{:.shortcuts}
|
||||
|
||||
## Reference
|
||||
### Reference
|
||||
|
||||
See [vim-projectionist](https://github.com/tpope/vim-projectionist).
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
title: Python
|
||||
category: Python
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### Tuples (immutable)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
title: Controllers
|
||||
title: Rails controllers
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### Common stuff
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
---
|
||||
title: Form helpers
|
||||
hljs_languages: [haml]
|
||||
title: Rails form helpers
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## Form builder
|
||||
|
||||
### Form builder
|
||||
|
||||
```haml
|
||||
- form_for @post do |f|
|
||||
```
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
title: Helpers
|
||||
title: Rails helpers
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### Date
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
---
|
||||
title: i18n
|
||||
title: Rails i18n
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### References
|
||||
|
||||
* <http://guides.rubyonrails.org/i18n.html>
|
||||
* <http://rails-i18n.org/wiki>
|
||||
* <https://github.com/svenfuchs/i18n>
|
||||
* <https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml>
|
||||
|
||||
### Example
|
||||
|
||||
```rb
|
||||
t('my.messages.hello')
|
||||
|
||||
|
@ -12,7 +22,8 @@ t(:hello, scope: [:my, :messages])
|
|||
|
||||
t('my.messages.hello', default: "Hello")
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
en:
|
||||
|
@ -26,7 +37,8 @@ en:
|
|||
```rb
|
||||
t('hello', name: "John")
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
hello: "Hello %{name}"
|
||||
|
@ -38,7 +50,8 @@ hello: "Hello %{name}"
|
|||
# from the 'books/index' view
|
||||
t('.title')
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
en:
|
||||
|
@ -53,7 +66,8 @@ en:
|
|||
t(:inbox, count: 1) #=> 'one message'
|
||||
t(:inbox, count: 2) #=> '2 messages'
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
inbox:
|
||||
|
@ -69,7 +83,8 @@ inbox:
|
|||
l(Time.now)
|
||||
l(Time.now, format: :short)
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
en:
|
||||
|
@ -85,7 +100,8 @@ en:
|
|||
```rb
|
||||
l(Date.today)
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
en:
|
||||
|
@ -104,7 +120,8 @@ en:
|
|||
User.model_name.human #=> "User"
|
||||
Child.model_name.human(count: 2) #=> "Children"
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
en:
|
||||
|
@ -121,7 +138,8 @@ en:
|
|||
```rb
|
||||
User.human_attribute_for :name #=> "Name"
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
en:
|
||||
|
@ -138,7 +156,8 @@ en:
|
|||
```rb
|
||||
error_messages_for(...)
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
activerecord:
|
||||
|
@ -150,6 +169,8 @@ activerecord:
|
|||
blank: "Please enter a name."
|
||||
```
|
||||
|
||||
### Scopes
|
||||
|
||||
Possible scopes (in order):
|
||||
|
||||
```yml
|
||||
|
@ -181,7 +202,8 @@ validates
|
|||
form_for @post do
|
||||
f.label :body
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
helpers:
|
||||
|
@ -197,7 +219,8 @@ helpers:
|
|||
form_for @post do
|
||||
f.submit
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
helpers:
|
||||
|
@ -223,14 +246,14 @@ number_to_rounded(3.14, precision: 0) #=> "3"
|
|||
number_to_human(12_000) #=> "12 Thousand"
|
||||
number_to_human_size(12345) #=> "12.3 kb"
|
||||
```
|
||||
{:.light}
|
||||
|
||||
### Delimited
|
||||
|
||||
```rb
|
||||
number_to_delimited(n)
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
number:
|
||||
|
@ -266,7 +289,8 @@ number:
|
|||
```rb
|
||||
number_to_percentage(n)
|
||||
```
|
||||
{:.light}
|
||||
|
||||
#### YAML
|
||||
|
||||
```yml
|
||||
number:
|
||||
|
@ -278,6 +302,8 @@ number:
|
|||
|
||||
## Programmatic access
|
||||
|
||||
### Programmatic access
|
||||
|
||||
```rb
|
||||
I18n.backend.store_translations :en, ok: "Ok"
|
||||
I18n.locale = :en
|
||||
|
@ -288,11 +314,3 @@ I18n.available_locales
|
|||
I18n.translate :ok # aka, I18n.t
|
||||
I18n.localize date # aka, I18n.l
|
||||
```
|
||||
{:.light}
|
||||
|
||||
## Reference
|
||||
|
||||
* http://guides.rubyonrails.org/i18n.html
|
||||
* http://rails-i18n.org/wiki
|
||||
* https://github.com/svenfuchs/i18n
|
||||
* https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en.yml
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
title: Migrations
|
||||
title: Rails migrations
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
### Automatically make migrations
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
---
|
||||
title: Rails plugins
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
Generate a plugin
|
||||
-----------------
|
||||
### Generate a plugin
|
||||
|
||||
Generate a Rails Engine plugin:
|
||||
|
||||
|
@ -13,10 +13,14 @@ Generate a Rails Engine plugin:
|
|||
Initializers
|
||||
------------
|
||||
|
||||
### Initializers
|
||||
|
||||
* [Rails::Railtie](http://edgeapi.rubyonrails.org/classes/Rails/Railtie.html)
|
||||
* [EngineYard blog
|
||||
post](http://www.engineyard.com/blog/2010/extending-rails-3-with-railties/)
|
||||
|
||||
### Initializer method
|
||||
|
||||
Subclass Railtie and provide an `initializer` method.
|
||||
|
||||
module NewPlugin
|
||||
|
@ -36,8 +40,12 @@ Subclass Railtie and provide an `initializer` method.
|
|||
Custom routes
|
||||
-------------
|
||||
|
||||
### Custom routes
|
||||
|
||||
* [ActionDispatch::Routing::Mapper](http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper.html)
|
||||
|
||||
### Creating routes
|
||||
|
||||
To create custom `routes.rb` keywords:
|
||||
|
||||
# # routes.rb:
|
||||
|
@ -65,6 +73,8 @@ Example with a block:
|
|||
Custom generators
|
||||
-----------------
|
||||
|
||||
### Custom generators
|
||||
|
||||
* [Guide: generators](http://guides.rubyonrails.org/generators.html)
|
||||
* [ActiveRecord::Generators::Base](http://api.rubyonrails.org/classes/ActiveRecord/Generators/Base.html)
|
||||
|
||||
|
@ -118,6 +128,8 @@ When invoking `rails g XXX:YYY`:
|
|||
ActiveModel 'acts as'
|
||||
---------------------
|
||||
|
||||
### acts as
|
||||
|
||||
# yaffle/lib/yaffle/acts_as_yaffle.rb
|
||||
module Yaffle
|
||||
module ActsAsYaffle
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
---
|
||||
title: Routes
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
---
|
||||
|
||||
## Multiple resources (`resources`)
|
||||
## Resources
|
||||
|
||||
### Multiple resources (`resources`)
|
||||
|
||||
resources :photos
|
||||
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
---
|
||||
title: Rails tricks
|
||||
category: Rails
|
||||
layout: 2017/sheet
|
||||
tags: [Archived]
|
||||
archived: This sheet may describe practices that might be outdated.
|
||||
---
|
||||
|
||||
### Sass source maps
|
||||
|
||||
in config/environments/development.rb:
|
||||
|
||||
# Source maps for Sass
|
||||
|
@ -12,7 +17,7 @@ in config/environments/development.rb:
|
|||
# Don't break apart
|
||||
config.assets.debug = false
|
||||
|
||||
Partial locals
|
||||
### Partial locals
|
||||
|
||||
<%= render 'article', full: true %>
|
||||
<%= render 'article' %>
|
||||
|
@ -21,12 +26,12 @@ Partial locals
|
|||
...
|
||||
<% end %>
|
||||
|
||||
HTML in i18n
|
||||
### HTML in i18n
|
||||
|
||||
en:
|
||||
read_more_html: "read <b>more</b>..."
|
||||
|
||||
Exception handling:
|
||||
### Exception handling
|
||||
|
||||
# config/application.rb
|
||||
config.exceptions_app = self.routes
|
||||
|
@ -40,25 +45,25 @@ Exception handling:
|
|||
end
|
||||
end
|
||||
|
||||
Rails updating:
|
||||
### Rails updating
|
||||
|
||||
rake rails:update
|
||||
|
||||
Distinct pluck:
|
||||
### Distinct pluck
|
||||
|
||||
Article.distinct.pluck('author')
|
||||
|
||||
Relation#merge
|
||||
### Relation#merge
|
||||
|
||||
scope :with_drafts, -> {
|
||||
uniq.joins(:articles).merge(Article.draft)
|
||||
}
|
||||
|
||||
Order
|
||||
### Order
|
||||
|
||||
scope :recent, -> { order created_at: :desc }
|
||||
|
||||
Group by month
|
||||
### Group by month
|
||||
|
||||
.group("to_char(created_at, 'YYYY-MM')")
|
||||
.group("to_char(created_at, 'YYYY-MM')").count
|
||||
|
|
Loading…
Reference in New Issue