Skip to content

Instantly share code, notes, and snippets.

View parrish's full-sized avatar

Michael Parrish parrish

View GitHub Profile
@parrish
parrish / unique_classifiers.js
Created May 15, 2014 19:55
MongoDB unique classifiers per day
var userMap = function() {
day = Date.UTC(this.created_at.getFullYear(), this.created_at.getMonth(), this.created_at.getDate());
emit({ day: day, user_id: this.user_id }, { count: 1 });
}
var userReduce = function(key, values) {
var count = 0;
values.forEach(function(v) {
count += v['count'];
@parrish
parrish / pre-commit
Last active August 29, 2015 14:03
Git whitespace pre-commit hook
#!/bin/sh
# http://stackoverflow.com/a/6262715
# .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
# A git hook script to find and fix trailing whitespace
# in your commits. Bypass it with the --no-verify option
# to git-commit
#
@parrish
parrish / throttle.bash
Created June 25, 2014 17:57
OS X bandwidth throttling
function dethrottle {
sudo ipfw delete 1
}
function throttle {
if test $# -eq 0
then
echo 'throttle <port> <bandwidth (KB)>'
elif test $# -eq 1
then
@parrish
parrish / combine_chimp_csv.rb
Created June 11, 2015 17:22
Combines chimp discussion data with chimp classification data
#!/usr/bin/env ruby
date = ARGV[0]
unless date
puts "usage: ruby #{ __FILE__ } <date>"
puts " eg: ruby #{ __FILE__ } 2015-06-07"
exit
end
require 'spec_helper'
# Think you've fixed it? Try
# `while rake spec:controllers; do :; done`
# and grab a coffee
RSpec.describe SomethingsController, type: :controller do
# ...
describe '#create' do
# ...
@parrish
parrish / deferred_proxy.rb
Created February 26, 2012 01:02
DeferredProxy
require 'thread'
require 'fiber'
require 'benchmark'
include Benchmark
class DeferredProxy < BasicObject
def initialize(&block)
@fiber = ::Fiber.new do
thread = ::Thread.new{ @result = block.call }
::Fiber.yield
@parrish
parrish / bundle_app.rb
Created March 6, 2012 21:05
Bundle App
require 'rubygems'
require 'aws-sdk'
is_clean = `git diff-index HEAD`.chomp.empty?
unless is_clean
puts 'You currently have uncommitted changes. Stash or commit them before bundling.'
exit
end
@parrish
parrish / account-bar.cjsx.diff
Created December 7, 2015 21:31
account-menu hacky work around
diff --git a/app/partials/account-bar.cjsx b/app/partials/account-bar.cjsx
index 0976873..435711c 100644
--- a/app/partials/account-bar.cjsx
+++ b/app/partials/account-bar.cjsx
@@ -46,6 +46,9 @@ module.exports = React.createClass
@setState {unread: !!conversations.length}
.catch (e) -> throw new Error(e)
+ close: ->
+ document.querySelector('.account-menu.modal-form-underlay').click()
@parrish
parrish / bson2json
Created July 25, 2013 20:42
Convert BSON to a valid JSON document
#!/usr/bin/env ruby
data = `bsondump #{ ARGV[0] }`.chomp
data.gsub! /ObjectId\(\s?(\"\w+\")\s?\)/, '\1'
data.gsub! /Date\(\s?(\w+)\s?\)/, '\1'
data = data.split "\n"
data = "[#{ data.join(', ') }]"
File.open(ARGV[1], 'w') do |f|
SELECT
"access_control_lists".*
FROM "access_control_lists"
WHERE
("access_control_lists"."roles" && '{owner}') AND
"access_control_lists"."resource_type" = 'Project' AND
"access_control_lists"."resource_id" IN (53, 55)