├── .gitignore ├── Dockerfile ├── .prettierrc ├── sheets ├── gpg.md ├── brew.md ├── date.md ├── es2015.md ├── es2016.md ├── es2017.md ├── es2018.md ├── fetch.md ├── gpgconf.md ├── sh.md ├── css-font.md ├── flexbox.md ├── jade.md ├── expect.js.md ├── flowtype.md ├── gutom.md ├── harvey-js.md ├── package.md ├── commander-js.md ├── css-animation.md ├── css-selectors.md ├── handlebars-js.md ├── immutable-js.md ├── css-background.md ├── factory_girl.md ├── phoenix-ecto@1.3.md ├── mongodb.md ├── jquery-cdn.md ├── crypto.md ├── freenode.md ├── simple_form.md ├── passenger.md ├── yaml.md ├── sh-pipes.md ├── perl-pie.md ├── google-webfonts.md ├── nocode.md ├── man.md ├── nodejs-assert.md ├── appcache.md ├── browser-sync.md ├── rack-test.md ├── rails-features.md ├── ansible-examples.md ├── rails-gems.md ├── nock.md ├── ansible-roles.md ├── cidr.md ├── mixpanel.md ├── premailer.md ├── html-share.md ├── ncftp.md ├── rake.md ├── ubuntu.md ├── html-microformats.md ├── weinre.md ├── ruby21.md ├── js-speech.md ├── linux.md ├── nodejs-path.md ├── siege.md ├── qunit.md ├── top.md ├── rubygems.md ├── analytics.md ├── frequency-separation-retouching.md ├── phoenix@1.2.md ├── wip │ ├── timewarrior.md │ ├── compose-key.md │ └── php.md ├── animated_gif.md ├── inline-docs.md ├── sed.md ├── handlebars.js.md ├── harvey.js.md ├── ledger-query.md ├── ansi.md ├── commander.js.md ├── ruby.md ├── watchman.md ├── zuul.md ├── cordova.md ├── ledger-csv.md ├── gmail.md ├── gh-pages.md ├── immutable.js.md ├── rename.md ├── css-antialias.md ├── elixir-metaprogramming.md ├── vagrant.md ├── znc.md ├── analytics.js.md ├── c_preprocessor.md ├── less.md ├── applinks.md ├── flashlight.md ├── ie_bugs.md ├── sql-join.md ├── applescript.md ├── dom-selection.md ├── bookshelf.md ├── zombie.md ├── jquery.md ├── virtual-dom.md ├── inkscape.md ├── ledger-periods.md ├── mocha.md ├── modernizr.md ├── pass.md ├── blessed.md ├── social-images.md ├── ets.md ├── emacs.md ├── macos-mouse-acceleration.md ├── chunky_png.md ├── nodejs-process.md ├── vimscript-snippets.md ├── machinist.md ├── google_analytics.md ├── js-appcache.md ├── rst.md ├── spreadsheet.md ├── mocha-html.md ├── browserify.md ├── make-assets.md ├── vows.md ├── postgresql.md ├── nopt.md ├── parsimmon.md ├── deis.md ├── css-system-font-stack.md ├── ledger-examples.md ├── promise.md ├── ledger-format.md ├── js-lazy.md ├── web-workers.md ├── cron.md ├── jscoverage.md ├── mocha-tdd.md ├── bundler.md ├── deku.md ├── nodejs.md ├── rails-tricks.md ├── dom-range.md ├── git-branch.md ├── meow.md ├── polyfill.io.md ├── resolutions.md ├── weechat.md ├── imagemagick.md ├── tomdoc.md ├── travis-gh-pages.md ├── mocha-blanket.md ├── nodejs-fs.md ├── tape.md ├── yargs.md ├── moment.md ├── sequelize.md ├── awscli.md ├── curl.md ├── umdjs.md ├── figma.md ├── editorconfig.md ├── vim-unite.md ├── ffmpeg.md ├── layout-thrashing.md ├── watchexec.md ├── superagent.md ├── co.md ├── ember.md ├── projectionist.md ├── minimist.md ├── rsync.md ├── sinon-chai.md ├── firebase.md ├── express.md ├── ios-provision.md ├── ansible.md ├── kramdown.md ├── dockerfile.md ├── rdoc.md ├── js-model.md ├── exunit.md ├── activeadmin.md ├── flynn.md ├── js-array.md ├── find.md ├── html-email.md ├── js-fetch.md ├── git-log.md ├── markdown.md ├── middleman.md ├── unicode.md ├── zsh.md └── brunch.md ├── assets └── favicon.png ├── support ├── format.sh ├── check.sh └── status.sh ├── _docs └── images │ └── gitpod_preview_tut.png ├── netilfy.toml ├── docker-compose.yml ├── .gitpod.yml ├── .travis.yml ├── package.json ├── .github └── workflows │ └── rebase.yml ├── README.md ├── Makefile └── CONTRIBUTING.md /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /devhints-engine 3 | /public 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:10 2 | RUN mkdir -p /app 3 | WORKDIR /app 4 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } 5 | -------------------------------------------------------------------------------- /sheets/gpg.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: GPG 3 | category: Hidden 4 | redirect_to: /gnupg 5 | --- 6 | -------------------------------------------------------------------------------- /assets/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstacruz/cheatsheets-ng/master/assets/favicon.png -------------------------------------------------------------------------------- /sheets/brew.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Homebrew 3 | category: Hidden 4 | redirect_to: /homebrew 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/date.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Date 3 | categoroy: Hidden 4 | redirect_to: /datetime 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/es2015.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ES2015 3 | category: JavaScript 4 | redirect_to: /es6 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/es2016.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ES2016 3 | category: JavaScript 4 | redirect_to: /es6 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/es2017.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ES2017 3 | category: JavaScript 4 | redirect_to: /es6 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/es2018.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ES2018 3 | category: JavaScript 4 | redirect_to: /es6 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/fetch.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: fetch() 3 | category: Hidden 4 | redirect_to: /js-fetch 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/gpgconf.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: gpgconf 3 | category: Hidden 4 | redirect_to: /gnupg 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/sh.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Shell scripting 3 | category: CLI 4 | redirect_to: /bash 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/css-font.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: CSS font 3 | category: Hidden 4 | redirect_to: /css#fonts 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/flexbox.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Flexbox 3 | category: Hidden 4 | redirect_to: /css-flexbox 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/jade.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Jade 3 | category: JavaScript libraries 4 | redirect_to: /pug 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/expect.js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: expect.js 3 | category: Hidden 4 | redirect_to: /expectjs 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/flowtype.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Flow 3 | redirect_to: /flow 4 | category: JavaScript libraries 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/gutom.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Gutom 3 | category: Hidden 4 | redirect_to: /ph-food-delivery 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/harvey-js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Harvey.js 3 | category: Hidden 4 | redirect_to: /harvey.js 5 | --- 6 | -------------------------------------------------------------------------------- /support/format.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | perl -p -i -e 's/^{:(.*?)}$//g' sheets/{,*/}*.md 3 | -------------------------------------------------------------------------------- /sheets/package.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: package.json 3 | category: Hidden 4 | redirect_to: /package.json 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/commander-js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Commander.js 3 | category: Hidden 4 | redirect_to: /commander.js 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/css-animation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: CSS animations 3 | category: Hidden 4 | redirect_to: /css#animation 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/css-selectors.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: CSS selectors 3 | category: Hidden 4 | redirect_to: /css#selectors 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/handlebars-js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Handlebars.js 3 | category: Hidden 4 | redirect_to: /handlebars.js 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/immutable-js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Immutable.js 3 | category: Hidden 4 | redirect_to: /immutable.js 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/css-background.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: CSS background 3 | category: Hidden 4 | redirect_to: /css#background 5 | --- 6 | -------------------------------------------------------------------------------- /sheets/factory_girl.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Factory Girl 3 | category: JavaScript libraries 4 | redirect_to: /factory_bot 5 | --- 6 | -------------------------------------------------------------------------------- /_docs/images/gitpod_preview_tut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rstacruz/cheatsheets-ng/master/_docs/images/gitpod_preview_tut.png -------------------------------------------------------------------------------- /sheets/phoenix-ecto@1.3.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Phoenix: Ecto models" 3 | category: Hidden 4 | redirect_to: /phoenix-ecto 5 | deprecated: true 6 | --- 7 | -------------------------------------------------------------------------------- /sheets/mongodb.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: MongoDB 3 | category: Development 4 | tags: [WIP] 5 | --- 6 | 7 | ## Querying 8 | 9 | ```js 10 | { name: 'john' } 11 | { name: { $eq: 'john' } } 12 | ``` 13 | -------------------------------------------------------------------------------- /netilfy.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | publish = 'public' 3 | command = 'make build' 4 | 5 | [build.environment] 6 | NODE_VERSION = '10.15.0' 7 | 8 | [context.deploy-preview.environment] 9 | DEPLOY_PREVIEW = '1' 10 | -------------------------------------------------------------------------------- /sheets/jquery-cdn.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: jQuery CDN 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Google jQuery 7 | 8 | 9 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | web: 5 | build: . 6 | volumes: 7 | - '.:/app' 8 | ports: 9 | - '19400:19400' 10 | environment: 11 | PORT: '19400' 12 | command: 'yarn develop' 13 | user: '1000' 14 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: gitpod/workspace-full 2 | 3 | github: 4 | # Prebuild the docker image for gitpod - https://www.gitpod.io/docs/46_prebuilds/ 5 | prebuilds: 6 | # enable for the master/default branch 7 | master: true 8 | 9 | tasks: 10 | - init: bundle install -------------------------------------------------------------------------------- /support/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Print files that need to be updated. 3 | output=$(grep -l "^{:" sheets/{,*/}*.md) 4 | if [ -z "$output" ]; then 5 | echo "OK" >&1 6 | exit 0 7 | else 8 | echo "! These files need to be updated:" 9 | echo $output 10 | exit 16 11 | fi 12 | -------------------------------------------------------------------------------- /sheets/crypto.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Cryptography 3 | tags: [WIP] 4 | --- 5 | 6 | ### Password algorithms 7 | 8 | * [PBKDF2](http://en.wikipedia.org/wiki/PBKDF2) - password-based key derivation function 9 | 10 | * [HMAC](http://en.wikipedia.org/wiki/HMAC) - Hash-based message authentication code 11 | -------------------------------------------------------------------------------- /sheets/freenode.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Freenode 3 | --- 4 | 5 | ### irc.freenode.net 6 | 7 | /msg nickserv identify [nick] 8 | /msg nickserv info 9 | 10 | ### Add a nick 11 | 12 | /nick newnick 13 | /msg nickserv identify 14 | /msg nickserv group 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '10' 4 | cache: 5 | directories: 6 | - node_modules 7 | script: 8 | # - yarn run prettier:check 9 | - yarn build 10 | 11 | after_success: 12 | - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then ./node_modules/.bin/gh-pages -d public; fi 13 | -------------------------------------------------------------------------------- /sheets/simple_form.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: SimpleForm 3 | --- 4 | 5 | ```ruby 6 | <%= f.input :email, required: false, autofocus: true %> 7 | <%= f.input :password, required: false %> 8 | <%= f.input :remember_me, as: :boolean %> 9 | <%= f.button :submit, "Sign in" %> 10 | ``` 11 | 12 | ```ruby 13 | simple_form_for @x, 14 | wrapper: :small 15 | ``` 16 | -------------------------------------------------------------------------------- /sheets/passenger.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Phusion Passenger 3 | tags: [WIP] 4 | --- 5 | 6 | ### Nginx configuration 7 | 8 | ```conf 9 | server { 10 | listen 80; 11 | server_name www.yourhost.com; 12 | root /somewhere/public; # <--- be sure to point to 'public'! 13 | passenger_enabled on; 14 | autoindex on; # Show directory listings 15 | } 16 | ``` 17 | -------------------------------------------------------------------------------- /sheets/yaml.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Yaml 3 | category: Markup 4 | layout: 2017/sheet 5 | prism_languages: [yaml] 6 | --- 7 | 8 | ### Multiline strings 9 | 10 | ```yaml 11 | Multiline: | 12 | hello 13 | world 14 | ``` 15 | 16 | ### Inheritance 17 | 18 | ```yaml 19 | parent: &defaults 20 | a: 2 21 | b: 3 22 | 23 | child: 24 | <<: *defaults 25 | b: 4 26 | ``` 27 | -------------------------------------------------------------------------------- /sheets/sh-pipes.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Shell: named pipes" 3 | category: CLI 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Named pipes 8 | 9 | ```sh 10 | diff <(ls ./old) <(ls ./new) 11 | ``` 12 | 13 | This creates a virtual file with the contents of the output of `ls ./old`. 14 | 15 | ### References 16 | 17 | * [Named pipe](https://en.wikipedia.org/wiki/Named_pipe) _(wikipedia.org)_ 18 | -------------------------------------------------------------------------------- /sheets/perl-pie.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Perl-pie 3 | category: Development 4 | --- 5 | 6 | ### Search and replace 7 | 8 | ```sh 9 | perl -p -i -e 's/hello/hola/g' *.txt 10 | ``` 11 | 12 | ### Back-referencing 13 | 14 | Use `\1` et al. 15 | 16 | ```sh 17 | # '@include align-items(center);' => 'align-items: center;' 18 | perl -p -i -e "s/\@include (align-items)\((.*)\);/\1: \2;/g" 19 | ``` 20 | -------------------------------------------------------------------------------- /sheets/google-webfonts.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Google Webfonts 3 | --- 4 | 5 | ### Link tag 6 | 7 | 8 | 9 | ### CSS import 10 | 11 | @import url(http://fonts.googleapis.com/css?family=Open+Sans); 12 | @import url(http://fonts.googleapis.com/css?family=Open+Sans:400,400italic|Montserrat:400,700); 13 | -------------------------------------------------------------------------------- /sheets/nocode.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Nocode 3 | layout: 2017/sheet 4 | updated: 2018-03-17 5 | intro: | 6 | [Nocode](https://github.com/kelseyhightower/nocode) is the best way to write secure and reliable applications. Write nothing; deploy nowhere. 7 | --- 8 | 9 | ## Nothing 10 | 11 | 12 | 13 |































