Skip to content

Instantly share code, notes, and snippets.

View heftig's full-sized avatar
🦄
Horsing around

Jan Alexander Steffens heftig

🦄
Horsing around
View GitHub Profile
diff --git i/Rakefile w/Rakefile
index d1bbfa6..ecf10bb 100644
--- i/Rakefile
+++ w/Rakefile
@@ -52,7 +52,7 @@ end
load_configuration
-unless BUILD_CONFIG[:config_version] == 179
+unless BUILD_CONFIG[:config_version] == 180
def caseperm(str, num)
str.each_char.map.with_index do |c,i|
if num[i] == 0
c.downcase
else
c.upcase
end
end.join
end
class Hash
def map_value
each_pair.with_object({}) { |(key, value), result| result[key] = yield value }
end
def map_key
each_pair.with_object({}) { |(key, value), result| result[yield key] = value }
end
def map_pair(&blk)
escape_char /
comment_char %
% Locale for English locale in Germany, using period decimal seperator
LC_IDENTIFICATION
title "English locale for Germany"
source ""
address ""
contact ""
email ""
require 'benchmark'
class A
attr_accessor :foo
def initialize
@foo = 0
end
def test_direct
class ErrorRounder
def initialize
@error = 0.0
end
def round(x, n=0)
out = (x - @error).round(n)
@error += out - x
out
end
def replace_line_in_file(old,new,file)
File.open(file) do |f|
File.open(file + ".new", "w") do |f2|
f.each_line do |line|
f2.puts line.gsub(old, new)
end
end
end
File.rename(file + ".new", file)
end
filename="foobar"
File.open(filename, "r") do |fr|
File.open(filename + "~nop", "w") do |fw|
fr.each_line do |line|
fw.write line.gsub(".", "")
end
File.rename(filename + "~nop", filename)
end
end
require 'socket'
sockpath = "/tmp/foosock"
if ARGV.first == "server"
socket = UNIXServer.new sockpath
begin
while client_sock = socket.accept do
Thread.start do
puts "New connection"
class PokerGame
include Enumerable
include Comparable
attr_reader :hands, :deck
RANKS = %w{ 2 3 4 5 6 7 8 9 T J Q K A }
SUITS = %w{ S H D C }
def initialize(hands, cards)
@deck = RANKS.product(SUITS).map(&:join)