Skip to content

Instantly share code, notes, and snippets.

@joseanpg
joseanpg / declarative style evaluation.js
Created September 22, 2011 20:29 — forked from bga/declarative style evaluation.js
declarative style evaluation.js
/*
http://twitter.com/#!/bga_/status/116861871423885312
*/
Object.prototype.thunk = function(name, calc) {
Object.defineProperty(this,name,{get: function() {
var ret = calc();
delete this[name] // memo result
this[name] = ret;
@joseanpg
joseanpg / coater.js
Created September 23, 2011 05:30
Consulta
var one = function(arg){return 'Hola ' + arg;};
var two = function(arg){return 'Adios ' + arg;};
alert(one('Otoño'));
alert(two('Verano'));
//Siglos después descubrimos que hay que preprocesar el argumento :)
Function.prototype.makeCoat = function() {
var service = this;
@joseanpg
joseanpg / coolcodebytheface.js
Created July 23, 2012 19:26
Who decides who is a jsRockStar?
function ImTheLeche(legoCreator) {
return function(){
return function(protopato) {
legoCreator.gn = legoCreator.prototype =
Object.create(protopato,{constructor:{value:legoCreator}});
return {init:function(){
var fakeMVCfever =
Object.create(legoCreator.gn,{constructor:{value:this.init}});
return legoCreator.apply(fakeMVCfever,arguments);}
}
@joseanpg
joseanpg / RLD_default_nuestro.properties
Created August 8, 2012 12:29
RoboMind :: Leccion 2
### Control structures ###
If=si
Else=en_caso_contrario
Procedure=aprende_procedimiento
Repeat=repite
RepeatWhile=repite_mientras
Return=regresar
Break=truncar
End=fin
@joseanpg
joseanpg / extend_and_merge.js
Created August 15, 2012 21:55
Extend and Merge (don't overwrite properties that reference objects)
(function(carrier){
var hasOwn = Object.prototype.hasOwnProperty;
var slice = Array.prototype.slice;
function extend(obj,src){
for (var p in src){
if (hasOwn.call(src,p)) {
if (p in obj && typeof obj[p] === 'object' && obj[p]) {
extend(obj[p],src[p]);
@joseanpg
joseanpg / reparte.hs
Created September 7, 2012 20:50
reparte.hs
import System.Environment
type Vec = [Int] -- (Int,Int,Int,Int,Int,Int)
data UnaSol = UnaSol { values :: [Vec], rest :: Vec} deriving (Show)
type Sol = [UnaSol]
beta :: Vec -> [Int] -> Sol
beta t [] = [UnaSol [] t]
@joseanpg
joseanpg / Function.prototype.call.call_behaviour.md
Created September 20, 2012 20:13
Function.prototype.call.call behaviour
@joseanpg
joseanpg / comments.txt
Created November 4, 2012 12:56
Understanding cool-tree.aps
Datatype ->
class Datatype_class : public tree_node
constructor_of_Datatype ->
class constructor_class : public Datatype_class {
...
constructor_class(...)
Datatype constructor( par1, par2, ... ) {
return new constructor_class(par1, par2, ...);
@joseanpg
joseanpg / 00-cool-ast.hs
Created November 17, 2012 12:33
Understanding cool-tree.java
{- This is mine -}
data Symbol = Symbol { id :: Int
, str :: String
}
data Program = Program { classes :: Classes}
data Class_ = Class_ { name :: Symbol
, parent :: Symbol
@joseanpg
joseanpg / 00-SymbolTable.java
Created November 18, 2012 08:26
Symbols and Tables :: Cool Support Code
class SymbolTable {
private Stack tbl;
public SymbolTable() { tbl = new Stack();}
public void enterScope() { tbl.push(new Hashtable());}
public void exitScope() {
if (tbl.empty()) { Utilities.fatalError("existScope: can't remove scope from an empty symbol table.");}
tbl.pop();