14 | -------------------------------------------------------------------------------- /support/status.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | total="$(git ls-files | grep \.md | wc -l)" 4 | echo "Checking $total files..." 5 | 6 | yarn run prettier:check > __list.txt 7 | echo "See __list.txt" 8 | # to_update=$(echo $output | grep "success formatting" | awk '{ print $3 }') 9 | # updated=$(echo $output | grep "unchanged" | awk '{ print $1 }') 10 | 11 | # echo "- $updated of $total files OK." 12 | # echo "- $to_update files need updating." 13 | -------------------------------------------------------------------------------- /sheets/man.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Man 3 | category: CLI 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Man paths 8 | 9 | | `1` | General User Commands | 10 | | `2` | System Calls | 11 | | `3` | Library Routines | 12 | | `4` | Special Files and Sockets | 13 | | `5` | File formats and Conventions | 14 | | `6` | Games and Fun Stuff | 15 | | `7` | Miscellaneous Documentation | 16 | | `8` | System Administration | 17 | | `9` | Kernel and Programming Style | 18 | | `n` | Tcl/Tk | 19 | -------------------------------------------------------------------------------- /sheets/nodejs-assert.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: assert 3 | category: Node.js 4 | --- 5 | 6 | ### Assertions 7 | 8 | ```js 9 | const assert = require('assert') 10 | ``` 11 | 12 | ```js 13 | assert(val) 14 | assert.equal(actual, expected) 15 | assert.notEqual(a, e) 16 | ``` 17 | 18 | ```js 19 | assert.deepEqual(a, e) 20 | assert.notDeepEqual(a, e) 21 | ``` 22 | 23 | ```js 24 | assert.throws(fn) 25 | ``` 26 | 27 | ### References 28 | 29 | * http://nodejs.org/api/assert.html 30 | -------------------------------------------------------------------------------- /sheets/appcache.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Appcache 3 | category: HTML 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Format 8 | 9 | ``` 10 | CACHE MANIFEST 11 | # version 12 | 13 | CACHE: 14 | http://www.google.com/jsapi 15 | /assets/app.js 16 | /assets/bg.png 17 | 18 | NETWORK: 19 | * 20 | ``` 21 | 22 | Note that Appcache is deprecated! 23 | 24 | See: [Using the application cache](https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache) _(developer.mozilla.org)_ 25 | -------------------------------------------------------------------------------- /sheets/browser-sync.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Browsersync 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Installing browser-sync 7 | 8 | ```bash 9 | npm i -g browser-sync 10 | ``` 11 | 12 | ### Start a server 13 | 14 | ```bash 15 | browser-sync start --server --files='**/*.html, **/*.css' 16 | ``` 17 | 18 | ### Options 19 | 20 | ```bash 21 | --port=N 22 | --proxy="http://127.0.0.1:3000" 23 | ``` 24 | 25 | ### References 26 | 27 | * [browsersync.io](http://browsersync.io) 28 | -------------------------------------------------------------------------------- /sheets/rack-test.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: rack-test 3 | category: Ruby libraries 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Methods 8 | 9 | ```ruby 10 | get 'url' 11 | post 'url', 'name' => 'john' 12 | put 13 | patch 14 | delete 15 | options 16 | head 17 | ``` 18 | 19 | ```ruby 20 | authorize 'user', 'pass' 21 | env 'rack.session', csrf: 'token' 22 | header 'Content-Type', 'text/html' 23 | ``` 24 | 25 | See [rack/test.rb](https://github.com/brynary/rack-test/blob/master/lib/rack/test.rb). 26 | -------------------------------------------------------------------------------- /sheets/rails-features.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rails features 3 | category: Rails 4 | tags: [WIP] 5 | --- 6 | 7 | ### Page caching 8 | 9 | ```rb 10 | class WeblogController < ActionController::Base 11 | caches_page :show, :new 12 | end 13 | ``` 14 | 15 | This will generate cache files such as `weblog/show/5.html` and 16 | `weblog/new.html`, which match the URLs used that would normally trigger dynamic 17 | page generation. See: [Page caching](https://github.com/rails/actionpack-page_caching) 18 | -------------------------------------------------------------------------------- /sheets/ansible-examples.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ansible examples 3 | category: Ansible 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Examples 8 | 9 | * [Ruby installation](https://github.com/chelsea/ansible-example-ruby/blob/master/roles/webserver/tasks/main.yml) _(github.com)_ 10 | * [Postgres installation](https://github.com/chelsea/ansible-example-ruby/blob/master/roles/db/tasks/main.yml) _(github.com)_ 11 | * [GitLab installation](https://github.com/tingtun/ansible-playbook-gitlab) _(github.com)_ 12 | -------------------------------------------------------------------------------- /sheets/rails-gems.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rails gems 3 | category: Rails 4 | --- 5 | 6 | ### Rico's preferred rails gems 7 | 8 | Development: 9 | 10 | gem 'spring' # code reloading 11 | gem 'letter_opener' 12 | gem 'better_errors' 13 | gem 'meta-tags' 14 | gem 'guard-rspec' 15 | 16 | Prod: 17 | 18 | gem 'kaminari' # pagination 19 | gem 'devise' 20 | gem 'meta-tags', require: 'meta_tags' 21 | gem 'friendly_id' 22 | gem 'bourbon' 23 | gem 'neat' 24 | gem 'turbolinks' 25 | -------------------------------------------------------------------------------- /sheets/nock.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Nock 3 | category: JavaScript libraries 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Nock 8 | 9 | ```js 10 | scope = nock('http://foo.com') 11 | scope = nock('http://foo.com', { allowUnmocked: true }) 12 | ``` 13 | 14 | ```js 15 | nock('http://foo.com') 16 | .get('/user') 17 | .reply(200, { id: 1234 }) 18 | ``` 19 | 20 | ### Filtering 21 | 22 | ```js 23 | nock('http://foo.com') 24 | .filteringPath(/[&\?]token=[^&]*/g, '') 25 | .get('/user') 26 | 27 | // catches "/user?token=..." as well 28 | ``` 29 | -------------------------------------------------------------------------------- /sheets/ansible-roles.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ansible roles 3 | category: Ansible 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Structure 8 | 9 | roles/ 10 | common/ 11 | tasks/ 12 | handlers/ 13 | files/ # 'copy' will refer to this 14 | templates/ # 'template' will refer to this 15 | meta/ # Role dependencies here 16 | vars/ 17 | defaults/ 18 | main.yml 19 | 20 | ### References 21 | 22 | * http://www.ansibleworks.com/docs/playbooks_roles.html 23 | -------------------------------------------------------------------------------- /sheets/cidr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: CIDR 3 | category: Misc 4 | updated: 2018-05-14 5 | --- 6 | 7 | ### CIDR ranges 8 | 9 | | Range | First IP | Last IP | 10 | | --------------- | -------- | -------------- | 11 | | **10.0.0.0/24** | 10.0.0.0 | 10.0.0.255 | 12 | | **10.0.0.0/16** | 10.0.0.0 | 10.0.255.255 | 13 | | **10.0.0.0/8** | 10.0.0.0 | 10.255.255.255 | 14 | | **0.0.0.0/0** | (all) | (all) | 15 | 16 | ### Resources 17 | 18 | * [CIDR range calculator](http://ipaddressguide.com/cidr#range) _(ipaddressguide.com)_ 19 | -------------------------------------------------------------------------------- /sheets/mixpanel.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mixpanel 3 | layout: 2017/sheet 4 | category: Analytics 5 | --- 6 | 7 | ### Identify 8 | 9 | ```js 10 | mixpanel.identify('284') 11 | mixpanel.people.set({ $email: 'hi@gmail.com' }) 12 | ``` 13 | 14 | ```js 15 | // Set common properties 16 | mixpanel.register({ age: 28, gender: 'male' }) 17 | ``` 18 | 19 | ### Track events 20 | 21 | ```js 22 | mixpanel.track('Login success') 23 | mixpanel.track('Search', { query: 'cheese' }) 24 | ``` 25 | 26 | ### References 27 | 28 | * 29 | -------------------------------------------------------------------------------- /sheets/premailer.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Premailer 3 | --- 4 | 5 | ### Special properties 6 | 7 | | Property | Description | 8 | | ------------------------ | ------------------------------------------ | 9 | | `-premailer-width` | Available on table, th and td elements | 10 | | `-premailer-height` | Available on table, tr, th and td elements | 11 | | `-premailer-cellpadding` | Available on table elements | 12 | | `-premailer-cellspacing` | Available on table elements | 13 | -------------------------------------------------------------------------------- /sheets/html-share.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Share links 3 | layout: 2017/sheet 4 | category: HTML 5 | updated: 2017-09-04 6 | --- 7 | 8 | ## Share links 9 | 10 | 11 | 12 | #### Facebook 13 | 14 | ```html 15 | 16 | ``` 17 | 18 | #### Twitter 19 | 20 | ```html 21 | 22 | ``` 23 | 24 | #### Google Plus 25 | 26 | ```html 27 | 28 | ``` 29 | -------------------------------------------------------------------------------- /sheets/ncftp.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ncftp 3 | category: CLI 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Bookmarking 8 | 9 | ```bash 10 | $ ncftp 11 | $ open -u username ftp.host.com 12 | $ bookmark bookmarkname 13 | ``` 14 | 15 | ### Mass download 16 | 17 | ```bash 18 | $ ncftpget -R bookmarkname /www/ . 19 | ``` 20 | 21 | ### Mass upload 22 | 23 | ```bash 24 | $ ncftpput -R bookmarkname /www/ . 25 | ``` 26 | 27 | ### Upload just the changed files 28 | 29 | ```bash 30 | $ git show --pretty="format:" --name-only HEAD~1 31 | $ ncftpget -R -C log bookmarkname /www/ . 32 | ``` 33 | -------------------------------------------------------------------------------- /sheets/rake.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rake 3 | category: Ruby 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Basic syntax 8 | 9 | ```rb 10 | namespace :foo do 11 | desc "Description" 12 | task :bar do 13 | ... 14 | end 15 | 16 | task :baz => :dependency do 17 | end 18 | 19 | task :baz => [:dep1, :dep2, :dep3] do 20 | end 21 | end 22 | 23 | # rake foo:bar 24 | ``` 25 | 26 | ### Rake task with arguments 27 | 28 | ```rb 29 | desc "Do something" 30 | task :workit, [:id] => :environment do |_, args| 31 | id = args[:id] 32 | end 33 | 34 | # rake workit[234] 35 | ``` 36 | -------------------------------------------------------------------------------- /sheets/ubuntu.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ubuntu 3 | --- 4 | 5 | ### Aptitude stuff 6 | 7 | aptitude search mysql # Look for something 8 | dpkg -S `which tsclient` # What package does it belong to? 9 | dpkg -L aria2c # What does this package provide? 10 | dpkg -i *.deb # Install a deb file 11 | dpkg -s nodejs # Show info 12 | 13 | dpkg --get-selections # list installed packages 14 | 15 | ### Apt archives path 16 | 17 | /var/cache/apt/archives 18 | 19 | ### List services 20 | 21 | service --status-all 22 | -------------------------------------------------------------------------------- /sheets/html-microformats.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Microformats 3 | category: HTML 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Author 8 | 9 | ```html 10 | 14 | 15 | ``` 16 | 17 | ### Time 18 | 19 | ```html 20 | 21 | ``` 22 | -------------------------------------------------------------------------------- /sheets/weinre.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Weinre 3 | category: JavaScript libraries 4 | --- 5 | 6 | * [Weinre](http://people.apache.org/~pmuellr/weinre/) 7 | 8 | Install: 9 | 10 | $ npm install -g weinre 11 | 12 | Start the server: 13 | 14 | $ weinre --boundHost 0.0.0.0 15 | $ open http://localhost:8080 16 | 17 | 18 | -------------------------------------------------------------------------------- /sheets/ruby21.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ruby 2.1 3 | category: Ruby 4 | --- 5 | 6 | ### Named arguments with defaults 7 | 8 | # length is required 9 | def pad(num, length:, char: "0") 10 | num.to_s.rjust(length, char) 11 | end 12 | 13 | pad(42, length: 6) #=> "000042" 14 | pad(42) #=> # 15 | 16 | ### Module.prepend 17 | 18 | prepend(Module.new do 19 | define_method ... 20 | end) 21 | 22 | ### References 23 | 24 | * http://globaldev.co.uk/2013/03/ruby-2-0-0-in-detail 25 | * http://globaldev.co.uk/2014/05/ruby-2-1-in-detail 26 | -------------------------------------------------------------------------------- /sheets/js-speech.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: JavaScript speech synthesis 3 | category: JavaScript 4 | layout: 2017/sheet 5 | weight: -1 6 | --- 7 | 8 | ## SpeechSynthesisUtterance 9 | 10 | 11 | 12 | ```js 13 | function speak(message) { 14 | var msg = new SpeechSynthesisUtterance(message) 15 | var voices = window.speechSynthesis.getVoices() 16 | msg.voice = voices[0] 17 | window.speechSynthesis.speak(msg) 18 | } 19 | ``` 20 | 21 | ```js 22 | speak('Hello, world') 23 | ``` 24 | 25 | See: [SpeechSynthesisUtterance](https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance) _(developer.mozilla.org)_ 26 | -------------------------------------------------------------------------------- /sheets/linux.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Linux 3 | --- 4 | 5 | ### Mounting a RAM drive 6 | 7 | $ mount -t tmpfs -o size=5G,nr_inodes=5k,mode=700 tmpfs /tmp 8 | 9 | ### Visudo 10 | 11 | sudo visudo 12 | 13 | username ALL=(ALL) NOPASSWD:/sbin/restart whatever 14 | 15 | ### Display the amount of available disk space 16 | 17 | ```sh 18 | df 19 | df -h # human-readable format 20 | df -a # all filesystems 21 | ``` 22 | 23 | ### Display disk usage 24 | 25 | ```sh 26 | du 27 | du -hsx * | sort -rh | head -10 # largest 10 folders 28 | ``` 29 | 30 | ### Answer yes in a bash script 31 | 32 | ```bash 33 | yes | /your/command 34 | ``` 35 | -------------------------------------------------------------------------------- /sheets/nodejs-path.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: path 3 | category: Node.js 4 | --- 5 | 6 | ### Finding real paths 7 | 8 | ```js 9 | fs.realpath('/etc/passwd', (err, path) => { 10 | // path === "/private/etc/passwd" 11 | }) 12 | ``` 13 | 14 | ### Joining paths 15 | 16 | ```js 17 | dir = path.join('etc', 'passwd') 18 | dir = path.resolve('/etc', 'passwd', '..', 'var') 19 | ``` 20 | 21 | ### dirname and basename 22 | 23 | ```js 24 | path.dirname('/etc/passwd') // => "/etc" 25 | path.basename('/etc/passwd') // => "passwd" 26 | path.basename('/etc/rc.d', '.d') // => "rc" 27 | ``` 28 | 29 | ### References 30 | 31 | - 32 | -------------------------------------------------------------------------------- /sheets/siege.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Siege 3 | category: Others 4 | --- 5 | 6 | ``` 7 | siege -b -c=10 -t=5m http://... 8 | ``` 9 | 10 | ``` 11 | -c, --concurrent=N 12 | -t, --time=MINSm 13 | -r, --reps=N 14 | ``` 15 | 16 | ``` 17 | -i, --internet Hit URLs randomly 18 | -b, --benchmark No delay between requests 19 | ``` 20 | 21 | ### Configuration 22 | 23 | ``` 24 | -f, --file=FILE load urls.txt 25 | -R, --rc=FILE load siegerc 26 | ``` 27 | 28 | > Also see: [siegerc](https://gist.github.com/stansmet/3067988) 29 | 30 | ### Headers 31 | 32 | ``` 33 | -H, --header="Cookie: foo=bar" 34 | -A, --user-agent="Mozilla" 35 | -T, --content-type="text/html" 36 | ``` 37 | -------------------------------------------------------------------------------- /sheets/qunit.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Qunit 3 | category: JavaScript libraries 4 | --- 5 | 6 | QUnit.module('a'); 7 | QUnit.test('ok', function (t) { ... }); 8 | 9 | ### Hooks 10 | 11 | // each test 12 | QUnit.testStart(function) 13 | QUnit.testEnd(function) 14 | 15 | // each module 16 | QUnit.moduleStart(function) 17 | QUnit.moduleEnd(function) 18 | 19 | // all 20 | QUnit.begin(function) 21 | QUnit.done(function) 22 | 23 | ### Assertions 24 | 25 | t.equal(actual, expected) 26 | t.deepEqual(actual, expected) 27 | t.strictEqual(actual, expected) 28 | t.propEqual(actual, expected) 29 | 30 | t.notEqual 31 | 32 | t.expect(amount) 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cheatsheets", 3 | "version": "1.0.0", 4 | "devDependencies": { 5 | "gh-pages": "^1.1.0", 6 | "prettier-eslint-cli": "^4.7.1" 7 | }, 8 | "license": "MIT", 9 | "main": "index.js", 10 | "scripts": { 11 | "build": "echo \"Try 'make build'\"; exit 1", 12 | "deploy": "echo \"Try 'make build' then 'make deploy'\"; exit 1", 13 | "develop": "make develop", 14 | "lint:check": "./support/check.sh", 15 | "lint:fix": "./support/format.sh", 16 | "prettier:check": "prettier-eslint --list-different 'sheets/**/*.md'", 17 | "prettier:fix": "prettier-eslint --write 'sheets/**/*.md'", 18 | "status": "./support/status.sh" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sheets/top.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: top 3 | category: CLI 4 | layout: 2017/sheet 5 | updated: 2020-01-01 6 | intro: See the processes in your Unix machine. 7 | --- 8 | 9 | ### Shortcuts 10 | 11 | | Shortcut | Description | 12 | | --------- | --------------------- | 13 | | `h` | shows help | 14 | | `q` | quits the program | 15 | | `m` | switches memory view | 16 | | `k` | kills process | 17 | | `Shift+p` | sorts by CPU usage | 18 | | `Shift+m` | sorts by memory usage | 19 | | `Shift+r` | reverses sorting | 20 | | `Shift+l` | searches for string | 21 | | `o` | adds a filter | 22 | | `=` | clears filters | 23 | {: .-shortcuts} 24 | -------------------------------------------------------------------------------- /sheets/rubygems.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rubygems 3 | category: Ruby 4 | --- 5 | 6 | gem build *.gemspec # Build a gem 7 | gem install *.gem # Install locally 8 | gem push *.gem # Upload to rubygems.org 9 | gem yank foogem -v 0.0.1 # Take it back 10 | 11 | gem owner foogem -a rico@ricostacruz.com 12 | 13 | gem list # List local gems 14 | gem which rake # Point to where lib/rake.rb is 15 | gem search -r rails # [remote] Search for gems 16 | 17 | # https://github.com/fnando/gem-open 18 | gem open foogem 19 | GEM_EDITOR="vim" gem open foogem 20 | 21 | cd $(basename `gem which rake`) # Go to a gem's path 22 | -------------------------------------------------------------------------------- /sheets/analytics.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Analytics libraries 3 | layout: 2017/sheet 4 | --- 5 | 6 | ### Mixpanel 7 | 8 | ```js 9 | mixpanel.identify('284') 10 | mixpanel.people.set({ $email: 'hi@gmail.com' }) 11 | mixpanel.register({ age: 28, gender: 'male' }) /* set common properties */ 12 | ``` 13 | 14 | See: [mixpanel](./mixpanel) 15 | 16 | 17 | 18 | ### Google Analytics's analytics.js 19 | 20 | ```js 21 | ga('create', 'UA-XXXX-Y', 'auto') 22 | ga('create', 'UA-XXXX-Y', { userId: 'USER_ID' }) 23 | ``` 24 | 25 | ```js 26 | ga('send', 'pageview') 27 | ga('send', 'pageview', { dimension15: 'My custom dimension' }) 28 | ``` 29 | 30 | See: [analytics.js](./analytics.js) 31 | 32 | 33 | -------------------------------------------------------------------------------- /sheets/frequency-separation-retouching.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Frequency separation retouching 3 | category: Others 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Frequency separation retouching in Photoshop 8 | 9 | Duplicate the layer twice. Perform these in each layer: 10 | 11 | 12 | 13 | #### Lower layer 14 | 15 | * Apply **Gaussian Blur** 16 | 17 | #### Upper layer 18 | 19 | * Set layer mask to **Linear light** 20 | * Image → **Apply Image** 21 | * Layer: _(select the lower layer)_ 22 | * Blending mode: `Subtract` 23 | * Scale: `2` 24 | * Offset: `128` 25 | 26 | ### Reference 27 | 28 | * 29 | 30 | 31 | -------------------------------------------------------------------------------- /sheets/phoenix@1.2.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Phoenix 1.2 3 | category: Elixir 4 | layout: 2017/sheet 5 | weight: -1 6 | updated: 2018-01-15 7 | --- 8 | 9 | See [Phoenix](./phoenix) for a more updated cheatsheet. 10 | 11 | ### Directory structure (Legacy 1.2) 12 | 13 | ``` 14 | ├── _build 15 | ├── config/ 16 | ├── deps/ 17 | ├── lib/ 18 | │ ├── hello/ 19 | │ ├── hello.ex 20 | ├── node_modules/ 21 | ├── priv/ 22 | ├── test/ 23 | └── web/ 24 | │ ├── channels/ 25 | │ ├── controllers/ 26 | │ ├── models/ 27 | │ ├── static/ 28 | │ ├── templates/ 29 | │ ├── views/ 30 | │ ├── gettext.ex 31 | │ ├── router.ex 32 | │ ├── web.ex 33 | ├── mix.exs 34 | ``` 35 | 36 | This is Phoenix 1.2's structure. Phoenix 1.3 has no `models`. 37 | -------------------------------------------------------------------------------- /sheets/wip/timewarrior.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Timewarrior 3 | category: CLI 4 | tags: [WIP] 5 | intro: | 6 | [Timewarrior](http://timewarrior.net/) is a time tracker for the command line. 7 | --- 8 | 9 | ### Stopwatch 10 | 11 | ``` 12 | timew start [tags] 13 | timew start 10:30 14 | ``` 15 | 16 | ``` 17 | timew stop 18 | timew cancel # cancel current tracking 19 | timew continue # continues last thing 20 | ``` 21 | 22 | See: [Stopwatch](https://taskwarrior.org/docs/timewarrior/stopwatch.html) _(taskwarrior.org)_ 23 | 24 | ### Past logs 25 | 26 | ``` 27 | timew track 9am - 11am 'Staff Meeting' 28 | ``` 29 | 30 | ### Reporting 31 | 32 | ``` 33 | timew month 34 | timew day 35 | timew summary 36 | timew summary :week 37 | ``` 38 | -------------------------------------------------------------------------------- /sheets/animated_gif.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Animated GIFs 3 | category: CLI 4 | layout: 2017/sheet 5 | --- 6 | 7 | ## Animated GIFs 8 | 9 | 10 | 11 | ### Convert MP4 to GIF 12 | 13 | ```bash 14 | mkdir -p gif 15 | mplayer -ao null -vo gif89a:outdir=gif $INPUT 16 | mogrify -format gif *.png 17 | gifsicle --colors=256 --delay=4 --loopcount=0 --dither -O3 gif/*.gif > ${INPUT%.*}.gif 18 | rm -rf gif 19 | ``` 20 | 21 | You'll need `mplayer`, `imagemagick` and `gifsicle`. This converts frames to .png, then turns them into an animated gif. 22 | 23 | ### A given range 24 | 25 | ```bash 26 | mplayer -ao null -ss 0:02:06 -endpos 0:05:00 -vo gif89a:outdir=gif videofile.mp4 27 | ``` 28 | 29 | See `-ss` and `-endpos`. 30 | -------------------------------------------------------------------------------- /sheets/inline-docs.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Inline documentation 3 | --- 4 | 5 | * Ruby: rdoc 6 | * JavaScript: jsdoc 7 | 8 | ### RDoc 9 | 10 | # Gets a circle's area 11 | # 12 | # @example 13 | # 14 | # area(3) 15 | # #=> 28.27 16 | # 17 | # @param [Number] r The radius of the ricle 18 | # @return [true] If so 19 | # 20 | # == Definition lists 21 | # 22 | # list:: hi. 23 | # +foo+:: parameterized 24 | # 25 | # == Definition lists 26 | # [foo] also 27 | # [bar] like this 28 | 29 | http://rdoc.rubyforge.org/RDoc/Markup.html 30 | 31 | ### Jsdoc 32 | 33 | /** 34 | * Ads numbers 35 | * 36 | * @this {Circle} 37 | * @param {Number} r The radius 38 | -------------------------------------------------------------------------------- /sheets/sed.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: sed 3 | category: CLI 4 | layout: 2017/sheet 5 | intro: | 6 | Here's home hints on using sed. 7 | --- 8 | 9 | ### In place replacements 10 | 11 | #### In GNU sed: use `-i` without arg. 12 | 13 | ```bash 14 | sed -i -e 's/foo/bar/' example.md 15 | ``` 16 | 17 | #### In OSX, `-i ''` is required. 18 | 19 | ```bash 20 | sed -i '' -e 's/foo/bar/' example.md 21 | ``` 22 | 23 | ### File regions 24 | 25 | #### Print until a certain line is met 26 | 27 | ```bash 28 | sed '/begin api/q' 29 | ``` 30 | 31 | #### Print until a certain line is met, but not that line 32 | 33 | ```bash 34 | sed '/^# begin/,$d' 35 | ``` 36 | 37 | #### Print everything after a given line 38 | 39 | ```bash 40 | sed -n '/end api/,$p' 41 | ``` 42 | -------------------------------------------------------------------------------- /sheets/handlebars.js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Handlebars.js 3 | category: JavaScript libraries 4 | layout: 2017/sheet 5 | weight: -1 6 | --- 7 | 8 | ### Helpers 9 | 10 | #### Defining 11 | 12 | ```js 13 | Handlebars.registerHelper('link_to', function() { 14 | return "" + this.body + '' 15 | }) 16 | ``` 17 | 18 | #### Using 19 | 20 | ```js 21 | var context = { posts: [{ url: '/hello-world', body: 'Hello World!' }] } 22 | var source = '
    {{#posts}}
  • {{{link_to}}}
  • {{/posts}}
' 23 | ``` 24 | 25 | ```js 26 | var template = Handlebars.compile(source) 27 | template(context) 28 | ``` 29 | 30 | #### Rendered output 31 | 32 | ```html 33 | 36 | ``` 37 | -------------------------------------------------------------------------------- /sheets/harvey.js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Harvey.js 3 | category: JavaScript libraries 4 | layout: 2017/sheet 5 | intro: | 6 | [Harvey.js](http://harvesthq.github.io/harvey/) helps you build responsive interfaces. 7 | --- 8 | 9 | ### Usage 10 | 11 | ```js 12 | Harvey.attach('(min-width: 600px)', { 13 | setup: function() { 14 | // Called on first enter 15 | }, 16 | on: function() { 17 | // Called on every enter 18 | }, 19 | off: function() { 20 | // Called on every exit 21 | } 22 | }) 23 | ``` 24 | 25 | ### Deprecated 26 | 27 | Harvey.js hasn't been updated in a while, as of time of writing. Consider [enquire.js](https://github.com/WickyNilliams/enquire.js) instead. 28 | 29 | ### References 30 | 31 | * 32 | -------------------------------------------------------------------------------- /sheets/ledger-query.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ledger queries 3 | category: Ledger 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Query characters 8 | 9 | | Query | Description | 10 | | --------------- | ----------- | 11 | | `@payee` | Payee | 12 | | `%tag` | Tag | 13 | | `=note` | Note | 14 | | `#code` | Code | 15 | | --- | --- | 16 | | `TERM and TERM` | Boolean and | 17 | | `TERM or TERM` | Boolean or | 18 | | `not TERM` | Boolean not | 19 | 20 | ### Examples 21 | 22 | ```sh 23 | ledger r @taco 24 | ledger r comment =~ /landline/ 25 | ``` 26 | 27 | ## References 28 | 29 | 30 | 31 | * 32 | -------------------------------------------------------------------------------- /sheets/ansi.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ansi codes 3 | category: CLI 4 | --- 5 | 6 | Format 7 | 8 | \033[#m 9 | 10 | Where: 11 | 12 | 0 clear 13 | 1 bold 14 | 4 underline 15 | 5 blink 16 | 17 | 30-37 fg color 18 | 40-47 bg color 19 | 20 | 1K clear line (to beginning of line) 21 | 2K clear line (entire line) 22 | 2J clear screen 23 | 0;0H move cursor to 0;0 24 | 25 | 1A move up 1 line 26 | 27 | Colors 28 | 29 | 0 black 30 | 1 red 31 | 2 green 32 | 3 yellow 33 | 4 blue 34 | 5 magenta 35 | 6 cyan 36 | 7 white 37 | 38 | Stuff 39 | 40 | hide_cursor() { printf "\e[?25l"; } 41 | show_cursor() { printf "\e[?25h"; } 42 | -------------------------------------------------------------------------------- /sheets/commander.js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Commander.js 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Initialize 7 | 8 | ```js 9 | var cli = require('commander') 10 | ``` 11 | 12 | ### Options 13 | 14 | ```js 15 | cli 16 | .version(require('../package').version) 17 | .usage('[options] ') 18 | .option('-w, --words ', 'generate words') 19 | .option('-i, --interval ', 'interval [1000]', 1000) 20 | .option('-s, --symbols', 'include symbols') 21 | .parse(process.argv) 22 | ``` 23 | 24 | ### Help 25 | 26 | ```js 27 | .on('--help', function() { 28 | console.log('') 29 | }) 30 | ``` 31 | 32 | ### Commands 33 | 34 | ```js 35 | cli.outputHelp() 36 | cli.args == ['hello'] 37 | ``` 38 | 39 | ### Other useful things 40 | 41 | ```js 42 | process.exit(0) 43 | ``` 44 | -------------------------------------------------------------------------------- /sheets/ruby.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ruby 3 | category: Ruby 4 | --- 5 | 6 | * `$!` - latest error message 7 | * `$@` - location of error 8 | * `$_` - string last read by gets 9 | * `$.` - line number last read by interpreter 10 | * `$&` - string last matched by regexp 11 | * `$~` - the last regexp match, as an array of subexpressions 12 | * `$n` - the nth subexpression in the last match (same as `$~[n]`) 13 | * `$=` - case-insensitivity flag 14 | * `$/` - input record separator 15 | * `$\` - output record separator 16 | * `$0` - the name of the ruby script file 17 | * `$*` (or `ARGV`) - the command line arguments 18 | * `$$` - interpreter's process ID 19 | * `$?` - exit status of last executed child process 20 | * `$-i` `$-l` `$-p` `$-v` - Command line switches 21 | * `$-v` (or `$VERBOSE`) - verbose mode 22 | -------------------------------------------------------------------------------- /sheets/watchman.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Watchman 3 | layout: 2017/sheet 4 | updated: 2017-10-18 5 | weight: -1 6 | keywords: 7 | - "watchman watch ~/src" 8 | - "watchman watch-list" 9 | - "watchman -- trigger ~/rsc remake '*.js' -- make " 10 | --- 11 | 12 | ### Getting started 13 | 14 | ```bash 15 | watchman watch ./src 16 | ``` 17 | 18 | Adds `./src` to the watch list. 19 | 20 | ```bash 21 | watchman -- trigger ./src retest '*.js' -- npm test 22 | ``` 23 | 24 | Adds a trigger called `retest` to run `npm test` every time `*.js` changes in `./src`. 25 | 26 | ### Watching 27 | 28 | ``` 29 | watchman watch ~/src 30 | watchman watch-list 31 | watchman watch-del ~/src 32 | ``` 33 | 34 | ## Also see 35 | 36 | * [Documentation](https://facebook.github.io/watchman/docs/install.html) _(facebook.github.io)_ 37 | -------------------------------------------------------------------------------- /sheets/zuul.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Zuul 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Getting started 7 | 8 | Sign up for opensauce: 9 | 10 | 11 | 12 | * http://saucelabs.com/opensauce 13 | 14 | Install [zuul](https://npmjs.com/package/zuul): 15 | 16 | ``` 17 | npm i -g zuul 18 | ``` 19 | 20 | Configure zuul: 21 | 22 | ```yml 23 | # ~/.zuulrc 24 | sauce_username: me 25 | sauce_key: abc12348-e3e2-... 26 | ``` 27 | 28 | Add `.zuul.yml` to your project: 29 | 30 | ```yml 31 | # .zuul.yml 32 | ui: mocha-bdd 33 | browsers: 34 | - name: chrome 35 | version: latest 36 | - name: ie 37 | version: 6..latest 38 | - name: firefox 39 | version: latest 40 | ``` 41 | 42 | Try to run tests: 43 | 44 | ``` 45 | zuul test/test.js 46 | zuul --local test/test.js 47 | ``` 48 | -------------------------------------------------------------------------------- /sheets/cordova.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Cordova 3 | category: Misc 4 | tags: [Outdated] 5 | --- 6 | 7 | ### Commands 8 | 9 | ```bash 10 | cordova plugin ls 11 | cordova plugin search facebook 12 | cordova plugin add com.phonegap.plugins.facebookconnect 13 | ``` 14 | 15 | ```bash 16 | cordova platform add ios 17 | cordova platform ls 18 | cordova platform update ios 19 | cordova platform check 20 | ``` 21 | 22 | ### Some plugins 23 | 24 | You'll likely need these: 25 | 26 | * [org.apache.cordova.console](https://github.com/apache/cordova-plugin-console) 27 | * [org.apache.cordova.inappbrowser](https://github.com/apache/cordova-plugin-inappbrowser) 28 | * [org.apache.cordova.statusbar](https://github.com/apache/cordova-plugin-statusbar) 29 | * org.apache.cordova.splashscreen 30 | * com.phonegap.plugins.facebookconnect 31 | -------------------------------------------------------------------------------- /sheets/ledger-csv.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ledger CSV format 3 | category: Ledger 4 | layout: 2017/sheet 5 | --- 6 | 7 | ## Ledger CSV format 8 | 9 | 10 | 11 | ``` 12 | $ ledger csv 13 | ``` 14 | 15 | 16 | 17 | ```csv 18 | date , ? , desc , account , currency , amt , pending/cleared , ? 19 | "2013/09/02" , "" , "things" , "Assets:Cash" , "P" , "-2000" , "*" , "" 20 | "2013/09/02" , "" , "things" , "Liabilities:Card" , "P" , "-200" , "*" , "" 21 | "2013/09/02" , "" , "things" , "Expenses:Things" , "P" , "2200" , "*" , "" 22 | "2013/09/04" , "" , "stuff" , "Assets:Cash" , "P" , "-20" , "*" , "" 23 | "2013/09/04" , "" , "stuff" , "Expneses:Others" , "P" , "20" , "*" , "" 24 | ``` 25 | -------------------------------------------------------------------------------- /sheets/gmail.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Gmail settings 3 | --- 4 | 5 | ### IMAP settings 6 | 7 | | Key | Value | 8 | | -------- | ------------------------- | 9 | | Host | `imap.gmail.com` | 10 | | Port | `993` | 11 | | SSL | `Yes` | 12 | | Username | full `username@gmail.com` | 13 | 14 | ### SMTP settings 15 | 16 | | Key | Value | 17 | | ------------------ | ---------------- | 18 | | Host | `smtp.gmail.com` | 19 | | SSL port | `465` | 20 | | TLS/STARTTLS port | `587` | 21 | | Use authentication | `yes` | 22 | 23 | ### POP3 settings 24 | 25 | | Key | Value | 26 | | ---- | --------------- | 27 | | Host | `pop.gmail.com` | 28 | | Port | `995` | 29 | | SSL | `Yes` | 30 | -------------------------------------------------------------------------------- /sheets/gh-pages.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: GitHub pages 3 | category: Jekyll 4 | layout: 2017/sheet 5 | --- 6 | 7 | ## Custom domains 8 | 9 | ### Setting up CNAME file 10 | 11 | ```sh 12 | $ echo "foobar.com" > CNAME 13 | $ git commit && git push 14 | ``` 15 | 16 | Create a `CNAME` file with your domain on it. 17 | 18 | See: [Setting up a custom domain](https://help.github.com/articles/quick-start-setting-up-a-custom-domain/) _(github.com)_ 19 | 20 | ### Set up your domain 21 | 22 | #### For subdomains (eg, www) 23 | 24 | ``` 25 | CNAME => username.github.io 26 | ``` 27 | 28 | #### For apex domains 29 | 30 | ``` 31 | ALIAS => username.github.io 32 | ``` 33 | 34 | #### For Apex domains (alternative) 35 | 36 | ``` 37 | A => 192.30.252.153 38 | A => 192.30.252.154 39 | ``` 40 | 41 | ### References 42 | 43 | 44 | 45 | * 46 | -------------------------------------------------------------------------------- /sheets/immutable.js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Immutable.js 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Maps 7 | 8 | ```js 9 | var map = Immutable.Map({ a: 1, b: 2, c: 3 }) 10 | ``` 11 | 12 | ```js 13 | map.set('b', 50) 14 | map.get('b') // => 50 15 | ``` 16 | 17 | ### Lists 18 | 19 | ```js 20 | var list = Immutable.List.of(1, 2) 21 | ``` 22 | 23 | ```js 24 | list.push(3, 4, 5) 25 | list.unshift(0) 26 | list.concat(list2, list3) 27 | list.get(0).size 28 | ``` 29 | 30 | ### Nested maps 31 | 32 | ```js 33 | var nested = Immutable.fromJS({ user: { profile: { name: 'John' } } }) 34 | 35 | nested 36 | // Update 37 | .mergeDeep({ user: { profile: { age: 90 } } }) 38 | .setIn(['user', 'profile', 'name'], 'Jack') 39 | .updateIn(['user', 'profile', 'name'], s => s.toUpperCase()) 40 | 41 | // Get 42 | .getIn(['user', 'profile', 'name']) // 'JACK' 43 | ``` 44 | -------------------------------------------------------------------------------- /sheets/rename.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: rename 3 | category: CLI 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Installation 8 | 9 | ```bash 10 | brew install rename 11 | ``` 12 | 13 | See: 14 | 15 | ### Regex substitution 16 | 17 | ```bash 18 | rename 's/hello/world/' *.txt 19 | ``` 20 | 21 | Rename `hello.txt` to `world.txt` and so on in `*.txt`. 22 | 23 | ### Replace extension 24 | 25 | ```bash 26 | rename -s .png .jpg.png *.png 27 | ``` 28 | 29 | Replace `.png` with `.jpg.png` in `*.png`. 30 | 31 | ### Options 32 | 33 | | Option | Description | 34 | | ------ | ------------------------- | 35 | | `-n` | Simulation | 36 | | `-l` | Symlink instead of rename | 37 | | `-i` | Interactive | 38 | 39 | ## Also see 40 | 41 | * [Rename website](http://plasmasturm.org/code/rename/) _(plasmasturm.org)_ 42 | -------------------------------------------------------------------------------- /sheets/css-antialias.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: CSS antialiasing 3 | category: CSS 4 | layout: 2017/sheet 5 | updated: 2017-08-26 6 | intro: | 7 | Here's a 4-line snippet on how to get beautiful, antialiased text with CSS. 8 | --- 9 | 10 | ### Antialias 11 | 12 | 13 | 14 | ```css 15 | * { 16 | -webkit-font-smoothing: antialiased; 17 | -moz-osx-font-smoothing: grayscale; 18 | } 19 | ``` 20 | 21 | ### Support 22 | 23 | * Firefox 25+ on OSX 24 | * Webkits (Chrome, Safari, etc) 25 | 26 | ## References 27 | 28 | 29 | 30 | * [maxvoltar.com](http://maxvoltar.com/archive/-webkit-font-smoothing) 31 | * [maximilianhoffman.com](http://maximilianhoffmann.com/posts/better-font-rendering-on-osx) 32 | * [ilikekillnerds.com](http://ilikekillnerds.com/2010/12/a-solution-to-stop-font-face-fonts-looking-bold-on-mac-browsers/) 33 | 34 | 35 | -------------------------------------------------------------------------------- /sheets/elixir-metaprogramming.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Elixir metaprogramming 3 | category: Elixir 4 | --- 5 | 6 | ## Kernel 7 | 8 | Most of these magic is defined in [Kernel.SpecialForms](http://devdocs.io/elixir/elixir/kernel.specialforms). 9 | 10 | ### Pseudo-variables 11 | 12 | ```elixir 13 | __DIR__ # current dir 14 | __MODULE__ # current module 15 | __CALLER__ # caller of the function 16 | ``` 17 | 18 | ### [`__ENV__`](http://devdocs.io/elixir/elixir/kernel.specialforms#__ENV__/0) 19 | 20 | ```elixir 21 | Map.keys(__ENV__) 22 | [:__struct__, :aliases, :context, :context_modules, :export_vars, :file, 23 | :function, :functions, :lexical_tracker, :line, :macro_aliases, :macros, 24 | :module, :requires, :vars] 25 | ``` 26 | 27 | ```elixir 28 | __CALLER__.module |> Module.definitions_in |> IO.inspect 29 | ``` 30 | 31 | ```elixir 32 | apply(Enum, :reverse, [[1, 2, 3]]) 33 | ``` 34 | -------------------------------------------------------------------------------- /sheets/vagrant.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Vagrant 3 | category: Devops 4 | layout: 2017/sheet 5 | intro: | 6 | [Vagrant](http://vagrantup.com) lets you build isolated virtual environments for your apps. 7 | --- 8 | 9 | ### Get started 10 | 11 | Add some base boxes: 12 | 13 | 14 | 15 | ```bash 16 | vagrant box add precise64 http://files.vagrantup.com/precise64.box 17 | ``` 18 | 19 | Work it: 20 | 21 | ```bash 22 | mkdir test_box 23 | cd test_box 24 | vagrant init precise64 25 | ``` 26 | 27 | Run it: 28 | 29 | ```bash 30 | vagrant up 31 | vagrant ssh 32 | ``` 33 | 34 | To stop, use one of the following: 35 | 36 | ```bash 37 | vagrant ssh # then: sudo shutdown -h now 38 | vagrant suspend 39 | vagrant destroy # !! 40 | ``` 41 | 42 | ### Also see 43 | 44 | * [Vagrant website](http://vagrantup.com) _(vagrantup.com)_ 45 | * [Vagrantfile cheatsheet](./vagrantfile) 46 | -------------------------------------------------------------------------------- /sheets/znc.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ZNC bouncer 3 | intro: ZNC is an IRC bouncer. 4 | --- 5 | 6 | ### Start 7 | 8 | ``` 9 | /msg *status addserver irc.undernet.org [6667] 10 | /msg *status connect 11 | ``` 12 | 13 | ``` 14 | /msg *status loadmod webadmin 15 | /msg *status loadmod admin 16 | /msg *status loadmod away 17 | /msg *status loadmod awaynick 18 | /msg *status loadmod clientnotify # Notifies when another client logs 19 | /msg *status loadmod keepnick 20 | /msg *status loadmod kickrejoin 21 | ``` 22 | 23 | ### Away 24 | 25 | ``` 26 | /msg *status loadmod away 27 | ``` 28 | 29 | ``` 30 | /msg *away away 31 | /msg *away back 32 | /msg *away show #=> Show messages 33 | /msg *away delete all 34 | ``` 35 | 36 | ### Watch 37 | 38 | ``` 39 | /msg *status loadmod watch 40 | ``` 41 | 42 | ``` 43 | /msg *watch list 44 | /msg *watch add * *watch *rico* 45 | /msg *watch add * *watch *%nick%* 46 | ``` 47 | -------------------------------------------------------------------------------- /.github/workflows/rebase.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/cirrus-actions/rebase 2 | on: 3 | issue_comment: 4 | types: [created] 5 | 6 | name: Automatic Rebase 7 | 8 | jobs: 9 | rebase: 10 | name: Rebase 11 | if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@master 15 | - name: Automatic Rebase 16 | uses: cirrus-actions/rebase@v1.2.0 17 | env: 18 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 19 | 20 | # https://github.community/t5/GitHub-Actions/Workflow-is-failing-if-no-job-can-be-ran-due-to-condition/m-p/38186#M3250 21 | always_job: 22 | name: Always run job 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Always run 26 | run: echo "This job is used to prevent the workflow to fail when all other jobs are skipped." 27 | -------------------------------------------------------------------------------- /sheets/analytics.js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Google Analytics's analytics.js 3 | category: Analytics 4 | updated: 2017-10-29 5 | intro: | 6 | Google Analytics's analytics.js is deprecated. 7 | --- 8 | 9 | ### Page view 10 | 11 | ```js 12 | ga('create', 'UA-XXXX-Y', 'auto') 13 | ga('create', 'UA-XXXX-Y', { userId: 'USER_ID' }) 14 | ``` 15 | 16 | ```js 17 | ga('send', 'pageview') 18 | ga('send', 'pageview', { dimension15: 'My custom dimension' }) 19 | ``` 20 | 21 | ### Events 22 | 23 | ```js 24 | ga('send', 'event', 'button', 'click', { color: 'red' }) 25 | ``` 26 | 27 | ```js 28 | ga('send', 'event', 'button', 'click', 'nav buttons', 4) 29 | /* ^category ^action ^label ^value */ 30 | ``` 31 | 32 | ### Exceptions 33 | 34 | ```js 35 | ga('send', 'exception', { 36 | exDescription: 'DatabaseError', 37 | exFatal: false, 38 | appName: 'myapp', 39 | appVersion: '0.1.2' 40 | }) 41 | ``` 42 | -------------------------------------------------------------------------------- /sheets/c_preprocessor.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: C Preprocessor 3 | --- 4 | 5 | ### Compiling 6 | 7 | $ cpp -P file > outfile 8 | 9 | ### Includes 10 | 11 | #include "file" 12 | 13 | ### Defines 14 | 15 | #define FOO 16 | #define FOO "hello" 17 | 18 | #undef FOO 19 | 20 | ### If 21 | 22 | #ifdef DEBUG 23 | console.log('hi'); 24 | #elif defined VERBOSE 25 | ... 26 | #else 27 | ... 28 | #endif 29 | 30 | ### Error 31 | 32 | #if VERSION == 2.0 33 | #error Unsupported 34 | #warning Not really supported 35 | #endif 36 | 37 | ### Macro 38 | 39 | #define DEG(x) ((x) * 57.29) 40 | 41 | ### Token concat 42 | 43 | #define DST(name) name##_s name##_t 44 | DST(object); #=> "object_s object_t;" 45 | 46 | ### file and line 47 | 48 | #define LOG(msg) console.log(__FILE__, __LINE__, msg) 49 | #=> console.log("file.txt", 3, "hey") 50 | -------------------------------------------------------------------------------- /sheets/less.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Less.js 3 | --- 4 | 5 | ### Functions 6 | 7 | unit(30px / 5px) #=> 6 8 | unit(5, px) #=> 5px 9 | 10 | e("ms:stuff()") #=> ms:stuff() (unquote) 11 | 12 | %("count: %d", 1+2) #=> "count: 3" 13 | 14 | iscolor(@x) 15 | isstring(@x) 16 | isnumber(@x) 17 | iskeyword(@x) 18 | isurl(url(...)) 19 | ispixel() 20 | isem() 21 | ispercentage() 22 | isunit() 23 | 24 | hue(@color) 25 | saturation(@color) 26 | lightness(@color) 27 | luma(@color) 28 | luminance(@color) 29 | 30 | fade(@color, amount) 31 | fadein(@color, amount) 32 | fadeout(@color, amount) 33 | spin(@color, degrees) 34 | mix(@a, @b, amount) 35 | 36 | ### Conditionals 37 | 38 | .image when (luma(@color) > 50%) { } 39 | .image when (not(...)) { } 40 | .image when (default()) {} 41 | .image when (e(@shape) = 'circle') { } 42 | -------------------------------------------------------------------------------- /sheets/applinks.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Applinks 3 | category: HTML 4 | --- 5 | 6 | ### Meta tags 7 | 8 | #### iOS 9 | 10 | ```html 11 | 12 | 13 | 14 | ``` 15 | 16 | #### Android 17 | 18 | ```html 19 | 20 | 21 | 22 | ``` 23 | 24 | #### Web 25 | 26 | ```html 27 | 28 | ``` 29 | 30 | ### Device types 31 | 32 | * `ios` 33 | * `ipad` 34 | * `iphone` 35 | * `android` 36 | * `windows_phone` 37 | * `web` 38 | 39 | ### Reference 40 | 41 | * [applinks.org](http://applinks.org/documentation/) _(applinks.org)_ 42 | -------------------------------------------------------------------------------- /sheets/flashlight.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Flashlight 3 | category: Apps 4 | layout: 2017/sheet 5 | --- 6 | 7 | ## Commands 8 | 9 | 10 | 11 | ### Events and reminders 12 | 13 | * `add Dinner with Rico 5 pm tomorrow` 14 | * `remind Go to school at 2:30pm` 15 | * `remind Go to school in 15 mins` 16 | 17 | ### DuckDuckGo 18 | 19 | * `!g foo` 20 | * `!mdn settimeout` 21 | 22 | ### System 23 | 24 | * `shutdown` 25 | * `restart` 26 | * `logout` 27 | * `sleep` 28 | * `ejall` 29 | * `screen saver` 30 | 31 | ### Emoji 32 | 33 | * `emoji grin` 34 | * `:rocket:` 35 | 36 | ### Web search 37 | 38 | * `/react` 39 | 40 | Prefix with `/` to do a web search. 41 | 42 | ### References 43 | 44 | * [Flashlight](http://flashlight.nateparrott.com/) 45 | * [Flashlight on GitHub](https://github.com/nate-parrott/Flashlight) 46 | * [Creating a plugin](https://github.com/nate-parrott/Flashlight/wiki/Creating-a-Plugin) 47 | -------------------------------------------------------------------------------- /sheets/ie_bugs.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Legacy IE bugs 3 | category: HTML 4 | layout: 2017/sheet 5 | updated: 2017-10-29 6 | tags: [Outdated] 7 | intro: | 8 | A bunch of bugs to take care of if you're going to target legacy IE browsers. 9 | --- 10 | 11 | ### IE8: 'change' event 12 | 13 | The 'change' event doesn't always fire. Not for checkboxes, radios, multi-select lists. Use the `click` handler instead. References: [(1)](http://stackoverflow.com/questions/8005442/checkbox-change-event-works-when-click-the-label-in-ie8-ie7) 14 | 15 | ### IE8: label with input 16 | 17 | Clicking label with input inside doesn't focus the input. References: [(1)](http://www.gtalbot.org/BrowserBugsSection/MSIE7Bugs/LabelForWithImage.html) 18 | 19 | ### IE8: Opacity propagation 20 | 21 | An element's 'opacity' value isn't propagated to its positioned descendants. References: [Test case](http://jhop.me/tests/bugs/ie8/opacity_positioned.html) 22 | -------------------------------------------------------------------------------- /sheets/sql-join.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: SQL joins 3 | layout: 2017/sheet 4 | updated: 2017-10-30 5 | weight: -1 6 | --- 7 | 8 | ### Example 9 | 10 | ``` 11 | SELECT * FROM order_items \ 12 | LEFT OUTER JOIN orders \ 13 | ON order_items.order_id = orders.id 14 | ``` 15 | 16 | 17 | 18 | Joins are typically added to `SELECT` statements to add more columns and records. 19 | 20 | ### Diagram 21 | 22 | ``` 23 | SELECT * FROM `A` INNER JOIN `B` 24 | ``` 25 | 26 | 27 | 28 | ``` 29 | ┌────────┐ 30 | │ A ┌───┼────┐ 31 | │ │ ∩ │ │ 32 | └────┼───┘ B │ 33 | └────────┘ 34 | ``` 35 | 36 | 37 | 38 | | Join | What | 39 | | ---------------- | --------------- | 40 | | Inner join | `∩` | 41 | | Left outer join | `A` + `∩` | 42 | | Right outer join | `∩` + `B` | 43 | | Full outer join | `A` + `∩` + `B` | 44 | -------------------------------------------------------------------------------- /sheets/applescript.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: AppleScript 3 | updated: 2018-03-17 4 | layout: 2017/sheet 5 | category: macOS 6 | prism_languages: [applescript] 7 | --- 8 | 9 | ### Running 10 | 11 | ```applescript 12 | osascript -e "..." 13 | ``` 14 | 15 | ```applescript 16 | display notification "X" with title "Y" 17 | ``` 18 | 19 | ### Comments 20 | 21 | ```applescript 22 | -- This is a single line comment 23 | ``` 24 | 25 | ```applescript 26 | # This is another single line comment 27 | ``` 28 | 29 | ```applescript 30 | (* 31 | This is 32 | a multi 33 | line comment 34 | *) 35 | ``` 36 | 37 | ### Say 38 | 39 | ```applescript 40 | -- default voice 41 | say "Hi I am a Mac" 42 | ``` 43 | 44 | ```applescript 45 | -- specified voice 46 | say "Hi I am a Mac" using "Zarvox" 47 | ``` 48 | 49 | ### Beep 50 | 51 | ```applescript 52 | -- beep once 53 | beep 54 | ``` 55 | 56 | ```applescript 57 | -- beep 10 times 58 | beep 10 59 | ``` 60 | -------------------------------------------------------------------------------- /sheets/dom-selection.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: DOM Selection 3 | category: JavaScript 4 | --- 5 | 6 | ### Selection 7 | 8 | ```js 9 | var sel = document.getSelection() 10 | ``` 11 | 12 | See: 13 | 14 | ### Selection methods 15 | 16 | ```js 17 | sel.removeAllRanges() // deselects 18 | sel.addRange(range) // sets a selection 19 | sel.removeRange(range) // remove a range 20 | ``` 21 | 22 | ```js 23 | sel.rangeCount // ranges 24 | sel.getRangeAt(0) // get the 0th range 25 | ``` 26 | 27 | ### Collapsing 28 | 29 | ```js 30 | sel.collapse(parent, offset) 31 | sel.collapseToEnd() 32 | sel.collapseToStart() 33 | sel.isCollapsed 34 | ``` 35 | 36 | ```js 37 | sel.containsNode(node) 38 | ``` 39 | 40 | ### Deleting 41 | 42 | ```js 43 | sel.deleteFromDocument() 44 | ``` 45 | 46 | ### Events 47 | 48 | ```js 49 | document.addEventListener('selectionchange', () => { 50 | /* ... */ 51 | }) 52 | ``` 53 | -------------------------------------------------------------------------------- /sheets/bookshelf.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Bookshelf.js 3 | category: JavaScript libraries 4 | --- 5 | 6 | ## Model 7 | 8 | ```js 9 | Summary = bookshelf.Model.extend({ 10 | tableName: 'summaries', 11 | hasTimestamps: true, 12 | hasTimestamps: ['created_at', 'updated_at'] 13 | }) 14 | ``` 15 | 16 | ### Associations 17 | 18 | ```js 19 | Summary = bookshelf.Model.extend({ 20 | book() { 21 | return this.belongsTo(Book) 22 | }, 23 | author() { 24 | return this.hasOne(Author) 25 | } 26 | // belongsToMany 27 | // hasMany 28 | // hasMany().through() 29 | }) 30 | ``` 31 | 32 | ### CRUD 33 | 34 | ```js 35 | Book.create({ title: '...' }).save() 36 | new Book({ title: '...' }).save() 37 | 38 | new Book({ id: 1 }).fetch() 39 | 40 | Book.where({ id: 1 }).fetch() 41 | Book.where('favorite_color', 'red').fetch() 42 | Book.where('favorite_color', '<>', 'red').fetch() 43 | Book 44 | .query((q) => q.orderBy('updated_at') 45 | ``` 46 | -------------------------------------------------------------------------------- /sheets/zombie.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Zombie 3 | category: JavaScript libraries 4 | intro: | 5 | [Zombie](https://github.com/assaf/zombie) is a tool for headless browser testing in Node.js. 6 | --- 7 | 8 | ### Simple exmaple 9 | 10 | ```js 11 | browser 12 | .visit('http://.../', () => { 13 | /* ... */ 14 | }) 15 | .fill('email', 'zombie@underworld.dead') 16 | .fill('password', 'eat-the-living') 17 | .select('Born', '1985') 18 | .uncheck('Send newsletter') 19 | .clickLink('Link name') 20 | .pressButton('Sign', () => { 21 | /* ... */ 22 | }) 23 | ``` 24 | 25 | ### Expectations 26 | 27 | ```js 28 | expect(browser.query('#brains')) 29 | ``` 30 | 31 | ```js 32 | expect(browser.body.queryAll('.hand')).length(2) 33 | ``` 34 | 35 | ```js 36 | console.log(browser.html()) 37 | console.log(browser.html('table.parts')) 38 | ``` 39 | 40 | ```js 41 | expect(Browser.text('.card-nopad small'), 'A better way to get around!') 42 | ``` 43 | -------------------------------------------------------------------------------- /sheets/jquery.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: jQuery 3 | category: JavaScript libraries 4 | layout: 2017/sheet 5 | tags: [WIP] 6 | weight: -1 7 | --- 8 | 9 | ### Traversing 10 | 11 | ```js 12 | $('.box') 13 | .children() 14 | .closest('div') 15 | .filter(':selected') 16 | .find('div') 17 | .has('div') 18 | .first() 19 | .next('div') 20 | .nextUntil('div') 21 | ``` 22 | 23 | ## Advanced features 24 | 25 | ### Extending selectors 26 | 27 | ```js 28 | $.expr[':'].inline = function(el) { 29 | return $(el).css('display') === 'inline' 30 | } 31 | ``` 32 | 33 | Enables `$(':inline')` 34 | 35 | ### Extend CSS properties 36 | 37 | ```js 38 | $.cssHooks.someCSSProp = { 39 | get: function(elem, computed, extra) {}, 40 | set: function(elem, value) {} 41 | } 42 | 43 | // Disable "px" 44 | $.cssNumber['someCSSProp'] = true 45 | ``` 46 | 47 | ### fn.animate() hooks 48 | 49 | ```js 50 | $.fn.step.someWhatever = function(fx) { 51 | // ... 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /sheets/virtual-dom.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Virtual-dom 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Importing 7 | 8 | ```js 9 | var h = require('virtual-dom/h') 10 | var diff = require('virtual-dom/diff') 11 | var patch = require('virtual-dom/patch') 12 | var createElement = require('virtual-dom/create-element') 13 | ``` 14 | 15 | ### Rendering 16 | 17 | ```js 18 | const tree = h('div', { style: { color: 'blue' } }, ['hello']) 19 | let el = createElement(tree) 20 | document.body.appendChild(el) 21 | ``` 22 | 23 | Use `createElement()` to create the root DOM node. 24 | 25 | ### Updating 26 | 27 | ```js 28 | const tree2 = h('div', { style: { color: 'blue' } }, ['hello world']) 29 | const delta = diff(tree, tree2) 30 | 31 | // Update `el` that was made by `createElement()` 32 | el = patch(el, delta) 33 | ``` 34 | 35 | Use `patch()` to update the DOM. 36 | 37 | ### References 38 | 39 | * [virtual-dom](https://www.npmjs.com/package/virtual-dom) _(npmjs.com)_ 40 | -------------------------------------------------------------------------------- /sheets/inkscape.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Inkscape 3 | category: Apps 4 | layout: 2017/sheet 5 | tags: [WIP] 6 | --- 7 | 8 | ### All 9 | 10 | | Shortcut | Description | 11 | | ----------- | --------------------------- | 12 | | `-` _/_ `=` | Zoom in/out | 13 | | `3` _/_ `4` | Zoom to selection / drawing | 14 | | `5` _/_ `6` | Zoom to page / page width | 15 | 16 | 17 | 18 | ### Select tool (F1) 19 | 20 | | Shortcut | Description | 21 | | -------- | ----------- | 22 | | `[ ]` | Rotate | 23 | 24 | 25 | 26 | ### Edit path (F2) 27 | 28 | | Shortcut | Description | 29 | | -------- | ----------- | 30 | | `Ctrl` | constraint | 31 | 32 | 33 | 34 | ### Dragging an anchor handle 35 | 36 | | Shortcut | Description | 37 | | -------- | ------------------ | 38 | | `Ctrl` | snap to 15 degrees | 39 | | `Alt` | ? | 40 | 41 | 42 | -------------------------------------------------------------------------------- /sheets/ledger-periods.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ledger periods 3 | category: Ledger 4 | --- 5 | 6 | [INTERVAL] [BEGIN] [END] 7 | 8 | Interval: 9 | 10 | every day 11 | every week 12 | every month 13 | every quarter 14 | every year 15 | every N days # N is any integer 16 | every N weeks 17 | every N months 18 | every N quarters 19 | every N years 20 | daily 21 | weekly 22 | biweekly 23 | monthly 24 | bimonthly 25 | quarterly 26 | yearly 27 | 28 | Begin: 29 | 30 | from 31 | since 32 | 33 | The end time can be either of: 34 | 35 | to 36 | until 37 | 38 | Spec: 39 | 40 | 2004 41 | 2004/10 42 | 2004/10/1 43 | 10/1 44 | october 45 | oct 46 | this week # or day, month, quarter, year 47 | next week 48 | last week 49 | 50 | Examples: 51 | 52 | $ ledger r -p "since last month" 53 | 54 | See: http://ledger-cli.org/3.0/doc/ledger3.html#Period-Expressions 55 | -------------------------------------------------------------------------------- /sheets/mocha.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Mocha.js 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### BDD 7 | 8 | ```js 9 | mocha.setup('bdd') 10 | 11 | describe('something', function() { 12 | beforeEach(function() { 13 | /* ... */ 14 | }) 15 | 16 | it('should work', function() { 17 | /* ... */ 18 | }) 19 | }) 20 | ``` 21 | 22 | ### Async via callbacks 23 | 24 | ```js 25 | it('should save', function(done) { 26 | const user = new User() 27 | user.save(function(err) { 28 | if (err) throw err 29 | done() 30 | }) 31 | }) 32 | ``` 33 | 34 | You can also return a `Promise`. 35 | 36 | ### Chai: Shoulds 37 | 38 | ```js 39 | chai.should() 40 | ``` 41 | 42 | ```js 43 | foo.should.be.a('string') 44 | foo.should.equal('bar') 45 | foo.should.have.length(3) 46 | tea.should.have.property('flavors').with.length(3) 47 | ``` 48 | 49 | ### See also 50 | 51 | * [Mocha TDD](mocha-tdd.html) 52 | * [Mocha HTML](mocha-html.html) 53 | * [Chai](chai.html) 54 | * [Sinon](sinon.html) 55 | * [Sinon Chai](sinon-chai.html) 56 | -------------------------------------------------------------------------------- /sheets/modernizr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Modernizr 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Script 7 | 8 | 9 | 10 | ### Detections 11 | 12 | JavaScript 13 | 14 | * js 15 | 16 | CSS 17 | 18 | * flexbox 19 | * rgba 20 | * hsla 21 | * multiplebgs 22 | * backgroundsize 23 | * borderimage 24 | * borderradius 25 | * boxshadow 26 | * textshadow 27 | * opacity 28 | * cssanimations 29 | * csscolumns 30 | * cssgradients 31 | * cssreflections 32 | * csstransforms 33 | * csstransforms3d 34 | * csstransitions 35 | * fontface 36 | * generatedcontent 37 | 38 | HTML5 39 | 40 | * canvas 41 | * canvastext 42 | * webgl 43 | * touch 44 | * geolocation 45 | * postmessage 46 | * websqldatabase 47 | * indexeddb 48 | * hashchange 49 | * history 50 | * draganddrop 51 | * websockets 52 | * video 53 | * audio 54 | * localstorage 55 | * sessionstorage 56 | * webworkers 57 | * applicationcache 58 | * svg 59 | * inlinesvg 60 | * smil 61 | * svgclippaths 62 | -------------------------------------------------------------------------------- /sheets/pass.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Pass 3 | layout: 2017/sheet 4 | category: CLI 5 | --- 6 | 7 | ### Create 8 | 9 | ```bash 10 | $ pass init [-p] 11 | $ pass git init 12 | $ pass git remote add origin 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 | [![Status](https://travis-ci.org/rstacruz/cheatsheets.svg?branch=master)](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 | [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](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 | 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 | 81 | ``` 82 | 83 | ``` 84 | 60 | 61 | ## Reference 62 | 63 | * [vim-projectionist](https://github.com/tpope/vim-projectionist) _(github.com)_ 64 | -------------------------------------------------------------------------------- /sheets/minimist.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: minimist 3 | category: JavaScript libraries 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Usage 8 | 9 | ```js 10 | var minimist = require('minimist') 11 | ``` 12 | 13 | 14 | 15 | ```js 16 | var args = minimist(process.argv.slice(2), { 17 | string: 'lang', // --lang xml 18 | boolean: ['version'], // --version 19 | alias: { v: 'version' } 20 | }) 21 | ``` 22 | 23 | ```js 24 | console.log(args) 25 | ``` 26 | 27 | All options are optional, but it's recommended you set `string` and `boolean` at least. 28 | 29 | ### All options 30 | 31 | ```js 32 | var args = minimist(process.argv.slice(2), { 33 | string: [ 'lang' ], 34 | boolean: [ 'pager' ], 35 | alias: { h: 'help', v: 'version' }, 36 | default: { lang: 'en' }, 37 | '--': true, 38 | stopEarly: true, /* populate _ with first non-option */ 39 | unknown: function () { ... } /* invoked on unknown param */ 40 | }) 41 | ``` 42 | 43 | All options are optional. 44 | 45 | ### Result 46 | 47 | With `--lang xml --no-pager -h index.js package.json`, you get: 48 | 49 | 50 | 51 | ``` 52 | args == { 53 | lang: 'xml', 54 | version: false, 55 | h: true, 56 | help: true, 57 | _: [ 'index.js', 'package.json' ] 58 | } 59 | ``` 60 | 61 | ## Meow 62 | 63 | ### Help and version 64 | 65 | Use [meow](https://www.npmjs.com/package/meow) to automatically add support for `--help`, `--version` and more. 66 | 67 | 68 | 69 | ```js 70 | meow( 71 | ` 72 | Usage: 73 | $0 FILES [options] 74 | 75 | Options: 76 | -h, --help print usage information 77 | -v, --version show version info and exit 78 | `, 79 | { 80 | alias: { h: 'help', v: 'version' } 81 | /* minimist options */ 82 | } 83 | ) 84 | ``` 85 | 86 | ### Reference 87 | 88 | * 89 | * 90 | -------------------------------------------------------------------------------- /sheets/rsync.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rsync 3 | category: CLI 4 | layout: 2017/sheet 5 | weight: -1 6 | --- 7 | 8 | ### Basic example 9 | 10 | 11 | 12 | ```bash 13 | # syncing folder src into dest: 14 | rsync -avz ./src /dest 15 | 16 | # syncing the content of src into dest: 17 | rsync -avz ./src/ /dest 18 | ``` 19 | 20 | ### OSX 21 | 22 | ```bash 23 | --exclude '.Trashes' 24 | --exclude '.Spotlight-V100' 25 | --exclude '.fseventsd' 26 | ``` 27 | 28 | ### Transfer options 29 | 30 | ```bash 31 | -z, --compress 32 | -n, --dry-run 33 | --partial # allows resuming of aborted syncs 34 | --bwlimit=RATE # limit socket I/O bandwidth 35 | ``` 36 | 37 | ### Display options 38 | 39 | ```bash 40 | -q, --quiet 41 | -v, --verbose 42 | --stats 43 | -h, --human-readable 44 | --progress 45 | -P # same as --partial --progress 46 | ``` 47 | 48 | ### Skipping options 49 | 50 | ```bash 51 | -u, --update # skip files newer on dest 52 | -c, --checksum # skip based on checksum, not mod-time & size 53 | ``` 54 | 55 | ### Backup options 56 | 57 | ```bash 58 | -b, --backup # backup with suffix 59 | --suffix=SUFFIX # default ~ without --backup-dir 60 | --backup-dir=DIR 61 | ``` 62 | 63 | ### Include options 64 | 65 | ```bash 66 | --exclude=PATTERN 67 | --include=PATTERN 68 | ``` 69 | 70 | ```bash 71 | --exclude-from=FILE 72 | --include-from=FILE 73 | --files-from=FILE # read list of filenames from FILE 74 | ``` 75 | 76 | ### Archive options 77 | 78 | ```bash 79 | -a, --archive # archive (-rlptgoD) 80 | ``` 81 | 82 | ```bash 83 | -r, --recursive 84 | -l, --links # copy symlinks as links 85 | -p, --perms # preserve permissions 86 | -t, --times # preserve times 87 | -g, --group # preserve group 88 | -o, --owner # preserve owner 89 | -D # --devices --specials 90 | ``` 91 | 92 | ```bash 93 | --delete # Delete extra files 94 | ``` 95 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Developer notes 2 | 3 | ## Dev setup (Docker) 4 | 5 | You need [Docker][docker] (with docker-compose). 6 | 7 | [docker]: https://gist.github.com/rstacruz/297fc799f094f55d062b982f7dac9e41 8 | 9 | ```sh 10 | alias dr='docker-compose run --rm --service-ports web' 11 | 12 | git clone https://github.com/rstacruz/cheatsheets-ng.git 13 | cd cheatsheets-ng 14 | 15 | # first time setup 16 | dr yarn --force 17 | 18 | # start server 19 | dr yarn develop 20 | ``` 21 | 22 | This starts a server in . You can also use `docker-compose up`. 23 | 24 | ## Dev setup (traditional) 25 | 26 | You need recent versions of [Yarn] and [Node.js]. 27 | 28 | [yarn]: https://yarnpkg.com 29 | [node.js]: https://nodejs.org/ 30 | 31 | ```sh 32 | git clone https://github.com/rstacruz/cheatsheets-ng.git 33 | cd cheatsheets-ng 34 | 35 | # first time setup 36 | yarn --force 37 | 38 | # start server 39 | yarn develop 40 | ``` 41 | 42 | Unless you override `$PORT`, this starts a server in . 43 | 44 | ## Linting 45 | 46 | **Linters** - this lists files that need updating. 47 | 48 | ```bash 49 | yarn run lint:check 50 | yarn run prettier:check 51 | ``` 52 | 53 | **Formatters** - this tries to auto-format files. 54 | 55 | ```bash 56 | yarn run prettier:fix 57 | ``` 58 | 59 | ## Troubleshooting 60 | 61 | Clean your cache using `sudo rm -rf node_modules public devhints-engine` if you have problems trying to start the server in Docker. 62 | 63 | 75 | -------------------------------------------------------------------------------- /sheets/sinon-chai.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Sinon-chai 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Initialization 7 | 8 | ```js 9 | var sinon = require('sinon') 10 | require('chai').use(require('sinon-chai')) 11 | ``` 12 | 13 | ### Assertions 14 | 15 | ```js 16 | expect(spy).called 17 | expect(spy).calledOnce 18 | expect(spy).calledTwice 19 | expect(spy).calledThrice 20 | expect(spy).calledBefore 21 | expect(spy).calledAfter 22 | expect(spy).calledWithNew 23 | expect(spy).alwaysCalledWithNew 24 | expect(spy).calledOn 25 | expect(spy).alwaysCalledOn 26 | expect(spy).calledWith 27 | expect(spy).alwaysCalledWith 28 | expect(spy).calledWithExactly 29 | expect(spy).alwaysCalledWithExactly 30 | expect(spy).calledWithMatch 31 | expect(spy).alwaysCalledWithMatch 32 | expect(spy).returned 33 | expect(spy).alwaysReturned 34 | expect(spy).threw 35 | expect(spy).alwaysThrew 36 | ``` 37 | 38 | ### Should 39 | 40 | ```js 41 | spy.should.have.been.called 42 | spy.should.have.been.calledOnce 43 | spy.should.have.been.calledTwice 44 | spy.should.have.been.calledThrice 45 | spy1.should.have.been.calledBefore(spy2) 46 | spy1.should.have.been.calledAfter(spy2) 47 | spy.should.have.been.calledWithNew 48 | spy.should.always.have.been.calledWithNew 49 | spy.should.have.been.calledOn(context) 50 | spy.should.always.have.been.calledOn(context) 51 | spy.should.have.been.calledWith(...args) 52 | spy.should.always.have.been.calledWith(...args) 53 | spy.should.always.have.been.calledWithExactly(...args) 54 | spy.should.always.have.been.calledWithExactly(...args) 55 | spy.should.have.been.calledWithMatch(...args) 56 | spy.should.always.have.been.calledWithMatch(...args) 57 | spy.should.have.returned(returnVal) 58 | spy.should.have.always.returned(returnVal) 59 | spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing) 60 | spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing) 61 | ``` 62 | 63 | ### See also 64 | 65 | * [Sinon-chai](https://github.com/domenic/sinon-chai) _(github.com)_ 66 | -------------------------------------------------------------------------------- /sheets/firebase.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Firebase 3 | tags: [WIP] 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Authenticating 8 | 9 | ```js 10 | FB = new Firebase('https://xxx.firebase.io') 11 | FB.auth(TOKEN, (err, result) => { 12 | /* ... */ 13 | }) 14 | ``` 15 | 16 | ```js 17 | FB.authAnonymously(/* ... */) 18 | FB.authWithPassword(/* ... */) 19 | FB.authWithOAuthPopup(/* ... */) 20 | FB.authWithOAuthToken(/* ... */) 21 | ``` 22 | 23 | ### Using 24 | 25 | ```js 26 | Users = FB.child('users') 27 | ``` 28 | 29 | ```js 30 | // Create 31 | user = Users.push((first: 'Frank'), (last: 'Sinatra')) 32 | ``` 33 | 34 | ```js 35 | // Retrieve 36 | user = Users.child('alan') // gets `users/alan` 37 | ``` 38 | 39 | ```js 40 | // Update 41 | user.set((first: 'Miles'), (last: 'Davis')) 42 | user.update((first: 'Miles')) 43 | user.setWithPriority( 44 | { 45 | /* ... */ 46 | }, 47 | priority 48 | ) 49 | ``` 50 | 51 | ```js 52 | // Destroy 53 | user.remove() 54 | ``` 55 | 56 | ```js 57 | // Getting 58 | user.name() // primary id 59 | 60 | user.once( 61 | 'value', 62 | snap => { 63 | snap.name() // primary id 64 | snap.val() // value 65 | }, 66 | err => { 67 | /* ... */ 68 | } 69 | ) 70 | ``` 71 | 72 | ```js 73 | // traversal 74 | user.parent() 75 | ``` 76 | 77 | ### Querying 78 | 79 | ```js 80 | const Users = FB.child('users') 81 | ``` 82 | 83 | ```js 84 | Users.startAt(1000) 85 | .limit(50) 86 | .equalTo(priority, [name]) 87 | .on('child_added', snap => { 88 | /* ... */ 89 | }) 90 | ``` 91 | 92 | ### Lists 93 | 94 | ```js 95 | const Posts = FB.child('posts') 96 | const post = Posts.push({ title: 'How to do things', author: 'alan' }) 97 | ``` 98 | 99 | ### References 100 | 101 | * [Firebase API docs](https://www.firebase.com/docs/web/api/) _(firebase.com)_ 102 | * [Firebase recipes](https://www.firebase.com/docs/web/recipes.html) _(firebase.com)_ 103 | -------------------------------------------------------------------------------- /sheets/express.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Express.js 3 | category: JavaScript libraries 4 | --- 5 | 6 | ### Settings 7 | 8 | ```js 9 | app.set('x', 'yyy') 10 | app.get('x') //=> 'yyy' 11 | 12 | app.enable('trust proxy') 13 | app.disable('trust proxy') 14 | 15 | app.enabled('trust proxy') //=> true 16 | ``` 17 | 18 | ### Env 19 | 20 | ```js 21 | app.get('env') 22 | ``` 23 | 24 | ### Config 25 | 26 | ```js 27 | app.configure('production', function() { 28 | app.set... 29 | }) 30 | ``` 31 | 32 | ### Wares 33 | 34 | ```js 35 | app.use(express.static(__dirname + '/public')) 36 | app.use(express.logger()) 37 | ``` 38 | 39 | ### Helpers 40 | 41 | ```js 42 | app.locals({ 43 | title: 'MyApp' 44 | }) 45 | ``` 46 | 47 | ## Request & response 48 | 49 | ### Request 50 | 51 | ```js 52 | // GET /user/tj 53 | req.path // => "/user/tj" 54 | req.url // => "/user/tj" 55 | req.xhr // => true|false 56 | req.method // => "GET" 57 | req.params 58 | req.params.name // => "tj" 59 | req.params[0] 60 | ``` 61 | 62 | ```js 63 | // GET /search?q=tobi+ferret 64 | req.query.q // => "tobi ferret" 65 | ``` 66 | 67 | ```js 68 | req.cookies 69 | ``` 70 | 71 | ```js 72 | req.accepted 73 | // [ { value: 'application/json', quality: 1, type: 'application', subtype: 'json' }, 74 | // { value: 'text/html', quality: 0.5, type: 'text',subtype: 'html' } ] 75 | ``` 76 | 77 | ```js 78 | req.is('html') 79 | req.is('text/html') 80 | ``` 81 | 82 | ```js 83 | req.headers 84 | req.headers['host'] 85 | req.headers['user-agent'] 86 | req.headers['accept-encoding'] 87 | req.headers['accept-language'] 88 | ``` 89 | 90 | ### Response 91 | 92 | ```js 93 | res.redirect('/') 94 | res.redirect(301, '/') 95 | ``` 96 | 97 | ```js 98 | res.set('Content-Type', 'text/html') 99 | ``` 100 | 101 | ```js 102 | res.send('hi') 103 | res.send(200, 'hi') 104 | ``` 105 | 106 | ```js 107 | res.json({ a: 2 }) 108 | ``` 109 | -------------------------------------------------------------------------------- /sheets/ios-provision.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: iOS Provisioning Profiles 3 | tags: [Outdated] 4 | --- 5 | 6 | ### Types of profiles 7 | 8 | * **Development** - deploy to an iPhone via XCode 9 | * **Adhoc** - deploy via testflightapp.com 10 | * **Appstore** - only used for submitting to the app store 11 | 12 | ### Requirements 13 | 14 | | What | Dev | Adhoc | Appstore | 15 | | --------------- | --- | ----- | -------- | 16 | | CSR file | | √ | √ | 17 | | Device UDIDs | √ | √ | | 18 | | Developers list | √ | | | 19 | 20 | ### Obtaining a CSR file 21 | 22 | Needed for Adhoc & Appstore builds. 23 | 24 | * Open _Keychain Access.app_ 25 | * _Keychain Access_ menu -> _Certificate Assistant_ menu -> _Request a certificate..._ 26 | * User email address is _your email_ 27 | * Common name is _your name_ 28 | * CA Email address is _blank_ 29 | * Request is _Saved to disk_ 30 | 31 | ### Get the `.cer` files 32 | 33 | Needed for Adhoc & Appstore builds. 34 | 35 | * in the iOS dev portal, go to _Certificates_, and download the certificate. 36 | Install it on the dev machine. 37 | 38 | ### Obtaining device UDIDs 39 | 40 | Needed for Dev and Adhoc builds. 41 | 42 | * via iTunes: http://whatsmyudid.com 43 | * via XCode: cmd+shift+2 (Organizer), Devices 44 | 45 | ## For developers 46 | 47 | Don't ever ask Xcode to _Fix issue..._ for you. 48 | 49 | ### Using a provisioning profile 50 | 51 | No need to use `.mobileprovision` files since XCode 5. 52 | 53 | * Open the `*.mobileprovision` file using Finder 54 | * XCode Project -> _Build settings_ tab -> _Code signing_ section -> 55 | _Provisioning Profile_ section 56 | * Set _Debug_ to the _development_ profile 57 | * Set _Release_ to the _ad-hoc_ profile 58 | 59 | ### Building an .ipa (Adhoc or Appstore) 60 | 61 | * In the toolbar, select "iOS Device" as the target 62 | * _Product_ menu -> _Archive_ 63 | * In the Organizer (Cmd+Shift+2) -> _Archives_ tab -> _Distribute..._ button 64 | -------------------------------------------------------------------------------- /sheets/ansible.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Ansible 3 | category: Ansible 4 | --- 5 | 6 | ## Getting started 7 | 8 | ### Hosts 9 | 10 | $ sudo mkdir /etc/ansible 11 | $ sudo vim /etc/ansible/hosts 12 | 13 | [example] 14 | 192.0.2.101 15 | 192.0.2.102 16 | 17 | ### Running a playbook 18 | 19 | $ ansible-playbook playbook.yml 20 | 21 | ## Tasks 22 | 23 | - hosts: all 24 | user: root 25 | sudo: no 26 | vars: 27 | aaa: bbb 28 | tasks: 29 | - ... 30 | handlers: 31 | - ... 32 | 33 | ### Includes 34 | 35 | tasks: 36 | - include: db.yml 37 | handlers: 38 | - include: db.yml user=timmy 39 | 40 | ## Handlers 41 | 42 | handlers: 43 | - name: start apache2 44 | action: service name=apache2 state=started 45 | 46 | tasks: 47 | - name: install apache 48 | action: apt pkg=apache2 state=latest 49 | notify: 50 | - start apache2 51 | 52 | ## Vars 53 | 54 | - host: lol 55 | vars_files: 56 | - vars.yml 57 | vars: 58 | project_root: /etc/xyz 59 | tasks: 60 | - name: Create the SSH directory. 61 | file: state=directory path=${project_root}/home/.ssh/ 62 | only_if: "$vm == 0" 63 | 64 | ## Roles 65 | 66 | - host: xxx 67 | roles: 68 | - db 69 | - { role:ruby, sudo_user:$user } 70 | - web 71 | 72 | # Uses: 73 | # roles/db/tasks/*.yml 74 | # roles/db/handlers/*.yml 75 | 76 | ### Task: Failures 77 | 78 | - name: my task 79 | command: ... 80 | register: result 81 | failed_when: "'FAILED' in result.stderr" 82 | 83 | ignore_errors: yes 84 | 85 | changed_when: "result.rc != 2" 86 | 87 | ### Env vars 88 | 89 | vars: 90 | local_home: "{{ lookup('env','HOME') }}" 91 | 92 | ## References 93 | 94 | * [Intro](http://www.ansibleworks.com/docs/intro_configuration.html) 95 | * [Modules](http://www.ansibleworks.com/docs/modules.html) 96 | -------------------------------------------------------------------------------- /sheets/kramdown.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Kramdown 3 | category: Markup 4 | --- 5 | 6 | ### Configuration 7 | 8 | #### Options 9 | 10 | | Option | Description | 11 | | ------------------ | -------------------------------------------------------------------- | 12 | | `parse_block_html` | process kramdown syntax inside blocks | 13 | | `parse_span_html` | process kramdown syntax inside inlines | 14 | | `html_to_native` | convert html elements to native elements | 15 | | `hard_wrap` | Only for [GFM parser](http://kramdown.gettalong.org/parser/gfm.html) | 16 | 17 | #### Example 18 | 19 | ``` 20 | {::options parse_block_html="true" /} 21 | ``` 22 | 23 | ### For jekyll (gh-pages) 24 | 25 | ```yaml 26 | # _config.yml 27 | markdown: kramdown 28 | kramdown: 29 | input: GFM 30 | ``` 31 | 32 | ### Footnotes (Kramdown) 33 | 34 | ``` 35 | This is some text.[^1]. Other text.[^footnote]. 36 | 37 | [^1]: Some *crazy* footnote definition. 38 | ``` 39 | 40 | ### Abbreviations (Kramdown) 41 | 42 | ``` 43 | This is some text not written in HTML but in another language! 44 | 45 | *[another language]: It's called Markdown 46 | *[HTML]: HyperTextMarkupLanguage 47 | ``` 48 | 49 | ### Classes and IDs (Kramdown) 50 | 51 | #### Paragraphs & IDs 52 | 53 | ``` 54 | A simple paragraph with an ID attribute. 55 | {:#para-one} 56 | ``` 57 | 58 | #### Attributes 59 | 60 | ``` 61 | > A blockquote with a title 62 | {:title="The blockquote title"} 63 | ``` 64 | 65 | #### List item 66 | 67 | ``` 68 | * {:.cls} This item has the class "cls" 69 | ``` 70 | 71 | #### Code fences 72 | 73 | ```` 74 | ``` 75 | Some code here 76 | ``` 77 | {:.ruby} 78 | ```` 79 | 80 | #### Indented code 81 | 82 | ``` 83 | {:.ruby} 84 | Some code here 85 | ``` 86 | 87 | ### References 88 | 89 | * http://kramdown.gettalong.org/syntax.html 90 | * http://kramdown.gettalong.org/parser/kramdown.html 91 | -------------------------------------------------------------------------------- /sheets/dockerfile.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Dockerfile 3 | category: Devops 4 | layout: 2017/sheet 5 | prism_languages: [docker] 6 | updated: 2018-03-17 7 | --- 8 | 9 | ## Reference 10 | 11 | 12 | 13 | ### Inheritance 14 | 15 | ```docker 16 | FROM ruby:2.2.2 17 | ``` 18 | 19 | ### Variables 20 | 21 | ```docker 22 | ENV APP_HOME /myapp 23 | RUN mkdir $APP_HOME 24 | ``` 25 | 26 | ```docker 27 | ARG APP_HOME="" 28 | RUN mkdir $APP_HOME 29 | ``` 30 | 31 | ### Initialization 32 | 33 | ```docker 34 | RUN bundle install 35 | ``` 36 | 37 | ```docker 38 | WORKDIR /myapp 39 | ``` 40 | 41 | ```docker 42 | VOLUME ["/data"] 43 | # Specification for mount point 44 | ``` 45 | 46 | ```docker 47 | ADD file.xyz /file.xyz 48 | COPY --chown=user:group host_file.xyz /path/container_file.xyz 49 | ``` 50 | 51 | ### Onbuild 52 | 53 | ```docker 54 | ONBUILD RUN bundle install 55 | # when used with another file 56 | ``` 57 | 58 | ### Commands 59 | 60 | ```docker 61 | EXPOSE 5900 62 | CMD ["bundle", "exec", "rails", "server"] 63 | ``` 64 | 65 | ### Entrypoint 66 | 67 | ```docker 68 | ENTRYPOINT ["executable", "param1", "param2"] 69 | ENTRYPOINT command param1 param2 70 | ``` 71 | 72 | Configures a container that will run as an executable. 73 | 74 | ```docker 75 | ENTRYPOINT exec top -b 76 | ``` 77 | 78 | This will use shell processing to substitute shell variables, and will ignore any `CMD` or `docker run` command line arguments. 79 | 80 | ### Metadata 81 | 82 | ```docker 83 | LABEL version="1.0" 84 | ``` 85 | 86 | ```docker 87 | LABEL "com.example.vendor"="ACME Incorporated" 88 | LABEL com.example.label-with-value="foo" 89 | ``` 90 | 91 | ```docker 92 | LABEL description="This text illustrates \ 93 | that label-values can span multiple lines." 94 | ``` 95 | 96 | ## See also 97 | 98 | 99 | 100 | * [Docker docs](https://docs.docker.com/engine/reference/builder/) _(docs.docker.com)_ 101 | -------------------------------------------------------------------------------- /sheets/rdoc.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Rdoc 3 | category: Markup 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Basic RDoc format 8 | 9 | ```rb 10 | # Foo. 11 | # 12 | # @example 13 | # 14 | # y 15 | # g 16 | # 17 | # @param [String] param_name The xx and xx. 18 | # 19 | # @see http://url.com 20 | # 21 | # @return [true] if so 22 | ``` 23 | 24 | ### Inline 25 | 26 | ```markdown 27 | _bold_ 28 | _emphasized_ 29 | +code+ 30 | ``` 31 | 32 | ```markdown 33 | http://www.link.com 34 | See Models::User@Examples 35 | {Google}[http://google.com] 36 | ``` 37 | 38 | ### Skip 39 | 40 | ```rb 41 | def input # :nodoc: 42 | ``` 43 | 44 | ```rb 45 | module MyModule # :nodoc: all 46 | ``` 47 | 48 | ### Definition lists 49 | 50 | ```rb 51 | # == Definition lists 52 | # 53 | # list:: hi. 54 | # +foo+:: parameterized 55 | ``` 56 | 57 | ```rb 58 | # == Definition lists 59 | # [foo] also 60 | # [bar] like this 61 | ``` 62 | 63 | ### Return types 64 | 65 | ```rb 66 | # @return [String] 67 | # @return [String, nil] the name 68 | ``` 69 | 70 | ### Callseq 71 | 72 | ```rb 73 | # :call-seq: 74 | # ARGF.readlines(sep=$/) -> array 75 | # ARGF.readlines(limit) -> array 76 | # ARGF.readlines(sep, limit) -> array 77 | # 78 | # ARGF.to_a(sep=$/) -> array 79 | # ARGF.to_a(limit) -> array 80 | # ARGF.to_a(sep, limit) -> array 81 | ``` 82 | 83 | ### Category 84 | 85 | ```rb 86 | # :category: Utilities 87 | ``` 88 | 89 | ### Sections 90 | 91 | ```rb 92 | # :section: Expiry methods 93 | # methods relating to expiring 94 | 95 | def expire! 96 | def expired? 97 | ... 98 | ``` 99 | 100 | ### Using tomdoc 101 | 102 | ```rb 103 | # :markup: TomDoc 104 | ``` 105 | 106 | Place this at the beginning of the file. 107 | 108 | ## Also see 109 | 110 | 111 | 112 | * 113 | * 114 | 115 | -------------------------------------------------------------------------------- /sheets/js-model.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: js-model 3 | category: JavaScript libraries 4 | layout: 2017/sheet 5 | intro: | 6 | [js-model](http://benpickles.github.io/js-model/) is a library for RESTful models in JavaScript. 7 | --- 8 | 9 | ### Example 10 | 11 | ```js 12 | Project = Model('project', function() { 13 | this.extend({ 14 | findByTitle: title => { 15 | /*...*/ 16 | } 17 | }) 18 | 19 | this.include({ 20 | markAsDone: () => { 21 | /*...*/ 22 | } 23 | }) 24 | }) 25 | ``` 26 | 27 | ```js 28 | project = Project.find(1) 29 | project = Project.findByTitle('hello') 30 | ``` 31 | 32 | ```js 33 | project.markAsDone() 34 | ``` 35 | 36 | In Rails, be sure to set `ActiveRecord::Base.include_root_in_json = false` to make persistence work properly. 37 | 38 | ### Persistence 39 | 40 | ```js 41 | Project('hi', function() { 42 | this.persistence(Model.REST, '/projects') 43 | this.persistence(Model.localStorage) 44 | }) 45 | ``` 46 | 47 | ```js 48 | Project.load(function() { 49 | // Loaded 50 | }) 51 | ``` 52 | 53 | ### Attrs 54 | 55 | ```js 56 | project = new Project((name: 'Hello')) 57 | 58 | project.attr('name', 'Hey') 59 | project.attr('name') 60 | 61 | project.save() 62 | project.destroy() 63 | ``` 64 | 65 | ### Collection 66 | 67 | ```js 68 | Food.add(egg) 69 | Food.all() 70 | Food.select(food => { 71 | /* ... */ 72 | }) 73 | Food.first() 74 | ``` 75 | 76 | ```js 77 | Food.find(id) 78 | ``` 79 | 80 | ### Events 81 | 82 | #### Classes 83 | 84 | ```js 85 | Project.bind('add', obj => { 86 | /*...*/ 87 | }) 88 | Project.bind('remove', obj => { 89 | /*...*/ 90 | }) 91 | ``` 92 | 93 | #### Instances 94 | 95 | ```js 96 | project.bind('update', () => { 97 | /*...*/ 98 | }) 99 | project.bind('destroy', () => { 100 | /*...*/ 101 | }) 102 | ``` 103 | 104 | ```js 105 | project.trigger('turn_blue') 106 | ``` 107 | 108 | ## References 109 | 110 | 111 | 112 | * 113 | -------------------------------------------------------------------------------- /sheets/exunit.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ExUnit 3 | category: Elixir 4 | layout: 2017/sheet 5 | updated: 2017-08-26 6 | --- 7 | 8 | ### Test cases 9 | 10 | ```elixir 11 | defmodule MyTest do 12 | use ExUnit.Case 13 | use ExUnit.Case, async: true # for async 14 | 15 | test "the truth" do 16 | assert 1 + 1 == 2 17 | end 18 | end 19 | ``` 20 | 21 | ### Capture IO 22 | 23 | ```elixir 24 | import ExUnit.CaptureIO 25 | 26 | test "capture io" do 27 | result = capture_io(fn -> 28 | IO.puts "sup" 29 | end) 30 | 31 | assert result == "sup\n" 32 | end 33 | ``` 34 | 35 | ### Capture logs 36 | 37 | ```elixir 38 | config :ex_unit, capture_logs: true 39 | ``` 40 | 41 | ### Async 42 | 43 | ```elixir 44 | defmodule AssertionTest do 45 | # run concurrently with other test cases 46 | use ExUnit.Case, async: true 47 | end 48 | ``` 49 | 50 | ### Assertions 51 | 52 | ```elixir 53 | assert x == y 54 | refute x == y 55 | 56 | assert_raise ArithmeticError, fn -> 57 | 1 + "test" 58 | end 59 | 60 | assert_raise ArithmeticError, "message", fn -> ... 61 | assert_raise ArithmeticError, ~r/message/, fn -> ... 62 | 63 | flunk "This should've been an error" 64 | ``` 65 | 66 | See: [Assertions](http://devdocs.io/elixir/ex_unit/exunit.assertions) 67 | 68 | ## Setup 69 | 70 | ### Pattern matching 71 | 72 | ```elixir 73 | setup do 74 | {:ok, name: "John"} 75 | end 76 | ``` 77 | 78 | ```elixir 79 | test "it works", %{name: name} do 80 | assert name == "John" 81 | end 82 | ``` 83 | 84 | ### Setup 85 | 86 | ```elixir 87 | defp my_hook(_context) do 88 | # Invoked in every block in "a block" 89 | {:ok, name: "John", age: 54} 90 | end 91 | 92 | describe "a block" do 93 | setup [:my_hook] 94 | 95 | test "John's age", context do 96 | assert context[:name] == "John" 97 | assert context[:age] == 54 98 | end 99 | end 100 | ``` 101 | 102 | ## Also see 103 | 104 | 105 | 106 | * [ExUnit Docs](http://devdocs.io/elixir/ex_unit/exunit#configure/1) 107 | -------------------------------------------------------------------------------- /sheets/activeadmin.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: ActiveAdmin 3 | category: Ruby 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Listing scopes 8 | 9 | Allows you to filter listings by a certain scope. 10 | 11 | 12 | 13 | ```ruby 14 | scope :draft 15 | scope :for_approval 16 | ``` 17 | 18 | ```ruby 19 | scope :public, if: ->{ current_admin_user.can?(...) } 20 | scope "Unapproved", :pending 21 | scope("Published") { |books| books.where(:published: true) } 22 | ``` 23 | 24 | ### Sidebar filters 25 | 26 | ```ruby 27 | filter :email 28 | filter :username 29 | ``` 30 | 31 | ### Custom actions 32 | 33 | You can define custom actions for models. 34 | 35 | 36 | 37 | ```ruby 38 | before_filter only: [:show, :edit, :publish] do 39 | @post = Post.find(params[:id]) 40 | end 41 | ``` 42 | 43 | #### Make the route 44 | 45 | ```ruby 46 | member_action :publish, method: :put do 47 | @post.publish! 48 | redirect_to admin_posts_path, notice: "The post '#{@post}' has been published!" 49 | end 50 | ``` 51 | 52 | #### Link it in the index 53 | 54 | ```ruby 55 | index do 56 | column do |post| 57 | link_to 'Publish', publish_admin_post_path(post), method: :put 58 | end 59 | end 60 | ``` 61 | 62 | #### And link it in show/edit 63 | 64 | ```ruby 65 | action_item only: [:edit, :show] do 66 | @post = Post.find(params[:id]) 67 | link_to 'Publish', publish_admin_post_path(post), method: :put 68 | end 69 | ``` 70 | 71 | ### Columns 72 | 73 | ```ruby 74 | column :foo 75 | ``` 76 | 77 | ```ruby 78 | column :title, sortable: :name do |post| 79 | strong post.title 80 | end 81 | ``` 82 | 83 | ### Other helpers 84 | 85 | ```ruby 86 | status_tag "Done" # Gray 87 | status_tag "Finished", :ok # Green 88 | status_tag "You", :warn # Orange 89 | status_tag "Failed", :error # Red 90 | ``` 91 | 92 | ### Disabling 'new post' 93 | 94 | ```ruby 95 | ActiveAdmin.register Post do 96 | actions :index, :edit 97 | # or: config.clear_action_items! 98 | end 99 | ``` 100 | -------------------------------------------------------------------------------- /sheets/flynn.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Flynn 3 | category: Devops 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### General workflow 8 | 9 | * Start a flynn cluster (on amazon or vagrant) 10 | * `flynn cluster add` to add that cluster 11 | * `flynn create NAME` in your app 12 | * `git push flynn master` to deploy 13 | 14 | ### Creating a cluster (AWS) 15 | 16 | ```bash 17 | flynn install # (provisions AWS EC2 stuff) 18 | flynn key add # (adds your pubkey to AWS) 19 | ``` 20 | 21 | #### What it does 22 | 23 | * This creates `XXXX.flynnhub.com` 24 | * Dashboard in `dashboard.XXXX.flynnhub.com` 25 | * Use `flynn -a dashboard env get LOGIN_TOKEN` to get login token 26 | * Apps live in `APP.XXXX.flynnhub.com` 27 | 28 | ### Using a flynn cluster 29 | 30 | #### Managed in `~/.flynnrc`: 31 | 32 | 33 | 34 | ```bash 35 | flynn cluster 36 | flynn cluster add [-g githost] [-p pin] NAME URL KEY 37 | flynn cluster remove NAME 38 | flynn cluster default NAME # use this current 39 | ``` 40 | 41 | ### Setting up a new app 42 | 43 | ```bash 44 | cd ~/project 45 | flynn create example # adds the `flynn` remote 46 | flynn route # prints http routes 47 | git push flynn master 48 | ``` 49 | 50 | ## Commands 51 | 52 | ### Environment vars 53 | 54 | ```bash 55 | flynn env 56 | flynn env set FOO=bar BAZ=foobar 57 | flynn env unset FOO 58 | ``` 59 | 60 | ### Scale 61 | 62 | ```bash 63 | flynn ps 64 | flynn scale web=3 65 | ``` 66 | 67 | ### Logs 68 | 69 | ```bash 70 | flynn log 71 | flynn log flynn-d55c7a... 72 | ``` 73 | 74 | ### Running commands 75 | 76 | ```bash 77 | flynn run rake db:migrate 78 | ``` 79 | 80 | ### Manage routes 81 | 82 | ```bash 83 | flynn route 84 | flynn route add http example.com 85 | # then make a CNAME from example.com to myapp.xxxx.flynnhub.com 86 | ``` 87 | 88 | ### More 89 | 90 | ```bash 91 | flynn ps 92 | flynn kill 93 | 94 | flynn meta 95 | flynn meta set foo=baz 96 | ``` 97 | 98 | ## References 99 | 100 | * [Flynn website](https://flynn.io/) _(flynn.io)_ 101 | -------------------------------------------------------------------------------- /sheets/js-array.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: JavaScript Arrays 3 | category: JavaScript 4 | layout: 2017/sheet 5 | --- 6 | 7 | ### Arrays 8 | 9 | ```bash 10 | list = [a,b,c,d,e] 11 | ``` 12 | 13 | 14 | 15 | ```bash 16 | list[1] // → b 17 | list.indexOf(b) // → 1 18 | ``` 19 | 20 | ### Subsets 21 | 22 | #### Immutable 23 | 24 | ```bash 25 | list.slice(0,1) // → [a ] 26 | list.slice(1) // → [ b,c,d,e] 27 | list.slice(1,2) // → [ b ] 28 | ``` 29 | 30 | #### Mutative 31 | 32 | ```bash 33 | re = list.splice(1) // re = [b,c,d,e] list == [a] 34 | re = list.splice(1,2) // re = [b,c] list == [a,d,e] 35 | ``` 36 | 37 | ### Adding items 38 | 39 | #### Mutative 40 | 41 | ```bash 42 | list.push(X) // list == [_,_,_,_,_,X] 43 | list.unshift(X) // list == [X,_,_,_,_,_] 44 | list.splice(2, 0, X) // list == [_,_,X,_,_,_] 45 | ``` 46 | 47 | #### Immutable 48 | 49 | ```bash 50 | list.concat([X,Y]) // → [_,_,_,_,_,X,Y] 51 | ``` 52 | 53 | ### Inserting 54 | 55 | ```bash 56 | // after -- [_,_,REF,NEW,_,_] 57 | list.splice(list.indexOf(REF)+1, 0, NEW)) 58 | ``` 59 | 60 | ```bash 61 | // before -- [_,_,NEW,REF,_,_] 62 | list.splice(list.indexOf(REF), 0, NEW)) 63 | ``` 64 | 65 | ### Replace items 66 | 67 | ```bash 68 | list.splice(2, 1, X) // list == [a,b,X,d,e] 69 | ``` 70 | 71 | ### Removing items 72 | 73 | ```bash 74 | list.pop() // → e list == [a,b,c,d] 75 | list.shift() // → a list == [b,c,d,e] 76 | list.splice(2, 1) // → [c] list == [a,b,d,e] 77 | ``` 78 | 79 | ### Iterables 80 | 81 | ```bash 82 | .filter(n => ...) => array 83 | ``` 84 | 85 | ```bash 86 | .find(n => ...) // es6 87 | .findIndex(...) // es6 88 | ``` 89 | 90 | ```bash 91 | .every(n => ...) => Boolean // ie9+ 92 | .some(n => ..) => Boolean // ie9+ 93 | ``` 94 | 95 | ```bash 96 | .map(n => ...) // ie9+ 97 | .reduce((total, n) => total) // ie9+ 98 | .reduceRight(...) 99 | ``` 100 | -------------------------------------------------------------------------------- /sheets/find.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Find 3 | category: CLI 4 | layout: 2017/sheet 5 | updated: 2019-10-01 6 | --- 7 | 8 | ### Usage 9 | 10 | 11 | 12 | ```bash 13 | find 14 | ``` 15 | 16 | ### Conditions 17 | 18 | ```bash 19 | -name "*.c" 20 | ``` 21 | 22 | ```bash 23 | -user jonathan 24 | -nouser 25 | ``` 26 | 27 | ```bash 28 | -type f # File 29 | -type d # Directory 30 | -type l # Symlink 31 | ``` 32 | 33 | ```bash 34 | -depth 2 # At least 3 levels deep 35 | -regex PATTERN 36 | ``` 37 | 38 | ```bash 39 | -size 8 # Exactly 8 512-bit blocks 40 | -size -128c # Smaller than 128 bytes 41 | -size 1440k # Exactly 1440KiB 42 | -size +10M # Larger than 10MiB 43 | -size +2G # Larger than 2GiB 44 | ``` 45 | 46 | ```bash 47 | -newer file.txt 48 | -newerm file.txt # modified newer than file.txt 49 | -newerX file.txt # [c]hange, [m]odified, [B]create 50 | -newerXt "1 hour ago" # [t]imestamp 51 | ``` 52 | 53 | ### Access time conditions 54 | 55 | ```bash 56 | -atime 0 # Last accessed between now and 24 hours ago 57 | -atime +0 # Accessed more than 24 hours ago 58 | -atime 1 # Accessed between 24 and 48 hours ago 59 | -atime +1 # Accessed more than 48 hours ago 60 | -atime -1 # Accessed less than 24 hours ago (same a 0) 61 | -ctime -6h30m # File status changed within the last 6 hours and 30 minutes 62 | -mtime +1w # Last modified more than 1 week ago 63 | ``` 64 | 65 | These conditions only work in MacOS and BSD-like systems (no GNU/Linux support). 66 | 67 | ### Condition flow 68 | 69 | ```bash 70 | \! -name "*.c" 71 | \( x -or y \) 72 | ``` 73 | 74 | ### Actions 75 | 76 | ```bash 77 | -exec rm {} \; 78 | -print 79 | -delete 80 | ``` 81 | 82 | ### Examples 83 | 84 | ```bash 85 | find . -name '*.jpg' 86 | find . -name '*.jpg' -exec rm {} \; 87 | ``` 88 | 89 | ```bash 90 | find . -newerBt "24 hours ago" 91 | ``` 92 | 93 | ```bash 94 | find . -type f -mtime +29 # find files modified more than 30 days ago 95 | ``` 96 | -------------------------------------------------------------------------------- /sheets/wip/php.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: PHP 3 | category: PHP 4 | layout: 2017/sheet 5 | prism_languages: [php] 6 | --- 7 | 8 | ### Hello world 9 | 10 | #### hello.php 11 | 12 | ```php 13 | 20, 33 | "banana" => 30 34 | ); 35 | echo $fruitsArray['banana']; 36 | ``` 37 | 38 | Or cast as object 39 | 40 | ```php 41 | banana; 45 | ``` 46 | 47 | ### Inspecting objects 48 | 49 | ```php 50 | name = 'bob'; 67 | 68 | echo $person->name; 69 | ``` 70 | 71 | ### Getters and setters 72 | 73 | ```php 74 | class Person 75 | { 76 | public $name = ''; 77 | 78 | public function getName() 79 | { 80 | return $this->name; 81 | } 82 | 83 | public function setName($name) 84 | { 85 | $this->name = $name; 86 | return $this; 87 | } 88 | } 89 | 90 | $person = new Person(); 91 | $person->setName('bob'); 92 | 93 | echo $person->getName(); 94 | ``` 95 | 96 | ### isset vs empty 97 | 98 | ```php 99 | $options = [ 100 | 'key' => 'value', 101 | 'blank' => '', 102 | 'nothing' => null, 103 | ]; 104 | 105 | var_dump(isset($options['key']), empty($options['key'])); // true, false 106 | var_dump(isset($options['blank']), empty($options['blank'])); // true, true 107 | var_dump(isset($options['nothing']), empty($options['nothing'])); // false, true 108 | ``` 109 | -------------------------------------------------------------------------------- /sheets/html-email.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: HTML emails 3 | category: HTML 4 | layout: 2017/sheet 5 | updated: 2017-08-29 6 | --- 7 | 8 | ### Properties to avoid 9 | 10 | | Property | Where | 11 | | -------------------- | ----------------------- | 12 | | `position` | (Outlook, Gmail, Yahoo) | 13 | | `display` | (Outlook, Gmail) | 14 | | `float` | (Outlook) | 15 | | --- | --- | 16 | | `height` | (Outlook) | 17 | | `width` _in p/div_ | (Outlook) | 18 | | `padding` _in p/div_ | (Outlook) | 19 | | `background` | (Outlook, Gmail) | 20 | | `min-width` | (Outlook) | 21 | | `max-width` | (Outlook) | 22 | | --- | --- | 23 | | `opacity` | (Outlook, Gmail, Yahoo) | 24 | | `box-shadow` | (Outlook, Gmail, Yahoo) | 25 | | --- | --- | 26 | | `rgba()` | (Outlook) | 27 | | `data-uri` | (all webmail) | 28 | 29 | ### Selectors to avoid 30 | 31 | | `E[attr]` | (Outlook, Gmail) | 32 | | `E:nth-child(n)` | (Outlook, Gmail) | 33 | | `::before` _and_ `::after` | (Outlook, Yahoo, Gmail) | 34 | | `E F` | (Gmail) | 35 | | `E + F`, `E > F` _etc_ | (Outlook, Gmail) | 36 | 37 | Inline your CSS as much as possible. 38 | 39 | ### Basic layout 40 | 41 | ```html 42 |
43 | 44 | 45 | 48 | 49 | 50 |
46 | ··· 47 |
51 | ``` 52 | 53 | ### Responsive 54 | 55 | ```html 56 | 59 | ``` 60 | 61 | `