Skip to content

Instantly share code, notes, and snippets.

@geastwood
geastwood / make.md
Last active August 29, 2015 14:03
make
  • make with no argument will run the first rule
  • run multiple tasks by spacing the task names
  • for a detailed example check nodeunit Makefile
@geastwood
geastwood / parsing.md
Last active August 29, 2015 14:03
Rendering Engine

Overview

Parsing a document means translating it to a structure the code can use. The result of parsing is usually a tree of nodes that represent the structure of the document. This is called a parse tree or a syntax tree.

Grammars

Parsing is based on the syntax rules the document obeys: the language or format it was written in. Every format you can parse must have deterministic grammar consisting of vocabulary and syntax rules.

Parser–Lexer combination

Parsing can be separated into two sub processes: lexical analysis and syntax analysis.

Lexical analysis is the process of breaking the input into tokens

Tokens are the language vacabulary: the collection of valid building blocks.

@geastwood
geastwood / useStrictMode.md
Last active August 29, 2015 14:03
strict mode
  • this will not refer to window object
  • callee, caller of arguments object are not allowed under strict mode
  • under strict mode parameter is not refereced linked to arguments object, no strict mode, parameter is a reference of the arguments object.
(function() {
    var nostrict = function(x) {
        arguments[0] = 'modified';
        console.log('arguments[0] =', arguments[0]);
        console.log('x=', arguments[0]);
 console.log('under non-strict mode,', x === arguments[0]); // log true
@geastwood
geastwood / named_function.js
Created June 26, 2014 07:17
named function
var constructor = function() {return null;};
var f = function f() {
return constructor();
};
f();
// Under ES3
// logs {}, object literal
// Under ES5

Generate take-away

Concept 1: Iterators

In computer programming, an iterator is an object that enables a programmer to traverse a container.

When invoked, generator functions return iterators

Concept 2: Run-to-completion

Run-to-completion scheduling is a scheduling model in which each task runs until it either finishes, or explicitly yields control back to the scheduler.

/*
* Mongoose magic
*/
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/fei');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function() {
var kittySchema = mongoose.Schema({
name: String
define(function() {
var ScriptLoader = function(url, ns, onLoadCallback, name) {
this.url = url; // url of the module
this.ns = ns; // source obj/ns obj to bind 'define' method
this.onLoadCallback = onLoadCallback;
this.name = name; // dependency name
this.load();
};

Apache

server

/etc/init.d/apache2 start/stop/restart

folder structure

/etc/apache2/ // main folder
# Apache
```
/etc/init.d/apache2 start/stop/restart
```
@geastwood
geastwood / vim_cheat_sheet.md
Last active December 23, 2016 18:56
vim, cheatsheet

Vim CHEAT SHEET

Folding

Keystrokes Description
zc Close a fold
zo Open a fold
za Toggle a fold
zR Open all folds