Skip to content

Instantly share code, notes, and snippets.

View gerardpaapu's full-sized avatar
🏠
Working from home

Gerard Paapu gerardpaapu

🏠
Working from home
View GitHub Profile
class Doctor extends PlayerRole
teamName: 'Doctor'
advice:
'unless:hunt': ->
# if the doctor chooses the same player
# as the wolves choose to hunt
# prevent the hunt method
@choosePlayer() is @chooseInnocent()
var Advice = function (type, advice) {
this.type = type;
this.advice = advice;
};
Advice.adviseMethod = function (method, advice, combine) {
if (typeof combine != 'function') { // TODO: don't use typeof
combine = Advice.Types[combine] || Advice.Types.none;
}
@gerardpaapu
gerardpaapu / OrderedSet.js
Created April 21, 2012 04:42
First output from the chitchat compiler (after the new grammar overhaul)
// Chitchat Source
// -----------------
//
// ;;; OrderedSet
// ;;; ----------
// ;;;
// ;;; A Collection class that wraps an Array.
// ;;; It maintains immutability, an order, and
// ;;; does not contain duplicates
// ;;;
{Primitive} = require './primitive.coffee'
{Symbol} = require './symbol.coffee'
define = new Primitive (stx, env, evaluate) ->
[place, expr] = stx
throw new SyntaxError() unless place instanceof Symbol
throw new Error("#{place.value} already defined") if env.contains(place.value)
env.set place.value, evaluate(expr, env)
;;; OrderedSet
;;; ----------
;;;
;;; A Collection class that wraps an Array.
;;; It maintains immutability, an order, and
;;; does not contain duplicates
;;;
;;; Items of the Ordered Set should implement 'Ord'
(class OrderedSet
(constructor (items, ordered, distinct)
###
A Parser from A to B is a function that takes A and returns
a Parsing Result where the 'value' is a Tree of B and the 'rest'
is a B
e.g. a Parser<String, Syntax> will consume a string and return a Parsing
Result that contains a Tree of Syntax and a String of the Remainder to
Parse.
// with let
for (let i = 0; i < children.length; ++i) {
let (child = children[i])
setTimeout(function(){ doSomethingTo(child) }, 1000)
}
@gerardpaapu
gerardpaapu / ihfhMqfN.html
Created May 16, 2012 04:52 — forked from anonymous/ihfhMqfN
a guest on May 15th, 2012 - this.x in setValues is a number. In update it's NaN
<!DOCTYPE html>
<html>
<head>
<title> test </title>
</head>
<body>
<canvas id="myCanvas" width="512" height="512" style="border:1px solid #c3c3c3;">Your browser is bad and you should feel bad (no canvas support)</canvas>
function initParticles () {
for (var i = 0; i < 10; i++) {
particles.push(new particle());
particles[i].setValues(
Math.random() * 50, // x
Math.random() * 50, // u
Math.random() * 10, // vx
Math.random() * 10, // vy
1, // radius
"#0000FF", // color
@gerardpaapu
gerardpaapu / nuevo.js
Created May 16, 2012 05:53
'new' keyword and Object.create
// nuevo(Klass, [arg, ...]) is roughly the same as
// new Klass(arg, ...)
//
// This should (hopefully) illustrate the relationship between
// Object.create and 'new'
//
// new Constructor ties together
// - creating an instance of the prototype
// - initializing it
// - possibly returning a totally different value