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 / a.md
Created April 22, 2014 11:47
Patch for Ruby 2.1.1
ruby-install -p https://gist.githubusercontent.com/judofyr/11175629/raw/2f22144e3ca261e9e989fcb9a205b473c208007f/patch.diff ruby 2.1.1
type Foo = distinct int
template `&`(a: Foo, b: Foo): expr =
debugEcho "anding"
const x = a
Foo(int(a) + int(b))
echo int(Foo(1) & Foo(2) & Foo(3) & Foo(4) & Foo(5))
set -e
DIR="docs"
BRANCH="gh-pages"
# Stage all files in the directory
find "$DIR" -type f | xargs git update-index --add
# Write the sub-tree
TREE=$(git write-tree --prefix="$DIR")
---
extension: xml
layout: nil
filter:
- erb
---
<% pages = @pages.find(:limit => 10,
:in_directory => 'posts',
:sort_by => 'created_at',
:reverse => true) -%>
(defun scheme-run-outline (arg)
(interactive "p")
(save-excursion
(outline-previous-visible-heading arg)
(setq before (point))
(outline-next-visible-heading arg)
(scheme-send-region before (point))))
(define-key scheme-mode-map (kbd "C-c C-o") 'scheme-run-outline)
# Mixin to scan an array for objects that respond to a given method
module WithMethod
# Iterates through the array and returns a list of items that
# respond to method
def with_method(method)
self.select do |item|
item.respond_to(method)
end
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US'>
<head>
<title>Hampton Catlin Is Totally Awesome</title>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
</head>
<body>
<!-- You're In my house now! -->
<div class='header'>
Yes, ladies and gentileman. He is just that egotistical.
Author.new do
name "Magnus Holm"
location :norway
nickname :judofyr
blog judofyr.net
twitter @judofyr
github / judofyr
end
// This would be sweet Miko:
// Go Object.property!
Speck.describe("your mother") {
it.should("be true") {
true.should = true
}
it.should("not be false") {
false.should_not = true
}