From aff701a60082d53b2f6475b262d5dc3ce4e70f26 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Sun, 5 Jul 2020 23:13:06 +1000 Subject: [PATCH] Cleanup: formatting update (2020-07-05) (#1496) --- brunch.md | 97 --------------------------------- c_preprocessor.md | 64 ++++++++++++++-------- deku.md | 12 ++--- deku@1.md | 32 +++++++---- dom-range.md | 50 +++++++++-------- dom-selection.md | 42 ++++++++------- ec2.md | 67 ----------------------- git-extras.md | 74 +++++++++++++++---------- gmail.md | 21 -------- promise.md | 71 ++++++++++++++---------- ruby.md | 42 +++++++++------ travis.md | 135 ++++++++++++++++++++++++---------------------- 12 files changed, 307 insertions(+), 400 deletions(-) delete mode 100644 brunch.md delete mode 100644 ec2.md delete mode 100644 gmail.md diff --git a/brunch.md b/brunch.md deleted file mode 100644 index a5bd7574d..000000000 --- a/brunch.md +++ /dev/null @@ -1,97 +0,0 @@ ---- -title: Brunch -category: JavaScript libraries ---- - -## Paths - - / - app/ - assets/ - vendor/ - public/ - config.coffee - -## Config - -```js -module.exports = { - files: { - javascripts: { # or 'stylesheets' or 'templates' - order: { - before: [ 'normalize.css' ], - after: [ 'helpers.css' ], - - joinTo: 'app.js', - joinTo: { - 'js/app.js': /^app/, - 'js/vendor.js': /^vendor/ - }, - pluginHelpers: 'js/vendor.js' - } - } - - paths: { - public: 'public', # where to compile - watched: ['app','test','vendor'], # what to monitor - } - - modules: { - wrapper: 'amd', - definition: 'amd', - nameCleaner: (path) => path.replace(/^app\//, '') - } - - npm: { styles, globals } - - plugins: { - sass: { ... } - } - - // brunch w --apply testing - // BRUNCH_ENV=testing brunch build - overrides: { - production: { - optimize: true, - sourceMaps: false, - plugins: { autoReload: { enabled: false } } - } - } - - onCompile: (files, assets) => { ... } -``` - -## Plugins - - plugins: - uglify: - mangle: true - compress: - global_defs: - DEBUG: false - -## Extensions - -Compile to CSS - - * stylus-brunch - * less-brunch - * sass-brunch - -Compile to HTML - - * static-jade-brunch - -Embedded templates - - * emblem-brunch - -Etc - - * uglify-js-brunch - * jshint-brunch - * imageoptimizer-brunch - -## References - - * diff --git a/c_preprocessor.md b/c_preprocessor.md index 69f5f8233..745012113 100644 --- a/c_preprocessor.md +++ b/c_preprocessor.md @@ -1,50 +1,72 @@ --- title: C Preprocessor category: C-like +layout: 2017/sheet +intro: | + Quick reference for the [C macro preprocessor](https://en.m.wikipedia.org/wiki/C_preprocessor), which can be used independent of C/C++. --- +## Reference +{: .-three-column} + ### Compiling - $ cpp -P file > outfile +``` +$ cpp -P file > outfile +``` ### Includes - #include "file" +``` +#include "file" +``` ### Defines - #define FOO - #define FOO "hello" +``` +#define FOO +#define FOO "hello" - #undef FOO +#undef FOO +``` ### If - #ifdef DEBUG - console.log('hi'); - #elif defined VERBOSE - ... - #else - ... - #endif +``` +#ifdef DEBUG + console.log('hi'); +#elif defined VERBOSE + ... +#else + ... +#endif +``` ### Error - #if VERSION == 2.0 - #error Unsupported - #warning Not really supported - #endif +``` +#if VERSION == 2.0 + #error Unsupported + #warning Not really supported +#endif +``` ### Macro - #define DEG(x) ((x) * 57.29) +``` +#define DEG(x) ((x) * 57.29) +``` ### Token concat - #define DST(name) name##_s name##_t - DST(object); #=> "object_s object_t;" +``` +#define DST(name) name##_s name##_t +DST(object); #=> "object_s object_t;" +``` ### file and line - #define LOG(msg) console.log(__FILE__, __LINE__, msg) - #=> console.log("file.txt", 3, "hey") +``` +#define LOG(msg) console.log(__FILE__, __LINE__, msg) +#=> console.log("file.txt", 3, "hey") +``` diff --git a/deku.md b/deku.md index a720f0904..24b53576f 100644 --- a/deku.md +++ b/deku.md @@ -1,9 +1,12 @@ --- title: Deku v2 category: JavaScript libraries +layout: 2017/sheet +intro: | + Quick reference for [Deku](https://www.npmjs.com/package/deku), a minimal virtual DOM library. --- -## Components +### Components ```js /** @jsx element */ @@ -29,7 +32,7 @@ function onRemove ({ props, dispatch, path }) { ... } export default { render, onCreate, onRemove } ``` -## Rendering +### Rendering ```js import { createStore } from 'redux' @@ -42,8 +45,5 @@ let store = createStore(reducer) let render = createRenderer(document.body, store.dispatch) // Update the page and add redux state to the context -render( - Hello World!, - store.getState() - ) +render(Hello World!, store.getState()) ``` diff --git a/deku@1.md b/deku@1.md index 09a2785e1..ef9ef8403 100644 --- a/deku@1.md +++ b/deku@1.md @@ -1,36 +1,47 @@ --- title: Deku v1 category: JavaScript libraries +layout: 2017/sheet +intro: | + Quick reference for [Deku](https://www.npmjs.com/package/deku), a minimal virtual DOM library. **Deprecated:** This is for Deku v1. See [deku](./deku) for a more updated cheatsheet. --- -This is for Deku v1. See [deku](./deku) for a more updated cheatsheet. +### Example ```js /** @jsx element */ -import element from 'virtual-element' // replacement for React.createElement -import {render, tree} from 'deku' +import element from 'virtual-element' // replacement for React.createElement +import { render, tree } from 'deku' var app =
Hello World!
render(tree(app), document.body) ``` -## Components +### Components ```js Button = { - render () { return } + render() { + return + } } App = { - render () { return
} + render() { + return ( +
+
+ ) + } } render(tree(), document.body) render(tree(element(App)), document.body) ``` -## Component props/state +### Component props/state ```js App = { @@ -50,13 +61,14 @@ App = { render(tree(), document.body) ``` -## Events +### Events ```js {props.text} ``` -## Magic virtual element +### Magic virtual element + Use [magic-virtual-element](https://github.com/dekujs/magic-virtual-element) to enable nice classnames. ``` @@ -64,7 +76,7 @@ import element from 'magic-virtual-element'
``` -## Reference +### Reference ``` name = 'MyComponent' diff --git a/dom-range.md b/dom-range.md index 6cb2185af..409e5fc51 100644 --- a/dom-range.md +++ b/dom-range.md @@ -1,17 +1,23 @@ --- title: DOM Range category: JavaScript +layout: 2017/sheet +intro: | + Quick reference to the HTML [DOM createRange API](https://devdocs.io/dom/range). --- +## Reference +{:.-three-column} + ### Creating ranges -See ```js var range = document.createRange() ``` +See: + ## Methods -See ```js range @@ -27,41 +33,41 @@ range .selectNodeContents(node) ``` +See: + ### Collapsing ```js -range - .collapse() // to end (a single point) - .collapse(true) // to start (a single point) - .collapsed // true | false +range.collapse() // to end (a single point) +range.collapse(true) // to start (a single point) +range.collapsed // true | false ``` ### Operations ```js -range - .cloneContents() // copy => DocumentFragment - .extractContents() // cut => DocumentFragment - .deleteContents() // delete - - .insertNode(node) +range.cloneContents() // copy => DocumentFragment +range.extractContents() // cut => DocumentFragment +range.deleteContents() // delete ``` -### Etc +```js +range.insertNode(node) +``` + +### String ```js -range - .toString() +range.toString() ``` ### Read-only attributes ```js -range - .collapsed // true/false - .startContainer // Node - .startOffset - .endContainer // Node - .endOffset - .commonAncestorContainer // closest of start and end containers +range.collapsed // => true/false +range.startContainer // => Node +range.startOffset +range.endContainer // => Node +range.endOffset +range.commonAncestorContainer // closest of start and end containers ``` diff --git a/dom-selection.md b/dom-selection.md index 1fdd5f9ef..3e05ec470 100644 --- a/dom-selection.md +++ b/dom-selection.md @@ -1,50 +1,52 @@ --- title: DOM Selection category: JavaScript +layout: 2017/sheet +intro: | + Quick introduction to the HTML [DOM selection API](https://devdocs.io/dom/selection). --- -## Selection -See +## Reference +{: .-three-column} + +### Selection ```js -var selection = document.getSelection() +var sel = document.getSelection() ``` -## Methods +See: + +### Methods ```js -selection - .removeAllRanges() // deselects - .addRange(range) // sets a selection - .removeRange(range) // remove a range +sel.removeAllRanges() // deselects +sel.addRange(range) // sets a selection +sel.removeRange(range) // remove a range ``` ```js -selection - .rangeCount // ranges - .getRangeAt(0) // get the 0th range +sel.rangeCount +sel.getRangeAt(0) // get the 0th range ``` ### Collapsing ```js -selection - .collapse(parent, offset) - .collapseToEnd() - .collapseToStart() - .isCollapsed +sel.collapse(parent, offset) +sel.collapseToEnd() +sel.collapseToStart() +sel.isCollapsed ``` ```js -selection - .containsNode(node) +sel.containsNode(node) ``` ### Deleting ```js -selection - .deleteFromDocument() +sel.deleteFromDocument() ``` ### Events diff --git a/ec2.md b/ec2.md deleted file mode 100644 index 1ae570961..000000000 --- a/ec2.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: EC2 API tools -category: Devops ---- - -### Install - - $ sudo apt-get install ec2-api-tools ec2-ami-tools - $ brew install ec2-api-tools ec2-ami-tools - -### Pem files - - $ brew info ec2-api-tools - - * Before you can use these tools you must export some variables to your $SHELL - and download your X.509 certificate and private key from Amazon Web Services. - - * Your certificate and private key are available at - [aws-portal.amazon.com](http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key). - - * Download two `.pem` files, one starting with `pk-`, and one starting with `cert-`. - You need to put both into a folder in your home directory, `~/.ec2`. - -### Key pair - - # To use public images (AMI's), you need an SSH keypair from EC2. - ec2-add-keypair my-keypair > ~/.ec2/my-keypair.pem - chmod 600 ec2-keypair.pem - -### Start an instance - - # Start an instance using a given AMI image: - # (Use the Ubuntu locator, or ec2-describe-images) - ec2-run-instances ami-xxxxxx -k ec2-keypair - - # Open up ports (in the 'default' security group): - ec2-authorize default -p 22 - ec2-authorize default -p 80 - - # Connect - ssh -i ~/.ec2/my-keypair.pem root@ec2-xxx.amazonaws.com - -### Management - - # Show running instances - ec2-describe-instances - - # Kill an instance - ec2-terminate-instances i-yourinstance - -### Misc - - # Create a security group - ec2-add-group group_name -d "Description" - - # Show images (AMI's) owned by amazon, or me - ec2-describe-images -o self -o amazon - -### Ubuntu images - - * [Ubuntu EC2 AMI locator](http://cloud-images.ubuntu.com/locator/ec2/) - -### Change certificates - - EC2_CERT_PATH="$HOME/.ec2" - export EC2_PRIVATE_KEY="$(/bin/ls $EC2_CERT_PATH/pk-*.pem | /usr/bin/head -1)" - export EC2_CERT="$(/bin/ls $EC2_CERT_PATH/cert-*.pem | /usr/bin/head -1)" diff --git a/git-extras.md b/git-extras.md index 209b79cc6..21cd80d40 100644 --- a/git-extras.md +++ b/git-extras.md @@ -1,65 +1,85 @@ --- title: Git extras category: Git +layout: 2017/sheet +intro: | + Quick reference to some utilities in the [git-extras](https://github.com/tj/git-extras) utilities. --- +## References + ### Git-flow - $ git feature myfeature - switched to branch 'feature/rofl' +```sh +$ git feature myfeature + switched to branch 'feature/rofl' - $ ... - $ git checkout develop - $ git feature finish myfeature - merging 'feature/rofl' into develop - deleted branch 'feature/rofl' +$ ... +$ git checkout develop +$ git feature finish myfeature + merging 'feature/rofl' into develop + deleted branch 'feature/rofl' +``` Also `git-bug` and `git-refactor`. ### Branches - $ git delete-merged-branches - # hint: do `git remote prune origin` after +```sh +$ git delete-merged-branches + # hint: do `git remote prune origin` after - $ git create-branch development - $ git delete-branch development +$ git create-branch development +$ git delete-branch development - $ git fresh-branch gh-pages +$ git fresh-branch gh-pages +``` ### Inspecting - $ git summary # repo age, commits, active days, etc - $ git impact # impact graph - $ git effort # commits per file +```sh +$ git summary # repo age, commits, active days, etc +$ git impact # impact graph +$ git effort # commits per file +``` ### Github - $ git fork strongloop/express - # sync your fork with the original repository: - $ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git - $ git fetch upstream; git merge upstream/master - +```sh +$ git fork strongloop/express +# sync your fork with the original repository: +$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git +$ git fetch upstream; git merge upstream/master +``` ### Tags - $ git release v1.0.0 # commit, tag, push-tags - $ git delete-tag v1.0.0 +```sh +$ git release v1.0.0 # commit, tag, push-tags +$ git delete-tag v1.0.0 +``` ### Conveniences - $ git ignore "*.log" +```sh +$ git ignore "*.log" +``` ### Locking Assumes that changes will not be committed. - $ git lock config/database.yml - $ git unlock config/database.yml +```sh +$ git lock config/database.yml +$ git unlock config/database.yml +``` ### Etc - $ git obliterate secret.yml # remove all references to it +```sh +$ git obliterate secret.yml # remove all references to it +``` ### References - * https://github.com/visionmedia/git-extras +- https://github.com/visionmedia/git-extras diff --git a/gmail.md b/gmail.md deleted file mode 100644 index 165df4d6a..000000000 --- a/gmail.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: Gmail ---- - -### IMAP - - * `imap.gmail.com:993` - * SSL: yes - * Username: full `username@gmail.com` - -### SMTP - - * `smtp.gmail.com` - * SSL port: 465 - * TLS/STARTTLS port: 587 - * Use authentication: yes - -### POP3 - - * `pop.gmail.com:995` - * SSL: yes diff --git a/promise.md b/promise.md index 1c6a0c43e..03a33d5c5 100644 --- a/promise.md +++ b/promise.md @@ -1,59 +1,74 @@ --- title: Promises category: JavaScript +intro: A quick reference to the [Promise API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). --- -Based on the [Promise API reference][promise] (mozilla.org). -{:.brief-intro.center} - -[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise +## Reference +{:.-three-column} ### Creating promises ```js -new Promise(function (ok, err) { - doStuff(function () { - if (success) { ok(); } - else { err(); } - }); +new Promise((resolve, reject) => { + doStuff(() => { + if (success) { + resolve('good') + } else { + reject(new Error('oops')) + } + }) }) ``` +Use [new Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Contstructor) to create new promises. + ### Consuming promises ```js promise - .then(okFn, errFn) - .catch(errFn) + .then((result) => { + /* success */ + }) + .catch((error) => { + /* failure */ + }) ``` +[then()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) runs a function when a promise resolves. [catch()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) runs when a promise fails. + ### Multiple promises ```js -var promises = [ - promise1(), promise2(), ... -] +const promises = [promise1(), promise2() /* ... */] +``` -// succeeds when all succeed -Promise.all(promises) - .then(function (results) { - }); +```js +// Succeeds when all succeed +Promise.all(promises).then((results) => { + /* ... */ +}) +``` -// succeeds when one finishes first -Promise.race(promises) - .then(function (result) { - }); +```js +// Succeeds when one finishes first +Promise.race(promises).then((result) => { + /* ... */ +}) ``` ### Converting other promises ```js -return Promise.resolve("result"); -return Promise.resolve(promise); -return Promise.resolve(thenable); +return Promise.resolve('result') +return Promise.resolve(promise) +return Promise.resolve(thenable) -return Promise.reject("reason"); +return Promise.reject('reason') -Promise.resolve($.get('http://google.com')) -.then(...) +Promise.resolve(result).then(() => { + /* ... */ +}) ``` + +`Promise.resolve(val)` will return a promise that resolves to the value given to it. diff --git a/ruby.md b/ruby.md index 11d980b68..5fccc5bf7 100644 --- a/ruby.md +++ b/ruby.md @@ -1,21 +1,31 @@ --- title: Ruby category: Ruby +tags: [WIP] +layout: 2017/sheet +intro: | + Quick reference to some features of the Ruby programming language. --- -* `$!` - latest error message -* `$@` - location of error -* `$_` - string last read by gets -* `$.` - line number last read by interpreter -* `$&` - string last matched by regexp -* `$~` - the last regexp match, as an array of subexpressions -* `$n` - the nth subexpression in the last match (same as `$~[n]`) -* `$=` - case-insensitivity flag -* `$/` - input record separator -* `$\` - output record separator -* `$0` - the name of the ruby script file -* `$*` (or `ARGV`) - the command line arguments -* `$$` - interpreter's process ID -* `$?` - exit status of last executed child process -* `$-i` `$-l` `$-p` `$-v` - Command line switches -* `$-v` (or `$VERBOSE`) - verbose mode +### Reference + +{:.-one-column} + +| Code | Description | +| ----------------------- | --------------------------------------------------------- | +| `$!` | latest error message | +| `$@` | location of error | +| `$_` | string last read by gets | +| `$.` | line number last read by interpreter | +| `$&` | string last matched by regexp | +| `$~` | the last regexp match, as an array of subexpressions | +| `$n` | the nth subexpression in the last match (same as `$~[n]`) | +| `$=` | case-insensitivity flag | +| `$/` | input record separator | +| `$\` | output record separator | +| `$0` | the name of the ruby script file | +| `$*` (or `ARGV`) | the command line arguments | +| `$$` | interpreter's process ID | +| `$?` | exit status of last executed child process | +| `$-i` `$-l` `$-p` `$-v` | Command line switches | +| `$-v` (or `$VERBOSE`) | verbose mode | diff --git a/travis.md b/travis.md index a8d5a2237..8ce0ea46b 100644 --- a/travis.md +++ b/travis.md @@ -1,109 +1,114 @@ --- title: Travis.yml category: Devops +layout: 2017/sheet +prism_languages: [yaml] +intro: | + Quick reference for [Travis CI](https://travis-ci.org) yaml configuration. See [official documentation](https://docs.travis-ci.com/user/customizing-the-build/). --- -### Node +## Reference +{:.-three-column} -```yml +### Node.js + +```yaml language: node_js node_js: -- '4' + - '4' ``` -* Provides: 0.10, 0.8, 0.6, 0.11 (latest dev) -* Defaults install to `npm install` -* Defaults test to `npm test` +Defaults install to `npm install`, and defaults test to `npm test`. ### Ruby -```yml +```yaml language: ruby rvm: -- 2.0.0 -- 1.9.3 -- 1.8.7 -- rbx-19mode -- jruby-19mode -- jruby-18mode + - 2.0.0 + - 1.9.3 + - 1.8.7 ``` -* Defaults install to `bundle install` -* Defaults test to `rake` +Defaults install to `bundle install`, defaults test to `rake`. ### Build lifecycle -* `before_install` -* `install` -* `before_script` -* `script` -* `after_success` or `after_failure` -* `after_script` -* OPTIONAL `before_deploy` -* OPTIONAL `deploy` -* OPTIONAL `after_deploy` +| Lifecycle | +| ---------------------------------- | +| `before_install` | +| `install` | +| --- | +| `before_script` | +| `script` | +| --- | +| `after_success` or `after_failure` | +| `after_script` | +| --- | +| `before_deploy` (optional) | +| `deploy` (optional) | +| `after_deploy` (optional) | ### Branches - branches: - except: [".."] - only: ["master"] +```yaml +branches: + except: ['..'] + only: ['master'] +``` ### Environment vars - env: - - "rack=master" - - "rack=1.3.4" +```yaml +env: + - 'rack=master' + - 'rack=1.3.4' +``` ### Custom test command - script: make test - before_script: make pretest - after_script: make clean +```yaml +script: make test +before_script: make pretest +after_script: make clean - before_script: - - make pretest1 - - make pretest2 +before_script: + - make pretest1 + - make pretest2 +``` ### Branches - branches: - except: - - legacy +```yaml +branches: + except: + - legacy - only: - - gh-pages - - /^deploy/ + only: + - gh-pages + - /^deploy/ +``` ### Apt packages - before_install: - - sudo apt-get update -q - - sudo apt-get install gcc-4.8 -y +```yaml +before_install: + - sudo apt-get update -q + - sudo apt-get install gcc-4.8 -y +``` + ### Etc - gemfile: - - gemfiles/Gemfile.rails-2.3.x - - gemfiles/Gemfile.rails-3.0.x - -### Notifications - - notifications: - email: - - dropbox+travis@ricostacruz.com - - email: - recipients: - - dropbox+travis@ricostacruz.com - on_success: # default: change - on_failure: # default: always - - irc: "chat.freenode.net#travis" +```yaml +gemfile: + - gemfiles/Gemfile.rails-2.3.x + - gemfiles/Gemfile.rails-3.0.x +``` ### References - * http://about.travis-ci.org/docs/user/build-configuration/ - * http://about.travis-ci.org/docs/user/languages/javascript-with-nodejs/ - * http://about.travis-ci.org/docs/user/languages/ruby/ +- http://about.travis-ci.org/docs/user/build-configuration/ +- http://about.travis-ci.org/docs/user/languages/javascript-with-nodejs/ +- http://about.travis-ci.org/docs/user/languages/ruby/