This commit is contained in:
Rico Sta. Cruz 2016-01-07 12:47:48 +08:00
parent ce76b735f4
commit 6e2a22b82b
12 changed files with 475 additions and 127 deletions

60
awesome-redux.md Normal file
View File

@ -0,0 +1,60 @@
---
title: Awesome-redux
category: Ruby
---
### [redux-actions](https://www.npmjs.com/package/redux-actions)
Create action creators in flux standard action format.
```js
increment = createAction('INCREMENT', amount => amount)
increment = createAction('INCREMENT') // same
err = new Error()
increment(42) === { type: 'INCREMENT', payload: 42 }
increment(err) === { type: 'INCREMENT', payload: err, error: true }
```
### [flux-standard-action](https://github.com/acdlite/flux-standard-action)
A standard for flux action objects.
```
{ type: 'ADD_TODO', payload: { text: 'Work it' } }
{ type: 'ADD_TODO', payload: new Error(), error: true }
```
An action may have an `error`, `payload` and `meta` and nothing else.
### [redux-promise](https://github.com/acdlite/redux-promise)
Pass promises to actions. Dispatches a flux-standard-action.
```js
increment = createAction('INCREMENT') // redux-actions
increment(Promise.resolve(42))
```
### [redux-effects](https://www.npmjs.com/package/redux-effects)
Pass side effects declaratively to keep your actions pure.
```js
{
type: 'EFFECT_COMPOSE',
payload: {
type: 'FETCH'
payload: {url: '/some/thing', method: 'GET'}
},
meta: {
steps: [ [success, failure] ]
}
}
```
### [redux-multi](https://github.com/ashaffer/redux-multi)
Dispatch multiple actions in one action creator.
```js
store.dispatch([
{ type: 'INCREMENT', payload: 2 },
{ type: 'INCREMENT', payload: 3 }
])
```

View File

