From 7d9f263daa194b8c5fac16304325483c289e7565 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Wed, 29 May 2013 20:19:07 +0800 Subject: [PATCH] Yeaaahh. --- cron.md | 26 +++++++++++ curl.md | 4 +- express.md | 69 ++++++++++++++++++++++++++++ ios.md | 6 ++- makefile.md | 3 ++ node-package.md | 58 ++++++++++++++++++++++++ nodejs.md | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ postgresql.md | 8 ++++ rails-models.md | 2 +- rails-tricks.md | 6 +++ sequelize.md | 60 ++++++++++++++++++++++++ sinon.md | 49 ++++++++++++++++++++ travis.md | 53 ++++++++++++++++++++++ vim.md | 4 ++ 14 files changed, 462 insertions(+), 4 deletions(-) create mode 100644 cron.md create mode 100644 express.md create mode 100644 node-package.md create mode 100644 nodejs.md create mode 100644 rails-tricks.md create mode 100644 sequelize.md create mode 100644 sinon.md create mode 100644 travis.md diff --git a/cron.md b/cron.md new file mode 100644 index 000000000..86bdaa1b0 --- /dev/null +++ b/cron.md @@ -0,0 +1,26 @@ +title: Cron +---- + +### Format + + * Min Hour Day Month Weekday + + +### Format + + * * * * * command to be executed + ┬ ┬ ┬ ┬ ┬ + │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ └───── day of week (0 - 6) (0 or 6 are Sunday to Saturday, or use names) + │ │ │ └────────── month (1 - 12) + │ │ └─────────────── day of month (1 - 31) + │ └──────────────────── hour (0 - 23) + └───────────────────────── min (0 - 59) + +### Examples + + 0 * * * * every hour + */15 * * * * every 15 mins + 0 */2 * * * every 2 hours + 0 0 0 * 0 every sunday midnight diff --git a/curl.md b/curl.md index 6fdd2f1d8..88e80da05 100644 --- a/curl.md +++ b/curl.md @@ -11,12 +11,14 @@ Options: Data options: - -d # --data: HTTP post data + -d # --data: HTTP post data, URL encoded (eg, status="Hello") -G # --get: send -d data via get Headers: -A # --user-agent + -b name=val # --cookie + -b FILE # --cookie SSL: diff --git a/express.md b/express.md new file mode 100644 index 000000000..75f7819a8 --- /dev/null +++ b/express.md @@ -0,0 +1,69 @@ +title: Express.js +--- + +### Settings + + app.set('x', 'yyy') + app.get('x') //=> 'yyy' + + app.enable('trust proxy') + app.disable('trust proxy') + + app.enabled('trust proxy') //=> true + +### Env + + app.get('env') + +### Config + + app.configure('production', function() { + app.set... + }); + +### Wares + + app.use(express.static(__dirname + '/public')); + app.use(express.logger()); + +### Helpers + + app.locals({ + title: "MyApp", + }); + +### Request + + req.params + + // GET /user/tj + req.params.name //=> "tj" + + req.params[0] + + // GET /search?q=tobi+ferret + req.query.q // => "tobi ferret" + + req.cookies + + req.accepted + [ { value: 'application/json', quality: 1, type: 'application', subtype: 'json' }, + { value: 'text/html', quality: 0.5, type: 'text',subtype: 'html' } ] + + req.is('html') + req.is('text/html') + + req.path + req.xhr + +## Response + + res.redirect('/') + res.redirect(301, '/') + + res.set('Content-Type', 'text/html') + + res.send('hi') + res.send(200, 'hi') + + res.json({ a: 2 }) diff --git a/ios.md b/ios.md index f06fbf6d4..1e59fb5e6 100644 --- a/ios.md +++ b/ios.md @@ -2,9 +2,11 @@ Multiple Exchange accounts: scp root@iphone.local:/private/var/mobile/Library/Preferences/com.apple.accountsettings.plist . -Winterboard themes: +Paths: - /Library/Themes + /Library/Themes # Winterboard themes + /User/Media/DCIM/100APPLE # Photos + /User/Media/Recordings # Voice recordings Copy photos: diff --git a/makefile.md b/makefile.md index d3a041e5c..d6e2d2c72 100644 --- a/makefile.md +++ b/makefile.md @@ -27,9 +27,12 @@ ### Find files FILES = $(shell find images -name "*") + FILES = $(shell find test/*.js) $(patsubst images/%, assets/%, $(shell find images -name "*")) + + ### Substitutions # Same diff --git a/node-package.md b/node-package.md new file mode 100644 index 000000000..afb83fdef --- /dev/null +++ b/node-package.md @@ -0,0 +1,58 @@ +title: Package JSON +--- + +### Basic + + { + "name": "expo", + "description": "", + "keywords": [""], + "author": "Rico Sta. Cruz ", + "version": "0.1.0", + "engines": {"node": ">=0.8.0"}, + } + +### Dependencies + + "dependencies": { + "colors" : "*", + "flatiron" : "0.1.x", + "flatiron" : "~0.1.0", + "plates" : "https://github.com/:user/:project/tarball/:branch", + "stuff": "git://github.com/user/project.git#commit-ish" + }, + "devDependencies": { ... }, + +### Scripts + + "scripts": { + "start": "node ./bin/xxx", /* npm start */ + "test": "vows --spec --isolate", /* npm test */ + } + +### Git + + "repository": { + "type": "git", + "url": "https://github.com/nodejitsu/http-server.git" + }, + +### Main entry point + + "main": "index", + "main": "./lib/http-server", + +### Bin + + "bin": { + "command": "./bin/command" + }, + +### Misc + + "private": true, + "preferGlobal": true, + "license": "MIT" + + +http://package.json.nodejitsu.com/ diff --git a/nodejs.md b/nodejs.md new file mode 100644 index 000000000..b53614147 --- /dev/null +++ b/nodejs.md @@ -0,0 +1,118 @@ +title: NodeJS api +---- + +## Globals + + __filename + __dirname + +## [fs] + +### Reading + + fs.readFile('file.txt', function(err, data) { .. }); + fs.readFile('file.txt', {encoding: 'utf-8'}, function(err, data) { .. }); + +### Writing + + fs.writeFile('output.txt', function(err) { .. }); + fs.appendFile('output.txt', function(err) { .. }); + +### Watch + + fs.watch('dir OR file.txt', { persistent: true }, function(event, file) { + event; /* rename | change */ + }); + +### Getting info + + fs.exists('file.txt', function(exists /*bool*/) { ... }); + + fs.stat('file.txt', function(stats) { + stats.isFile(); + stats.isDirectory(); + stats.isSymbolicLink(); + }); + +### File operations + + fs.rename('old.txt', 'new.txt', function(){}); + fs.chown('file.txt', uid, gid, function(){}); + fs.symlink('src', 'dest', function(){}); + fs.unlink('path', function(){}); + fs.rmdir('path', function(){}); + + fs.readdir('path', function(err, files) { .. }); /* `files` = array of names */ + +### Path + + fs.realpath('/etc/passwd', function(err, path) { /* "/private/etc/passwd" */ }); + +### Sync + + data = fs.readFileSync('input.txt'); + fs.writeFileSync('output.txt', data); + fs.appendFileSync('output.txt', data); + fs.existsSync('file.txt'); + +## [process] + +### Streams + + process.stdin.resume(); /* paused by default */ + process.stdin.setEncoding('utf8'); + + process.stdin.on('data', function(chunk) { ... }); + process.stdin.on('end', function() { ... }); + + process.stdout.write('...'); + process.stderr.write('...'); + +### stuff + + process.argv; //=> ['node', 'file.js', 'one', 'two'] + process.env; //=> {TERM: 'screen-256color', SHELL: '/bin/bash', ...} + + process.exit(); + process.exit(1); + +### Directories + + process.cwd(); //=> "/tmp" + process.chdir('dir'); + +## [path] + + fs.realpath('/etc/passwd', function(err, path) { /* "/private/etc/passwd" */ }); + + dir = path.join('etc', 'passwd'); + dir = path.resolve('/etc', 'passwd', '..', 'var'); + + path.dirname('/etc/passwd') //=> "/etc" + path.basename('/etc/passwd') //=> "passwd" + path.basename('/etc/rc.d', '.d') //=> "rc" + +### exec + + var exec = require('child_process').exec, + + var child = exec('cat *.js bad_file | wc -l', + function (error, stdout, stderr) { + console.log('stdout: ' + stdout); + console.log('stderr: ' + stderr); + if (error !== null) { + console.log('exec error: ' + error); + } + }); + +[all]: http://nodejs.org/api/all.html +[process]: http://nodejs.org/api/process.html +[fs]: http://nodejs.org/api/fs.html + +## Snippets + + info = require('../package.json') + info.version + + + process.stdout.write(util.inspect(objekt, false, Infinity, true) + '\n'); diff --git a/postgresql.md b/postgresql.md index 564b599cc..72ec4ac0c 100644 --- a/postgresql.md +++ b/postgresql.md @@ -1,5 +1,13 @@ +### Console + + $ psql + +### Commands * Show tables: `\dt` * Show databases: `\l` * Show columns of a table: `\d table` or `\d+ table` +### Creating database + + $ createdb databasename diff --git a/rails-models.md b/rails-models.md index 2191c2717..193bdf4f1 100644 --- a/rails-models.md +++ b/rails-models.md @@ -224,7 +224,7 @@ API ### Sorting posts.order(:title) - posts.order(:title).reverse + posts.order("title DESC") ### Mass updates diff --git a/rails-tricks.md b/rails-tricks.md new file mode 100644 index 000000000..8ccfaf058 --- /dev/null +++ b/rails-tricks.md @@ -0,0 +1,6 @@ + +in config/environments/development.rb: + + # Source maps for Sass + config.sass.debug_info = true + config.sass.line_comments = false diff --git a/sequelize.md b/sequelize.md new file mode 100644 index 000000000..78b51ff0e --- /dev/null +++ b/sequelize.md @@ -0,0 +1,60 @@ +title: Sequelize +--- + +### API + + sequelize.sync().done -> ... + +### Models + + Project = sequelize.define('Project', { + title: Sequelize.STRING, + description: Sequelize.TEXT, + myDate: { type: Sequelize.DATE, defaultValue: Sequelize.NOW }, + title: { type: Sequelize.STRING, allowNull: false }, + id: { type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true }, + }, { + classMethods: { ... }, + instanceMethods: { ... } + }); + + Project.hasMany(Task) + +### Finders + + Project.find(123).success (project) -> + + Project.find({ where: {title: 'Hello'} }) + Project.find({ where: {id: [1,3,4]} }) + Project.find({ where: ["id > ?", 25] }) + + Project.find( + where: {title: 'a'} + attributes: ['id', ['name', 'title']] + ) + + .findOrCreate(...) + + .findAll + .findAll({ where: ... }) + .findAll({ order: 'title DESC' }) + .findAll({ limit: 10 }) + .findAll({ offset: 10, limit: 2 }) + + .count() + + +### Build + + item = Project.build({ ... }) + + item.title = '...' + + item.save().success (item) -> + + item.updateAttributes({ title: '...' }) + + item.destroy().success -> + + item.values + diff --git a/sinon.md b/sinon.md new file mode 100644 index 000000000..6c9bcf08a --- /dev/null +++ b/sinon.md @@ -0,0 +1,49 @@ +title: Sinon +--- + +### Spy + + var fn = sinon.spy(); + fn(); + fn.calledOnce == true + fn.calledCount == 1 + +### Spy something + + sinon.spy($, 'ajax') + +### Stub + + var fn = sinon.stub().returns(42); + fn() == 42 + + fn.withArgs(42).returns(1); + fn.withArgs(43).throws("TypeError"); + stub.returnsArg(0); // Return 1st argument + stub.callsArg(0); + +### Stub something + + sinon.stub($, 'ajax'); + $.ajax.calledWithMatch({ url: '/x' }); + $.ajax.restore(); + + sinon.stub($, 'ajax', function() { return 'x' }); + +### Fake server + + server = sinon.fakeServer.create(); + + $.get('/file.json', ...); + server.requests[0].respond( + 200, + { "Content-Type": "application/json" }, + JSON.stringify([{ id: 1, text: "Provide examples", done: true }]) + ); + + server.restore(); + +### Fake XHR + + xhr = sinon.useFakeXMLHttpRequest(); + xhr.restore(); diff --git a/travis.md b/travis.md new file mode 100644 index 000000000..8c1dc7fa7 --- /dev/null +++ b/travis.md @@ -0,0 +1,53 @@ +title: Travis (.travis.yml) +--- + +### Node + + language: node_js + node_js: + - "0.10" + + * Provides: 0.10, 0.8, 0.6, 0.11 (latest dev) + * Defaults install to `npm install` + * Defaults test to `npm test` + +### Ruby + + language: ruby + rvm: + - 1.9.3 + - 1.8.7 + - rbx-19mode + - jruby-19mode + - jruby-18mode + + * * Defaults install to `bundle install` + * Defaults test to `rake` + +### Branches + + branches: + except: [".."] + only: ["master"] + +### Environment vars + + env: + - "rack=master" + - "rack=1.3.4" + +### Custom config + + script: make test + before_script: make pretest + after_script: make clean + + before_script: + - make pretest1 + - make pretest2 + +### 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/ diff --git a/vim.md b/vim.md index c40ce5168..986efe1cc 100644 --- a/vim.md +++ b/vim.md @@ -85,3 +85,7 @@ Marks `. # Last change `` # Last jump +Calculator +---------- + +(Insert mode) =128/2