Skip to content

Instantly share code, notes, and snippets.

View aflatter's full-sized avatar

Alexander Flatter aflatter

View GitHub Profile

Keybase proof

I hereby claim:

  • I am aflatter on github.
  • I am aflatter (https://keybase.io/aflatter) on keybase.
  • I have a public key ASBYWX2aLIubpZMajGoWwIjWI0XiIPkqUEU2Dq8eAuZdxQo

To claim this, I am signing this object:

# An empty hash does not result in creating a new instance of the type.
# Required because that's what we get back from the relation.
class OptionalCoercer
def initialize(type)
@type = type
end
def call(value)
return unless value
value.values.any? ? type.new(value) : nil
@aflatter
aflatter / password.rb
Created March 12, 2015 14:37
SCrypt::Password attribute type for Virtus
require 'scrypt'
module Virtus
class Attribute
class Password < ::Virtus::Attribute
primitive SCrypt::Password
def coerce(value)
value ? SCrypt::Password.new(value) : nil
rescue SCrypt::Errors::InvalidHash
@aflatter
aflatter / bundix.rb
Last active August 29, 2015 14:05
Writes a gems.nix for use with the nixpkgs/pleasant-ruby
require 'bundler'
require 'erb'
# Generates a Nix expression for bundler-managed dependencies.
module Bundix
class << self
def run(gemfile = './Gemfile', lockfile = 'Gemfile.lock')
gems = resolve_deps(gemfile, lockfile)
checksums = compute_checksums(gems)
write_expr(gems, checksums)
require 'celluloid'
def pusher(condition)
sleep 5
condition.signal 'Wibble'
end
def puller(condition)
value = condition.wait
puts "Pulled: #{value}"
@aflatter
aflatter / future_plexer.rb
Created May 8, 2013 00:52
The FuturePlexer for Celluloid :-)
require 'celluloid'
class FuturePlexer
class DrainedError < StandardError; end
attr_accessor :futures
def initialize(futures)
self.futures = futures
end
@aflatter
aflatter / test.html
Created December 15, 2011 14:40
Webkit transitions on a newly attached element don't work. Probably related to http://code.google.com/p/chromium/issues/detail?id=82500
<html>
<head>
<title>Test</title>
<style type="text/css">
div {
position: absolute;
height: 200px;
}
.slide {
@aflatter
aflatter / inter.js
Created April 4, 2011 20:55 — forked from phreax/inter.js
var app = require('app')
var assert = require('assert')
var db = app.db;
var get_state = function(cb) {
db.get('_state', function(err,doc) {
if(err) {
@aflatter
aflatter / inter.js
Created April 4, 2011 19:59 — forked from phreax/inter.js
var app = require('app')
var assert = require('assert')
var db = app.db;
var get_state = function(callback) {
db.get('_state', function(err,doc) {
if(err) {
var common = require('../common'),
assert = common.assert;
var Script = process.binding("evals").Script;
var sandbox = Script.createContext({x: "x"});
sandbox.window = sandbox;
//Script.runInContext("window = this;", sandbox);