Skip to content

Instantly share code, notes, and snippets.

@hexgnu
hexgnu / $
Created June 10, 2011 15:29
$ script
# Filename $
#!/bin/bash
$@
# Add this to .bashrc
# PATH=$PATH:`pwd`
@hexgnu
hexgnu / memento.rb
Created August 3, 2011 23:35
Memento Pattern
class Originator
def state=(state)
puts "Originator: setting state to " + state
@state = state
end
def save_to_memento
puts "Originator: Saving to memento."
Memento.new(@state)
end
@hexgnu
hexgnu / convenient.rb
Created August 5, 2011 21:45
'Convenient'
class Convenient
instance_methods.each do |meth|
puts "We dont want anybody touching #{meth}"
private :"#{meth}"
end
def initialize
puts 'HA you cant do shit with me bitch'
end
end
@hexgnu
hexgnu / about.md
Created August 10, 2011 04:39 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@hexgnu
hexgnu / is-even.clj
Created August 16, 2011 06:21
Kind of a heavy handed way to get even...
(defn is-even? [n]
(if (= n 0)
true
(not (is-even? (dec n)))))
@hexgnu
hexgnu / y_combinator.rb
Created August 17, 2011 18:39
Y Combinator in Ruby
# Define the Y combinator
module Y
extend self
def combinator(&generator)
lambda do |x|
lambda do |*args|
generator.call(x.call(x)).call(*args)
end
end.call(lambda do |x|
lambda do |*args|
@hexgnu
hexgnu / single_attr_accessor.rb
Created August 29, 2011 20:47
Dont ever do this evar!!!
#!/usr/bin/env ruby -w
class Foo; end
f = Foo.new
f.instance_eval do
class << self
attr_accessor :baz
end
end
@hexgnu
hexgnu / Failbot
Created November 17, 2011 15:35
Failboat
Failures:
1) Admin::UsersController access is granted for social volt employees with role admin
Failure/Error: login_as(role)
NoMethodError:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.delete
# ./spec/support/controller_macros.rb:10:in `login_as'
# ./spec/controllers/admin/users_controller_spec.rb:11:in `block (5 levels) in <top (required)>'
@hexgnu
hexgnu / gist:1374265
Created November 17, 2011 19:49
gemfile.lock
GIT
remote: https://github.com/maxjustus/grant.git
revision: 89d6833e792f92ab8d3a7ce918ede53a2b9ebeb3
specs:
grant (2.0.0)
GIT
remote: https://github.com/maxjustus/paperclip-s3.git
revision: 9a4fd58124f3960aee43261fdb368e72d87b5601
specs:
@hexgnu
hexgnu / z_score
Created November 21, 2011 21:24
Mapping from user input to scores
require 'distribution'
module Z
extend self
Z_EPSILON = 10e-16
Z_MAX = 6.0
def critical_z(p)
minz = -Z_MAX
maxz = Z_MAX
zval = 0.0