Skip to content

Instantly share code, notes, and snippets.

View parrish's full-sized avatar

Michael Parrish parrish

View GitHub Profile
@parrish
parrish / pg_locks.sql
Created June 30, 2016 14:33
Show info on postgres locks
SELECT bl.pid AS blocked_pid,
a.usename AS blocked_user,
ka.query AS current_statement_in_blocking_process,
now() - ka.query_start AS blocking_duration,
kl.pid AS blocking_pid,
ka.usename AS blocking_user,
a.query AS blocked_statement,
now() - a.query_start AS blocked_duration
FROM pg_catalog.pg_locks bl
JOIN pg_catalog.pg_stat_activity a ON a.pid = bl.pid
[
{
"left": 1,
"right": 2,
"operator": "<"
},
"and",
[
{
"left": 2,
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)
@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()
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 / 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
@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 / 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 / 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 / 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|