Skip to content

Instantly share code, notes, and snippets.

View dhotson's full-sized avatar

Dennis Hotson dhotson

View GitHub Profile
@dhotson
dhotson / oedipus.rb
Created May 14, 2012 11:08
Oedipus Sphinx2 rails instrumentation
# config/initializers/oedipus.rb
require "oedipus"
# Monkey patch in oedipus instrumentation
module Oedipus
class LogSubscriber < ActiveSupport::LogSubscriber
def search(event)
output = "%s (%.2fms)" % ['Sphinx', event.duration]
debug " #{color(output, RED, true)}"
build tools {
build-essential {
apt {
package manager {
'apt-get' runs from /usr/bin.
} ✓ package manager
apt source {
} ✓ apt source
apt source {
} ✓ apt source
dep "sphinx.src" do
source "http://sphinxsearch.com/files/sphinx-2.0.4-release.tar.gz"
define_var :base_dir, :default => Pathname.new(File.dirname(__FILE__) + "/../lib/sphinx2").cleanpath
provides var(:base_dir) + "/bin/searchd"
prefix var(:base_dir)
install { shell "make install" }
meet do
shell "mkdir -p #{var(:base_dir) / 'binlog'}"
@dhotson
dhotson / chipmunk.rb
Created June 22, 2012 13:23
Example of Chipmunk Physics library usage in Ruby
# See: https://github.com/beoran/chipmunk/tree/master/spec
# + http://chipmunk-physics.net/release/ChipmunkLatest-Docs/
require 'chipmunk' # gem install chipmunk
s = CP::Space.new
s.gravity = vec2(0,0)
b1 = CP::Body.new(5, 7)
b1.pos = vec2(400,600)
b1.v = vec2(30,1)
# screen had it right, C-B is too hard to reach.
unbind C-b
set -g prefix `
# set -g prefix `
# http://blog.hawkhost.com/2010/06/28/tmux-the-terminal-multiplexer/
unbind %
bind | split-window -h
bind - split-window -v
def fib
f0, f1 = 0, 1
loop do
f0, f1 = f1, (f0 + f1)
r = yield f1
return if !r
end
end
fib do |n|
<?php
function ($) {
echo "Hello $!\n";
}
("world");
function test($̀a) { echo $̀a; }
test("zomg!\n");
<?php
function ($hello, $hello, $̀) {
echo "$hello$hello$̀\n";
}
("lolol", "trolo", "!");
<?php
require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../lib/kelpie/lib/kelpie.php';
require_once 'KelpieSymfonyAdaptor.php';
$app = new Silex\Application();
$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello '.$app->escape($name);
});
<?php
use Symfony\Component\HttpFoundation\Request;
class KelpieSymfonyAdaptor
{
public function __construct($app)
{
$this->_app = $app;
}