13 | $ pass git push -u --all
14 | ```
15 |
16 | ### Store
17 |
18 | ```bash
19 | $ pass insert [-m] twitter.com/rsc
20 | $ pass generate [-n] twitter.com/rsc length
21 | ```
22 |
23 | ### Retrieve
24 |
25 | ```bash
26 | $ pass ls twitter.com/
27 | $ pass show twitter.com/rsc
28 | ```
29 |
30 | ### Search
31 |
32 | ```bash
33 | $ pass find twitter.com
34 | ```
35 |
36 | ### Management
37 |
38 | ```bash
39 | $ pass mv twitter.com twitter.com/rsc
40 | $ pass rm [-rf] twitter.com
41 | $ pass cp twitter.com/rsc twitter.com/ricosc
42 | ```
43 |
44 | ```bash
45 | $ pass edit twitter.com/rsc
46 | ```
47 |
48 | ### Synchronize
49 |
50 | ```bash
51 | $ pass git push
52 | $ pass git pull
53 | ```
54 |
55 | ### References
56 |
57 | * [Passwordstore website](http://passwordstore.org) _(passwordstore.org)_
58 |
--------------------------------------------------------------------------------
/sheets/blessed.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Blessed
3 | category: JavaScript libraries
4 | layout: 2017/sheet
5 | ---
6 |
7 | ### Screen
8 |
9 | ```js
10 | screen = blessed.screen({
11 | smartCSR: true, // optimize for flickering
12 | autoPadding: true // ...
13 | })
14 |
15 | screen.append(Element)
16 | screen.destroy()
17 |
18 | screen.width
19 | screen.height
20 | screen.title = 'My window title'
21 |
22 | screen.key(['escape', 'q', 'C-c'], (ch, key) => {
23 | /*...*/
24 | })
25 | ```
26 |
27 | ### Element
28 |
29 | ```js
30 | box = blessed.box({
31 | style: { fg, bg, border.fg, scrollbar.bg, focus.bg, hover.bg },
32 | border: { type: ('line'|'bg'), bg, fg, bold, underline }
33 | tags: true, // parse {bold}tags{/bold}
34 |
35 | top, left, width, height,
36 | width: '100%',
37 | height: '100%-1',
38 | top: 'center'
39 | })
40 | ```
41 |
42 | ### Tags
43 |
44 | ```
45 | {bold}
46 | {right} {center}
47 | {|} left-right separator
48 | {#c0ff33-fg}{/}
49 | ```
50 |
51 | ```js
52 | blessed.escape('...')
53 | ```
54 |
--------------------------------------------------------------------------------
/sheets/social-images.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Social media images
3 | ---
4 |
5 | ### Facebook
6 |
7 | | What | Dimensions |
8 | | :-------------------- | ---------------------------------------: |
9 | | Cover photo | 851 x 315 |
10 | | Display picture | 168 x 168 ? |
11 | | Highlighted image | 1200 x 717 (appears 843 x 504) |
12 | | Share link (og:image) | 940 x 492 (1.91:1, appears as 470 x 246) |
13 | | Share link (square) | 1:1, appears as 114 x 114? |
14 |
15 | ### Twitter
16 |
17 | | What | Dimensions |
18 | | :---------------------- | ---------------------------: |
19 | | Page header | 1500 x 500 |
20 | | Display picture | 400 x 400 (shown as 200x200) |
21 | | In-stream photo preview | 440 x 220 (2:1) |
22 |
23 | ### References
24 |
25 | * https://developers.facebook.com/docs/plugins/checklist/
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | This repo is archived.
4 |
5 |
6 | Head onto the main repo for Devhints cheatsheets:
7 | github.com/rstacruz/cheatsheets
8 |
9 |
10 |
11 |
12 | ---
13 |
14 | # Devhints
15 |
16 | > TL;DR for developer documentation - a ridiculous collection of cheatsheets
17 |
18 | [](https://travis-ci.org/rstacruz/cheatsheets 'See test builds')
19 |
20 |
21 |
22 |
23 |
24 |
25 | ✨ devhints.io ✨
26 |
27 |
28 |
29 |
30 | ---
31 |
32 | See [CONTRIBUTING.md](CONTRIBUTING.md) for developer notes.
33 |
34 | [](https://gitpod.io/#https://github.com/rstacruz/cheatsheets)
35 |
--------------------------------------------------------------------------------
/sheets/wip/compose-key.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Compose key
3 | ---
4 |
5 | ### Common symbols
6 |
7 | | Character | Shortcut | Description |
8 | | --------- | -------- | --------------- |
9 | | • | `.=` | Filled bullet |
10 | | · | `.-` | Middle dot |
11 | | × | `xx` | Multiplication |
12 | | ® | `oR` | Registered sign |
13 | | ™ | `tm` | Trademark sign |
14 | | ∴ | `:.` | Therefore |
15 | | § | `OS` | Section sign |
16 | | ♥ | `<3` | Heart |
17 | | → | `->` | Arrow |
18 | | ⇒ | `=>` | Arrow |
19 | | ☺ | `:)` | Smile |
20 |
21 | ## Refreneces
22 |
23 | * [Common compose key combinations](https://en.m.wikipedia.org/wiki/Compose_key#Common_compose_combinations) _(en.wikipedia.org)_
24 | * [GtkComposeTable](https://help.ubuntu.com/community/GtkComposeTable) _(help.ubuntu.com)_
25 | * [Complete list](https://www.x.org/releases/X11R7.7/doc/libX11/i18n/compose/en_US.UTF-8.html) _(x.org)_
26 |
--------------------------------------------------------------------------------
/sheets/ets.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Erlang ETS
3 | category: Elixir
4 | layout: 2017/sheet
5 | weight: -1
6 | ---
7 |
8 | ## ETS
9 |
10 | ### Usage
11 |
12 | ```elixir
13 | iex> table = :ets.new(:my_table, [])
14 | 8211
15 | ```
16 |
17 | ```elixir
18 | iex> :ets.insert(table, {:fruit, "Apple"})
19 | iex> :ets.lookup(table, :fruit)
20 | [{:fruit, "Apple"}]
21 | ```
22 |
23 | ```elixir
24 | iex> :ets.delete(table)
25 | iex> :ets.delete_all_objects(table)
26 | ```
27 |
28 | ### Flags
29 |
30 | ```elixir
31 | iex> table = :ets.new(:my_table, [:set, :protected])
32 | ```
33 |
34 |
35 |
36 | | `:set` | no duplicate keys (or: `:ordered_set`, `:bag`, `:duplicate_bag`) |
37 | | `:protected` | only this process can use it (or: `:public`, `:private`) |
38 |
39 | ### Ordered sets
40 |
41 | ```elixir
42 | :ets.first(table)
43 | :ets.last(table)
44 | :ets.next(table, key)
45 | :ets.prev(table, key)
46 | ```
47 |
48 | ## References
49 |
50 |
51 |
52 | *
53 | *
54 |
--------------------------------------------------------------------------------
/sheets/emacs.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Emacs
3 | category: Apps
4 | updated: 2019-01-04
5 | tags: [WIP]
6 | ---
7 |
8 | ## Shortcuts
9 |
10 |
11 |
12 | ### Movements
13 |
14 | | Description | Key |
15 | | ------------------------- | --------------- |
16 | | Up/down | `C-n` _/_ `C-p` |
17 | | left/right | `C-f` _/_ `C-b` |
18 | | | |
19 | | Page up/page down | `C-v` _/_ `M-v` |
20 | | | |
21 | | Beginning/end of line | `C-a` _/_ `C-e` |
22 | | Beginning/end of sentence | `M-a` _/_ `M-e` |
23 |
24 |
25 |
26 | ### Basic
27 |
28 | | Description | Key |
29 | | ----------- | ----------- |
30 | | Find file | `C-x` `C-f` |
31 | | Save file | `C-x` `C-s` |
32 |
33 |
34 |
35 | ### Command line
36 |
37 | | Description | Key |
38 | | ----------------- | ----- |
39 | | Open command line | `M-x` |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/sheets/macos-mouse-acceleration.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Mouse Acceleration
3 | layout: 2017/sheet
4 | category: macOS
5 | updated: 2018-03-20
6 | weight: -1
7 | keywords:
8 | - "defaults write .GlobalPreferences com.apple.mouse.scaling -1"
9 | intro: |
10 | Disable mouse acceleration with this one weird trick.
11 | ---
12 |
13 | ## Acceleration
14 |
15 | ### Disabling
16 |
17 | ```bash
18 | defaults write .GlobalPreferences com.apple.mouse.scaling -1
19 | ```
20 |
21 | Note: Log out to take effect. If you change _Tracking Speed_ under System Preferences, it will undo this fix. Only affects the mouse, not the trackpad.
22 |
23 | ### Re-enabling
24 |
25 | Under _System Preferences_ → _Mouse_, change _Tracking Speed_.
26 |
27 | ### Trackpad acceleration
28 |
29 | ```bash
30 | defaults write .GlobalPreferences com.apple.trackpad.scaling -1
31 | ```
32 |
33 | Works the same way, but only affects trackpads.
34 |
35 | ## References
36 |
37 | * [Disabling mouse acceleration](https://stackoverflow.com/questions/5782884/disabling-mouse-acceleration-in-mac-os-x) _(stackoverflow.com)_
38 |
--------------------------------------------------------------------------------
/sheets/chunky_png.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Chunky PNG
3 | category: Ruby libraries
4 | layout: 2017/sheet
5 | ---
6 |
7 | ## Chunky PNG
8 |
9 |
10 |
11 | ### Loading
12 |
13 | ```ruby
14 | image = ChunkyPNG::Image.from_file('file.png')
15 | ```
16 |
17 | #### Alternate ways
18 |
19 | ```ruby
20 | image = ChunkyPNG::Image.from_blob(File.read('file.png'))
21 | image = ChunkyPNG::Image.from_io(io)
22 | ```
23 |
24 | Loads from `file.png`.
25 |
26 | ### Saving
27 |
28 | ```ruby
29 | image.save('filename.png')
30 | ```
31 |
32 | #### Alternate ways
33 |
34 | ```ruby
35 | File.open('newfile.png', 'wb') { |io| image.write(io) }
36 | binary_string = image.to_blob
37 | ```
38 |
39 | Writes an image to `newfile.png`.
40 |
41 | ### Drawing
42 |
43 | ```ruby
44 | image[0, 0] = ChunkyPNG::Color.rgba(255, 0,0, 128)
45 | image.line(1, 1, 10, 1, ChunkyPNG::Color.from_hex('#aa007f'))
46 | ```
47 |
48 | ### Canvas
49 |
50 | ```ruby
51 | crop(x, y, w, h)
52 | ```
53 |
54 | ### Transforms
55 |
56 | ```ruby
57 | new_image = image.flip_horizontally.rotate_right
58 | ```
59 |
--------------------------------------------------------------------------------
/sheets/nodejs-process.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: process
3 | category: Node.js
4 | ---
5 |
6 | ### Streams
7 |
8 | ```js
9 | process.stdout.write('...')
10 | process.stderr.write('...')
11 | process.stdin.read()
12 | ```
13 |
14 | ### Reading from stdin
15 |
16 | ```js
17 | function stdin(fn) {
18 | var data = ''
19 |
20 | process.stdin.setEncoding('utf8')
21 | process.stdin.on('readable', function() {
22 | var chunk = process.stdin.read()
23 | if (chunk !== null) data += chunk
24 | })
25 |
26 | process.stdin.on('end', function() {
27 | fn(null, data)
28 | })
29 | }
30 | ```
31 |
32 | ### stuff
33 |
34 | ```js
35 | process.argv
36 | // => ['node', 'file.js', 'one', 'two']
37 | ```
38 |
39 | ```js
40 | process.env
41 | // => {TERM: 'screen-256color', SHELL: '/bin/bash', ...}
42 | ```
43 |
44 | ```js
45 | process.exit()
46 | process.exit(1)
47 | ```
48 |
49 | ### Directories
50 |
51 | ```js
52 | process.cwd()
53 | // => "/tmp"
54 | ```
55 |
56 | ```js
57 | process.chdir('dir')
58 | ```
59 |
60 | ### References
61 |
62 | -
63 |
--------------------------------------------------------------------------------
/sheets/vimscript-snippets.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vimscript snippets
3 | category: Vim
4 | ---
5 |
6 | ### Bind function to key and command
7 |
8 | ```vim
9 | command! YoFunctionHere call s:YoFunctionHere()
10 | nnoremap x :call FunctionHere()
11 |
12 | function! s:FunctionHere()
13 | " ...do something here
14 | endfunction
15 | ```
16 |
17 | ### Call a function in insert mode
18 |
19 | ```vim
20 | inoremap X =script#myfunction()
21 | inoremap =MyVimFunc()?'':''
22 | ```
23 |
24 | ### Checking plugins
25 |
26 | ```
27 | if globpath(&rtp, "plugin/commentary.vim") != ""
28 | ```
29 |
30 | Checks if there's a `plugin/commentary.vim` in the runtime path.
31 |
32 | ### Autoload
33 |
34 | ```vim
35 | " autoload/hello.vim
36 | if exists("g:hello_loaded") | finish | endif
37 | let g:hello_loaded=1
38 |
39 | function hello#method()
40 | endfunction
41 | ```
42 |
43 | Calling `hello#method()` will load autoload the script.
44 |
45 | ### Version checking
46 |
47 | ```vim
48 | if version < 704
49 | echom "requires vim >= 7.4"
50 | endif
51 | ```
52 |
--------------------------------------------------------------------------------
/sheets/machinist.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Machinist
3 | category: Ruby libraries
4 | ---
5 |
6 | ### Installing
7 |
8 | # Gemfile
9 | gem 'machinist', '>= 2.0.0.beta2', group: 'test'
10 |
11 | # ~$ bundle
12 | # ~$ rails generate machinist:install
13 |
14 | ### Building objects
15 |
16 | User.make
17 |
18 | # `make` builds it, and `make!` builds+saves it
19 | User.make!
20 | User.make! name: "David"
21 | User.make!(:admin)
22 |
23 | ### Defining blueprints
24 |
25 | User.blueprint do
26 | name { "User #{sn}" }
27 | email { "user-#{sn}@example.com" }
28 | end
29 |
30 | User.blueprint(:admin) do
31 | name { "Admin User #{sn}" }
32 | admin { true }
33 | end
34 |
35 | ### Associations
36 |
37 | Post.blueprint do
38 | author { User.make }
39 |
40 | comments(3) # Makes 3 comments (has_many / habtm)
41 |
42 | author # autodetect (Assumes there's User.blueprint)
43 |
44 | end
45 |
46 | ### References
47 |
48 | * [https://github.com/notahat/machinist](https://github.com/notahat/machinist)
49 |
--------------------------------------------------------------------------------
/sheets/google_analytics.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Google Analytics
3 | ---
4 |
5 | ### Pageview
6 |
7 | // Analytics.js
8 | ga('create', 'UA-XXXX-Y', 'auto');
9 | ga('send', 'pageview');
10 |
11 | ### Track events
12 |
13 | // ga.js
14 | // [..., category, action, label, value (int), noninteraction (bool)]
15 | _gaq.push(['_trackEvent', 'Videos', 'Play', 'Birthday video', true])
16 | _gaq.push(['_trackEvent', 'Projects', 'Donate', 'Project name'])
17 | _gaq.push(['_trackEvent', 'Accounts', 'Login'])
18 |
19 | // Analytics.js
20 | // , , category, action, label, value (int)
21 | ga('send', 'event', 'button', 'click', 'nav buttons', 4);
22 |
23 | ### Variables
24 |
25 | // [..., index, name, value, scope (optional)]
26 | _gaq.push(['_setCustomVar', 1, 'Logged in', 'Yes', 2]);
27 |
28 | // Scope = 1 (visitor), 2 (session), 3 (page, default)
29 |
30 | https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables
31 | https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
32 |
--------------------------------------------------------------------------------
/sheets/js-appcache.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: applicationCache
3 | category: JavaScript
4 | layout: 2017/sheet
5 | tags: [Deprecated]
6 | ---
7 |
8 | ## Reference
9 |
10 |
11 |
12 | ### applicationCache checking
13 |
14 | ```js
15 | if (window.applicationCache) {
16 | // "Naturally" reload when an update is available
17 | var reload = false
18 |
19 | window.applicationCache.addEventListener(
20 | 'updateready',
21 | () => {
22 | if (
23 | window.applicationCache.status === window.applicationCache.UPDATEREADY
24 | ) {
25 | window.applicationCache.swapCache()
26 | reload = true
27 | }
28 | },
29 | false
30 | )
31 |
32 | setInterval(() => {
33 | try {
34 | // There's nothing to update for first-time load, browser freaks out :/
35 | window.applicationCache.update()
36 | } catch (e) {}
37 | }, 1000 * 60 * 60) // Every hour
38 | }
39 | ```
40 |
41 | This is a deprecated HTML feature. See: [Using the application cache](https://developer.mozilla.org/en-US/docs/HTML/Using_the_application_cache) _(developer.mozilla.org)_
42 |
--------------------------------------------------------------------------------
/sheets/rst.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: ReStructuredText
3 | category: Markup
4 | ---
5 |
6 | ### Comments
7 |
8 | ```rst
9 | .. @theme 2010
10 | .. include:: ../themes/2010/common.rst
11 | .. contents::
12 | .. |substitute| replace:: replacement name
13 | ```
14 |
15 | ### Headings
16 |
17 | ```rst
18 | Heading
19 | =======
20 | ```
21 |
22 | ```rst
23 | .. class:: brief
24 |
25 | Hello there. |substitute| **This is bold**
26 | ```
27 |
28 | ```rst
29 | - Bullet list with a link_ (or `link with words`_)
30 | - Yes
31 |
32 | .. _link: http://link.org
33 | ```
34 |
35 | ### PDF page break
36 |
37 | ```rst
38 | .. raw:: pdf
39 |
40 | PageBreak oneColumn
41 | ```
42 |
43 | ### Link targets
44 |
45 | ```rst
46 | Internal link target_.
47 |
48 | .. _target:
49 |
50 | This is where _target will end up in.
51 | ```
52 |
53 | ### Tables (?)
54 |
55 | ```rst
56 | .. class:: hash-table
57 |
58 | .. list-table::
59 |
60 | * - :key:`Cuisine:`
61 | - :val:`French/fusion`
62 | * - :key:`Number of ingredients:`
63 | - :val:`8`
64 | * - :key:`Preparation time:`
65 | - :val:`30 hours`
66 | ```
67 |
--------------------------------------------------------------------------------
/sheets/spreadsheet.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Spreadsheet functions
3 | ---
4 |
5 | ### If
6 |
7 | ```
8 | =IF(test, then, else)
9 | =IF(EQ(A1, "paid"), "true", "false")
10 | ```
11 |
12 | ### Comparators
13 |
14 | | Expression | Description |
15 | | ----------- | --------------------- |
16 | | `=EQ(a,b)` | Equal |
17 | | `=NE(a,b)` | Not equal |
18 | | | |
19 | | `=GT(a,b)` | Greater than |
20 | | `=GTE(a,b)` | Greater than or equal |
21 | | | |
22 | | `=LT(a,b)` | Less than |
23 | | `=LTE(a,b)` | Less than or equal |
24 |
25 | ### Math
26 |
27 | ```
28 | =POW(2, 32) # 2^32
29 | =SIN() ACOS() etc
30 | =CEILING(n,sig,mode)
31 | =FLOOR(n,sig,mode)
32 | =INT(n)
33 | ```
34 |
35 | ```
36 | =SUM(range)
37 | ```
38 |
39 | ```
40 | =SUMIF(range, criteria, sum_range)
41 | =SUMIF(A1:A5, ">300", B1:B5) # if A# is >300, use B#
42 | ```
43 |
44 | ### Core
45 |
46 | ```
47 | =TO_DATE(number)
48 | ```
49 |
50 | ### Vlook
51 |
52 | ```
53 | =VLOOKUP(value, range, column_index)
54 | ```
55 |
--------------------------------------------------------------------------------
/sheets/mocha-html.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Mocha HTML
3 | category: JavaScript libraries
4 | ---
5 |
6 | This is a mocha template that loads js/css from cdn.
7 |
8 | ```html
9 |
10 |
11 |
12 |
13 | Mocha
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | ```
32 |
--------------------------------------------------------------------------------
/sheets/browserify.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Browserify
3 | category: JavaScript libraries
4 | ---
5 |
6 | ### Options
7 |
8 | ```bash
9 | browserify input.js
10 | -o output.js
11 | -t coffeeify
12 | -t [ coffeeify --extension coffee ]
13 | --debug
14 | ```
15 |
16 | ```bash
17 | -u react # --exclude: omit a file
18 | -x react # --external: reference in another bundle
19 | -i react # --ignore: stub a file
20 | -s Myapp # --standalone: generate a UMD bundle
21 | ```
22 |
23 | ### Programmatic usage
24 |
25 | ```js
26 | browserify = require('browserify')
27 | browserify()
28 | .add('main.js')
29 | .bundle()
30 | .transform(coffeeify)
31 | .transform({ extensions: '.coffee' }, coffeeify)
32 | .pipe(process.stdout)
33 |
34 | browserify({})
35 | ```
36 |
37 | ### Tools
38 |
39 | * watchify _(recompiles on demand)_
40 | * beefy _(http server)_
41 | * debowerify
42 | * es6ify _(es6 to es5)_
43 |
44 | ### Transforms
45 |
46 | * coffeeify
47 | * ractify
48 | * reactify
49 | * brfs
50 | * cssify
51 |
52 | See: [List of Transforms](https://github.com/substack/node-browserify/wiki/list-of-transforms) _(github.com)_
53 |
--------------------------------------------------------------------------------
/sheets/make-assets.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Make for assets
3 | hljs_languages: [makefile]
4 | ---
5 |
6 | ## Basic compiling
7 |
8 | ```makefile
9 | bin := ./node_modules/.bin
10 |
11 | all: build/foo.js
12 |
13 | build/%.js: src/%.coffee
14 | @$(bin)/coffee < $^ > $@
15 | ```
16 |
17 | ## Stylus + Autoprefixer
18 |
19 | bin := ./node_modules/.bin
20 | stylus := $(bin)/stylus
21 | autoprefixer := $(bin)/autoprefixer
22 | styl_files := $(shell find web/ -name "*.styl")
23 |
24 | all: public/app.css
25 |
26 | public/app.css: css/app.styl
27 |
28 | %.css: %.styl $(styl_files)
29 | @$(stylus) $< | $(autoprefixer) -b "> 1%" > $@
30 |
31 | ## Hint
32 |
33 | hint:
34 | $(js_files)
35 |
36 | ## Watching
37 |
38 | watch:
39 | @echo "... watching for changes"
40 | @while true; do make -s; sleep 1; done
41 |
42 | ## Browserify
43 |
44 | js_files := $(shell find web/ -name "*.js")
45 |
46 | public/app.js: web/app.js
47 | public/vendor.js: web/vendor.js
48 |
49 | public/%.js: web/%.js $(js_files)
50 | $(browserify) -t [ cssify -x .css ] $< > $@
51 |
--------------------------------------------------------------------------------
/sheets/vows.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vows
3 | category: JavaScript libraries
4 | ---
5 |
6 | ### CoffeeScript usage
7 |
8 | ```coffee
9 | vows = require "vows"
10 | assert = require "assert"
11 |
12 | vows
13 | .describe('My tests')
14 | .addBatch
15 | 'context':
16 | topic: ->
17 | 100
18 | 'should work': (number) ->
19 | assert.equal number, 100
20 |
21 | .export(module)
22 | ```
23 |
24 | ### Running
25 |
26 | ```bash
27 | vows test/*-test.* --spec
28 | ```
29 |
30 | ### Assertions
31 |
32 | ```js
33 | assert.equal(a, b)
34 | assert.notEqual(a, b)
35 | assert.strictEqual(a, b)
36 | ```
37 |
38 | ```js
39 | assert.isNaN(number)
40 | assert.instanceOf(object, klass)
41 | assert.isUndefined(object)
42 | assert.isFunction(func)
43 | assert.isNull(object)
44 | assert.isNotZero(object)
45 | assert.isObject(object)
46 | assert.isString(object)
47 | ```
48 |
49 | ### Async
50 |
51 | ```coffee
52 | vows
53 | .addBatch
54 | topic: ->
55 | doStuff()
56 | @callback 2
57 | 'check things': (n) ->
58 | assert.equal 2, n
59 | ```
60 |
61 | ### References
62 |
63 | * [Vowsjs.org](http://vowsjs.org/)
64 |
--------------------------------------------------------------------------------
/sheets/postgresql.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: PostgreSQL
3 | ---
4 |
5 | ## PostgreSQL
6 |
7 |
8 |
9 | ### Console
10 |
11 | ```sh
12 | psql
13 | ```
14 |
15 | ### Commands
16 |
17 | | Command | Description |
18 | | ------------- | ---------------------- |
19 | | `\du` | Show roles |
20 | | `\dt` | Show tables |
21 | | `\l` | Show databases |
22 | | `\c` | Connect to a database |
23 | | | |
24 | | `\d ` | Show columns |
25 | | `\d+ ` | Show columns (verbose) |
26 | | | |
27 | | `\q` | Quit |
28 |
29 | These are commands in `psql`. Replace anything within `` accordingly.
30 |
31 | ### Managing databases
32 |
33 | | Command | Description |
34 | | ------------------- | --------------- |
35 | | `createdb ` | Create database |
36 | | `dropdb ` | Drop database |
37 | | | |
38 | | `createuser ` | Create a user |
39 |
40 | These are shell commands.
41 |
--------------------------------------------------------------------------------
/sheets/nopt.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Nopt
3 | category: JavaScript libraries
4 | ---
5 |
6 | ### Basic example
7 |
8 | ```js
9 | var args = require('nopt')({
10 | foo: [String, null],
11 | size: ['big', 'medium', 'small'],
12 | many: [String, Array],
13 | debug: Boolean,
14 | version: Boolean,
15 | help: Boolean
16 | }, {
17 | h: '--help',
18 | v: '--version'
19 | }, process.argv);
20 |
21 | args == {
22 | debug: true,
23 | version: true,
24 | size: 'big',
25 | argv: {
26 | remain: ['...', '...'],
27 | cooked: /* ... */,
28 | original: /* ... */
29 | }
30 | }
31 | ```
32 |
33 | ### Example (continued)
34 |
35 | ```js
36 | if (args.help) {
37 | console.log(
38 | [
39 | 'Usage:',
40 | ' hicat [options] [file]',
41 | '',
42 | 'Options:',
43 | ' -h, --help print usage information',
44 | ' -v, --version show version info and exit'
45 | ].join('\n')
46 | )
47 | process.exit(0)
48 | }
49 |
50 | if (args.version) {
51 | console.log(require('../package.json').version)
52 | process.exit(0)
53 | }
54 | ```
55 |
56 | ### References
57 |
58 | -
59 |
--------------------------------------------------------------------------------
/sheets/parsimmon.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Parsimmon
3 | category: JavaScript libraries
4 | ---
5 |
6 | ### Basic usage
7 |
8 | ```js
9 | const P = require('parsimmon')
10 |
11 | P.regexp(/[a-z]+/).parse('hello')
12 | //=> { status: true, value: ['hello'] }
13 | ```
14 |
15 | ### Atoms
16 |
17 | ```js
18 | P.regexp(/[a-z]+/)
19 | P.string('hello')
20 | P.oneOf('abc') // like P.regexp(/[abc]/)
21 |
22 | P.whitespace
23 | P.optWhitespace
24 | P.eof
25 | ```
26 |
27 | ## Combinators
28 |
29 | ```js
30 | P.seq(a, b, c) // sequence of these
31 | P.alt(a, b) // any of these
32 | P.sepBy(a, P.string(',')) // sequence of `a`, separated by ','
33 | P.sepBy1(a, P.string(',')) // same, at least once
34 |
35 | a.or(b) // like P.alt(a, b)
36 | a.skip(b) // parses `b` but discards it
37 |
38 | a.many()
39 | a.times(3)
40 | a.times(1, 4) // 1 <= x <= 4
41 | a.atMost(10)
42 | a.atLeast(10)
43 | ```
44 |
45 | ### Formatting
46 |
47 | ```js
48 | P.seq(P.number, P.oneOf('+-*/'), P.number).map(([left, oper, right]) => ({
49 | oper,
50 | left,
51 | right
52 | }))
53 | ```
54 |
55 | ## Reference
56 |
57 | * [API reference](https://github.com/jneen/parsimmon/blob/master/API.md) _(github.com)_
58 |
--------------------------------------------------------------------------------
/sheets/deis.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Deis
3 | category: Devops
4 | layout: 2017/sheet
5 | ---
6 |
7 | ### Deploy
8 |
9 | ```
10 | deis create app-name
11 | git push deis master
12 | deis open
13 | ```
14 |
15 | ### Deploy dockerfile
16 |
17 | ```sh
18 | $ deis create app-name
19 | $ deis pull redis:latest
20 | Creating build... done, v2
21 | # default process type is `cmd`
22 | ```
23 |
24 | ### Config
25 |
26 | ```
27 | deis config:list
28 | deis config:set FOO=bar BAZ=foo
29 | deis config:unset FOO
30 | deis config:pull # writes to .env
31 | deis config:push # reads from .env
32 | ```
33 |
34 | ### Managing instances
35 |
36 | ```
37 | deis logs
38 | deis run rake db:migrate
39 | deis ps
40 | ```
41 |
42 | ### Custom domains
43 |
44 | ```
45 | deis domains:list
46 | deis domains:add www.myapp.com
47 | deis domains:remove www.myapp.com
48 | ```
49 |
50 | ### Limits
51 |
52 | ```sh
53 | deis limits:set web=1G
54 | deis limits:set web=1024 --cpu
55 | # (`web` is a process type)
56 | ```
57 |
58 | ### Sharing
59 |
60 | ```
61 | deis perms:create otheruser
62 | ```
63 |
64 | ### SSL
65 |
66 | ```
67 | deis certs:add server.crt server.key
68 | ```
69 |
70 | See: [SSL](http://docs.deis.io/en/latest/using_deis/app-ssl/)
71 |
--------------------------------------------------------------------------------
/sheets/css-system-font-stack.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: "CSS system fonts"
3 | category: CSS
4 | layout: 2017/sheet
5 | weight: -3
6 | tags: [Featurable]
7 | ---
8 |
9 | ### System fonts
10 |
11 | ```css
12 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
13 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
14 | ```
15 |
16 | This uses whatever system font is available. See: [System shock - Designing Medium](https://medium.design/system-shock-6b1dc6d6596f?gi=90078e194544) _(medium.com)_
17 |
18 | ### Explanation
19 |
20 | | Font | OS |
21 | | -------------------- | ----------------------- |
22 | | `-apple-system` | OS X (10.11+), iOS (9+) |
23 | | `BlinkMacSystemFont` | OS X, Chrome |
24 | | `Segoe UI` | Windows |
25 | | `Roboto` | Android 4.0+ |
26 | | `Oxygen` | Linux, KDE |
27 | | `Ubuntu` | Linux, Ubuntu |
28 | | `Cantarell` | Linux, GNOME |
29 | | `Fira Sans` | Firefox OS |
30 | | `Droid Sans` | Android (until 3.2) |
31 | | `Helvetica Neue` | OS X (10.9) |
32 |
--------------------------------------------------------------------------------
/sheets/ledger-examples.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Ledger examples
3 | category: Ledger
4 | ---
5 |
6 | Inspecting transactions:
7 |
8 | # show me expenses for october (--period)
9 | ledger r Expenses -p oct
10 |
11 | # what's the most expensive? (--sorted)
12 | ledger r Expenses -S amount --tail 10
13 |
14 | # how much was spent on grocery? (--weekly, --monthly)
15 | ledger r Grocery
16 | ledger r Grocery -W
17 | ledger r Grocery -M
18 |
19 | # what did I spend my Mastercard on? (--period, --begin, --end)
20 | ledger r mastercard
21 | ledger r mastercard -p "january"
22 | ledger r mastercard -b 01/25 -e 01/31
23 |
24 | Graphing:
25 |
26 | # Graph my bank account balance, monthly
27 | ledger r Savings -M
28 |
29 | # Graph my expenses, monthly (-n = --collapse)
30 | ledger r Expenses -M -n
31 |
32 | # ...what's the average per month?
33 | ledger r Expenses -M -n --average
34 |
35 | Simple:
36 |
37 | # what did I do yesterday?
38 | # ..list transactions on this day
39 | ledger r -p 01/26
40 | ledger r -p yesterday
41 |
42 | Switches:
43 |
44 | # what's everything I got in USD? (--exchange)
45 | ledger b Assets -X USD
46 |
--------------------------------------------------------------------------------
/sheets/promise.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Promises
3 | category: JavaScript
4 | ---
5 |
6 | Based on the [Promise API reference][promise] (mozilla.org).
7 | {:.brief-intro.center}
8 |
9 | [promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
10 |
11 | ### Creating promises
12 |
13 | ```js
14 | new Promise(function(ok, err) {
15 | doStuff(function() {
16 | if (success) {
17 | ok()
18 | } else {
19 | err()
20 | }
21 | })
22 | })
23 | ```
24 |
25 | ### Consuming promises
26 |
27 | ```js
28 | promise.then(okFn, errFn).catch(errFn)
29 | ```
30 |
31 | ### Multiple promises
32 |
33 | ```js
34 | var promises = [
35 | promise1(), promise2(), ...
36 | ]
37 |
38 | // succeeds when all succeed
39 | Promise.all(promises)
40 | .then(function (results) {
41 | });
42 |
43 | // succeeds when one finishes first
44 | Promise.race(promises)
45 | .then(function (result) {
46 | });
47 | ```
48 |
49 | ### Converting other promises
50 |
51 | ```js
52 | return Promise.resolve("result");
53 | return Promise.resolve(promise);
54 | return Promise.resolve(thenable);
55 |
56 | return Promise.reject("reason");
57 |
58 | Promise.resolve($.get('http://google.com'))
59 | .then(...)
60 | ```
61 |
--------------------------------------------------------------------------------
/sheets/ledger-format.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Ledger format
3 | category: Ledger
4 | ---
5 |
6 | ```
7 | 2015/01/01 Pay rent
8 | Assets:Savings -$300
9 | Expenses:Rent
10 | ```
11 |
12 | ### First line
13 |
14 | ```
15 | 2015/01/01 * Pay rent ; tagname:
16 | ^ ^ ^
17 | Date Flag Description ^ comment/tag
18 | ```
19 |
20 | ### Balance assertion
21 |
22 | ```
23 | 2015/01/01 Pay rent
24 | Assets:Savings -$300 = $1200 ; assert there's $1200 left after
25 | Expenses:Rent
26 | ```
27 |
28 | Flags:
29 |
30 | ```
31 | * cleared
32 | ! pending
33 | ```
34 |
35 | ## Accounts
36 |
37 | Only relevant with `--strict` or `--pedantic`
38 |
39 | ```
40 | account Expenses:Food
41 | note This account is all about the chicken!
42 | alias food
43 | payee ^(KFC|Popeyes)$
44 | check commodity == "$"
45 | assert commodity == "$"
46 | eval print("Hello!")
47 | default
48 | ```
49 |
50 | ## Others
51 |
52 | ```
53 | D $1,000.00 ; set default commodity
54 |
55 | alias Cash = Assets:Cash
56 |
57 | Y2015 ; set default year (you can use 01/25 as date after)
58 | ```
59 |
60 | ### Prefix all transactions with an account
61 |
62 | ```
63 | account Home
64 | include home.journal
65 | end
66 | ```
67 |
--------------------------------------------------------------------------------
/sheets/js-lazy.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: JavaScript lazy shortcuts
3 | category: JavaScript
4 | layout: 2017/sheet
5 | ---
6 |
7 | ## Shortcuts
8 |
9 |
10 |
11 | ### Examples
12 |
13 | ```js
14 | n = +'4096' // n === 4096
15 | s = '' + 200 // s === '200'
16 | ```
17 |
18 | ```js
19 | now = +new Date()
20 | isPublished = !!post.publishedAt
21 | ```
22 |
23 | ### Shortcuts
24 |
25 | | What | Lazy mode | "The right way" |
26 | | ---------------------- | ---------------------- | --------------------------------------- |
27 | | String to number | `+str` | `parseInt(str, 10)` _or_ `parseFloat()` |
28 | | Math floor | `num | 0` | `Math.floor(num)` |
29 | | Number to string | `'' + num` | `num.toString()` |
30 | | Date to UNIX timestamp | `+new Date()` | `new Date().getTime()` |
31 | | Any to boolean | `!!value` | `Boolean(value)` |
32 | | Check array contents | `if (~arr.indexOf(v))` | `if (arr.includes(v))` |
33 |
34 |
35 |
36 | `.includes` is ES6-only, otherwise use `.indexOf(val) !== -1` if you don't polyfill.
37 |
--------------------------------------------------------------------------------
/sheets/web-workers.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Web workers
3 | category: JavaScript
4 | updated: 2017-10-30
5 | layout: 2017/sheet
6 | weight: -1
7 | ---
8 |
9 | ## Web workers
10 |
11 | #### Client
12 |
13 | ```js
14 | var worker = new Worker('worker.js')
15 |
16 | worker.onmessage = function (message) {
17 | alert(JSON.stringify(message.data))
18 | })
19 |
20 | worker.postMessage('hello!')
21 | ```
22 |
23 | Messages can be anything that can be serialized into JSON (objects, arrays, strings, numbers, booleans). See: [structured clone](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
24 |
25 | #### Worker
26 |
27 | ```js
28 | self.onmessage = function (message) {
29 | ···
30 | }
31 |
32 | self.postMessage({ msg: 'hello' })
33 | ```
34 |
35 | ### Message data
36 |
37 | #### [MessageEvent]
38 |
39 | ```js
40 | bubbles: false
41 | cancelBubble: false
42 | cancelable: false
43 | clipboardData: undefined
44 | currentTarget: Worker
45 | data: "Hello" ← the data
46 | defaultPrevented: false
47 | eventPhase: 0
48 | lastEventId: ""
49 | origin: ""
50 | ports: Array[0]
51 | returnValue: true
52 | source: null
53 | srcElement: Worker
54 | target: Worker
55 | timeStamp: 1344821022383
56 | type: "message"
57 | ```
58 |
59 | These are the contents of `message` on onmessage.
60 |
--------------------------------------------------------------------------------
/sheets/cron.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Cron
3 | category: CLI
4 | layout: 2017/sheet
5 | updated: 2017-08-26
6 | weight: -3
7 | ---
8 |
9 | ## Format
10 |
11 |
12 |
13 | ### Format
14 |
15 | ```
16 | Min Hour Day Mon Weekday
17 | ```
18 |
19 |
20 |
21 | ```
22 | * * * * * command to be executed
23 | ```
24 |
25 | ```
26 | ┬ ┬ ┬ ┬ ┬
27 | │ │ │ │ └─ Weekday (0=Sun .. 6=Sat)
28 | │ │ │ └────── Month (1..12)
29 | │ │ └─────────── Day (1..31)
30 | │ └──────────────── Hour (0..23)
31 | └───────────────────── Minute (0..59)
32 | ```
33 |
34 |
35 |
36 | ### Examples
37 |
38 | | Example | Description |
39 | | -------------- | --------------------- |
40 | | `0 * * * *` | every hour |
41 | | `*/15 * * * *` | every 15 mins |
42 | | `0 */2 * * *` | every 2 hours |
43 | | `0 0 * * 0` | every Sunday midnight |
44 | | --- | --- |
45 | | `@reboot` | every reboot |
46 |
47 | ### Crontab
48 |
49 | ```bash
50 | # Adding tasks easily
51 | echo "@reboot echo hi" | crontab
52 | ```
53 |
54 | ```bash
55 | # Open in editor
56 | crontab -e
57 | ```
58 |
59 | ```bash
60 | # List tasks
61 | crontab -l [-u user]
62 | ```
63 |
--------------------------------------------------------------------------------
/sheets/jscoverage.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: jscoverage
3 | category: JavaScript libraries
4 | layout: 2017/sheet
5 | intro: |
6 | A small guide into installing [jscoverage](https://npmjs.com/package./jscoverage). Also see [mocha-blanket](./mocha-blanket).
7 | ---
8 |
9 | ### Install
10 |
11 | #### Install via npm
12 |
13 | ```bash
14 | npm install --save-dev jscoverage
15 | ```
16 |
17 | #### Ignore output
18 |
19 | ```bash
20 | echo coverage.html >> .gitignore
21 | ```
22 |
23 | ### package.json
24 |
25 | The `coverage` task injects your source files (`lib`) with jscoverage hooks, runs `mocha -R html-cov`, then restores later.
26 |
27 |
28 |
29 | ```bash
30 | /* directory */
31 | "coverage": "mv lib lib~; (jscoverage lib~ lib; mocha -R html-cov > coverage.html); rm -rf lib; mv lib~ lib"
32 | ```
33 |
34 |
35 |
36 | ```bash
37 | /* single file */
38 | "coverage": "(cp index.js index.js~; jscoverage index.js; mv index-cov.js index.js; mocha -R html-cov > coverage.html); mv index.js~ index.js"
39 | ```
40 |
41 |
42 |
43 | ### Run
44 |
45 | ```bash
46 | npm run coverage
47 | ```
48 |
49 | ```bash
50 | open coverage.html
51 | ```
52 |
53 | ### Caveats
54 |
55 | If you're using jsdom, be sure to expose the `window._$jscoverage` variable into
56 | the `global` scope.
57 |
--------------------------------------------------------------------------------
/sheets/mocha-tdd.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Mocha.js TDD interface
3 | category: JavaScript libraries
4 | updated: 2018-12-24
5 | ---
6 |
7 | ### TDD
8 |
9 | ```js
10 | mocha.setup('tdd')
11 |
12 | suite('something', () => {
13 | setup(() => {
14 | /* ... */
15 | })
16 |
17 | test('should work', () => {
18 | /* ... */
19 | })
20 |
21 | teardown(() => {
22 | /* ... */
23 | })
24 | })
25 | ```
26 |
27 | ### Async
28 |
29 | #### Using callbacks
30 |
31 | ```js
32 | test('should save', done => {
33 | var user = new User()
34 | user.save(err => {
35 | if (err) throw err
36 | done()
37 | })
38 | })
39 | ```
40 |
41 | #### Using callbacks
42 |
43 | ```js
44 | test('should save', () => {
45 | return new Promise((resolve, reject) => {
46 | /* ... */
47 | })
48 | })
49 | ```
50 |
51 | ### Chai: Expect
52 |
53 | ```js
54 | const expect = chai.expect
55 | ```
56 |
57 | ```js
58 | expect(foo).to.be.a('string')
59 | expect(foo).to.equal('bar')
60 | expect(foo).to.have.length(3)
61 | ```
62 |
63 | ```js
64 | expect(tea)
65 | .to.have.property('flavors')
66 | .with.length(3)
67 | ```
68 |
69 | Also see the [Chai](./chai) cheatsheet.
70 |
71 | ### See also
72 |
73 | - [Mocha BDD](./mocha)
74 | - [Mocha HTML](./mocha-html)
75 | - [Chai](./chai)
76 | - [Sinon](./sinon)
77 | - [Sinon Chai](./sinon-chai)
78 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | help:
2 | @echo
3 | @echo Makefile targets
4 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
5 | @echo
6 |
7 | SHEET_PATH := $(shell pwd -LP)/sheets
8 | PORT := 19400
9 | HOST := 0.0.0.0
10 |
11 | develop: devhints-engine ## Start development server [alias: dev]
12 | cd devhints-engine \
13 | && env SHEET_PATH=${SHEET_PATH} \
14 | yarn run gatsby develop --host ${HOST} --port ${PORT}
15 |
16 | develop-wip: devhints-engine ## Start development server, but only for wip/ [alias: wip]
17 | cd devhints-engine \
18 | && env SHEET_PATH=${SHEET_PATH}/wip \
19 | yarn run gatsby develop --host ${HOST} --port ${PORT}
20 |
21 | # Build
22 | build: public ## Build public/ for deployment
23 | public: devhints-engine
24 | cd devhints-engine \
25 | && env SHEET_PATH=${SHEET_PATH} yarn run build
26 | rm -rf ./public
27 | mv devhints-engine/public ./public
28 | echo "next.devhints.io" > public/CNAME
29 |
30 | devhints-engine: ## Update (or create) devhints-engine
31 | if [ ! -e devhints-engine ]; then \
32 | git clone https://github.com/rstacruz/devhints-engine.git -b master; fi
33 | cd devhints-engine && git pull origin master
34 | cd devhints-engine && yarn
35 |
36 | dev: develop
37 | wip: develop-wip
38 | .PHONY: devhints-engine dev
39 |
--------------------------------------------------------------------------------
/sheets/bundler.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Bundler
3 | category: Ruby
4 | ---
5 |
6 | ### Commands
7 |
8 | bundle # same as bundle install
9 | bundle install # installs gems
10 | bundle install -j3 # faster (3 jobs)
11 | bundle update # update all gems
12 | bundle update --source gemname # update specified gem
13 |
14 | bundle outdated # show outdated gems
15 | cd `bundle show rails` # inspect a gem's dir
16 |
17 | bundle gem # new gem skeleton
18 |
19 | ### Gems
20 |
21 | gem 'hello'
22 | gem 'hello', group: 'development'
23 |
24 | ### Github support
25 |
26 | gem 'hello', github: 'rstacruz/hello'
27 | gem 'hello', github: 'rstacruz/hello', 'branch: master'
28 |
29 | ### Grouping
30 |
31 | group :development do
32 | gem 'hello'
33 | end
34 |
35 | ### Deployment
36 |
37 | $ bundle install --without=test,development --deployment
38 |
39 | ### Local gem development
40 |
41 | In your Gemfile, define a Git source and a branch:
42 |
43 | gem 'hello', github: 'rstacruz/hello', branch: 'master'
44 |
45 | And then:
46 |
47 | $ bundle config --global local.xxx ~/projects/xxx
48 |
49 | ### Rake Gem tasks
50 |
51 | # Rakefile
52 | require 'bundler/gem_tasks'
53 |
54 | Terminal:
55 |
56 | $ rake release
57 | $ rake build
58 |
--------------------------------------------------------------------------------
/sheets/deku.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Deku v2
3 | category: JavaScript libraries
4 | ---
5 |
6 | ## Components
7 |
8 | ```js
9 | /** @jsx element */
10 | import { element } from 'deku'
11 |
12 | function render ({ props, children, context, path }) {
13 | // props = properties object
14 | // children = children array
15 | // path = path to current component (like 0.1.5.2)
16 | // context = common properties in all components
17 | return (
18 |
19 | {children}
20 |
21 | }
22 | }
23 |
24 | function onCreate ({ props, dispatch, path }) { ... }
25 | function onUpdate ({ props, dispatch, path }) { ... }
26 | function onRemove ({ props, dispatch, path }) { ... }
27 | // actually { children, props, path, context }
28 |
29 | export default { render, onCreate, onRemove }
30 | ```
31 |
32 | ## Rendering
33 |
34 | ```js
35 | import { createStore } from 'redux'
36 | import { dom, element } from 'deku'
37 |
38 | // Create a Redux store to handle all UI actions and side-effects
39 | let store = createStore(reducer)
40 |
41 | // Create a renderer that can turn vnodes into real DOM elements
42 | let render = createRenderer(document.body, store.dispatch)
43 |
44 | // Update the page and add redux state to the context
45 | render(Hello World!, store.getState())
46 | ```
47 |
--------------------------------------------------------------------------------
/sheets/nodejs.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Node.js API
3 | category: Node.js
4 | ---
5 |
6 | ## Globals
7 |
8 | __filename
9 | __dirname
10 |
11 | ### exec
12 |
13 | var exec = require('child_process').exec,
14 |
15 | var child = exec('cat *.js bad_file | wc -l',
16 | function (error, stdout, stderr) {
17 | console.log('stdout: ' + stdout);
18 | console.log('stderr: ' + stderr);
19 | if (error !== null) {
20 | console.log('exec error: ' + error);
21 | }
22 | });
23 |
24 | ## Snippets
25 |
26 | info = require('../package.json')
27 | info.version
28 |
29 | process.stdout.write(util.inspect(objekt, false, Infinity, true) + '\n');
30 |
31 | ## Spawn - passthru the in/out
32 |
33 | var spawn = require('child_process').spawn;
34 | var proc = spawn(bin, argv, { stdio: 'inherit' });
35 | proc.on('error', function(err) {
36 | if (err.code == "ENOENT") { "does not exist" }
37 | if (err.code == "EACCES") { "not executable" }
38 | });
39 | proc.on('exit', function(code) { ... });
40 |
41 | // also { stdio: ['pipe', 'pipe', process.stdout] }
42 | // also { stdio: [process.stdin, process.stderr, process.stdout] }
43 |
44 | proc.stdout.on('data', function (data) {
45 | });
46 | proc.stderr.on('data', function (data) {
47 | });
48 |
49 | [all]: http://nodejs.org/api/all.html
50 |
--------------------------------------------------------------------------------
/sheets/rails-tricks.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Rails tricks
3 | category: Rails
4 | ---
5 |
6 | in config/environments/development.rb:
7 |
8 | # Source maps for Sass
9 | config.sass.debug_info = true
10 | config.sass.line_comments = false
11 |
12 | # Don't break apart
13 | config.assets.debug = false
14 |
15 | Partial locals
16 |
17 | <%= render 'article', full: true %>
18 | <%= render 'article' %>
19 |
20 | <% if local_assigns[:full] %>
21 | ...
22 | <% end %>
23 |
24 | HTML in i18n
25 |
26 | en:
27 | read_more_html: "read more..."
28 |
29 | Exception handling:
30 |
31 | # config/application.rb
32 | config.exceptions_app = self.routes
33 |
34 | get '/404', to: 'errors#not_found'
35 | get '/500', to: 'errors#server_error'
36 |
37 | class ErrorsController
38 | def not_found
39 | render status: :not_found
40 | end
41 | end
42 |
43 | Rails updating:
44 |
45 | rake rails:update
46 |
47 | Distinct pluck:
48 |
49 | Article.distinct.pluck('author')
50 |
51 | Relation#merge
52 |
53 | scope :with_drafts, -> {
54 | uniq.joins(:articles).merge(Article.draft)
55 | }
56 |
57 | Order
58 |
59 | scope :recent, -> { order created_at: :desc }
60 |
61 | Group by month
62 |
63 | .group("to_char(created_at, 'YYYY-MM')")
64 | .group("to_char(created_at, 'YYYY-MM')").count
65 |
--------------------------------------------------------------------------------
/sheets/dom-range.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: DOM Range
3 | category: JavaScript
4 | ---
5 |
6 | ### Creating ranges
7 |
8 | See
9 |
10 | ```js
11 | var range = document.createRange()
12 | ```
13 |
14 | ## Methods
15 |
16 | See
17 |
18 | ```js
19 | range
20 | .setStart(startNode, startOffset)
21 | .setEnd(endNode, endOffset)
22 |
23 | .setStartBefore(node)
24 | .setStartAfter(node)
25 | .setEndBefore(node)
26 | .setEndAfter(node)
27 |
28 | .selectNode(node)
29 | .selectNodeContents(node)
30 | ```
31 |
32 | ### Collapsing
33 |
34 |
35 | ```js
36 | range
37 | .collapse() // to end (a single point)
38 | .collapse(true) // to start (a single point)
39 | .collapsed // true | false
40 | ```
41 |
42 | ### Operations
43 |
44 | ```js
45 | range
46 | .cloneContents() // copy => DocumentFragment
47 | .extractContents() // cut => DocumentFragment
48 | .deleteContents() // delete
49 |
50 | .insertNode(node)
51 | ```
52 |
53 | ### Etc
54 |
55 | ```js
56 | range.toString()
57 | ```
58 |
59 | ### Read-only attributes
60 |
61 |
62 | ```js
63 | range
64 | .collapsed /* true | false */
65 | .startContainer /* Node */
66 | .startOffset
67 | .endContainer /* Node */
68 | .endOffset
69 | .commonAncestorContainer /* closest of start and end containers */
70 | ```
71 |
--------------------------------------------------------------------------------
/sheets/git-branch.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Git branches
3 | category: Git
4 | layout: 2017/sheet
5 | updated: 2017-09-20
6 | ---
7 |
8 | ## Working with branches
9 |
10 |
11 |
12 | ### Creating
13 |
14 | ```bash
15 | git checkout -b $branchname
16 | git push origin $branchname --set-upstream
17 | ```
18 |
19 | Creates a new branch locally then pushes it.
20 |
21 | ### Getting from remote
22 |
23 | ```bash
24 | git fetch origin
25 | git checkout --track origin/$branchname
26 | ```
27 |
28 | Gets a branch in a remote.
29 |
30 | ### Delete local remote-tracking branches
31 |
32 | ```bash
33 | git remote prune origin
34 | ```
35 |
36 | Deletes `origin/*` branches in your local copy. Doesn't affect the remote.
37 |
38 | ### List existing branches
39 |
40 | ```bash
41 | git branch --list
42 | ```
43 |
44 | Existing branches are listed. Current branch will be highlighted with an asterisk.
45 |
46 | ### List merged branches
47 |
48 | ```bash
49 | git branch -a --merged
50 | ```
51 |
52 | List outdated branches that have been merged into the current one.
53 |
54 | ### Delete branch forcefully
55 |
56 | ```bash
57 | git branch -D $branchname
58 | ```
59 |
60 | Delete a branch irrespective of its merged status.
61 |
62 | ### Delete remote branch
63 |
64 | ```bash
65 | git push origin :$branchname
66 | ```
67 |
68 | Works for tags, too!
69 |
70 | ### Get current sha1
71 |
72 | ```bash
73 | git show-ref HEAD -s
74 | ```
75 |
--------------------------------------------------------------------------------
/sheets/meow.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Meow
3 | category: JavaScript libraries
4 | layout: 2017/sheet
5 | updated: 2017-10-30
6 | weight: -1
7 | intro: |
8 | [meow](https://npmjs.com/package/meow) is the easiest way to write command line apps for Node.js.
9 | ---
10 |
11 | ### Typical settings
12 |
13 | ```js
14 | const cli = require('meow')(
15 | `
16 | Usage: appname [options]
17 |
18 | Options:
19 | --lang LANG set the language
20 |
21 | Other options:
22 | -h, --help show usage information
23 | -v, --version print version info and exit
24 | `,
25 | {
26 | string: ['lang'],
27 | boolean: ['help', 'version'],
28 | alias: { h: 'help', v: 'version' }
29 | }
30 | )
31 | ```
32 |
33 | `string` and `boolean` lets meow/minimist know which flags expect arguments (`string`) and which don't (`boolean`).
34 |
35 | ### Using the result
36 |
37 | ```js
38 | cli.flags // { lang: 'en' }
39 | cli.input // []
40 | ```
41 |
42 | Yes, flags are automatically camelCased!
43 |
44 | ### Lesser-used settings
45 |
46 | ```js
47 | meow(`...`, {
48 | // Default values if flags are not specified
49 | default: { lang: 'en' },
50 |
51 | // allow using -- to stop processing flags
52 | '--': true,
53 |
54 | // Populate `_` with first non-option
55 | stopEarly: true,
56 |
57 | // Invoked on unknown param
58 | unknown: function () { ... }
59 | })
60 | ```
61 |
62 | Also see [minimist](minimist.html).
63 |
--------------------------------------------------------------------------------
/sheets/polyfill.io.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Polyfill.io
3 | category: JavaScript libraries
4 | updated: 2017-10-26
5 | layout: 2017/sheet
6 | intro: |
7 | [Polyfill.io](https://polyfill.io) is a service that serves JavaScript polyfills.
8 | ---
9 |
10 | ## Usage
11 |
12 | ### Default usage
13 |
14 | ```html
15 |
16 | ```
17 |
18 |
19 |
20 | This is the default script for Polyfill.io.
21 |
22 | ### References
23 |
24 | * [API example](https://polyfill.io/v2/docs/api) _(polyfill.io)_
25 | * [List of features](https://polyfill.io/v2/docs/features) _(polyfill.io)_
26 |
27 | ## Optimized
28 |
29 | ### For modern browsers
30 |
31 | ```html
32 |
33 | ```
34 |
35 | This only includes polyfill.io when necessary, skipping it for modern browsers for faster load times.
36 |
37 | ### Extra features
38 |
39 | ```html
40 |
41 | ```
42 |
43 |
44 |
45 | This is the same as the previous, but also adds a polyfill for `window.fetch()`. We add a `window.fetch` check and loads the additional `fetch` feature.
46 |
--------------------------------------------------------------------------------
/sheets/resolutions.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Screen resolutions
3 | layout: 2017/sheet
4 | updated: 2017-10-30
5 | weight: -1
6 | ---
7 |
8 | ## Resolutions
9 |
10 |
11 |
12 | ### Mobile
13 |
14 | | Resolution | DPPX | Actual resolution | DPPI | Actual PPI | Size | Devices |
15 | | ---------- | ---- | ----------------- | ------- | ---------- | ---- | ------------ |
16 | | 320 x 480 | @1x | 320 x 480 | 163 ppi | 163 ppi | 3.5" | iPhone 3GS |
17 | | 320 x 480 | @2x | 640 x 960 | 163 ppi | 326 ppi | 3.5" | iPhone 4S |
18 | | 320 x 568 | @2x | 640 x 1136 | 163 ppi | 326 ppi | 4" | iPhone SE |
19 | | 375 x 667 | @2x | 750 x 1334 | 163 ppi | 326 ppi | 4.7" | iPhone 7/8 |
20 | | 414 x 736 | @3x | 1242 x 2208 | 133 ppi | 401 ppi | 5.5" | iPhone 7+/8+ |
21 | | --- | --- | --- | ---- | --- | --- | --- |
22 | | 360 x 640 | @3x | 1080 x 1920 | 147 ppi | 441 ppi | 5" | Galaxy S4 |
23 |
24 |
25 |
26 | ### Tablet
27 |
28 | | Resolution | DPPX | Actual resolution | DPPI | Actual PPI | Size | Devices |
29 | | ---------- | ---- | ----------------- | ------- | ---------- | ---- | ---------------- |
30 | | 1024 x 768 | @2x | 2048 x 1536 | 163 ppi | 326 ppi | 7.9" | iPad Mini Retina |
31 | | 1024 x 768 | @2x | 2048 x 1536 | 132 ppi | 264 ppi | 9.7" | iPad Air |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/sheets/weechat.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Weechat
3 | category: Apps
4 | layout: 2017/sheet
5 | ---
6 |
7 | ## Keys
8 |
9 |
10 |
11 | ### Buffers
12 |
13 | | Shortcut | Description |
14 | | ------------- | -------------------------------- |
15 | | `^s` / `^u` | Set unread marker on all windows |
16 | | --- | --- |
17 | | `^p, A-left` | Switch buffer left |
18 | | `^n, A-right` | Switch buffer right |
19 | | `A-a` | Next buffer with activity |
20 | | `A-0...9` | Switch buffers |
21 | | --- | --- |
22 | | `F9` /`F10` | Scroll buffer title |
23 | | `F11` / `F12` | Scroll nick list |
24 | | --- | --- |
25 | | `A-w A-Left` | Switch windows |
26 | | `A-w A-b` | Balance windows |
27 |
28 |
29 |
30 | (`A-` is alt.)
31 |
32 | ### Window commands
33 |
34 | | Shortcut | Description |
35 | | ---------------- | ---------------- |
36 | | `/window splith` | Split horizontal |
37 | | `/window splitv` | Split vertical |
38 | | `/window zoom` | Zoom |
39 |
40 | ### Search
41 |
42 | | Shortcut | Description |
43 | | ----------------- | ----------- |
44 | | `^r` | Search |
45 | | `Enter` `^j` `^m` | Stop search |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/sheets/imagemagick.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Imagemagick
3 | ---
4 |
5 | ### Common options
6 |
7 | | Options | Description |
8 | | ------------------- | ------------------------------- |
9 | | `-resize 100x40` | Resize |
10 | | --- | --- |
11 | | `-crop 40x30+10+10` | Crop (`WIDTHxHEIGHT+X+Y`) |
12 | | `-crop 40x30-10-10` | Crop (`WIDTHxHEIGHT-X-Y`) |
13 | | --- | --- |
14 | | `-flip` | Flip vertical |
15 | | `-flop` | Flip horizontal |
16 | | `-transpose` | Flip vertical + rotate 90deg |
17 | | `-transverse` | Flip horizontal + rotate 270deg |
18 | | --- | --- |
19 | | `-rotate 90` | Rotate 90 degrees |
20 | | `-trim` | Trim image edges |
21 |
22 | ### Resize to fit
23 |
24 | ```bash
25 | convert input.jpg \
26 | -resize 80x80^ \
27 | -gravity center \
28 | -extent 80x80 \
29 | icon.png
30 | ```
31 |
32 | This resizes to `80x80`, fit to cover.
33 |
34 | ### Convert all images to another format
35 |
36 | ```bash
37 | mogrify -format jpg -quality 85 *.png
38 | ```
39 |
40 | This converts all `jpg` to `png`.
41 |
42 | ### Make a pdf
43 |
44 | ```bash
45 | convert *.jpg hello.pdf
46 | ```
47 |
48 | Converts a jpeg to PDF.
49 |
50 | ### References
51 |
52 | *
53 |
--------------------------------------------------------------------------------
/sheets/tomdoc.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Tomdoc
3 | category: Markup
4 | layout: 2017/sheet
5 | ---
6 |
7 | ### Basic example
8 |
9 |
10 |
11 | ```ruby
12 | # Public: Duplicate some text an arbitrary number of times.
13 | #
14 | # text - The String to be duplicated.
15 | # count - The Integer number of times to duplicate the text.
16 | #
17 | # Examples
18 | #
19 | # multiplex('Tom', 4)
20 | # # => 'TomTomTomTom'
21 | #
22 | # Returns the duplicated String.
23 | def multiplex(text, count)
24 | text * count
25 | end
26 | ```
27 |
28 | See [tomdoc.org](http://tomdoc.org/).
29 |
30 | ### Tags
31 |
32 | * `Deprecated`
33 | * `Internal`
34 | * `Public`
35 |
36 | ### Options
37 |
38 | ```ruby
39 | # options - The Hash options used to refine the selection (default: {}):
40 | # :color - The String color to restrict by (optional).
41 | # :weight - The Float weight to restrict by. The weight should
42 | # be specified in grams (optional).
43 | ```
44 |
45 | ### Yields
46 |
47 | ```ruby
48 | # Yields the Integer index of the iteration.
49 | ```
50 |
51 | ```ruby
52 | # Returns the duplicated String.
53 | ```
54 |
55 | ```ruby
56 | # Returns nothing.
57 | ```
58 |
59 | ```ruby
60 | # Raises Errno::ENOENT if the file can't be found.
61 | ```
62 |
63 | ```ruby
64 | # Returns something else and this is a wrapped
65 | # multi-line comment.
66 | ```
67 |
68 | ### Signatures
69 |
70 | ```ruby
71 | # Signature
72 | #
73 | # find_by_[_and_...](args)
74 | #
75 | ```
76 |
--------------------------------------------------------------------------------
/sheets/travis-gh-pages.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Deploy gh-pages via Travis
3 | category: Git
4 | ---
5 |
6 | Taken from https://medium.com/@nthgergo/publishing-gh-pages-with-travis-ci-53a8270e87db
7 |
8 | ### Create an OAuth token and encrypt it
9 |
10 | Use https://github.com/settings/tokens/new
11 |
12 | ```sh
13 | # via ruby
14 | gem install travis
15 | travis encrypt -r user/repo GITHUB_TOKEN=[the token here]
16 | ```
17 |
18 | ### Make it run the deploy script on deploy
19 |
20 | ```yaml
21 | # .travis.yml
22 | script:
23 | - bash ./scripts/deploy-to-gh-pages.sh
24 | env:
25 | global:
26 | - GITHUB_REPO: "user/repo"
27 | - secure: "nlnXJW/imf/w..." # <-- from travis-encrypt
28 | ```
29 |
30 | ### Write deployer
31 |
32 | Create the file `scripts/deploy-to-gh-pages.sh`
33 |
34 | ```sh
35 | #!/bin/bash
36 | # See https://medium.com/@nthgergo/publishing-gh-pages-with-travis-ci-53a8270e87db
37 | set -o errexit
38 |
39 | rm -rf public
40 | mkdir public
41 |
42 | # config
43 | git config --global user.email "nobody@nobody.org"
44 | git config --global user.name "Travis CI"
45 |
46 | # build (CHANGE THIS)
47 | make
48 |
49 | # deploy
50 | cd public
51 | git init
52 | git add .
53 | git commit -m "Deploy to Github Pages"
54 | git push --force --quiet "https://${GITHUB_TOKEN}@$github.com/${GITHUB_REPO}.git" master:gh-pages > /dev/null 2>&1
55 | ```
56 |
57 | From Ractive, this might be useful in certain cases:
58 |
59 | ```
60 | if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "master" ]; then exit 0; fi
61 | ```
62 |
--------------------------------------------------------------------------------
/sheets/mocha-blanket.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Mocha blanket
3 | category: JavaScript libraries
4 | layout: 2017/sheet
5 | intro: |
6 | Use [blanket](https://npmjs.com/package/blanket) for easy coverage reporting for Mocha JavaScript tests.
7 | ---
8 |
9 | ### Quickstart guide
10 |
11 | Install blanket:
12 |
13 |
14 |
15 | ```bash
16 | npm i --save-dev blanket
17 | ```
18 |
19 | In your test helpers, use Blanket before `require`ing:
20 |
21 | ```js
22 | if (process.env.COVERAGE) {
23 | require('blanket')({
24 | pattern: require('path').resolve('./index.js')
25 | })
26 | }
27 | thing = require('../index')
28 | ```
29 |
30 | Add to `package.json`:
31 |
32 | ```json
33 | "scripts": {
34 | "coverage": "env COVERAGE=1 mocha -R html-cov > coverage.html && open coverage.html"
35 | }
36 | ```
37 |
38 | Be sure to ignore it:
39 |
40 | ```bash
41 | echo "coverage.html" >> .gitignore
42 | ```
43 |
44 | Then run:
45 |
46 | ```bash
47 | npm run coverage
48 | ```
49 |
50 | ### Travis + coveralls.io support
51 |
52 | Visit [coveralls.io] then activate your repo. Then install the appropriate packages:
53 |
54 |
55 |
56 | ```bash
57 | npm i --save-dev mocha-lcov-reporter coveralls
58 | ```
59 |
60 | Add this to `.travis.yml`:
61 |
62 | ```yml
63 | after_success:
64 | - ./node_modules/.bin/mocha -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js
65 | ```
66 |
67 | Commit, push, wait for Travis to finish.
68 |
69 | [blanket]: https://www.npmjs.org/package/blanket
70 | [coveralls.io]: http://coveralls.io
71 |
--------------------------------------------------------------------------------
/sheets/nodejs-fs.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: fs
3 | category: Node.js
4 | ---
5 |
6 | ### Reading
7 |
8 | ```js
9 | fs.readFile('file.txt', (err, data) => {
10 | /* ... */
11 | })
12 | fs.readFile('file.txt', { encoding: 'utf-8' }, (err, data) => {
13 | /* ... */
14 | })
15 | ```
16 |
17 | ### Writing
18 |
19 | ```js
20 | fs.writeFile('output.txt', err => {
21 | /* ... */
22 | })
23 | fs.appendFile('output.txt', err => {
24 | /* ... */
25 | })
26 | ```
27 |
28 | ### Watch
29 |
30 | ```js
31 | fs.watch('dir OR file.txt', { persistent: true }, (event, file) => {
32 | event /* rename | change */
33 | })
34 | ```
35 |
36 | ### Getting info
37 |
38 | ```js
39 | fs.stat('file.txt', stats => {
40 | stats.isFile()
41 | stats.isDirectory()
42 | stats.isSymbolicLink()
43 | })
44 | ```
45 |
46 | ### File operations
47 |
48 | ```js
49 | fs.rename('old.txt', 'new.txt', function() {})
50 | fs.chown('file.txt', uid, gid, function() {})
51 | fs.symlink('src', 'dest', function() {})
52 | fs.unlink('path', function() {})
53 | fs.rmdir('path', function() {})
54 | ```
55 |
56 | ```js
57 | fs.readdir('path', (err, files) => {
58 | // files === array of names
59 | })
60 | ```
61 |
62 | ### Path
63 |
64 | ```js
65 | fs.realpath('/etc/passwd', (err, path) => {
66 | // path === "/private/etc/passwd"
67 | })
68 | ```
69 |
70 | ### Sync
71 |
72 | ```js
73 | data = fs.readFileSync('input.txt')
74 | fs.writeFileSync('output.txt', data)
75 | fs.appendFileSync('output.txt', data)
76 | fs.existsSync('file.txt')
77 | ```
78 |
79 | ### References
80 |
81 | - http://nodejs.org/api/fs.html
82 |
--------------------------------------------------------------------------------
/sheets/tape.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Tape
3 | category: JavaScript libraries
4 | ---
5 |
6 | ### Basic example
7 |
8 | ```js
9 | test('things', t => {
10 | t.equal('actual', 'expected')
11 | })
12 | ```
13 |
14 | ### Testing equality
15 |
16 | ```js
17 | t.equal('actual', 'expected')
18 | t.equal('actual', 'expected', 'should be equal') // messages are optional
19 | ```
20 |
21 | ### Basic assertions
22 |
23 | ```js
24 | t.ok(value, 'is truthy')
25 | t.notOk(value, 'is falsy')
26 | t.error(err, 'is falsy (print err.message)')
27 | ```
28 |
29 | ### Others
30 |
31 | ```js
32 | t.end(err)
33 | t.fail('msg')
34 | t.pass('msg')
35 | t.timeoutAfter(2000)
36 | t.skip('msg')
37 | ```
38 |
39 | ### Basic assertions
40 |
41 | ```js
42 | t.ok(value, 'is truthy')
43 | t.notOk(value, 'is falsy')
44 | t.error(err, 'is falsy (print err.message)')
45 | ```
46 |
47 | ### Testing equality, continued
48 |
49 | ```js
50 | t.equal(actual, expected, 'is equal')
51 | t.notEqual(/* ... */)
52 | ```
53 |
54 | ```js
55 | t.deepEqual(actual, expected, "is equal (use node's deepEqual)")
56 | t.notDeepEqual(/* ... */)
57 | ```
58 |
59 | ```js
60 | t.looseEqual(actual, expected, "is equal (use node's deepEqual with ==)")
61 | t.notLooseEqual(/* ... */)
62 | ```
63 |
64 | ```js
65 | t.throws(fn, /FooError/)
66 | t.throws(fn, FooError /* class */)
67 | t.doesNotThrow(/* ... */)
68 | ```
69 |
70 | ### Comments
71 |
72 | ```js
73 | t.comment('message')
74 | ```
75 |
76 | ### Asserting number of tests
77 |
78 | ```js
79 | t.plan(1)
80 | ```
81 |
82 | ### Isolating tests
83 |
84 | ```js
85 | test.only((t) => { ... })
86 | ```
87 |
--------------------------------------------------------------------------------
/sheets/yargs.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Yargs
3 | category: JavaScript libraries
4 | ---
5 |
6 | ### Basic usage
7 |
8 | ```js
9 | var argv = require('yargs').argv
10 |
11 | argv._ // [ ... ]
12 | argv.$0 // "node bin/mybin"
13 | argv.verbose // --verbose
14 | ```
15 |
16 | ### Help and version
17 |
18 | ```js
19 | var argv = require('yargs')
20 | // version
21 | .alias('v', 'version')
22 | .version(function() {
23 | return require('../package').version
24 | })
25 | .describe('v', 'show version information')
26 |
27 | // help text
28 | .alias('h', 'help')
29 | .help('help')
30 | .usage('Usage: $0 -x [num]')
31 | .showHelpOnFail(false, 'Specify --help for available options')
32 | ```
33 |
34 | ### Options
35 |
36 | ```js
37 | .option('f', {
38 | alias : 'file',
39 | describe: 'x marks the spot',
40 | type: 'string', /* array | boolean | string */
41 | nargs: 1,
42 | demand: true,
43 | demand: 'file is required',
44 | default: '/etc/passwd'
45 | // also: count:true, requiresArg:true
46 | })
47 |
48 | .options({
49 | f: { ... }
50 | })
51 | ```
52 |
53 | ### Examples and more help stuff
54 |
55 | ```js
56 | // more help
57 | .example('...')
58 | .epilog('copyright 2015')
59 | .command('start', 'start a server')
60 | ```
61 |
62 | ### Stacking
63 |
64 | ```js
65 | .count('verbose')
66 |
67 | argv.verbose // -vvv => 3
68 | ```
69 |
70 | ### Reject non explicits
71 |
72 | ```js
73 | .strict()
74 | ```
75 |
76 | ### Methods
77 |
78 | ```
79 | yargs.showHelp()
80 | yargs.help() //=>string
81 | ```
82 |
--------------------------------------------------------------------------------
/sheets/moment.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Moment.js
3 | category: JavaScript libraries
4 | layout: 2017/sheet
5 | updated: 2017-10-10
6 | tags: [Featurable]
7 | ---
8 |
9 | ### Parsing
10 |
11 | ```js
12 | m = moment('2013-03-01', 'YYYY-MM-DD')
13 | ```
14 |
15 | This parses the given date using the given format. Returns a moment object.
16 |
17 | ### Formatting
18 |
19 | ```js
20 | m
21 | .format()
22 | .format('dddd')
23 | .format('MMM Do YY') // → "Sep 2nd 07"
24 | .fromNow() // → "31 minutes ago"
25 | .calendar() // → "Last Friday at 9:32PM"
26 | ```
27 |
28 | ### Add
29 |
30 | ```js
31 | m.add(1, 'day')
32 | m.subtract(2, 'days')
33 | ```
34 |
35 | ```js
36 | m.startOf('day')
37 | m.endOf('day')
38 | m.startOf('hour')
39 | ```
40 |
41 | ### Internationalization
42 |
43 | ```js
44 | .format('L') // 06/09/2014
45 | .format('l') // 6/9/2014
46 | .format('LL') // June 9 2014
47 | .format('ll') // Jun 9 2014
48 | .format('LLL') // June 9 2014 9:32 PM
49 | .format('lll') // Jun 9 2014 9:32 PM
50 | .format('LLLL') // Monday, June 9 2014 9:32 PM
51 | .format('llll') // Mon, Jun 9 2014 9:32 PM
52 | ```
53 |
54 | See [datetime](./datetime) for more.
55 |
56 |
57 |
58 | ## References
59 |
60 | ### Alternatives
61 |
62 | * [You don't need Moment.js](https://github.com/you-dont-need/You-Dont-Need-Momentjs) _(github.com)_
63 |
64 | ### Also see
65 |
66 | * [Datetime cheatsheet](./datetime) _(devhints.io)_
67 | * [Moment website](http://momentjs.com/) _(momentjs.com)_
68 | * [Moment docs](http://momentjs.com/docs/) _(momentjs.com)_
69 |
--------------------------------------------------------------------------------
/sheets/sequelize.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Sequelize
3 | category: JavaScript libraries
4 | ---
5 |
6 | ### API
7 |
8 | ```js
9 | sequelize.sync().done -> ...
10 | ```
11 |
12 | ### Models
13 |
14 | ```js
15 | Project = sequelize.define('Project', {
16 | title: Sequelize.STRING,
17 | description: Sequelize.TEXT,
18 | myDate: { type: Sequelize.DATE, defaultValue: Sequelize.NOW },
19 | title: { type: Sequelize.STRING, allowNull: false },
20 | id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true },
21 | }, {
22 | classMethods: { ... },
23 | instanceMethods: { ... }
24 | });
25 | ```
26 |
27 | ```js
28 | Project.hasMany(Task)
29 | ```
30 |
31 | ### Finders
32 |
33 | ```js
34 | Project.find(123).success (project) ->
35 | ```
36 |
37 | ```js
38 | Project.find({ where: {title: 'Hello'} })
39 | Project.find({ where: {id: [1,3,4]} })
40 | Project.find({ where: ["id > ?", 25] })
41 | ```
42 |
43 | ```js
44 | Project.find(
45 | where: {title: 'a'}
46 | attributes: ['id', ['name', 'title']]
47 | )
48 | ```
49 |
50 | ```js
51 | .findOrCreate(...)
52 | ```
53 |
54 | ```js
55 | .findAll
56 | .findAll({ where: ... })
57 | .findAll({ order: 'title DESC' })
58 | .findAll({ limit: 10 })
59 | .findAll({ offset: 10, limit: 2 })
60 | ```
61 |
62 | ```js
63 | .count()
64 | ```
65 |
66 | ### Build
67 |
68 | ```js
69 | item = Project.build({ ... })
70 | ```
71 |
72 | ```js
73 | item.title = '...'
74 | ```
75 |
76 | ```js
77 | item.save().success (item) ->
78 | ```
79 |
80 | ```js
81 | item.updateAttributes({ title: '...' })
82 | ```
83 |
84 | ```js
85 | item.destroy().success ->
86 | ```
87 |
88 | ```js
89 | item.values
90 | ```
91 |
--------------------------------------------------------------------------------
/sheets/awscli.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: AWS CLI
3 | category: Devops
4 | layout: 2017/sheet
5 | ---
6 |
7 | ### EC2
8 |
9 | ```
10 | aws ec2 describe-instances
11 | aws ec2 start-instances --instance-ids i-12345678c
12 | aws ec2 terminate-instances --instance-ids i-12345678c
13 | ```
14 |
15 | ### S3
16 |
17 | ```
18 | aws s3 ls s3://mybucket
19 | aws s3 rm s3://mybucket/folder --recursive
20 | aws s3 cp myfolder s3://mybucket/folder --recursive
21 | aws s3 sync myfolder s3://mybucket/folder --exclude *.tmp
22 | ```
23 |
24 | ### ECS
25 |
26 | ```
27 | aws ecs create-cluster
28 | --cluster-name=NAME
29 | --generate-cli-skeleton
30 |
31 | aws ecs create-service
32 | ```
33 |
34 | ### Homebrew
35 |
36 | ```
37 | brew install awscli
38 | aws configure
39 | ```
40 |
41 | ### Configuration profiles
42 |
43 | ```
44 | aws configure --profile project1
45 | aws configure --profile project2
46 | ```
47 |
48 | ## Elastic Beanstalk
49 |
50 | ### Configuration
51 |
52 | * .elasticbeanstalk/config.yml - application config
53 | * .elasticbeanstalk/dev-env.env.yml - environment config
54 |
55 | ```
56 | eb config
57 | ```
58 |
59 | See:
60 |
61 | ## ebextensions
62 |
63 | *
64 | *
65 |
66 | ## Also see
67 |
68 | * [AWS CLI](https://aws.amazon.com/cli/)
69 | * [Documentation](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html)
70 | * [All commands](http://docs.aws.amazon.com/cli/latest/reference/#available-services)
71 |
--------------------------------------------------------------------------------
/sheets/curl.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Curl
3 | category: CLI
4 | layout: 2017/sheet
5 | updated: 2017-09-20
6 | ---
7 |
8 | ## Options
9 |
10 | ### Options
11 |
12 | ```bash
13 | -o # --output: write to file
14 | -u user:pass # --user: Authentication
15 | ```
16 |
17 | ```bash
18 | -v # --verbose
19 | -vv # Even more verbose
20 | -s # --silent
21 | ```
22 |
23 | ```bash
24 | -I # --head: headers only
25 | ```
26 |
27 | ### Request
28 |
29 | ```bash
30 | -X POST # --request
31 | -L # follow link if page redirects
32 | ```
33 |
34 | ### Data
35 |
36 | ```bash
37 | -d 'data' # --data: HTTP post data, URL encoded (eg, status="Hello")
38 | -d @file # --data via file
39 | -G # --get: send -d data via get
40 | ```
41 |
42 | ### Headers
43 |
44 | ```bash
45 | -A # --user-agent
46 | -b name=val # --cookie
47 | -b FILE # --cookie
48 | -H "X-Foo: y" # --header
49 | --compressed # use deflate/gzip
50 | ```
51 |
52 | ### SSL
53 |
54 | ```bash
55 | --cacert
56 | --capath
57 | ```
58 |
59 | ```bash
60 | -E, --cert # --cert: Client cert file
61 | --cert-type # der/pem/eng
62 | -k, --insecure # for self-signed certs
63 | ```
64 |
65 | ## Examples
66 |
67 |
68 |
69 | ```bash
70 | # Post data:
71 | curl -d password=x http://x.com/y
72 | ```
73 |
74 | ```bash
75 | # Auth/data:
76 | curl -u user:pass -d status="Hello" http://twitter.com/statuses/update.xml
77 | ```
78 |
79 | ```bash
80 | # multipart file upload
81 | curl -v -include --form key1=value1 --form upload=@localfilename URL
82 | ```
83 |
--------------------------------------------------------------------------------
/sheets/umdjs.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Universal JS module loader
3 | intro: |
4 | Templates for the Universal JS module loader (UMDJS).
5 | ---
6 |
7 | ### With dependency
8 |
9 | ```js
10 | ;(function(root, factory) {
11 | if (typeof define === 'function' && define.amd) {
12 | define(['jquery'], factory)
13 | } else if (typeof exports === 'object') {
14 | module.exports = factory(require('jquery'))
15 | } else {
16 | root.YourModule = factory(root.jQuery)
17 | }
18 | })(this, function(jquery) {
19 | return {}
20 | })
21 | ```
22 |
23 | Replace `jquery` with your dependency. See: [amdWebGlobal.js](https://github.com/umdjs/umd/blob/master/amdWebGlobal.js)
24 |
25 | ### No dependencies
26 |
27 | ```js
28 | ;(function(root, factory) {
29 | if (typeof define === 'function' && define.amd) {
30 | define(factory)
31 | } else if (typeof exports === 'object') {
32 | module.exports = factory()
33 | } else {
34 | root.YourModule = factory()
35 | }
36 | })(this, function() {
37 | return {}
38 | })
39 | ```
40 |
41 | ### Supports circular references
42 |
43 | ```js
44 | ;(function(root, factory) {
45 | if (typeof define === 'function' && define.amd) {
46 | define(['exports', 'jquery'], factory)
47 | } else if (typeof exports === 'object') {
48 | factory(exports, require('jquery'))
49 | } else {
50 | factory((root.YourModule = {}), root.jQuery)
51 | }
52 | })(this, function(exports, jQuery) {
53 | exports.action = function() {}
54 | })
55 | ```
56 |
57 | See: [commonjsStrict.js](https://github.com/umdjs/umd/blob/master/commonjsStrict.js)
58 |
59 | ### Reference
60 |
61 | * [umdjs/umd](https://github.com/umdjs/umd) _(github.com)_
62 |
--------------------------------------------------------------------------------
/sheets/figma.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Figma
3 | category: Apps
4 | tags: [WIP]
5 | ---
6 |
7 | ## Shortcuts
8 |
9 |
10 |
11 | ### Alignment
12 |
13 | | Description | Key |
14 | | ----------------------- | ----------- |
15 | | Align left | `Alt` + `A` |
16 | | Align top | `Alt` + `W` |
17 | | Align right | `Alt` + `D` |
18 | | Align bottom | `Alt` + `S` |
19 | | | |
20 | | Align vertical middle | `Alt` + `V` |
21 | | Align horizontal center | `Alt` + `H` |
22 |
23 |
24 |
25 | ### Move objects
26 |
27 | | Description | Key |
28 | | -------------- | ---------------------- |
29 | | Bring back | `Ctrl` + `[` |
30 | | Bring forward | `Ctrl` + `]` |
31 | | | |
32 | | Bring to front | `Ctrl` + `Shift` + `[` |
33 | | Bring to back | `Ctrl` + `Shift` + `]` |
34 |
35 |
36 |
37 | ### Zoom
38 |
39 | | Description | Key |
40 | | ----------------- | ------------- |
41 | | Zoom in | `+` |
42 | | Zoom out | `-` |
43 | | | |
44 | | Zoom to 100% | `Shift` + `0` |
45 | | Zoom to fit | `Shift` + `1` |
46 | | Zoom to selection | `Shift` + `2` |
47 | | | |
48 | | Zoom to frame | `n` |
49 |
50 |
51 |
52 | ### Navigate
53 |
54 | | Description | Key |
55 | | -------------- | ------ |
56 | | Previous frame | `Home` |
57 | | Next frame | `End` |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/sheets/editorconfig.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: editorconfig
3 | layout: 2017/sheet
4 | prism_languages: [ini]
5 | weight: -1
6 | updated: 2017-09-04
7 | ---
8 |
9 | ### Short example
10 |
11 |
12 |
13 | ```ini
14 | # editorconfig.org
15 | root = true
16 |
17 | [*]
18 | indent_style = space
19 | indent_size = 2
20 | tab_width = 2
21 | end_of_line = lf
22 | charset = utf-8
23 | trim_trailing_whitespace = true
24 | insert_final_newline = true
25 | ```
26 |
27 | This example should be fine for most projects indented by 2 spaces. See: [animate.css editorconfig](https://github.com/daneden/animate.css/blob/master/.editorconfig)
28 |
29 | ### Properties
30 |
31 | ```ini
32 | indent_style = {space|tab}
33 | indent_size = {4|tab}
34 | tab_width = 2
35 | end_of_line = {cr|lf|crlf}
36 | charset = {utf-8|utf-16be|utf-16le|latin1}
37 | trim_trailing_whitespace = false
38 | insert_final_newline = true
39 | max_line_length = 80
40 | ```
41 |
42 | ### Full example
43 |
44 | ```ini
45 | # top-most EditorConfig file
46 | root = true
47 |
48 | # Unix-style newlines with a newline ending every file
49 | [*]
50 | end_of_line = lf
51 | insert_final_newline = true
52 |
53 | # 4 space indentation
54 | [*.py]
55 | indent_style = space
56 | indent_size = 4
57 |
58 | # Tab indentation (no size specified)
59 | [*.js]
60 | indent_style = tab
61 |
62 | # Indentation override for all JS under lib directory
63 | [lib/**.js]
64 | indent_style = space
65 | indent_size = 2
66 |
67 | # Matches the exact files either package.json or .travis.yml
68 | [{package.json,.travis.yml}]
69 | indent_style = space
70 | indent_size = 2
71 | ```
72 |
73 | ### References
74 |
75 | * [EditorConfig website](http://EditorConfig.org) _(editorconfig.org)_
76 |
--------------------------------------------------------------------------------
/sheets/vim-unite.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Vim-Unite
3 | category: Vim
4 | layout: 2017/sheet
5 | ---
6 |
7 | ### Usage
8 |
9 | ```vim
10 | :Unite file
11 | :Unite file_rec/async:!
12 | :Unite tag
13 | :Unite buffer
14 | ```
15 |
16 | ### Sources
17 |
18 | * `file/new`
19 | * `file/async`
20 | * `file_rec/async`
21 | * `file_rec/git`
22 | * `buffer`
23 | * `buffer_tab` (current tab only)
24 | * `tab`
25 | * `register`
26 | * `bookmark`
27 | * `source`
28 |
29 | ### Options
30 |
31 | | Option | Description |
32 | | -------------------------- | ----------------------------------------------------------- |
33 | | `-start-insert` | |
34 | | `-no-quit` | |
35 | | `-winheight=10` | |
36 | | `-quick-match` | select by pressing asdf keys |
37 | | `-winwidth=40` | use with vertical |
38 | | `-no-split` | open in current buffer |
39 | | `-auto-preview` | great for outline |
40 | | `-vertical` | open as sidebar |
41 | | `-buffer-name=xxx -resume` | resume the next time it's called (faster) |
42 | | `-input=` | reset input (use with -resume) |
43 | | `-unique` | remove duplicates (eg, if using `file_rec` with `file_mru`) |
44 |
--------------------------------------------------------------------------------
/sheets/ffmpeg.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: ffmpeg
3 | category: CLI
4 | layout: 2017/sheet
5 | ---
6 |
7 | ### Common switches
8 |
9 | ```bash
10 | -codecs # list codecs
11 | -c:v # video codec (-vcodec) - 'copy' to copy stream
12 | -c:a # audio codec (-acodec)
13 | ```
14 |
15 | ```bash
16 | -fs SIZE # limit file size (bytes)
17 | ```
18 |
19 | ### Bitrate
20 |
21 | ```bash
22 | -b:v 1M # video bitrate (1M = 1Mbit/s)
23 | -b:a 1M # audio bitrate
24 | ```
25 |
26 | ### Video
27 |
28 | ```bash
29 | -aspect RATIO # aspect ratio (4:3, 16:9, or 1.25)
30 | -r RATE # frame rate per sec
31 | -s WIDTHxHEIGHT # frame size
32 | -vn # no video
33 | ```
34 |
35 | ### Audio
36 |
37 | ```bash
38 | -aq QUALITY # audio quality (codec-specific)
39 | -ar 44100 # audio sample rate (hz)
40 | -ac 1 # audio channels (1=mono, 2=stereo)
41 | -an # no audio
42 | -vol N # volume (256=normal)
43 | ```
44 |
45 | ## Example
46 |
47 | ### Ringtone conversion using ffmpeg
48 |
49 | ```bash
50 | ffmpeg -i foo.mp3 -ac 1 -ab 128000 -f mp4 -acodec libfaac -y target.m4r
51 | ```
52 |
53 | ### To web
54 |
55 | ```bash
56 | # no audio
57 | ffmpeg -i input.mov -vcodec h264 -an -strict -2 output.mp4
58 | ffmpeg -i input.mov -vcodec libvpx -an output.webm
59 | ```
60 |
61 | ```bash
62 | ffmpeg -i input.mov -vcodec h264 -acodec aac -strict -2 output.mp4
63 | ffmpeg -i input.mov -vcodec libvpx -acodec libvorbis output.webm
64 | ```
65 |
66 | ```html
67 |
71 | ```
72 |
--------------------------------------------------------------------------------
/sheets/layout-thrashing.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Layout thrashing
3 | category: HTML
4 | layout: 2017/sheet
5 | description: ""
6 | updated: 2017-10-19
7 | weight: -1
8 | intro: |
9 | These are CSS properties that will cause "layout thrashing". Avoid changing them to prevent bottlenecks in your UI performance.
10 | ---
11 |
12 | ## Layout thrashing
13 |
14 |
15 |
16 | ### Things that cause invalidation
17 |
18 | #### Element
19 |
20 | * clientHeight
21 | * clientLeft
22 | * clientTop
23 | * clientWidth
24 | * focus
25 | * getBoundingClientRect
26 | * getClientRects
27 | * innerText
28 | * offsetHeight
29 | * offsetLeft
30 | * offsetParent
31 | * offsetTop
32 | * offsetWidth
33 | * outerText
34 | * scrollByLines
35 | * scrollByPages
36 | * scrollHeight
37 | * scrollIntoView
38 | * scrollIntoViewIfNeeded
39 | * scrollLeft
40 | * scrollTop
41 | * scrollWidth
42 |
43 |
44 | #### MouseEvent
45 |
46 | * layerX
47 | * layerY
48 | * offsetX
49 | * offsetY
50 |
51 |
52 | #### Window
53 |
54 | * getComputedStyle
55 | * scrollBy
56 | * scrollTo
57 | * scrollX
58 | * scrollY
59 |
60 |
61 | #### Frame, Document & Image
62 |
63 | * height
64 | * width
65 |
66 |
67 | #### jQuery
68 |
69 | * $.fn.offset
70 | * $.fn.offsetParent
71 | * $.fn.position
72 | * $.fn.scrollLeft
73 | * $.fn.scrollTop
74 | * $.fn.css('...')
75 | * $.fn.text('...')
76 | * $(':hidden')
77 | * $(':contains')
78 |
79 |
80 | ## Also see
81 |
82 | *
83 | *
84 | *
85 |
--------------------------------------------------------------------------------
/sheets/watchexec.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Watchexec
3 | layout: 2017/sheet
4 | updated: 2017-10-18
5 | category: CLI
6 | weight: -1
7 | keywords:
8 | - "watchexec --excts js,jsx -- npm test"
9 | - "watchexec --help"
10 | intro: |
11 | [mattgreen/watchexec](https://github.com/mattgreen/watchexec) runs commands whenever certain files change.
12 | ---
13 |
14 | ### Installation
15 |
16 | #### OSX
17 |
18 | ```bash
19 | brew install watchexec
20 | ```
21 |
22 | #### Rust
23 |
24 | ```bash
25 | cargo install watchexec
26 | ```
27 |
28 | For Linux and Windows, get it from [GitHub releases](https://github.com/mattgreen/watchexec).
29 |
30 | ### Getting started
31 |
32 | ```bash
33 | watchexec --exts js,jsx -- npm test
34 | ```
35 |
36 | Runs `npm test` when `js,jsx` files change.
37 |
38 | ```bash
39 | watchman -w lib -w test -- npm test
40 | ```
41 |
42 | Runs `npm test` when `lib/` and `test/` files change.
43 |
44 | ### Other options
45 |
46 | #### Flags
47 |
48 | | Flag | Description |
49 | | ---------------- | ------------------------------------ |
50 | | `-c` `--clear` | Clear screen |
51 | | `-r` `--restart` | Restart process if its still running |
52 |
53 | #### Options
54 |
55 | | Flag | Description |
56 | | ----------------------- | ----------------------------- |
57 | | `-s` `--signal SIGKILL` | Kill signal to use |
58 | | `-d` `--debounce MS` | Debounce by `MS` milliseconds |
59 | | `-e` `--exts EXTS` | Extensions |
60 | | `-i` `--ignore PATTERN` | Ignore these files |
61 | | `-w` `--watch PATH` | Watch these directories |
62 |
63 | ## Also see
64 |
65 | * [mattgreen/watchexec](https://github.com/mattgreen/watchexec) _(github.com)_
66 |
--------------------------------------------------------------------------------
/sheets/superagent.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Superagent
3 | category: JavaScript libraries
4 | updated: 2018-04-21
5 | prism_languages: [javascript]
6 | tags:
7 | - WIP
8 | ---
9 |
10 | ### Response object
11 | ```javascript
12 | res: {
13 | // The HTTP Status Code (see: httpstatuses.com for definitions on HTTP status codes)
14 | status: 202,
15 | // True when res.status is 2xx
16 | ok: true,
17 | // True when res.status is 4xx or 5xx
18 | error: false,
19 | // True when res.status is 4xx
20 | clientError: false,
21 | // True when res.status is 5xx
22 | serverError: false,
23 |
24 | // True when res.status == 202
25 | accepted: true,
26 | // True when res.status == 204 || res.status == 1223
27 | noContent: false,
28 | // True when res.status == 400
29 | badRequest: false,
30 | // True when res.status == 401
31 | unauthorized: false,
32 | // True when res.status == 406
33 | notAcceptable: false,
34 | // True when res.status == 404
35 | notFound: false,
36 | // True when res.status == 403
37 | forbidden: false,
38 |
39 | // Unparsed response text
40 | text: '{"user":{"username":"JohnDoe","role":"admin"}}'
41 |
42 | // Parsed response text (only if response is 'application/json' or 'application/x-www-form-urlencoded'
43 | body: {
44 | // Example of parsed object from res.text
45 | user: {
46 | username: 'JohnDoe',
47 | role: 'admin'
48 | }
49 | }
50 |
51 | // The content-type (parsed from headers)
52 | type: 'application/json'
53 | // The charset (parsed from headers)
54 | charset: 'UTF-8'
55 | // Header object with each header field as a property
56 | headers: {
57 | 'content-type': 'application/json; charset=UTF-8',
58 | ...
59 | }
60 | }
61 | ```
62 |
--------------------------------------------------------------------------------
/sheets/co.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: co
3 | category: JavaScript libraries
4 | layout: 2017/sheet
5 | updated: 2017-10-27
6 | weight: -1
7 | intro: |
8 | [co](https://github.com/tj/co) allows you to use generators to manage async flow.
9 | ---
10 |
11 | [co]: https://github.com/tj/co
12 | [thunkify]: https://github.com/visionmedia/node-thunkify
13 | [unyield]: https://github.com/MatthewMueller/unyield
14 | [thenify]: https://www.npmjs.com/package/thenify
15 | [mz]: https://www.npmjs.com/package/mz
16 |
17 | ### Running generators
18 |
19 | ```js
20 | co(function * () {
21 | yield Promise.resolve(true)
22 | }).then(...)
23 | ```
24 |
25 | A generator can `yield` a thunk or promise. Using `co()` will immediately invoke the block inside it.
26 |
27 | ### Generator → Promise
28 |
29 | ```js
30 | var fn = co.wrap(function * (val) {
31 | return yield Promise.resolve(val)
32 | })
33 |
34 | fn().then(...)
35 | ```
36 |
37 | Use `co.wrap()`. Most of the time, you'll be using co.wrap.
38 |
39 | ### Generator → Node callback
40 |
41 | ```js
42 | var get = unyield(function * () {
43 | })
44 |
45 | get(function (err, res) { ... })
46 | ```
47 |
48 | Use [unyield]. (You can [thunkify] this later)
49 |
50 | ### Node callback → Thunk
51 |
52 | ```js
53 | var readFile = thunkify(fs.readFile)
54 |
55 | co(function*() {
56 | var data = yield readFile('index.txt', 'utf-8')
57 | })
58 | ```
59 |
60 | Use [thunkify]. You can yield this. You can also use [thenify] too.
61 |
62 | ### Using Node.js API
63 |
64 | ```js
65 | var readFile = require('mz/fs').readFile
66 |
67 | var getLines = co.wrap(function * (filename) {
68 | var data = yield readFile(filename, 'utf-8')
69 | return data.split('\n')
70 | })
71 |
72 | getLines('file.txt').then((lines) => { ... })
73 | ```
74 |
75 | Use [mz] for async Node.js API. You can also either [thunkify] or [thenify] them instead.
76 |
--------------------------------------------------------------------------------
/sheets/ember.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Ember.js
3 | category: JavaScript libraries
4 | tags: [Outdated]
5 | ---
6 |
7 | ### Routes
8 |
9 | ```js
10 | App.Router.map(function() {
11 | this.resource('trips', function() {
12 | this.route('item', { path: '/:trip_id' });
13 | });
14 |
15 | this.route('upcoming');
16 | this.route('about', { path: '/about' });
17 | this.route('schedules');
18 | this.route('history');
19 | this.route('post');
20 | });
21 | ```
22 |
23 | ### A route
24 |
25 | ```js
26 | App.IndexRoute = Ember.Route.extend({
27 | setupController: function(controller) {
28 | controller.set('title', 'my app');
29 | // {{title}}
30 | },
31 |
32 | setupController: function(controller, model) {
33 | controller.set("model", model);
34 | this.controllerFor('topPost').set('model', model);
35 | },
36 |
37 | model: function(params) {
38 | return this.store.find('posts');
39 | return this.store.find('post', params.post_id);
40 | },
41 |
42 | serialize: function(model) {
43 | // this will make the URL `/posts/foo-post`
44 | return { post_slug: model.get('slug') };
45 | }
46 | });
47 | ```
48 |
49 | ### View
50 |
51 | ```js
52 | App.InfoView = Ember.View.extend({
53 | templateName: 'input', /* optional */
54 |
55 | fooName: "Hello" /* {{ view.fooName }} */
56 |
57 | click: function(e) {
58 | "I was clicked";
59 | }
60 |
61 | });
62 | ```
63 |
64 | ### Markup
65 |
66 | ```
67 |
68 |