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 / log.txt
Created January 19, 2011 05:17
Net::HTTP::Server benchmark.
$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
$ ab -n 1000 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
@postmodern
postmodern / c_parser.rb
Created January 16, 2011 04:24
An ANSI C Parser using the Ruby Parslet library.
#
# A C Parser using the Parslet library.
#
# ANSI C Grammar:
#
# * http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
# * http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
#
require 'parslet'
@postmodern
postmodern / http_parser.rb
Created January 15, 2011 04:39
A pure Ruby HTTP parser using Parslet.
require 'parslet'
require 'pp'
class HTTPParser < Parslet::Parser
#
# Character Classes
#
rule(:digit) { match('[0-9]') }
rule(:digits) { digit.repeat(1) }
rule(:xdigit) { digit | match('[a-fA-F]') }
@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 }
#!/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 / 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'
@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 / 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 / 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 / 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.
#