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 / 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|
@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 / 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 / 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
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