Skip to content

Instantly share code, notes, and snippets.

View barrettclark's full-sized avatar

Barrett Clark barrettclark

View GitHub Profile
AllCops:
DisabledByDefault: true
TargetRubyVersion: 2.4
Bundler/DuplicatedGem:
Enabled: true
Bundler/OrderedGems:
Enabled: true
@barrettclark
barrettclark / README.md
Last active January 14, 2016 02:09 — forked from mbostock/.block
Donut Chart

This donut chart is constructed from a CSV file storing the populations of various age groups. The chart employs a number of D3 features:

WITH raw_data AS (
SELECT jurisdictions AS county, median_value AS value
FROM maryland_residential_sales_figures
WHERE median_value > 999
), ntiles AS (
SELECT county,
value,
ROW_NUMBER() OVER (PARTITION BY county ORDER BY value) AS row_number,
COUNT(*) OVER (PARTITION BY county ) AS total,
NTILE(2) OVER (PARTITION BY county ORDER BY value) AS bitile
@barrettclark
barrettclark / load_db_from_heroku.rake
Last active March 11, 2016 20:43
Rake task to load production data (from Heroku) to the local dev database
namespace :db do
namespace :heroku do
desc "capture DB Backup"
task :capture_backup => :environment do
if Rails.env == 'development'
Bundler.with_clean_env do
config = Rails.configuration.database_configuration[Rails.env]
system "heroku pg:backups capture"
end
end
@barrettclark
barrettclark / words.rb
Last active August 29, 2015 14:08
Whirly Word Solver
class WordList
attr_reader :words
def initialize
@words = Array.new
read_list
end
def check_letters(*letters)
letter_counts = letters.each_with_object(Hash.new(0)) { |letter, counts| counts[letter] += 1 }
@barrettclark
barrettclark / Rakefile
Last active August 29, 2015 14:07
A Rakefile to manage dev instances using Docker, boot2docker, and fig for configuration management.
namespace :boot2docker do
desc 'Start VM from any states'
task :start do
%x(boot2docker start > /dev/null 2>&1)
end
desc 'Setup shell'
task :shellinit => [:start] do
# NOTE: this does not set the env, so we have to do something different
# %x($(boot2docker shellinit > /dev/null 2>&1))
@barrettclark
barrettclark / pascal_triangle.rb
Created July 19, 2012 02:52
Pascal's Triangle Problem (recursive solution)
class PascalTriangle
def initialize
@digits = []
end
def calculate_row(row)
row = row.to_f
0.upto(row) { |column| @digits << calculate_number(row, column).to_i }
@digits
end
@barrettclark
barrettclark / Rakefile
Created January 7, 2011 17:44
Example file download rake task
require 'rake'
# http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html
require 'net/http'
desc "this is a test"
task :testing_rake do
puts "Hello from rake!"
end
namespace :remote_file do
" bind command-/ to toggle comment
" requires NERD Commenter to be installed: http://www.vim.org/scripts/script.php?script_id=1218
nmap <D-/> ,c<space>
vmap <D-/> ,c<space>
imap <D-/> <C-O>,c<space>
" bind \d to toggle file browser
" requires NERDTree
nmap <leader>d :NERDTreeToggle<CR>