diff --git a/animated_gif.md b/animated_gif.md new file mode 100644 index 000000000..f9d5d8977 --- /dev/null +++ b/animated_gif.md @@ -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 diff --git a/bookshelf.md b/bookshelf.md new file mode 100644 index 000000000..d95a75a14 --- /dev/null +++ b/bookshelf.md @@ -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/ diff --git a/brunch.md b/brunch.md new file mode 100644 index 000000000..1d69b0988 --- /dev/null +++ b/brunch.md @@ -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 diff --git a/chunky_png.md b/chunky_png.md new file mode 100644 index 000000000..ad1c0c0e2 --- /dev/null +++ b/chunky_png.md @@ -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 diff --git a/command_line.md b/command_line.md index ec8102797..e83aaf871 100644 --- a/command_line.md +++ b/command_line.md @@ -35,49 +35,6 @@ Sorting: -h Human-readable size (3k) -## Find (find) - -Usage: - - find - -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 Usage: diff --git a/express.md b/express.md index 75f7819a8..103be2c50 100644 --- a/express.md +++ b/express.md @@ -34,12 +34,15 @@ title: Express.js ### Request - req.params // GET /user/tj - req.params.name //=> "tj" - - req.params[0] + req.path //=> "/user/tj" + req.url //=> "/user/tj" + req.xhr //=> true|false + req.method //=> "GET" + req.params + req.params.name //=> "tj" + req.params[0] // GET /search?q=tobi+ferret req.query.q // => "tobi ferret" @@ -53,8 +56,6 @@ title: Express.js req.is('html') req.is('text/html') - req.path - req.xhr ## Response diff --git a/find.md b/find.md new file mode 100644 index 000000000..9c7a57ed2 --- /dev/null +++ b/find.md @@ -0,0 +1,43 @@ +# Find + +Usage: + + find + +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" + diff --git a/heroku.md b/heroku.md index 7d061421c..88975a190 100644 --- a/heroku.md +++ b/heroku.md @@ -12,6 +12,12 @@ # Transfer to another owner 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 # Start a database diff --git a/makefile.md b/makefile.md index d6e2d2c72..738691bc8 100644 --- a/makefile.md +++ b/makefile.md @@ -19,10 +19,25 @@ $< -- Prerequisite (first) $* -- 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 - gitdir ?= $(shell git --exec-path) - gitver ?= $(word 3,$(shell git --version)) + gitdir ?= $(shell git --exec-path) + gitver ?= $(word 3,$(shell git --version)) ### Find files @@ -31,13 +46,11 @@ $(patsubst images/%, assets/%, $(shell find images -name "*")) - - ### Substitutions # Same - $(SOURCE:.cpp=.o) - $(patsubst %.cpp, %.c, $(SOURCES)) + $(SOURCE:.cpp=.o) + $(patsubst %.cpp, %.c, $(SOURCES)) $(strip $(string_var)) @@ -53,15 +66,9 @@ ### Building files - %.o: %.c - ffmpeg -i $< > $@ # Input and output - foo $^ - -### Default task - - default: - @echo "hello." - @false + %.o: %.c + ffmpeg -i $< > $@ # Input and output + foo $^ ### Inclusion diff --git a/npm-package.md b/npm-package.md index 3c5e5d71d..8a856c6b8 100644 --- a/npm-package.md +++ b/npm-package.md @@ -58,5 +58,4 @@ title: Package JSON "preferGlobal": true, "license": "MIT" - [Reference](http://package.json.nodejitsu.com/) (Nodejitsu.com) diff --git a/psdrb.md b/psdrb.md new file mode 100644 index 000000000..0ca60b617 --- /dev/null +++ b/psdrb.md @@ -0,0 +1,77 @@ +# PSD.rb + +### Opening + + psd = PSD.new(file, parse_layer_images: true) + psd.parse! + +### Traversing + + # Gets the root node. + # A # 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 diff --git a/qjs.md b/qjs.md index 18d8fa878..2c467100a 100644 --- a/qjs.md +++ b/qjs.md @@ -3,12 +3,29 @@ title: Q.js ### Creating promises (Q.promise) - Q.promise (resolve, reject) -> + Q.promise (ok, fail) => asyncFunction -> if error - reject new Error("Failure") + fail new Error("Failure") 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 @@ -50,3 +67,7 @@ title: Q.js .catch (e) -> console.error "Oh well", e + +### Reference + + * https://github.com/kriskowal/q/wiki/API-Reference