@ -6,55 +6,41 @@ category: JavaScript libraries
Model Model
----- -----
# or Bookshelf.Mode.extend({..}) ```js
class Book extends Bookshelf.Model Summary = bookshelf.Model.extend({
tableName: 'books' tableName: 'summaries',
hasTimestamps: true,
hasTimestamps: ['created_at', 'updated_at'],
})
```
### Associations ### Associations
class Book extends Bookshelf.Model ```js
# Associations Summary = bookshelf.Model.extend({
author: -> @belongsTo(Author) book () {
summary: -> @hasOne(Summary) return this.belongsTo(Book)
pages: -> @hasMany(Pages) },
shelves: -> @belongsToMany(Shelves) author () {
return this.hasOne(Author)
}
// belongsToMany
// hasMany
// hasMany().through()
})
```
@hasMany(Comment) ### CRUD
.through(Chapter)
@belongsToMany(Comment) ```js
.withPivot(['created_at']) Book.create({ title: '..' }).save()
new Book({ title: '..' }).save()
### Collections new Book({ id: 1 }).fetch()
class Books extends Bookshelf.Collection Book.where({ id: 1 }).fetch()
model: Book Book.where('favorite_color', 'red').fetch()
Book.where('favorite_color', '<>', 'red').fetch()
books = new Books() Book
books.query(where: { id: 2 }) .query((q) => q.orderBy('updated_at')
.fetch() ```
.then ->
### Fetching associations
new Book(id: 1).summary().fetch()
.then (summary) ->
Manipulation
------------
### Reading (Fetch by ID)
new Story(id: 2).fetch()
.then (story) ->
story.id #=> 2
story.title #=> "Through the Looking Glass"
story.summary = "Hello"
story.save()
.then -> ...
### References
* http://bookshelfjs.org/

85
deku-v1.md Normal file
View File

@ -0,0 +1,85 @@
---
title: Deku v1
category: JavaScript libraries
---
```js
/** @jsx element */
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
```js
Button = {
render () { return <button>Submit</button> }
}
App = {
render () { return <div><Button /></div> }
}
render(tree(<App />), document.body)
render(tree(element(App)), document.body)
```
## Component props/state
```js
App = {
render ({ props, state }) {
return <div>{ /*...use state.store here*/ }</div>
}
initialState (props) {
return { store: store.getState() }
},
afterMount (comp, el, setState) {
store.subscribe(() => setState({ store: store.getState() }))
}
}
render(tree(<App />), document.body)
```
## Events
```js
<a onClick={onClick}>{props.text}</a>
```
## Magic virtual element
Use [magic-virtual-element](https://github.com/dekujs/magic-virtual-element) to enable nice classnames.
```
import element from 'magic-virtual-element'
<div style={style} class={[ 'button', '-active' ]}>
```
## Reference
```
name = 'MyComponent'
// Defaults
initialState (props) {...} // return initial state
defaultProps = { hi: 'hello' }
// Render
render ({props, state}, setState) {...}
// Lifecycle
beforeUpdate ({props, state, id}, nextProps, nextState) {}
afterRender ({props, state, id}, el) {}
afterUpdate ({props, state, id}, prevProps, prevState, setState) {}
afterMount ({props, state, id}, el, setState) {}
beforeUnmount ({props, state, id}, el) {}
```
See: <https://www.npmjs.com/package/deku>

103
deku.md
View File

@ -1,86 +1,49 @@
--- ---
title: Deku title: Deku v2
category: JavaScript libraries category: JavaScript libraries
--- ---
```js
/** @jsx element */
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 ```js
Button = { /** @jsx element */
render () { return <button>Submit</button> } import { element } from 'deku'
}
App = { function render ({ props, children, context, path }) {
render () { return <div><Button /></div> } // props = properties object
} // children = children array
// path = path to current component (like 0.1.5.2)
render(tree(<App />), document.body) // context = common properties in all components
// or with virtual-element return (
render(tree(element(App)), document.body) <div class='App' hidden={props.hidden} color={context.theme.color}>
``` {children}
</div>
## Component props/state
```js
App = {
render ({ props, state }) {
return <div>{ /*...use state.store here*/ }</div>
}
initialState (props) {
return { store: store.getState() }
},
afterMount (comp, el, setState) {
store.subscribe(() => setState({ store: store.getState() }))
} }
} }
render(tree(<App />), document.body) function onCreate ({ props, dispatch, path }) { ... }
function onUpdate ({ props, dispatch, path }) { ... }
function onRemove ({ props, dispatch, path }) { ... }
// actually { children, props, path, context }
export default { render, onCreate, onRemove }
``` ```
## Events ## Rendering
```js ```js
<a onClick={onClick}>{props.text}</a> import { createStore } from 'redux'
import { dom, element } from 'deku'
// Create a Redux store to handle all UI actions and side-effects
let store = createStore(reducer)
// Create a renderer that can turn vnodes into real DOM elements
let render = createRenderer(document.body, store.dispatch)
// Update the page and add redux state to the context
render(
<MyButton>Hello World!</MyButton>,
store.getState()
)
``` ```
## Magic virtual element
Use [magic-virtual-element](https://github.com/dekujs/magic-virtual-element) to enable nice classnames.
```
import element from 'magic-virtual-element'
<div style={style} class={[ 'button', '-active' ]}>
```
## Reference
```
name = 'MyComponent'
// Defaults
initialState (props) {...} // return initial state
defaultProps = { style: 'rout' }
// Render
render ({props, state}, setState) {...}
// Lifecycle
beforeUpdate ({props, state, id}, nextProps, nextState) {}
afterRender ({props, state, id}, el) {}
afterUpdate ({props, state, id}, prevProps, prevState, setState) {}
afterMount ({props, state, id}, el, setState) {}
beforeUnmount ({props, state, id}, el) {}
```
See: <https://www.npmjs.com/package/deku>

95
elixir.md Normal file
View File

@ -0,0 +1,95 @@
---
title: Elixir
category: Development
---
## Type checks
```elixir
is_atom/1
is_bitstring/1
is_boolean/1
is_function/1
is_function/2
is_integer/1
is_float/1
is_binary/1
is_list/1
is_map/1
is_tuple/1
is_nil/1
is_number/1
is_pid/1
is_port/1
is_reference/1
```
### Operators
```elixir
left != right # equal
left !== right # match
left ++ right # concat lists
left =~ right # regexp
```
### Numbers
```
abs(n)
rem(a, b) # remainder (modulo)
div(a, b) # integer division
round(n)
```
### Functions
```
apply(fn, args)
apply(module, fn, args)
```
### Inspecting
```elixir
inspect(arg, opts \\ [])
```
### Tuples
```elixir
elem(tuple, 1) # like tuple[1]
put_elem(tuple, index, value)
tuple_size(tuple)
```
### Maps
```elixir
put_in(data, keys, value)
Map.get(map, key)
Map.put(map, key, value)
```
### String
```elixir
String.length(str)
String.codepoints(string)
String.slice(str, 0..-1)
String.split(str, " ")
String.capitalize(str)
String.match(string, regex)
```
### Enum
```elixir
Enum.reduce(list, acc, fn)
Enum.map(list, fn)
# consider streams instead
```
There's really way too many things, just see <https://learnxinyminutes.com/docs/elixir/>.

View File

@ -20,3 +20,35 @@ function foo(x: string, y: number): string { ... }
// Arrays // Arrays
function total(numbers: Array<number>) { ... } function total(numbers: Array<number>) { ... }
``` ```
### Primitives
```
any
boolean
mixed
number
string
void
Array<T>
Class<T>
Function
Object
```
```js
var myNumbers: Array<number> = [42]
function foo(): any { return 42 }
var b: boolean = false
var b: ?boolean = false /* maybe */
var b: string | boolean = false /* maybe */
var a: Class<MyClass> = MyClass
var b: MyClass = new a()
// Function signature
var add: ((num1: number, num2: number) => number) = function(num1, num2) {
return num1 + num2;
};
```

View File

@ -5,6 +5,8 @@ title: Imagemagick
### Stuff ### Stuff
-resize 100x40 -resize 100x40
-crop 40x30+10+10 # (width)x(height)+(x)+y
-crop 40x30-10-10 # (width)x(height)+(x)+y
-flip # vertical -flip # vertical
-flop # horizontal -flop # horizontal
-transpose # flip vertical + rotate 90deg -transpose # flip vertical + rotate 90deg

75
jade.md
View File

@ -2,9 +2,82 @@
title: Jade title: Jade
--- ---
```
doctype html
// comment (html)
-// silent comment
html(lang='en')
- javascript()
h1.class#id(name='hi')
| Text. Hello there,
= name
if condition
p. hello
p.
multiline text
goes here
```
### Iteration ### Iteration
ul ```jade
ul
each user in users each user in users
li= user li= user
```
### Layouts
```jade
extends layout.jade
block title
| hello
block content
| hello
```
```jade
-// layout.jade
title
block title
body
block content
```
### Includes (partials)
```jade
include ./includes/head.jade
include:markdown article.md
```
### Mixins
```jade
mixin list
ul ..
+list
```
```jade
mixin pet(name)
span.pet= name
+pet('cat')
```
```jade
mixin article(title)
article
h2.title= title
block
+article('hello there')
p Content goes here
```

View File

@ -11,7 +11,6 @@ const cli = require('meow')(`
-h, --help show usage information -h, --help show usage information
-v, --version print version info and exit -v, --version print version info and exit
`, { `, {
alias: {
alias: { h: 'help', v: 'version', x: 'excludeTag' }, alias: { h: 'help', v: 'version', x: 'excludeTag' },
string: ['lang'], string: ['lang'],
boolean: ['pager'], boolean: ['pager'],

11
sass.md
View File

@ -36,6 +36,13 @@ category: CSS
http://sass-lang.com/documentation/Sass/Script/Functions.html http://sass-lang.com/documentation/Sass/Script/Functions.html
### Functions
unquote('hello')
quote(hello)
unit(3em) => 'em'
unitless(100px) => false
### Loops ### Loops
$i: 6; $i: 6;
@ -56,3 +63,7 @@ http://sass-lang.com/documentation/Sass/Script/Functions.html
length($list) length($list)
@each $item in $list { ... } @each $item in $list { ... }
## Reference
- <http://sass-lang.com/documentation/Sass/Script/Functions.html>

42
tape.md Normal file
View File

@ -0,0 +1,42 @@
---
title: Tape
category: JavaScript libraries
---
```js
test('things', (t) => {
t.plan(1)
t.equal('actual', 'expected')
t.equal('actual', 'expected', 'should be equal') // messages are optional
t.end(err)
t.fail('msg')
t.pass('msg')
t.timeoutAfter(2000)
t.skip('msg')
t.ok(value, 'is truthy')
t.notOk(value, 'is falsy')
t.error(err, 'is falsy (print err.message)')
t.equal(actual, expected, 'is equal')
t.notEqual
t.deepEqual(actual, expected, 'is equal (use node's deepEqual)')
t.notDeepEqual
t.looseEqual(actual, expected, 'is equal (use node's deepEqual with ==)')
t.notLooseEqual
t.throws(fn, /FooError/)
t.throws(fn, FooError /* class */)
t.doesNotThrow
t.comment('message')
})
```
```js
test.only((t) => { ... })
```