Skip to content

Instantly share code, notes, and snippets.

@leshill
leshill / git-peruse
Last active August 29, 2015 13:57
Peruse a git branch from a commit to the HEAD in chronological order (oldest to newest). Now with support for navigating across merges.
#!/bin/bash
#
# Peruse a git branch from a commit to the HEAD in chronological order (oldest
# to newest). This uses `git rev-list` to find the child commits; read up on
# the default mode.
#
# v0.2 Added support for folks who merge :)
#
delete_tag() {
Dir[File.dirname(__FILE__) + '/factories/*.rb'].each { |file| require file }
module AVCacheTTL
def self.included(base)
base.alias_method_chain :cache, :ttl
end
def cache_with_ttl(name = {}, options = nil, &block)
options = (options || {}).dup
return block.call if options.delete(:ignore_cache)
time = options.delete(:ttl)
time = time.from_now if time.respond_to?(:from_now)
#!/usr/bin/env ruby
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
require 'rubygems' unless ENV['NO_RUBYGEMS']
else
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT)
end
start_time = Time.now
puts "Starting MongoDB Benchmark..."
100000.times do |n|
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT)
start_time = Time.now
puts "Starting CouchDB Benchmark..."
100000.times do |n|
Person.new(:first_name => "Couch_#{n}", :last_name => "Man_#{n}").save
end
puts (Time.now - start_time)
class Hash
def intersection_equal?(other)
all? {|k, v| other.has_key?(k) ? other[k] == v : true }
end
end
# require 'webrat_ext'
module Webrat
module Methods
delegate_to_session :current_path
end
class Session
def current_path
URI.parse(current_url).path
end
# Ryan, the hits in the db approach is flawed (not currently atomic, and
# probably not really performant for high rates) -- but you knew that.
# So in the spirit of gets it done, I have followed along.
#
# API Example
## User Model
require 'digest/md5'
class User < ActiveRecord::Base
API_RATE_LIMIT_WINDOW = 2.minutes
def javascript_confirm(answer)
page.evaluate_script 'window._confirm = window.confirm'
page.evaluate_script "window.confirm = function(x) { return #{answer} }"
yield
page.evaluate_script 'window._confirm && (window.confirm = window._confirm)'
page.evaluate_script 'window._confirm = null'
end
class Array
def method_missing(method, *args, &block)
if key_value = dynamic_mapper?(method)
map_dynamically(key_value[1], key_value[2])
else
super
end
end
def dynamic_mapper?(method)