Skip to content

Instantly share code, notes, and snippets.

class Hangman
DICTIONARY = %w(pangolin ecstatic oligarchy corridor)
MAX = 6
def initialize(input=STDIN, output=STDOUT)
@input = input
@output = output
@guesses = 0
end
# fibonacci.rb
class Euler
def fib(n)
curr = 0
succ = 1
n.downto(0) do |x|
curr, succ = curr + succ, curr
end
return curr
@tehviking
tehviking / about_scoring_project.rb
Created April 10, 2011 04:58
My pre-refactoring (ugly, fragile) solution to the dice game Ruby koan.
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
@tehviking
tehviking / dice_koan_refacor.rb
Created April 10, 2011 06:25
Ruby Dice Koan after some help from friends; knocked about 20 lines off & cured some fragility.
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
@tehviking
tehviking / macruby-crash.txt
Created July 2, 2011 22:40
Crash in MacRuby with HotCocoa and BridgeSupport Preview 3
Process: Pants [57731]
Path: /Users/bhays/Sites/todogroove/mac/pants/Pants.app/Contents/MacOS/Pants
Identifier: Pants
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: macruby [57728]
Date/Time: 2011-07-02 16:39:27.576 -0600
OS Version: Mac OS X 10.6.6 (10J567)
Report Version: 6
@tehviking
tehviking / erb_vs_erubis.rb
Created November 10, 2011 17:09
JRuby in 1.9 UTF-8 breaks ERB: Java::JavaLang::ArrayIndexOutOfBoundsException in Default#index
#WORKS
# -*- coding: UTF-8 -*-
require 'erb'
template = ERB.new <<-EOF
<% 0.times do %>
<% end %>
@tehviking
tehviking / appconfig.txt
Created November 15, 2011 18:16
Full boot log for out of memory on TorqueBox
JBoss Bootstrap Environment
JBOSS_HOME: /Users/bhays/torquebox-current/jboss
JAVA: java
JAVA_OPTS: -Djava.net.preferIPv4Stack=true -Dprogram.name=run.sh -Djava.library.path=/Users/bhays/torquebox-current/jboss/bin/native/lib64
CLASSPATH: /Users/bhays/torquebox-current/jboss/bin/run.jar
@tehviking
tehviking / error.txt
Created December 1, 2011 23:05
JRuby-HEAD & Rake = :(
rake db:migrate
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake/version.rb:2 warning: already initialized constant VERSION
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake/version.rb:5 warning: already initialized constant MAJOR
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake/version.rb:5 warning: already initialized constant MINOR
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake/version.rb:5 warning: already initialized constant BUILD
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake/version.rb:5 warning: already initialized constant PATCH
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake/version.rb:6 warning: already initialized constant NUMBERS
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake.rb:27 warning: already initialized constant RAKEVERSION
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/rake/early_time.rb:17 warning: already initialized constant EARLY
/Users/bhays/.rvm/gems/jruby-head/gems/rake-0.9.2.2/lib/r
@tehviking
tehviking / deploy_utils.rb
Created December 6, 2011 22:50
jruby-head & torquebox-rake-support gem conflict
def exec_command(cmd)
IO.popen4( cmd ) do |pid, stdin, stdout, stderr|
trap("INT") do
puts "caught SIGINT, shutting down"
`taskkill /F /T /PID #{pid}` if windows?
end
stdin.close
[
Thread.new(stdout) {|stdout_io|
stdout_io.each_line do |l| # This is the line throwing the error... 295
@tehviking
tehviking / anagram_finder_spec.rb
Created May 1, 2012 04:13
Kata six: Anagrams (pairing with Dan Dorman)
class AnagramFinder
def find_anagrams(words)
output = []
while (target_word = words.shift)
matches = [target_word]
words.reject! do |word|
matches << word if check_for_anagram(word, target_word)
end
output << matches
end