Skip to content

Instantly share code, notes, and snippets.


Jake Moffatt jakeonrails

View GitHub Profile
jakeonrails / gist:c2f302bce7b1e4707faa
Created Apr 11, 2015
Circle CI Failure Bookmarklet
View gist:c2f302bce7b1e4707faa
"<style>textarea { font-size: large; font-family: monospace;}</style>" +
"<h4>Cucumber failures</h4><textarea style='height: 25%;width: 100%'>cucumber " +
$('').filter(function() {
return (this.textContent).match(/cucumber .+:\d+/)
}).map(function() {
return $(this).text().match(/cucumber (.+)/)[1]
).sort()).join(' ') +
View find_each_by_column.rb
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
jakeonrails / prepare-commit-message
Last active Aug 29, 2015
prepare-commit-message that requires a JIRA ID and adds it if the branch name contains one
View prepare-commit-message
#!/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.
jakeonrails / report_model_creation_counts.rb
Created Nov 10, 2011
Spits out a report at the end of your tests on how many times each model was created
View report_model_creation_counts.rb
if Rails.application.config.report_model_creation_counts
class ReportModelCreationCounts < ActiveRecord::Observer
@@creates = { |hash, key| hash[key] = 0 }
def after_create(record)
@@creates[record.class] += 1
jakeonrails / log_test_names.rb
Created Nov 10, 2011
Logs the current example before and after it runs
View log_test_names.rb
if Rails.application.config.log_test_names
RSpec.configure do |config|
config.before(:each) do |x|'*' * 10 + 'Start Example: ' + x.example.metadata[:example_group][:full_description])
config.after(:each) do |x|'*' * 10 + 'Finish Example: ' + x.example.metadata[:example_group][:full_description])
View sidebar.html.erb
<% @categories.each do |category| %>
<ul class="X">
<h5><%= link_to, category %></h5>
<% end %>
jakeonrails / api.rb
Created Dec 14, 2011
Loading a class inside a module within Rails 3.0
View api.rb
# within app/importer/api.rb
module Importer
class API
# class body here
jakeonrails / rubymine.log
Created Jan 31, 2012
rubymine markdown log
View rubymine.log
This file has been truncated, but you can view the full file.
2012-01-27 18:12:33,517 [4154324] INFO - plication.impl.ApplicationImpl - Not enough pooled threads; creating one at:
at com.intellij.openapi.application.impl.ApplicationImpl$1.newThread(
at java.util.concurrent.ThreadPoolExecutor.addThread(
at java.util.concurrent.ThreadPoolExecutor.addIfUnderMaximumPoolSize(
at java.util.concurrent.ThreadPoolExecutor.execute(
at java.util.concurrent.AbstractExecutorService.submit(
at com.intellij.openapi.application.impl.ApplicationImpl.executeOnPooledThread(
at com.intellij.openapi.project.FileContentQueue.queue(
jakeonrails / xml_parser.rb
Created Feb 11, 2012 — forked from kmile/xml_parser.rb
A small nokogiri xml reader DSL.
View xml_parser.rb
# A small DSL for helping parsing documents using Nokogiri::XML::Reader. The
# XML Reader is a good way to move a cursor through a (large) XML document fast,
# but is not as cumbersome as writing a full SAX document handler. Read about
# it here:
# Just pass the reader in this parser and specificy the nodes that you are interested
# in in a block. You can just parse every node or only look inside certain nodes.
# A small example:
jakeonrails / robot_user_agents.rb
Created Oct 15, 2012 — forked from Sjors/robot_user_agents.rb
Recognize search engines and spammers using
View robot_user_agents.rb
require 'net/http'
require 'xmlsimple'
url = ""
xml_data = Net::HTTP.get_response(URI.parse(url)).body
data = XmlSimple.xml_in(xml_data)
agents = data['user-agent'].select{|agent| type = agent["Type"].first; type.include?("R") || type.include?("S")}
agent_names = agents.collect {|agent| agent["String"].first}