Skip to content

Instantly share code, notes, and snippets.

View riethmayer's full-sized avatar

Jan Riethmayer riethmayer

View GitHub Profile
# Ummm ... well. Just some pseudo code I guess. Fork + complete as needed.
#
# Dependencies: Kombucha culture is expected to be installed in ~/kitchen
# If you don't have one you can easily obtain one from the internet.
rails kombucha -m ~/homemade.rb
# ~/homemade.rb
system %(
in terminal do:
defaults -currentHost write -globalDomain AppleFontSmoothing -int 2
@riethmayer
riethmayer / mongo
Created January 20, 2010 01:00
Mongodb startup script
#!/usr/bin/env ruby -w
# mongo ;; 2010 (cc) Jan Riethmayer
# This work is licensend under a Creative Commons Attribution 3.0 license.
require 'optparse'
options = {}
optparse = OptionParser.new do|opts|
opts.banner = <<-BANNER
Usage: sudo ./mongo [options]
@riethmayer
riethmayer / assertion_method.rb
Created January 20, 2010 19:23
use assert for design by contract
# Assertion Method
def assert(value, message="Assertion failed")
raise Exception, message, caller unless value
end
options[:cowfile] and
assert(options[:cowfile].to_s !~ /^\s*$/)
@riethmayer
riethmayer / use_fetch.rb
Created January 20, 2010 19:36
better use fetch
{}[:width] # => nil
{}[:width] || 40 # => 40
{:width => nil}[:width] || 40 # => 40
{:width => false}[:width] || 40 # => 40
{:width => 29}[:width] || 40 # => 29
{}.fetch(:width) # =>
# ~> -:7:in `fetch': key not found (IndexError)
{}.fetch(:width) { 40 } # => 40
@riethmayer
riethmayer / null_object.rb
Created January 20, 2010 19:42
Null object with caller for debug
class NullObject
def initialize
@origin = caller.first
end
def method_missing(*args, &block)
self
end
def nil?; true; end
@riethmayer
riethmayer / bouncer_method.rb
Created January 20, 2010 19:49
bouncer method
# Method whose job is to raise or do nothing
def check_child_exit_status
result = yield
status = $? || OpenStruct.new(:exitstatus => 0)
unless [0,172].include?(status.exitstatus)
raise ArgumentError,
"Command exited with status #{status.exitstatus}"
end
result
end
# name_spec.rb ;; 2010 (cc) Jan Riethmayer
# This work is licensend under a Creative Commons Attribution 3.0 license.
require "spec_helper"
describe "Name" do
it "should contain all prefixes" do
Name.parts.each do |part|
Name.compute.any? do |name|
name.match(/^#{part.capitalize}/)
end.should == true
# name.rb ;; 2010 (cc) Jan Riethmayer
# This work is licensend under a Creative Commons Attribution 3.0 license.
class Name
class << self
def parts
result = <<-NAMES
dev developer code arborium conservatory garden bit byte aid bot
open offen test behaviour mate rack ateer hash tree green grow
bloom karoshi flora keim flow forge former light nerds geeks rack
lab cultivation culture breed web mash restless awake less wheel
(defun haml-mumamo-chunk (pos min max)
(mumamo-find-possible-chunk pos min max
'haml-mumamo-bw-exc-start-fun
'haml-mumamo-bw-exc-end-fun
'haml-mumamo-fw-exc-start-fun
'haml-mumamo-fw-exc-end-fun))
(defun* haml-mumamo-exc-start-fun (pos lim max dir)
(if (or (null lim) (null max) (null pos)) (return))
(flet ((check-lim () (when (> (point) max) (return))))