Skip to content

Instantly share code, notes, and snippets.

View igstan's full-sized avatar

Ionuț G. Stan igstan

View GitHub Profile
@alandipert
alandipert / flp.clj
Created March 20, 2012 04:18
Function-level programming a la Backus
(ns flp
"Function-level programming a la Backus; see
http://www.stanford.edu/class/cs242/readings/backus.pdf"
(:refer-clojure :exclude [/]))
;;; Functional Forms - combine existing functions to form new ones.
(def ^{:doc "Composition"} ° comp)
(defn / [f]
@tonyg
tonyg / struct-map.rkt
Created February 26, 2012 23:20
Generic mapping over Racket structures
#lang racket/base
(provide current-struct-mappers
install-struct-mapper!
struct-map
struct-map/accumulator)
;; Parameter<Hash<StructType,Mapper>>
(define current-struct-mappers (make-parameter (hash)))
@tbroyer
tbroyer / Html5Historian.java
Created February 22, 2012 10:07
GWT PlaceHistoryHandler.Historian using HTML5 pushState and onpopstate
/*
* Copyright 2012 Thomas Broyer <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Object addTrait := method(obj,
resolutions := call evalArgAt(1)
if(resolutions isNil, resolutions = Map clone)
getSlot("obj") foreachSlot(name, value,
if(getSlot("self") hasLocalSlot(name),
if(name == "type", continue)
if(resolutions at(name) isNil, Exception raise("""Slot '#{name}' already exists in #{getSlot("self") type}[#{getSlot("self") uniqueId}]. Give it a new name in the map argument.""" interpolate))
getSlot("self") setSlot(resolutions at(name), getSlot("value"))
continue
@mgax
mgax / manage.py
Created January 20, 2012 19:22
Flask application template
#!/usr/bin/env python
import flask
import flaskext.script
default_config = {
}
def create_app():
import views
@frenchy64
frenchy64 / seq_type_annotation.clj
Created December 13, 2011 10:40
seq type annotation
;; Type annotation for seq, inspired by haskell
;; (+T <var> :- <interface/protocol>* => <classes>)
(+T clojure.core/seq :- (ISeq a) (ISeq b) => a -> b)
(+T clojure.core/seq :- (Seqable a) (ISeq b) => a -> b)
(+T clojure.core/seq :- nil -> nil)
(+T clojure.core/seq :- (Iterable a) (ISeq b) => a -> b)
(+T clojure.core/seq :- (PrimArray a) (ISeq b) => a -> b)
(+T clojure.core/seq :- (CharSequence a) (ISeq b) => a -> b)
@rbxbx
rbxbx / 1_oo.rb
Created November 17, 2011 01:48
Bootstrapping a lightweight Object System in Ruby
class Person
def initialize(name, age)
@name = name
@age = age
end
def set_name(new_name)
@name = new_name
end
@dvanhorn
dvanhorn / Evaluator.java
Created October 28, 2011 02:12
Compositional interpreter for lambda calculus as Visitor in Java for @ccshan @djspiewak @kaleidic
// Compositional evaluator as visitor
import java.math.BigInteger;
// Syntax
interface Exp {
<X> X accept(Visitor<X> v);
}
@angus-c
angus-c / nodeListMixin.js
Created October 12, 2011 19:06
array-like NodeList via mixins
var NodeList = function() {};
var nodeListExtras = {x: 23};
mixin(NodeList.prototype, Array.prototype, nodeListExtras);
function mixin(obj /*, mixins*/) {
var mixins = [].slice.call(arguments, 1);
for (var i=0; i<mixins.length; i++) {
var thisMixin = mixins[i];
var props = Object.getOwnPropertyNames(thisMixin);
for (var j=0; j<props.length; j++) {
-- A simple definition without using any fancy functions.
haskell>let ifMaybe pred value = if pred value then Just value else Nothing
haskell>:t ifMaybe
ifMaybe :: (a -> Bool) -> a -> Maybe a
haskell>ifMaybe (const True) 2
Just 2
haskell>ifMaybe (const False) 2
Nothing
-- Using functions from standard library.