Skip to content

Instantly share code, notes, and snippets.

View coffeeaddict's full-sized avatar

Hartog C. de Mik coffeeaddict

View GitHub Profile
@coffeeaddict
coffeeaddict / Bar.pm
Created June 15, 2009 12:14
Mocking about with DESTROY 4 eelkonio
package Bar;
use strict;
sub new {
my $class = ref($_[0]) || $_[0]; shift;
return bless({}, $class);
}
@coffeeaddict
coffeeaddict / exceptions.rb
Created October 19, 2009 07:07
it does work
module Exceptions
# custom exceptions / errors with custom default messages a-go-go
# the base for defined errors.
class DefinedError < RuntimeError
@msg = "Undefined Defined Error"
def message
return @msg || super
#!/usr/bin/perl -l
#
# hartog/20100311: break down a WSDL into a list of functions with
# input and output nicely tucked in.
#
# install the perl modules below, put this in your
# cgi-bin and get going.
#
# wouldn't be using this in a public space as it
# might consume a lot of resources...
class Foo
# same as attr_accessor :variant
def variant
return @variant
end
def variant=(arg)
@variant = arg
end
# make an alternative for send_later that accepts a run_at time
#
module Delayed
module MessageSending
def send_later_at(at, method, *args)
Delayed::Job.enqueue(
Delayed::PerformableMethod.new(self, method.to_sym, args),
0, #priority
at #run_at
)
@coffeeaddict
coffeeaddict / passphrase_generator.rb
Created August 23, 2010 19:07
Generate passwords
class PassphraseGenerator
WORDS_LIST = "/usr/share/dict/words"
@@words = nil
CONJUNCTIONS = %w(and or but you me we him + the -)
FUZZ = %w(! @ # $ % ^ & * - + ~ ` , . < > / ?);
# make a phrase of two words and a conjuction
#
# fuzz the words and return the fuzzed phrase and the original phrase
#
class CreateprogramDependencies < ActiveRecord::Migration
def self.up
create_table :program_dependencies do |t|
t.references :dependency, :polymorphic => true
t.references :program
end
end
def self.down
drop_table :program_dependencies
@coffeeaddict
coffeeaddict / i18n_scoped.rb
Created October 21, 2010 10:21
Scopes for I18n
# = I18n scoped
#
# Set a temporal default scope for I18n
#
# == Synopsis
#
# Given a locale YAML that looks like this:
#
# customers:
# firstname: Customer firstname
@coffeeaddict
coffeeaddict / game.rb
Created October 25, 2010 10:29
Bulls and Cows - an attempt to get a sane solution for http://rosettacode.org/wiki/Bulls_and_cows/Player
class Game
attr_reader :secret
def initialize
@secret = Secret.new
end
def console_play
bulls = -1
while bulls != 4
class A
has_many :abcees
has_many :bees, :through => :abcees
has_many :cees, :through => :abcees
end
class Bee
end
class Cee