This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_sql_creates | |
counts = Hash.new(0) | |
logger = -> (event, start, finish, id, payload) do | |
if (table = payload[:sql][/INSERT INTO "(.+?)"/, 1]) | |
counts[table] += 1 | |
end | |
end | |
subscription = ActiveSupport::Notifications.subscribe('sql.active_record', logger) | |
yield | |
ActiveSupport::Notifications.unsubscribe(subscription) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Change tab color based on pwd. | |
# | |
# If a directory contains a .tabcolor file, it will use the lines of that file | |
# as RGB values. It should look like: | |
# | |
# 255 | |
# 128 | |
# 96 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Usage: | |
# $ ruby code-challenge.rb <github.com repo> | |
repo = ARGV[0] | |
# Clear previous challenge | |
puts "Removing previous directories" | |
`rm -rf coding-challenge-source` | |
`rm -rf coding-challenge` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'awesome_print' | |
# Put this file into your spec/support directory in order to have RSpec automatically report | |
# on the total number of database records created during a run of your test suite. | |
class ActiveRecordInsertCountReport | |
include Singleton | |
def subscribe_to_notifications | |
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args| | |
name, start, ending, transaction_id, payload = args | |
table_name = payload[:sql][/insert into "(.+?)"/i, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RingBuffer | |
def initialize(redis=nil, list_key=nil) | |
@redis = redis | |
end | |
def next | |
JSON(@redis.rpoplpush(@list_key, @list_key))[0] | |
end | |
def add(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Set terminal tab / decoration color by the server name. | |
Get a random colour which matches the server name and use it for the tab colour: | |
the benefit is that each server gets a distinct color which you do not need | |
to configure beforehand. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Git Prepare Commit Message Hook Script | |
# | |
# Location: <repository>/.git/hooks/prepare-commit-msg | |
# | |
# This script will automatically add the correct | |
# JIRA ISSUE ID to the end of each commit message | |
# When the branch ID starts with the JIRA ISSUE ID. | |
# It can be overridden if specified in the message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Base | |
def self.find_each_by(column, options={}, &block) | |
return enum_for(:find_each_by_column) unless block_given? | |
last_value = last_id = nil | |
order = options.fetch(:order, :asc) | |
batch_size = options.fetch(:batch_size, 1000) | |
operator = order == :asc ? '>=' : '<=' | |
loop do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(window.open().document.body).html( | |
"<style>textarea { font-size: large; font-family: monospace;}</style>" + | |
"<h4>Cucumber failures</h4><textarea style='height: 25%;width: 100%'>cucumber " + | |
$.makeArray($.unique( | |
$('span.red').filter(function() { | |
return (this.textContent).match(/cucumber .+:\d+/) | |
}).map(function() { | |
return $(this).text().match(/cucumber (.+)/)[1] | |
}) | |
).sort()).join(' ') + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
class Parser | |
def parse(string) | |
stack = [] | |
tokens = string.split(' ') | |
tokens.each do |token| | |
if token =~ /\d/ | |
value = token.to_i |
NewerOlder