Skip to content

Instantly share code, notes, and snippets.

@simonkro
simonkro / build.sbt
Created November 26, 2015 14:32
Absolute minimal mysql and jooq test
name := "mysqltest"
version := "1.0"
scalaVersion := "2.10.6"
libraryDependencies += "org.jooq" % "jooq" % "3.7.1"
libraryDependencies += "org.jooq" % "jooq-scala" % "3.7.1"
@simonkro
simonkro / config.yml
Last active August 29, 2015 14:00
gilded_rose_with_config
Normal:
:change: -1
:decay: [0]
Sulfuras, Hand of Ragnaros:
:eternal: true
Aged Brie:
:change: +1
:decay: [0]
Backstage passes to a TAFKAL80ETC concert:
:change: +1
class GildedRose < Struct.new(:name, :days_remaining, :quality)
def tick
return if name == 'Sulfuras, Hand of Ragnaros'
self.days_remaining -= 1
case name
when 'Aged Brie' then
increase_quality
@simonkro
simonkro / threadsafe.rb
Created May 28, 2013 10:11
Untested ...
class ThreadSafeWrapper < Delegator
def initialize(obj)
super
@mutex = Mutex.new
end
def method_missing(m, *args, &block)
@mutex.synchronize { super }
end
@simonkro
simonkro / application.rb
Created January 13, 2013 00:32
Toying around with Gtk bindings
require 'gir_ffi-gtk3'
Gtk.init
app = Gtk::Application.new('org.gtk.example', :flags_none)
app.signal_connect('startup') do
window = Gtk::ApplicationWindow.new(app)
menu = Gtk::Menu.new
def make_change amount, coins = [1,2,5,10,20,50,100,200]
tree = Hash[coins.zip(coins)]
while tree[amount].nil? do
tree.keys.each do |value|
coins.each {|coin| tree[value + coin] ||= coin}
end
end
deep = lambda{|a| (coin = tree[a]) ? [coin] + deep[a - coin] : []}
deep[amount].sort.reverse
@simonkro
simonkro / roman.rb
Created December 4, 2012 07:56
Another Version
def digit_to_roman digit, one, five, ten
case d = digit % 10
when 0..3 then one * d
when 4 then one + five
when 5..8 then five + one * (d - 5)
when 9 then one + ten
end
end
def to_roman n
#Maybe it's not the way you would do it in ruby and code is not that
#beautiful and everyone knows how to read file line by line and how to make
#validation of inputs and how to use methods, global and local variables
#but I am sure my idea is genuis. Engoy
class Test
str=ARGV[0]
require 'number_converter'
ARGV.each do |input_number|
result = NumberConverter.new(input_number).convert
puts "#{input_number} = #{result}"
end
@simonkro
simonkro / one_thing.rb
Created December 3, 2012 20:09
Roman Numerals
p "Hi, what is your name ?"
@name = gets.chomp
p "Welcome to the quiz, #{@name}! " + "Please enter a Roman numeral with value between 1 and 4 here:"
a = gets.to_i
if a == 1
p "I"
end
if a == 2