Skip to content

Instantly share code, notes, and snippets.

@pqwy
pqwy / index.coffee
Created May 21, 2012 15:18
editor in derby
view.fn 'unwrap', (ob) ->
{ key, value } for own key, value of ob)
class A
include Mongoid::Document
embeds_one :b
end
class B
include Mongoid::Document
embedded_in :a
end
@pqwy
pqwy / gist:3883367
Created October 13, 2012 05:36
can't re-add live objects back into a relation
class A
include Mongoid::Document
has_many :bs
end
class B
include Mongoid::Document
belongs_to :a
end
@pqwy
pqwy / time-it.ls
Created October 23, 2012 00:11
v8: closure vs. lambda-lifting
# This is LiveScript, really, but GH can't colour it -- yet.
time = (n, target) ->
t0 = (new Date).getTime!
for i from 1 to n then r = target!
t = (new Date).getTime! - t0
ta = t / n
console.log "[time] #t ms (avg #ta ms)"
r
@pqwy
pqwy / gist:3988500
Created October 31, 2012 17:29
index occurrence ids
// nb. we have a typo with occurrences -- sometimes they are called "occurences".
var filter = {};
var projection = {
_id : true,
facebook_occurence_ids : true
};
db.movies.find(filter, projection)
@pqwy
pqwy / inversions.cpp
Created November 7, 2012 05:09
Inverzije...
#include <iostream>
#include <fstream>
#include <vector>
#include <sys/time.h>
using namespace std;
typedef vector<int> vec;
typedef vector<int>::iterator ix;
@pqwy
pqwy / app.ls
Created November 12, 2012 16:27
basic livescript/express scaffold
express = require \express
app = express!
..set \views, "#__dirname/../views"
..use express.static "#__dirname/../pub"
app.get '/', (req, res) ->
res.render 'index.jade'
app.listen 3001
@pqwy
pqwy / meta.rkt
Last active December 16, 2015 00:49
dat metacircular evaluation
#lang racket
;;
;; Run-of-the mill metacircular evaluator for (a small subset of) scheme.
;; Includes delimited continuations, and the tower of (positive) meta-levels.
;;
(struct closure [vars body environment])
(struct primitive [procedure])
@pqwy
pqwy / Peek.hs
Created November 27, 2013 02:29
peek / poke
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances, UndecidableInstances #-}
module Peek (
module Data.Monoid
, Store, runStore, store, stores
, Restorable, restore
, AutoSize, autoSizeOf
) where
@pqwy
pqwy / GenS.hs
Created November 27, 2013 19:29
autopeek / autopoke
{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances #-}
module GenS (AutoStorable) where
import Control.Applicative
import GHC.Generics
import Data.Word
import Foreign