Skip to content

Instantly share code, notes, and snippets.

Apache

server

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

folder structure

/etc/apache2/ // main folder
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();
};
/*
* 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

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.

@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
@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 / 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 / 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 / vm_git_repo
Last active August 29, 2015 14:04
vm git repo
bare clone
create a folder with name new_bare_clone.git
cd new_bare_clone.git
git init --bare
To push to this branch
git remote add origin "ssh://[email protected]/~/repos/to/folder"
From a local to push up
@geastwood
geastwood / chunkwmrc
Last active March 15, 2019 16:38
chunkwm+khd
#!/bin/bash
#
# NOTE: specify the desired level of logging.
#
# - none, debug, warn, error
#
chunkc core::log_level error