Skip to content

Instantly share code, notes, and snippets.

@matthewp
matthewp / rel-template.js
Created June 19, 2012 19:08
Synchronous loading of templates in a link tag.
(function() {
"use strict";
Object.defineProperty(HTMLLinkElement.prototype, 'template', {
get: function() {
if(!/template/i.test(this.rel)) {
return "";
}
var req = new XMLHttpRequest();
@rsms
rsms / struct1.ll
Created June 8, 2012 02:09
[hue] Prototypal inheritance experiment in LLVM IR
; ModuleID = 'struct1'
; Object = struct
; foo = 1
%ObjectT = type <{ i64 }> ; foo
@ObjectS = private unnamed_addr constant %ObjectT <{ i64 1 }>
; Shape = struct Object
; color = 0xff0000
; area = func () 0
; fillColor = func () @color / @area!
@alandipert
alandipert / reinvoke.cljs
Last active June 22, 2019 00:20
It's sweet that IFn is a protocol in ClojureScript
(extend-type js/RegExp
cljs.core/IFn
(-invoke ([this s] (re-matches this s))))
(#"foo.*" "foobar") ;=> "foobar"
(#"zoo.*" "foobar") ;=> nil
(filter #".*foo.*" ["foobar" "goobar" "foobaz"]) ;=> ("foobar" "foobaz")
@fjolnir
fjolnir / tlc.lua
Last active February 15, 2024 15:01
LuaJIT ObjC bridge
The bridge is now located at https://github.com/fjolnir/TLC
@datagrok
datagrok / gist:2199506
Last active April 8, 2023 17:36
Virtualenv's `bin/activate` is Doing It Wrong
@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@jlongster
jlongster / gist:1979842
Created March 5, 2012 17:50
Outlet meta-circular evaluator
;; Requires Outlet to run: https://github.com/jlongster/outlet
;;
;; Run with: `ol main.ol <input-file>`
;;
;; This is a meta-circular evaluator for a basic Lisp. It is
;; mostly taken from SICP 4.1*. I wanted to see if I could write a
;; debugger with it. Turns out if I want control over control flow I
;; need a register-based interpreter.
;;
;; * http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1
@dherman
dherman / 1-recursive.js
Created February 7, 2012 20:10
turning recursion into iteration in JS
// Version 1. Simple recursive function. Blows the stack for large nodes.
function replace(node, from, to) {
switch (node.type) {
case IF:
return {
type: IF,
test: replace(node.test, from, to),
then: replace(node.then, from, to),
else: replace(node.else, from, to)
};
@p8
p8 / lithp.rb
Created January 26, 2012 00:34 — forked from fogus/lithp.rb
class Lisp
Fs = {
:label => lambda {|name,value| Fs[name] = lambda { value } },
:car => lambda {|sexp| sexp.first },
:cdr => lambda {|sexp| sexp.slice(1, sexp.size) },
:cons => lambda {|head,tail| [head] + tail },
:atom => lambda {|sexp| !sexp.is_a?(Array) },
:eq => lambda {|a,b| a == b },
:if => lambda {|cnd,thn,els| cnd ? thn : els }
}
@tonyg
tonyg / minified-os.rkt
Created January 19, 2012 17:46
My, what a small operating system you have
#lang racket
(provide (struct-out subscription)
(struct-out message-handler)
(struct-out kernel-mode-transition)
make-vm
vm?
run-vm
nested-vm)