Skip to content

Instantly share code, notes, and snippets.

create_table :relationships do |t|
t.belongs_to :entity_left, polymorphic: true
t.belongs_to :entity_right, polymorphic: true
t.string :relationship_type
t.string :relationship_type_other
t.integer :ownership_percentage # For beneficial ownership
t.boolean :relationship_continues # For institution relationships
t.date :actioned_at # For institution relationships
t.string :status # For institution relationships
t.jsonb :other_metadata # For other relationships
@thegorgon
thegorgon / csv-chunker.rb
Last active July 22, 2021 20:32
CSV Chunker in Ruby
#! /usr/bin/env ruby
require 'fileutils'
require 'optparse'
require 'csv'
chunks = [[]]
options = { input: nil, output: nil, size: 1000 }

Keybase proof

I hereby claim:

  • I am thegorgon on github.
  • I am jreiss (https://keybase.io/jreiss) on keybase.
  • I have a public key whose fingerprint is 93AC 97F4 9EC7 F653 425B AEAC 8F86 D4A1 4B49 63F6

To claim this, I am signing this object:

@thegorgon
thegorgon / gist:88dae691a467bc9b293a
Last active August 29, 2015 14:14
Query for Superbowl Order Size by Region
SELECT
service_regions.name region_name,
COUNT(orders.id) order_count,
AVG(orders.price) avg_price,
STDDEV_POP(orders.price) std_price,
MIN(orders.price) min_price,
MAX(orders.price) max_price
FROM orders
INNER JOIN service_regions ON service_regions.id = orders.service_region_id
WHERE
@thegorgon
thegorgon / gist:86c662d15bfbd893f16d
Last active August 29, 2015 14:14
Query for Superbowl Offer Volume by Region
SELECT
service_regions.name region_name,
SUM(cart_items.quantity) total_quantity,
offers.name offer_name
FROM
orders
INNER JOIN cart_items ON cart_items.order_id = orders.id
INNER JOIN offers ON offers.id = cart_items.offer_id
INNER JOIN service_regions ON service_regions.id = orders.service_region_id
WHERE
@thegorgon
thegorgon / cleanup.sh
Created August 18, 2011 19:03
Cleanup Release Directory
function cleanup() {
for release in `ls -x /u/app/releases/`
do
if [ $release != "./" -a $release != "../" -a "`readlink /u/app/current`/" != "/u/app/releases/$release" ]; then `rm -rf /u/app/releases/$release`; fi
done
}
@thegorgon
thegorgon / wikicrawler.rb
Created May 26, 2011 18:24
Wikipedia Crawler
#!/usr/bin/ruby
require 'curb'
require 'nokogiri'
require 'cgi'
loop do
puts "What would you like to search? (:quit to exit)"
search = gets
break if search.strip == ":quit" || search.strip.length == 0
@thegorgon
thegorgon / uniq_constants.rb
Created April 14, 2011 19:41
Sometimes you want enumerable style uniqueness in class constants. This raises an error if two constants are defined with the same value.
class DuplicateConstantError < StandardError; end
module UniqConstants
def uniq_constants!
values = constants.group_by { |c| const_get(c) }
dupes = values.values.select { |a| a.length > 1 }
raise DuplicateConstantError, "Duplicate constants defined : #{dupes.flatten.inspect}" if dupes.present?
end
end
(function($) {
$.provide = function(object, name, features) {
object[name] = object[name] || {};
$.extend(object[name], features);
return object;
};
}(jQuery));
// Use Case :
// $.provide(GlobalObject, "Feature", {