Skip to content

Instantly share code, notes, and snippets.

View postmodern's full-sized avatar
🚀
releasing new versions

Postmodern postmodern

🚀
releasing new versions
View GitHub Profile
@postmodern
postmodern / countries.rb
Created March 20, 2010 00:17
A module containing Country names and codes
# Country Code List: ISO 3166-1993 (E)
module Countries
Mexico = 'MX'
GuineaBissau = 'GW'
Afghanistan = 'AF'
Ethiopia = 'ET'
SyrianArabRepublic = 'SY'
SvalbardJanMayenIslands = 'SJ'
Tonga = 'TO'
Pakistan = 'PK'
@postmodern
postmodern / dm_country_model.rb
Created March 20, 2010 00:38
A DataMapper model for representing Countries.
require 'dm-core'
require 'dm-validations'
require 'dm-predefined'
class Country
include DataMapper::Resource
include DataMapper::Migrations
include DataMapper::Predefined
@postmodern
postmodern / rack_files.rb
Created March 22, 2010 03:04
Please stop writing your own HTTP parsers, consider Rack next time.
#!/usr/bin/env ruby
require 'rack'
FILES = {
'/index.html' => 'index.html'
}
Rack::Handler.get('Thin').run proc { |env|
path = env['PATH_INFO']
@postmodern
postmodern / async_console.rb
Created March 23, 2010 03:07
An asynchronous Console that can evaluate Ruby code in the background.
require 'thread'
class AsyncConsole
#
# Creates a new Asynchronous Console, within the given context.
#
# @param [Module] context
# The context to evaluate code within.
#
@postmodern
postmodern / dm_api_key.rb
Created March 26, 2010 06:07
A basic DataMapper Type to represent unique API keys.
require 'digest/sha2'
module DataMapper
module Types
class APIKey < DataMapper::Type
primitive String
length 64
#
@postmodern
postmodern / Fib.java
Created April 12, 2010 06:56
Before getting into yet-another-pointless language war, here are some recent numbers. Argue less, code more.
public class Fib {
public static int fib(int n) {
if (n == 0 || n == 1)
return n;
return (fib(n-1) + fib(n-2));
}
public static void main(String[] args) {
for (int i = 0; i < 36; i++)
System.out.println("n=" + i + " => " + fib(i));
@postmodern
postmodern / array_comprehension.rb
Created October 1, 2010 07:50
Adds Haskell style list comprehensions to the Ruby Array
class Array
#
# Iterates over each permutation of the enumerable values within the
# {Array}.
#
# @yield [list]
# The given block will be passed each permutation of the enumerable
# values in the {Array}.
#
@postmodern
postmodern / drunqtxt.rb
Created October 5, 2010 06:35
Ruby script for enumerating drunq txts.
#!/usr/bin/env ruby
require 'rubygems'
gem 'combinatorics', '~> 0.2.0'
gem 'ffi-hunspell', '~> 0.2.0'
require 'combinatorics/list_comprehension'
require 'ffi/hunspell'
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
require 'raingrams'
MODEL_FILE = 'youtube_corpora.ngrams'
model = if File.file?(MODEL_FILE)
Raingrams::BigramModel.open(MODEL_FILE)
@postmodern
postmodern / email_parser.rb
Created January 12, 2011 04:42
Uses Parslet to parse and sanitize obfuscated email addresses.
#!/usr/bin/env ruby
require 'parslet'
class EmailParser < Parslet::Parser
rule(:space) { match('\s').repeat(1) }
rule(:space?) { space.maybe }
rule(:dash?) { match('[_-]').maybe }