Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'dm-core'
require 'pp'
DataMapper::Logger.new($stderr, :debug)
DataMapper.setup(:default, adapter: :postgres, database: 'dmbug')
class User
include DataMapper::Resource
property :id, Serial
@shanna
shanna / echo.c
Created April 23, 2010 07:27 — forked from paulsmith/echo.c
/**
* A simple preforking echo server in C.
*
* Building:
*
* $ gcc -Wall -o echo echo.c
*
* Usage:
*
* $ ./echo
require 'minitest/unit'
require 'minitest/spec'
require 'ansi'
class MiniTest::Unit
include ANSI::Code
PADDING_SIZE = 4
def run(args = [])
require 'rack'
require 'thin'
module Rack
module Test
class App
# Attempt to run a Rack app server instance in the same process as the a
# 'work' block. Came about because you can't see an unsaved DB transaction
# inside the Rack app if it happens in another process.
#
// Hacky prototype weak identity map extension.
#include <iostream>
#include <string>
#include <map>
#include <ruby/ruby.h>
#define ID_CONST_GET rb_intern("const_get")
#define CONST_GET(scope, constant) (rb_funcall(scope, ID_CONST_GET, 1, rb_str_new2(constant)))
require 'benchmark'
require 'sexpistol'
require 'sxp'
require 'strscan'
class Lexer < StringScanner
def next_token
# Housekeeping.
skip /\s*/
@shanna
shanna / Notes.rdoc
Created February 23, 2011 09:46
Sinatra routing inconsistency.
  • Original patch (no longer around) patching the inconsistency wasn’t deemed an API change not a bug in the lighthouse ticket and rejected.

  • Depending on oniguruma regexp removes a bunch of code. Legacy 1.8 users would need oniguruma which apparently isn’t an option because of people unlucky enough to be dealing with JRuby.

  • I was too lazy to both keep the inconsistency and support named groups properly while providing backwards compatibility for 1.8 users so I gave up and we run a fork.

  • I’ve been waiting for a major version bump (hence the tweet) to be in the works to satisfy semantic versioning since whoever rejected the ticket doesn’t think it’s a bug.

@shanna
shanna / gist:884377
Created March 24, 2011 01:12
shingles.rb
require 'set'
#==== See
# * http://github.com/matpalm/resemblance
class String
module Shingles
N_GRAM_LENGTH = 3
def shingles
@shingles ||= -> do
@shanna
shanna / gist:945986
Created April 28, 2011 07:51
Sinatra::Map
require 'sinatra/base'
require 'rack/utils'
module Sinatra
class Base
module Map
def map path, klass
path = map_compile path
[:get, :put, :post, :delete, :head].each do |verb|
send(verb, path) do
@shanna
shanna / installation.sh
Created June 20, 2011 16:38 — forked from mikhailov/installation.sh
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details: http://mikhailov.posterous.com/nginx
$ cd /usr/src
$ wget http://nginx.org/download/nginx-0.8.52.tar.gz
$ tar xzvf ./nginx-0.8.52.tar.gz
$ rm ./nginx-0.8.52.tar.gz
$ gem install s3sync capistrano capistrano-ext passenger --no-ri --no-rdoc
$ passenger-install-nginx-module
# Automatically download and install Nginx? 2. No: I want to customize my Nginx installation
# Where is your Nginx source code located?: /usr/src/nginx-0.8.52
# Where do you want to install Nginx to?: /opt/nginx