Skip to content

Instantly share code, notes, and snippets.

View dcosson's full-sized avatar

Danny Cosson dcosson

  • San Francisco, CA
View GitHub Profile
@dcosson
dcosson / hello.py
Last active August 29, 2015 14:06
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 hello.py [PORT-NUM] [NUMPROCS]
from flask import Flask
import os
import signal
@dcosson
dcosson / gist:27bcca9b9ad28a38ab60
Last active August 29, 2015 14:08
Rename an ios project

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
dcosson / gist:2defd0bd596f00e14f60
Last active August 29, 2015 14:22
Add an extra share button to mave
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"
style:UIBarButtonItemStylePlain
target:self action:@selector(foo)];
@dcosson
dcosson / add_ssh_key_from_s3.sh
Last active November 26, 2015 08:31
Add private key stored in S3 to ssh-agent
#!/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

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 / postgres-is-locked.md
Last active June 2, 2016 01:22
Dealing with weird migrations/table updates that have locked postgres

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,
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'])