Skip to content

Instantly share code, notes, and snippets.

View igstan's full-sized avatar

Ionuț G. Stan igstan

View GitHub Profile
(define (make-simple-generator iterable transformer)
(define (re-entry return)
(define (iter-action element)
(define (escaper new-re-entry)
(set! re-entry new-re-entry)
(return ( transformer element)))
(call-with-current-continuation escaper))
(for-each iter-action iterable)
(return 'Let-it-end!))
@DmitrySoshnikov
DmitrySoshnikov / harmony-iterator.js
Created March 11, 2011 08:38
harmony-iterators.js
//
// by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
// MIT Style License
// see also: http://wiki.ecmascript.org/doku.php?id=strawman:iterators
//
// ---------------------------------------
// 1. Iteration via for-in loop
// ---------------------------------------
@mattetti
mattetti / fsevents.rb
Created March 18, 2011 07:19
FSEvents API implementation in MacRuby
if RUBY_ENGINE == 'macruby'
framework 'CoreServices'
WATCHED_EXTS = "rb,builder,erb,nokogiri"
PASSENGER_RESTART_FILE = File.expand_path(File.join(File.dirname(__FILE__), "..", "tmp", "restart.txt"))
DELAY = 3
def modified_files(path)
Dir.glob("#{File.expand_path(path)}/*.{#{WATCHED_EXTS}}").map do |filename|
begin
@avernet
avernet / list-general.coffee
Created May 3, 2011 02:48 — forked from igstan/state-monad.coffee
State Monad in CoffeeScript
#### Monad - common code
# bind takes a step and processor,
# and combines them into a step
# (S t) -> (t -> S u) -> (S u)
bind = (step, processor) -> (container) ->
result = step container
(processor result.value) result.container
@swannodette
swannodette / gist:997140
Created May 28, 2011 19:26
type-inf.clj
(ns logic.y
(:refer-clojure :exclude [== reify inc])
(:use [clojure.core.logic minikanren prelude
nonrel match]))
(defna findo [x l o]
([_ [[?y :- o] . _] _]
(project [x ?y] (== (= x ?y) true)))
([_ [_ . ?c] _] (findo x ?c o)))
anonymous
anonymous / bootstrap.sh
Created June 2, 2011 17:19
Django on Heroku with Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
$ bin/rbx compile -e 'def m(a) p a end' -B -N m
================== :m ==================
Arguments: 1 required, 1 total
Locals: 1: a
Stack size: 3
Lines to IP: 1: -1..7
0000: push_self
0001: push_local 0 # a
@leibovic
leibovic / dominant-color.js
Created June 9, 2011 16:27
Dominant Color
function getDominantColor(aImg) {
let canvas = document.createElement("canvas");
canvas.height = aImg.height;
canvas.width = aImg.width;
let context = canvas.getContext("2d");
context.drawImage(aImg, 0, 0);
// keep track of how many times a color appears in the image
let colorCount = {};
@jbrains
jbrains / ListContract.java
Created July 15, 2011 11:45
An alternative contract test style in Java
package ca.jbrains.junit;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
@alandipert
alandipert / ded.clj
Created August 24, 2011 03:18
Command-line structural data editing
(ns ded
"Structural Data EDitor for Clojure with zippers. Inspired by Interlisp: http://larry.masinter.net/interlisp-ieee.pdf"
(:require [clojure.zip :as z])
(:use [clojure.pprint :only (with-pprint-dispatch code-dispatch pprint)]
[clojure.repl :only (source-fn)]))
(defn print-hr
"Prints 30 dashes and a newline."
[c]
(println (apply str (repeat 30 c))))