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
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 /
Last active Jun 2, 2016
Dealing with weird migrations/table updates that have locked postgres

See what is waiting on what:

    waiting.locktype           AS waiting_locktype,
    waiting.relation::regclass AS waiting_table,
    waiting_stm.query          AS waiting_query,
    waiting.mode               AS waiting_mode,                AS waiting_pid,
    other.locktype             AS other_locktype,
    other.relation::regclass   AS other_table,

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 /
Last active Nov 26, 2015
Add private key stored in S3 to ssh-agent
# 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 / gist:2defd0bd596f00e14f60
Last active Aug 29, 2015
Add an extra share button to mave
View gist:2defd0bd596f00e14f60
MaveSDK *mave = [MaveSDK sharedInstance];
[mave presentInvitePageModallyWithBlock:^(UIViewController *inviteController) {
if ([inviteController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navController = (UINavigationController *)inviteController;
// Here replace the method "foo" with your method to present a share sheet
// And you can of course use a button with an image instead of the title "Share"
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithTitle:@"Share"
target:self action:@selector(foo)];
dcosson / gist:27bcca9b9ad28a38ab60
Last active Aug 29, 2015
Rename an ios project
View gist:27bcca9b9ad28a38ab60

I was renaming a project from GrowthKit to Mave, and updating the prefix.

This got me 95% of the way there, there were a few things to clean up manually (not really sure why because the things I fixed manually matched these rules). Luckily the previous project name wasn't "View" or something that would conflict with any builtin types or setting names

rm -rf Pods
brew install rename 
shopt -s globstar     # requires bash 4.0+, makes ** recursive

rename s/GrowthKit/Mave/ **
dcosson /
Last active Aug 29, 2015
Flask Hello
# Simple http server to test concurrency or load balancing or whatever,
# specifying numprocs greater than 1 will run that many instances of the
# flask app in subprocesses on incrementing ports beginning with the one specified
# Run:
# sudo pip install flask
# python [PORT-NUM] [NUMPROCS]
from flask import Flask
import os
import signal

Keybase proof

I hereby claim:

  • I am dcosson on github.
  • I am dcosson ( on keybase.
  • I have a public key whose fingerprint is 7315 7FF6 9E72 ABBC 1CB1 0C11 5399 BD81 8F48 C11F

To claim this, I am signing this object:

View open-r10k-repo-pull-request
# Uses github's hub command line tool and r10kdiff gem to open a pull request
# for a repository containing a Puppetfile used by r10k.
# Assumes it should be from the current branch <Puppet Environment Name> in a
# fork to the same branch upstream (since you can't use feature branches in the
# same repository with r10k as it might deploy them as environments)
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
You can’t perform that action at this time.