Cleanup: formatting update (2020-07-05) (#1496)

This commit is contained in:
Rico Sta. Cruz 2020-07-05 23:13:06 +10:00 committed by GitHub
parent 6b43bf97da
commit aff701a600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 307 additions and 400 deletions

View File

@ -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
* <https://github.com/brunch/brunch/blob/master/docs/config.md>

View File

@ -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")
```

12
deku.md
View File

@ -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(
<MyButton>Hello World!</MyButton>,
store.getState()
)
render(<MyButton>Hello World!</MyButton>, store.getState())
```

View File

@ -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 = <div class='my-app'>Hello World!</div>
render(tree(app), document.body)
```
## Components
### Components
```js
Button = {
render () { return <button>Submit</button> }
render() {
return <button>Submit</button>
}
}
App = {
render () { return <div><Button /></div> }
render() {
return (
<div>
<Button />
</div>
)
}
}
render(tree(<App />), document.body)
render(tree(element(App)), document.body)
```
## Component props/state
### Component props/state
```js
App = {
@ -50,13 +61,14 @@ App = {
render(tree(<App />), document.body)
```
## Events
### Events
```js
<a onClick={onClick}>{props.text}</a>
```
## 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'
<div style={style} class={[ 'button', '-active' ]}>
```
## Reference
### Reference
```
name = 'MyComponent'

View File

@ -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 <http://devdocs.io/dom/document/createrange>
```js
var range = document.createRange()
```
See: <https://devdocs.io/dom/document/createrange>
## Methods
See <http://devdocs.io/dom/range>
```js
range
@ -27,41 +33,41 @@ range
.selectNodeContents(node)
```
See: <https://devdocs.io/dom/range>
### 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
```

View File

@ -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 <http://devdocs.io/dom/selection>
## Reference
{: .-three-column}
### Selection
```js
var selection = document.getSelection()
var sel = document.getSelection()
```
## Methods
See: <https://devdocs.io/dom/selection>
### 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

67
ec2.md
View File

@ -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)"

View File

@ -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

View File

@ -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

View File

@ -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.

42
ruby.md
View File

@ -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 |

135
travis.md
View File

@ -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
```
<https://docs.travis-ci.com/user/installing-dependencies/>
### 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: <always|never|change> # default: change
on_failure: <always|never|change> # 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/