Skip to content

Instantly share code, notes, and snippets.

View hinrik's full-sized avatar

Hinrik Örn Sigurðsson hinrik

View GitHub Profile
@hinrik
hinrik / replaygain-id3
Created January 5, 2010 02:24
Add ReplayGain information to id3 tags of mp3 files
#!/usr/bin/env perl
use strict;
use warnings;
use File::Which;
use Getopt::Long qw(:config auto_help);
use Pod::Usage;
use String::ShellQuote;
my $VERSION = '0.01';
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
@hinrik
hinrik / jquery_ui_confirm.js.coffee
Created February 25, 2012 17:08
A better Rails confirmation dialog
# Replace Rails' confirmation dialog with a translatable jQuery UI modal dialog.
# Requires i18n-js (https://github.com/fnando/i18n-js)
# Translation strings used: confirm.title, confirm.ok, confirm.cancel
$ ->
$.rails.confirm = (message) ->
$("#confirm_dialog").html('<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>' + message + '</p>')
false
if $('[data-confirm]')
$('body').append("<div id='confirm_dialog' title='" + I18n.t('confirm.title') + "'></div>")
diag_elem = $('#confirm_dialog')
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 / gist:305741
Created February 16, 2010 17:57
Supplying a custom FTS3 tokenizer to SQLite from Perl
use strict;
use warnings;
use Inline C => Config => LIBS => '-lsqlite3';
use Inline C => <<'END';
#include <sqlite3.h>
/* Not included in sqlite.h */
#define SQLITE_PRIVATE static
#define SQLITE_ENABLE_FTS3 1
#define UNUSED_PARAMETER(x) (void)(x)

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}"