Skip to content

Instantly share code, notes, and snippets.

View dingsdax's full-sized avatar
slow coding

Joesi D. dingsdax

slow coding
View GitHub Profile
dingsdax / gist:1080272
Created July 13, 2011 13:13
Jaro–Winkler distance in Ruby
# extension for array class
class Array
# select array items with index
# give a block both the item with index of array
# filtered by a select statement
def select_with_index
index = -1
select { |x| index += 1; yield(x, index) }
# return indices array of array item
dingsdax / gist:1118528
Created August 1, 2011 17:04
Ruby remote file checker
# from
require 'rubygems'
require 'open-uri'
require 'net/http'
def remote_file_exists?(url)
url = URI.parse(url)
Net::HTTP.start(, url.port) do |http|
return http.head(url.request_uri).code == "200"
dingsdax / random_time.rb
Created August 7, 2011 13:28
ruby random data generation
class Time
def self.random(years_back=5)
year = - rand(years_back) - 1
month = rand(12) + 1
day = rand(31) + 1
Time.local(year, month, day)
dingsdax / gist:1140739
Created August 11, 2011 20:51
Jim Breen's WWWJDIC regexp
# source:
# example_url:
# output:
# 先生 [せんせい] /(n) (1) teacher/master/doctor/(suf) (2) with names of teachers, etc. as an honorific/(P)/
# 先生に就く [せんせいにつく] /(exp,v5k) to study under (a teacher)/
# 先生の述 [せんせいのじゅつ] /(n) teachers statement (expounding)/
# 先生方 [せんせいがた] /(n) doctors/teachers/
# regexp
dingsdax / gist:1228537
Created September 20, 2011 07:02
crappy binary radix trie in ruby
# from
class Fixnum
def to_b(l = 8)
"0′" + self.to_s(2).rjust(l, "0")
def set?(i)
if((self & (1 << i)) != 0)
return true
dingsdax /
Created November 30, 2011 10:09
get & store all attachments in a mailbox directory
#!/usr/bin/perl -w
use strict;
use Mail::MboxParser;
use constant MAILBOX_DIR => "/var/mail/mymailboxdir";
use constant STORAGE_DIR => "/data";
if ( -z MAILBOX_DIR ) {
print STDERR "no mail.\n";
dingsdax / gist:ad517d63fbf7b5bd29c4
Last active September 28, 2015 12:47
Ruby NLP resources

Ruby NLP resources

dingsdax / gist:1566136
Created January 5, 2012 17:03
university ranking WebL wrapper script
// WebL Website (archived):
// get unique countrynames for the 500 top world universities
// get number of universities per country, pretty print statistics with a horizontal bar chart
// data from 2009 version of
import Str;
var startpage = GetURL("");
dingsdax / Rakefile.rb
Last active January 17, 2021 20:00
n-grams/tf-idf indexer written in ruby
require './lib/indexer.rb'
# rake task to build index
task :buildindex do
# mixin to overwrite get_class method
Indexer.class_eval do
def get_class f
f.split('/')[-2]# get class assignment implicitly with folder structure (first hierarchy level)
dingsdax /
Last active January 17, 2021 20:02
My solution to the Instagram Engineering challenge - The Unshredder

The challenge

The challenge was to write a short script in a scripting language of choice that takes in an image of mixed up uniform sized shreds and pieces them back into the unshredded and reconstituted image. That means the original image was divided into an even number of columns of same size and than those columns were shuffled randomly. Additionally the script should auto-detecting how wide the uniform strips are.

The solution

Before I started on my solution, I made some quick assumptions to simplify things:

  • I wanted to code it in Ruby, simply because it's a great language and I'm quite productive in it.
  • I wanted to define a simple distance measure which can be used for auto-detecting the column size and putting the shredded image back into its original state.