Skip to content

Instantly share code, notes, and snippets.

View hinrik's full-sized avatar

Hinrik Örn Sigurðsson hinrik

View GitHub Profile
require "string_pool"
pool = StringPool.new
pool.get("foo")
(0..500).each do |i|
# add random stuff to grow the pool
random_str = (1..8).map{ ((rand(2)==1?65:97) + rand(25)).chr }.join
pool.get(random_str)
abstract struct Foo
end
struct Bar < Foo
end
struct Baz < Foo
end
hash = {} of Foo => Int32
hash = {} of String => Hash(Int32, Int32) # | Hash(String, Hash(Int32, Int32))
hash["foo"] = {} of Int32 => Int32
hash["foo"][1] = 4
#hash["bar"]["baz"] = {} of Int32 => Int32
#hash["bar"]["baz"][1] = 4
puts hash
@hinrik
hinrik / dutch_mortgage.pl
Last active August 29, 2015 14:04
Dutch mortgage calculator for 2014
use 5.14.0;
use warnings;
use Getopt::Long qw(:config no_ignore_case bundling);
use List::Util 'sum';
use Spreadsheet::Engine::Function::PMT;
# up to date as of 2014
my $max_deduction = 51.5;
my $min_deduction = 42;
my $yearly_reduction = 5;
package Location;
sub new {
my ($class, %args) = @_;
my $subclass = "Location::$args{location_type}";
return bless \%args, $subclass;
}
package Location::Country;

I get asked by people wanting to visit Iceland what they should do while they're there. Rather than re-type (and mostly forget) the whole thing I just give them a link to this.

Stuff that isn't this guide

...as if you didn't know how to use Google.

  • I'm partial to The Lonely Planet guides whenever I visit other places. I haven't checked the one for Iceland but it's probably
@hinrik
hinrik / foostat.rb
Last active December 21, 2015 12:58
require 'celluloid/io'
require 'celluloid/autostart'
require 'net/sftp'
class Foo
include Celluloid::IO
def initialize
async.connect_and_stat
end

$ pocoirc -tv -s irc.oftc.net -n literal -N secret

2013-05-09 12:24:24 Started (pid 2295)
2013-05-09 12:24:24 Constructing global plugins
2013-05-09 12:24:24 [default]	Constructing local plugins
2013-05-09 12:24:24 [default]	Spawning IRC component (POE::Component::IRC::State)
2013-05-09 12:24:24 [default]	Registering plugins
2013-05-09 12:24:24 [default]	Connecting to IRC (irc.oftc.net)
2013-05-09 12:24:24 [default]	S_plugin_add: ARG0: 'Whois_3', ARG1: POE::Component::IRC::Plugin::Whois=HASH(0x2697ce0)
require 'celluloid'
require 'celluloid/io'
class EchoServer
include Celluloid::IO
finalizer :echo_finalize
def initialize(host, port)
puts "*** Starting echo server on #{host}:#{port}"
@hinrik
hinrik / Makefile
Created November 15, 2012 22:36 — forked from daurnimator/Makefile
Add utf8 locale to lpeg using ICU (from the C side)
LIBNAME = lpeg_utf8
OUT = $(LIBNAME).so
LUADIR = /usr/include/lua5.1/
LPEGDIR = ../lpeg-0.10.2/
CFLAGS = -O2 -fpic --pedantic -I$(LUADIR) -I$(LPEGDIR)
CC = gcc
$(OUT): lpeg_utf8.o