Skip to content

Instantly share code, notes, and snippets.

Danny Cosson dcosson

Block or report user

Report or block dcosson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dcosson
dcosson / ableton-pre-commit.py
Created Mar 3, 2012
Quick first attempt at using git for Ableton Live projects.
View ableton-pre-commit.py
#!/usr/bin/env python
""" A pre-commit git hook that gunzips the .als file and adds the resulting xml file to the git staging index.
Caveat:
It doesn't work perfectly to do a `git add` in a pre-commit hook - if nothing else in the repo has changed,
the pre-commit won't even be fired so nothing happens. If something else has changed, the pre-commit hook
doesn't get fired in time for the files it creates to show up in the list of files to be committed but the
files it creates do actually go into the commit. So it works, but that's kind of weird.
View google_directory_service.py
import json
import os
from googleapiclient import discovery
from oauth2client.service_account import ServiceAccountCredentials
def authenticated_directory_service(delegate_user_email):
""" Returns a service object for accessing the admin directory service.
"""
json_creds = json.loads(os.environ['GOOGLE_KEYFILE_JSON'])
@dcosson
dcosson / gist:3686437
Created Sep 9, 2012
Compile Vim on OSX (Mountain Lion)
View gist:3686437
# default vim on osx doesn't have python, ruby support or clipboard support. These configure options add all that
# I also ran into problems using rvm ruby, had to include those libs in the LDFLAGS for vim
# Steps:
$ rvm install 1.9.1
$ rvm use 1.9.1 # vim doesn't support anything higher
$ curl ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2 | tar xj
$ cd vim73
$ ./configure --with-features=huge --enable-perlinterp=yes --enable-rubyinterp=yes --enable-pythoninterp=yes --enable-multibyte
@dcosson
dcosson / postgres-is-locked.md
Last active Jun 2, 2016
Dealing with weird migrations/table updates that have locked postgres
View postgres-is-locked.md

See what is waiting on what:

SELECT 
    waiting.locktype           AS waiting_locktype,
    waiting.relation::regclass AS waiting_table,
    waiting_stm.query          AS waiting_query,
    waiting.mode               AS waiting_mode,
    waiting.pid                AS waiting_pid,
    other.locktype             AS other_locktype,
    other.relation::regclass   AS other_table,
View postgres-biggest-relations-size.md

For my own future reference, here's a query for finding size of the biggest relations in postgres, the tables and indexes. Taken from the wiki, but I've modified it so any pg_toast tables also display the tablename that they come from.

SELECT CASE WHEN relname like 'pg_toast%' THEN CONCAT(relname, ' (', CAST(rtrim(ltrim(relname, 'pg_toast_'), '_index') as INTEGER)::regclass, ')') ELSE relname END as relation, pg_size_pretty(pg_relation_size(C.oid)) AS "size" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') ORDER BY pg_relation_size(C.oid) DESC LIMIT 50;
@dcosson
dcosson / add_ssh_key_from_s3.sh
Last active Nov 26, 2015
Add private key stored in S3 to ssh-agent
View add_ssh_key_from_s3.sh
#!/bin/bash
#
# Download the specified ssh private key from s3 and add it to the ssh-agent so
# we can make requests to a git remote using it.
#
# Works by piping the ascii key through a named pipe to get it from standard
# out to a file descriptor that the ssh-add utility can read. The benefit of
# this over just saving it to a tmp file is the key never touches disk.
# Parse args
@dcosson
dcosson / gist:3839768
Created Oct 5, 2012
Count viewers on a mongrel2 site
View gist:3839768
# bash command to count the number of unique ip addresses in the mongrel2 access log (default format)
cat mongrel2.access.log | cut -f 4 -d : | cut -f 1 -d , | sort | uniq | wc -l
@dcosson
dcosson / gist:3430463
Created Aug 22, 2012
Phone number regex in js
View gist:3430463
// allows:
// 1235554567
// (123) 555-4567
// 123.555.4567
// 123-555-4567
/^\(?[0-9]{3}[.\-\)]?\s?[0-9]{3}[.-\s]?[0-9]{4}$/
@dcosson
dcosson / gist:3321717
Created Aug 11, 2012
kill zombie procs
View gist:3321717
# a quick shell command to kill all procs matching a grep pattern
for i in `ps aux | grep 'manage.py runserver' | grep -v grep | awk '{ printf "%s ", $2 }'` ; do sudo kill $i ; done
@dcosson
dcosson / gist:2918201
Created Jun 12, 2012
Archive a website (in this case, tourbie.com)
View gist:2918201
# Just a note to myself on how to archive a website
mkdir tourbie_archive
cd tourbie_archive
wget --mirror -p -nH -e robots=off --convert-links http://tourbie.com
# --mirror mirrors the site (recurses all links)
# -p downloads all the links necessary to view the site
# --convert-links converts all links starting with http://tourbie.com to be relative
# -e robots=off optional, ignore robots.txt (on tourbie.com, I had disallowed the static files directory in robots.txt)
You can’t perform that action at this time.