Skip to content

Instantly share code, notes, and snippets.

@jamesob
jamesob / no_more_bash.py
Created March 13, 2014 17:06
The Python snippet that obviated Bash forever
import subprocess
from collections import namedtuple
CallResult = namedtuple('CallResult', 'code,output')
def call(cmd):
try:
return CallResult(0, subprocess.check_output(cmd, shell=True))
### Keybase proof
I hereby claim:
* I am jamesob on github.
* I am job (https://keybase.io/job) on keybase.
* I have a public key whose fingerprint is 83AD 2F13 78E4 0054 338D EA84 277D E3F4 4582 D1A3
To claim this, I am signing this object:
@jamesob
jamesob / unisync.sh
Last active August 29, 2015 14:08
A simple, one-way sync optimized for local transfers.
#!/usr/bin/env sh
#
# A simple unidirectional sync optimized for local-to-local copies.
#
# Deletes files from each DEST not found in SOURCE.
#
# Usage:
#
# unisync.sh /path/to/source/ /path/to/dest1/ /path/to/dest2/
@jamesob
jamesob / practices.md
Last active August 29, 2015 14:10
Beliefs and best practices I've experimented with so far
category practice tried and in practice tried and not in practice not tried
diet consume refined sugar x
      | consume wheat | | [x](#wheat) |
      | consume caffeine | | [x](#caffeine) |
      | follow a paleo diet | [x](#paleo) | |
      | supplement with methylfolate  | [x](#folate) | |
      | supplement with fish oil  | [x](#fishoil) | |

lifestyle | MBSR meditation | x | | | cold showers | | x |

@jamesob
jamesob / setup.sh
Last active August 29, 2015 14:10
Setting up Ubuntu 14.04
#!/usr/bin/env sh
SAG="sudo apt-get -y"
SAGI="$SAG install"
# Last tested with 14.04.2
$SAGI \
redshift \
redshift-gtk \
@jamesob
jamesob / command.py
Last active August 29, 2015 14:18
Export automation sketch
"""
Export data necessary for financial reporting to an RDS instance.
"""
import logging
from django.core.management import base
logger = logging.getLogger('counsyl.product.billing')
@jamesob
jamesob / pg_cheatsheet.sql
Last active August 29, 2015 14:26
Postgresql shortcuts
-- get temptable info
select temp_files, pg_size_pretty(temp_bytes) from pg_stat_database;
-- get running queries
select pid, usename, query_start, state, substring(query from 0 for 90) from pg_stat_activity;
-- kill query
select pg_cancel_backend(the_pid);
@jamesob
jamesob / test.py
Last active August 29, 2015 14:27
Python3 syntax highlighting snafu
def main(a: str, b: int) -> str:
# whoaaaa, now we're not highlighting syntax properly anymore
c = a * b
for i in c:
d = i * 2
return d
@jamesob
jamesob / gist:1157814
Created August 19, 2011 19:47
sshfs mnt utility
#!/usr/local/bin/python
import argparse
import os
# User configuration
# ------------------
_MNT_DIR = "~/mnt/dev" # e.g. mount at ~/mnt/dev6
# ------------------
@jamesob
jamesob / gist:1212074
Created September 12, 2011 19:01
Anonymous functions are beautiful.
/*
* concise, but cryptic for the first two minutes you see this
*/
(function ($) {
$(selector).each(function () {
// code
});
$(selector).each(function () {