This commit is contained in:
Rico Sta. Cruz 2013-09-17 18:06:00 +08:00
parent 07b7550718
commit b67f66f0cd
12 changed files with 327 additions and 68 deletions

11
animated_gif.md Normal file
View File

@ -0,0 +1,11 @@
Convert mp4 to gif:
mkdir -p gif
mplayer -ao null -vo gif89a:outdir=gif $mp4
mogrify -format gif *.png
gifsicle --colors=256 --delay=4 --loopcount=0 --dither -O3 gif/*.gif > ${mp4%.*}.gif
rm -rf gif
Or a given range (-ss -endpos):
mplayer -ao null -ss 0:02:06 -endpos 0:05:00 -vo gif89a:outdir=gif videofile.mp4

56
bookshelf.md Normal file
View File

@ -0,0 +1,56 @@
# Bookshelf.js
Model
-----
class Book extends Bookshelf.Model
tableName: 'books'
### Associations
class Book extends Bookshelf.Model
# Associations
author: -> @belongsTo(Author)
summary: -> @hasOne(Summary)
pages: -> @hasMany(Pages)
shelves: -> @belongsToMany(Shelves)
@hasMany(Comment)
.through(Chapter)
@belongsToMany(Comment)
.withPivot(['created_at'])
### Collections
class Books extends Bookshelf.Collection
model: Book
books = new Books()
books.query(where: { id: 2 })
.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/

57
brunch.md Normal file
View File

@ -0,0 +1,57 @@
## Paths
/
app/
assets/
vendor/
public/
config.coffee
## Config
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\//, ''
# brunch b --apply production
overrides:
production:
optimize: true
sourceMaps: false
plugins: autoReload: enabled: false
## Plugins
plugins:
uglify:
mangle: true
compress:
global_defs:
DEBUG: false
## Stuff
* uglify-js-brunch
* stylus-brunch
* coffee-script-brunch
## References
* https://github.com/brunch/brunch/blob/master/docs/config.md

24
chunky_png.md Normal file
View File

@ -0,0 +1,24 @@
Loading
image = ChunkyPNG::Image.from_file('filename.png')
image = ChunkyPNG::Image.from_blob(File.read('file.png'))
image = ChunkyPNG::Image.from_io(io)
Saving
image.save('filename.png')
File.open('newfile.png', 'wb') { |io| image.write(io) }
binary_string = image.to_blob
Drawing
image[0, 0] = ChunkyPNG::Color.rgba(255, 0,0, 128)
image.line(1, 1, 10, 1, ChunkyPNG::Color.from_hex('#aa007f'))
Canvas
crop(x, y, w, h)
Transforms
new_image = image.flip_horizontally.rotate_right

View File

@ -35,49 +35,6 @@ Sorting:
-h Human-readable size (3k) -h Human-readable size (3k)
## Find (find)
Usage:
find <path> <conditions> <actions>
Conditions:
-name "*.c"
-user jonathan
-nouser
-type f # File
-type d # Directory
-type l # Symlink
-depth 2 # At least 3 levels deep
-regex PATTERN
-newer file.txt
-newerm file.txt # modified newer than file.txt
-newerX file.txt # [c]hange, [m]odified, [B]create
-newerXt "1 hour ago" # [t]imestamp
Condition flow:
\! -name "*.c"
\( x -or y \)
Actions:
-exec rm {} \;
-print
-delete
Examples:
find . -name '*.jpg'
find . -name '*.jpg' -exec rm {} \;
find . -newerBt "24 hours ago"
## Tail ## Tail
Usage: Usage:

View File

@ -34,12 +34,15 @@ title: Express.js
### Request ### Request
req.params
// GET /user/tj // GET /user/tj
req.params.name //=> "tj" req.path //=> "/user/tj"
req.url //=> "/user/tj"
req.params[0] req.xhr //=> true|false
req.method //=> "GET"
req.params
req.params.name //=> "tj"
req.params[0]
// GET /search?q=tobi+ferret // GET /search?q=tobi+ferret
req.query.q // => "tobi ferret" req.query.q // => "tobi ferret"
@ -53,8 +56,6 @@ title: Express.js
req.is('html') req.is('html')
req.is('text/html') req.is('text/html')
req.path
req.xhr
## Response ## Response

43
find.md Normal file
View File

@ -0,0 +1,43 @@
# Find
Usage:
find <path> <conditions> <actions>
Conditions:
-name "*.c"
-user jonathan
-nouser
-type f # File
-type d # Directory
-type l # Symlink
-depth 2 # At least 3 levels deep
-regex PATTERN
-newer file.txt
-newerm file.txt # modified newer than file.txt
-newerX file.txt # [c]hange, [m]odified, [B]create
-newerXt "1 hour ago" # [t]imestamp
Condition flow:
\! -name "*.c"
\( x -or y \)
Actions:
-exec rm {} \;
-print
-delete
Examples:
find . -name '*.jpg'
find . -name '*.jpg' -exec rm {} \;
find . -newerBt "24 hours ago"

View File

@ -12,6 +12,12 @@
# Transfer to another owner # Transfer to another owner
heroku sharing:transfer new@owner.com heroku sharing:transfer new@owner.com
## `logs` - Show logs
heroku logs
heroku logs -t # --tail (stream)
heroku logs -s app # --source (only on app logs)
## `pg` - Postgresql ## `pg` - Postgresql
# Start a database # Start a database

View File

@ -19,10 +19,25 @@
$< -- Prerequisite (first) $< -- Prerequisite (first)
$* -- Basename without extension of the target (?) $* -- Basename without extension of the target (?)
### Command prefixes
- Ignore errors
@ Don't print command
+ Run even if Make is in 'don't execute' mode
Examples:
build:
@echo "Building"
-gcc $< $@
@echo "Construction complete"
-include .depend
### Cool stuff ### Cool stuff
gitdir ?= $(shell git --exec-path) gitdir ?= $(shell git --exec-path)
gitver ?= $(word 3,$(shell git --version)) gitver ?= $(word 3,$(shell git --version))
### Find files ### Find files
@ -31,13 +46,11 @@
$(patsubst images/%, assets/%, $(shell find images -name "*")) $(patsubst images/%, assets/%, $(shell find images -name "*"))
### Substitutions ### Substitutions
# Same # Same
$(SOURCE:.cpp=.o) $(SOURCE:.cpp=.o)
$(patsubst %.cpp, %.c, $(SOURCES)) $(patsubst %.cpp, %.c, $(SOURCES))
$(strip $(string_var)) $(strip $(string_var))
@ -53,15 +66,9 @@
### Building files ### Building files
%.o: %.c %.o: %.c
ffmpeg -i $< > $@ # Input and output ffmpeg -i $< > $@ # Input and output
foo $^ foo $^
### Default task
default:
@echo "hello."
@false
### Inclusion ### Inclusion

View File

@ -58,5 +58,4 @@ title: Package JSON
"preferGlobal": true, "preferGlobal": true,
"license": "MIT" "license": "MIT"
[Reference](http://package.json.nodejitsu.com/) (Nodejitsu.com) [Reference](http://package.json.nodejitsu.com/) (Nodejitsu.com)

77
psdrb.md Normal file
View File

@ -0,0 +1,77 @@
# PSD.rb
### Opening
psd = PSD.new(file, parse_layer_images: true)
psd.parse!
### Traversing
# Gets the root node.
# A #<Node> can be a Group or a Layer.
node = psd.tree
node.root
node.descendants
node.ancestors
node.siblings
node.subtree
node.descendant_groups
node.descendant_layers
### Layer info
node.name #=> "Layer 2"
node.top #=> 3
node.left #=> 3
node.bottom
node.right
# Note: these are interchanged (?)
node.width
node.height
node.visible?
node.hidden?
node.layer?
node.group?
node.blending_mode #=> "normal"
node.opacity #=> 0..255
node.fill_opacity #=> 0..255
### Layer text
node.text #=> (Hash)
node.text[:value] #=> "Text here"
node.text[:font][:name] #=> "Arial"
node.text[:font][:sizes] #=> [6.9]
node.text[:font][:colors] #=> [[255,255,255,255]]
node.text[:font][:css] #=> "font-family: ...;"
node.text[:left] #=> 3
node.text[:top]
node.text[:right]
node.text[:bottom]
node.text[:transform] #=> (Hash)
### Layer effects
fx = node.info[:object_effects]
fx.data['Scl '] # ?
fx.data['GrFl'] # Gradient fill
### Layer mask
node.mask["mask_size"] == 0 # No mask
node.mask["mask_size"] == 20 # Has mask
node.mask["top"]
node.mask["left"]
node.mask["bottom"]
node.mask["right"]
### Reference
* https://github.com/layervault/psd.rb

27
qjs.md
View File

@ -3,12 +3,29 @@ title: Q.js
### Creating promises (Q.promise) ### Creating promises (Q.promise)
Q.promise (resolve, reject) -> Q.promise (ok, fail) =>
asyncFunction -> asyncFunction ->
if error if error
reject new Error("Failure") fail new Error("Failure")
else else
resolve deferred ok(data)
### For arrays
promises = [saveDisk(), saveCloud()]
# When all succeeds, or *at least one* error
Q.all(promises).done ->
alert "Saved"
# Same, but get the values
Q.all(promises).spread (a, b) ->
alert "Result A:" + a
alert "Result B:" + b
# When all either succeeds or errors
Q.allSettled(promises).done -> ...
### Creating promises from Node ### Creating promises from Node
@ -50,3 +67,7 @@ title: Q.js
.catch (e) -> .catch (e) ->
console.error "Oh well", e console.error "Oh well", e
### Reference
* https://github.com/kriskowal/q/wiki/API-Reference