Skip to content

Instantly share code, notes, and snippets.

def extract_session
envs = ObjectSpace.each_object(Hash).lazy.select { |env| env.key?("rack.version") && env.key?("rack.session") }
before = envs.to_a
GC.disable
yield
after = (envs.to_a - before)
raise "Could not extract session" unless after.size == 1
after.first['rack.session']
ensure
GC.enable
@judofyr
judofyr / lazy.scm
Created July 29, 2013 15:02
Lazy lists without closures in Scheme
#lang r5rs
; A lazy list is a cons of two values: a head (a value) and a tail,
; a lambda that returns other lazy list. It's very easy to create a
; closure-based implementation:
(define (lazy-from n)
(cons n (lambda () (lazy-from (+ 1 n)))))
(define (lazy-head lst) (car lst))
(define (lazy-tail lst) ((cdr lst)))
From 714fc294b5ade1f502c45fabab573630f09a0889 Mon Sep 17 00:00:00 2001
From: Magnus Holm <judofyr@gmail.com>
Date: Mon, 6 May 2013 22:27:03 +0200
Subject: [PATCH] Fix stupid bug
---
lib/bundler/resolver.rb | 47 ++++++++-----------------------------------
spec/resolver/basic_spec.rb | 22 ++++++++++++++++++++
2 files changed, 30 insertions(+), 39 deletions(-)
@judofyr
judofyr / age.py
Last active December 16, 2015 11:28
Secret Secure Relative Age Service
# paillier.py and primes.py attached below are verbatim from
# https://github.com/mikeivanov/paillier
#
# This code is licenced under # LGPL v3.
#
# Usage
# Person 1: python age.py MY_AGE
# Person 2: python age.py MY_AGE OUTPUT_FROM_PERSON1
#
# Person 2 should then post the output here and I can publicize the relative age.
@judofyr
judofyr / foo.html
Last active December 14, 2015 04:39
formproxy
<script>parent.postMessage("Hello world", "*")</script>
#!/usr/bin/env ruby
#
# Proof-of-Concept RCE exploit against Gemcutter
#
# ## Advisory
#
# ## Caveats
#
# ## Synopsis
#
@judofyr
judofyr / svg.css
Created November 2, 2012 13:13
Sass-mixin for SVG + PNG-fallback
.lt-ie9 .error {
background-image: url("images/sprites/sprite.png"); }
.error {
background-image: url("images/sprites/sprite.svg"); }
@judofyr
judofyr / gist:3833966
Created October 4, 2012 14:42
Issues with NPM's conceptual model

Let's say someone has implemented a module for sets that's being used in two modules.

a.js:

var set = require("set");

export.thing = set(1, 2, 3);
@judofyr
judofyr / bust_url.rb
Created September 25, 2012 15:07
Cache busting with Sass
# Use as: sass -r ./bust_url.rb
require 'digest/md5'
module Sass::Script::Functions
def bust_url(url)
url = url.value
source = options[:filename]
dir = File.dirname(source)
file = File.join(dir, url)
function loadScript(path, fn) {
var el = document.createElement('script')
, loaded = 0
, onreadystatechange = 'onreadystatechange'
, readyState = 'readyState';
el.onload = el.onerror = el[onreadystatechange] = function () {
if (loaded || (el[readyState] && !(/^c|loade/.test(el[readyState])))) return;
el.onload = el.onerror = el[onreadystatechange] = null;
loaded = 1;