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