Skip to content

Instantly share code, notes, and snippets.

@plexus
plexus / cedictloader.rb
Created October 18, 2011 14:16
CC-CEDICT loader
class CedictLoader
include Enumerable
URL = ENV['CEDICT'] || 'http://www.mdbg.net/chindict/export/cedict/cedict_1_0_ts_utf-8_mdbg.txt.gz'
def initialize(input = nil)
@input = input || (
require 'zlib'
require 'open-uri'
Zlib::GzipReader.new(open(URL)))
module Watchable
attr_reader :watchers
def watchers
@watchers ||= Hash.new{|hsh,k| hsh[k]=[]}
end
def watch(&blk)
b=WatcherBuilder.new self
blk[b] if block_given?
b
@plexus
plexus / the_road.md
Last active September 27, 2015 20:18
[POEM] The Road

The poem you are looking for has moved here.

Thanks, Arne

@plexus
plexus / kleurenplaten.html
Created December 2, 2011 23:15
Blader snel door kleurenplaten.nl
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
<script type="text/javascript">
var count = 7360;
$(document).keypress(function(event) {
//if ( event.which == 13 ) {
// event.preventDefault();
var url = 'http://www.kleurplaten.nl/kleurplaten/' + count + '.gif';
$('#tekening').attr('src', url);
@plexus
plexus / truth
Created December 5, 2011 11:55
[POEM] Truth
*WORK IN PROGRESS*
If there is truth to be found I'll find it
Truth is elusive
a trick of the light
you can see it from the corner of my eye
you can reach it in the blackness of the night
you can hear its solemn whisper in the silence
@plexus
plexus / svn_short_log
Created December 16, 2011 09:01
svn log, one line per commit
#!/usr/bin/awk -f
# Convert the "svn log" output into a one liner format, which is easier to grep
# or use in scripts. Pipe "svn log" into this script
# When we get a line that starts with a revision number, put the data in variables
/^r[0-9]+/ {
rev=$1
user=$3
date=$5
@plexus
plexus / .rvmrc
Created April 3, 2012 18:06
Ruby+Gems that Sprinkle specs fail on
rvm use 1.9.3-p125@sprinkle
@plexus
plexus / pg_dump_wrapper.bash
Created May 11, 2012 13:23
PostgreSQL database dump wrapper
#!/bin/bash
# pg_dump wrapper
# - add 'CREATE DATABASE' to dump
# - compress with bzip2
# - timestamp
if [[ "$1" == "" ]]; then
echo " Usage: "
echo " $0 <db_name>"
@plexus
plexus / root_certificates.rb
Created May 11, 2012 13:29
Monkey patch Ruby 1.9 net/http to read system's root certificates
# Please fork if you can improve this. (e.g. Windows support)
#
# Ruby 1.9 doesn't contain any SSL root certificates, neither does it read the ones
# installed with your operating system. This results in an error like
#
# SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
#
# This solution is based on http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/
# but can be used to monkey patch 3rd party tools, e.g. Github's 'gist' command.
#
# Very (very) naive wordt segmentation algorithm for Chinese
# (or any language with similar characteristics, works at the
# character level.)
class Partitioner
attr_reader :ngrams
# +ngrams+ Enumerable list of ngrams
def initialize(ngrams, lookahead = 6)
@lookahead = lookahead
@ngrams = {}