Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile
#!/bin/bash
FROM=$1
TO=$2
echo "Spliting '$TO' from '$FROM'"
git clone --no-hardlinks $FROM $TO
cd $TO
git filter-branch --subdirectory-filter $TO HEAD -- --all
git reset --hard
git gc --aggressive
git prune
@snusnu
snusnu / omg.rb
Created March 16, 2010 15:47 — forked from wycats/omg.rb
require ".bundle/environment"
Bundler.setup
require "action_controller/railtie"
class FooController < ActionController::Base
def bar
self.response_body = "HELLO"
end
end
#!/usr/bin/env ruby
# Collects trace stats using mtr. Accepts the following environment variables
# and delegates all real arguments to the underlying call to the mtr program.
#
# VERBOSE=true REPORT_DIR=/path/to/report ENDPOINTS=foo.com,bar.com THRESHOLD=10.0 ./rmtr.rb foo.com -r -c 1000
require 'fileutils'
THRESHOLD = ENV['THRESHOLD' ].to_i || 10
require 'rubygems'
require 'dm-core'
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
class Person
include DataMapper::Resource
property :id, Serial
property :name , String, :required => true
# Don't use this in production code! Extending lots of objects during runtime
# will have a negative impact on performance/memory because ruby clears out
# the method cache.
#
# A better approach to implement this is to write a custom DataMapper::Type that
# delegates all methods to the underlying BigDecimal and just overwrites #to_s
# Why on earth haven't I thought about that before! Thx dkubb :P
#
#
# When this module is activated, it will round all BigDecimal property values
  #dom_id => #to_s  # defaults to :id in AMo and does some yet to find out default in dm

And to make the following change in action_controller

  # action_controller/record_identifier:63
  if record_id = record.to_model.dom_id
@snusnu
snusnu / gist:306316
Created February 17, 2010 04:57 — forked from hassox/gist:306313
class ShardingMiddleware
def initialize(app)
@app = app
end
def call(env)
env['warden'].authenticate!
repo_name = env['warden'].account.repository_name
result = nil
Spec::Runner.configure do |config|
config.before do
repository do |r|
transaction = DataMapper::Transaction.new(r)
transaction.begin
r.adapter.push_transaction(transaction)
end
end
module ParameterSanitization
def self.included(host)
host.extend(ClassMethods)
host.send(:include, InstanceMethods)
end
module ClassMethods
attr_reader :resource, :properties_to_sanitize
def sanitize_resource_params(resource, *properties)
def with_dm_logger(level = :debug)
DataObjects::Mysql.logger.level = level
yield
ensure
DataObjects::Mysql.logger.level = :off
end