Skip to content

Instantly share code, notes, and snippets.

@nw
nw / ttt.php
Created September 10, 2015 02:33
<?php
$players = ["X", "O"];
$current_player_idx = getPlayerIdx();
$player = $players[$current_player_idx];
$next_player_idx = getNextPlayerIdx($current_player_idx);
$board = [
[null, null, null],
// Usage: node getStats.js yarnpkg/yarn '2016-10-11T14:50:00.000Z' username password
// Note: install `async` and `github` packages
var async = require('async')
, GitHubApi = require("github");
var github = new GitHubApi({
// required
version: "3.0.0",
protocol: "https",

Syntax

for ([initialization]; [condition]; [final-expression]) {
  statement
}

initialization

new Todo('todo');
function Todo(id){
this.items = [];
this.el = $(id);
<?php
class Singleton
{
/**
* @var Singleton The reference to *Singleton* instance of this class
*/
private static $instance;
/**
* Returns the *Singleton* instance of this class.
@nw
nw / superhack.js
Created November 23, 2010 02:22 — forked from creationix/superhack.js
// Add a handy super call for all objects
MyBaseClass.prototype.super = function () {
var parent = this.__proto__.__proto__;
var caller = arguments.callee.caller;
var fn;
if (caller.prototype === this.__proto__) {
return parent.constructor.apply(this, arguments);
} else {
// This is probably quite slow, but it doesn't seem to affect
// performance too much in real tests.
var assert = require('assert')
, subclass = function(type, proto){
// make sure we are extending a global constructor
// accepted: [Boolean, Number, String, Array, Object, Function, RegExp, Date]
if(!global[type.name] || global[type.name].name != type.name) throw new Error();
var constructor = proto.constructor,
keys = Object.keys(proto),
Obj = process.binding('evals').Script.runInNewContext('x = '+type.name), // eval ftw
@nw
nw / atm.php
Created September 9, 2015 02:43
<?php
/**
* Created by PhpStorm.
* User: nw
* Date: 9/8/15
* Time: 8:33 PM
*/
function ATM($withdraw, $balance)
{
$transaction_fee = 0.50;
result = {'array':[1,2,3],
'string':'hello',
'hash':{'a':1, 'b':2},
'date':new Date(), // Stores only milisecond resolution
'int':42,
'float':33.3333,
'regexp':/foobar/i,
'boolean':true,
'null':null};
Model.define('User',{
collection : 'test_user', // (optional) if not present uses the model name instead.
// defines your data structure
types: {
_id : Object, // if not defined, Mongoose automatically defines for you.
username: String,
first : String,
last : String,