Skip to content

Instantly share code, notes, and snippets.

View Fitzsimmons's full-sized avatar

Justin Fitzsimmons Fitzsimmons

View GitHub Profile
@Fitzsimmons
Fitzsimmons / ssh_into_ey_cloud.rb
Last active August 29, 2015 14:06
Quick way to ssh into every slice in an environment on EY Cloud
=begin
USAGE:
ruby ssh_into_ey_cloud.rb [name of environment]
=end
environment = ARGV[0]
require "rspec/core/formatters/base_text_formatter"
require 'headless'
require 'fileutils'
class AcceptanceVideoFormatter < RSpec::Core::Formatters::BaseTextFormatter
def initialize(output)
@headless = Headless.new(
video: {
nomouse: true,
@Fitzsimmons
Fitzsimmons / next_break_return.txt
Last active December 29, 2015 13:49
Showing the various ways of returning a value from a block (or failing to do so).
irb(main):001:0> A = [1,2,3]
=> [1, 2, 3]
irb(main):002:0> def test_next
irb(main):003:1> puts A.map{|x| next x}.inspect
irb(main):004:1> puts "Finished nexting!"
irb(main):005:1> end
=> nil
irb(main):006:0> test_next
[1, 2, 3]
Finished nexting!
@Fitzsimmons
Fitzsimmons / Clojure Confusion
Created November 20, 2013 17:04
Clojure Confusion
Sometimes it works...
Digest: [18 8c ab df 4a 78 3a 31 2e 9a 57 94 a8 b 76 42 6c 12 3d 83]
Offset: 3
Excerpt: [df 4a 78 3a]
Unsigned: [5f 4a 78 3a]
Squashed: 5f4a783a
------------------
WITH unified_materials AS(
-- Find the base materials (used to calculate the 'base price' for an item?)
SELECT typename, quantity FROM invtypematerials AS mats
INNER JOIN invtypes ON invtypes.typeid = mats.materialtypeid
WHERE mats.typeid = 11993
UNION
-- Find the complex materials (Never present in T1 stuff)
SELECT invtypes.typename,
@Fitzsimmons
Fitzsimmons / example_migration.rb
Created November 23, 2012 22:06
A quick and dirty example of how to import mongo documents into a postgres hybrid document store
require 'pg'
require 'mongo'
require 'nokogiri'
mongo_conn = Mongo::Connection.new.db("qcloud_dev")
pg_conn = PG.connect(:dbname => "poc")
standards_collection = mongo_conn["standards"]
sheets_collection = mongo_conn["sheets"]
def index
arel = DocumentFilter.find(params)
@documents = Pager.new(arel, :page => params[:page]).paged_results
end
non_paged_count | id [extra columns omitted]
-----------------+--------
130 | 239184
130 | 239183
[98 additional records omitted]
@Fitzsimmons
Fitzsimmons / pager.rb
Created October 31, 2012 19:20
Framework our quick hack to avoid the extra queries from Kaminari
class Pager
attr_reader :arel, :page, :per_page
def initialize(arel, options={})
@arel = arel
@page = Integer(options[:page]) rescue 1
@per_page = Integer(options[:per_page]) rescue arel.klass.default_per_page
end
def paged_results
@Fitzsimmons
Fitzsimmons / arel.rb
Created October 31, 2012 19:19
Modify an existing arel query to use the window function for the non_paged_count
results = arel.
select("COUNT(#{table_name}.id) OVER () AS non_paged_count, #{table_name}.*").
offset(offset).
limit(per_page).all