Skip to content

Instantly share code, notes, and snippets.

View bsmithyman's full-sized avatar
📎
"It looks like you're writing a distributed web app!"

Brendan Smithyman bsmithyman

📎
"It looks like you're writing a distributed web app!"
View GitHub Profile
@bsmithyman
bsmithyman / gb.py
Last active September 19, 2015 02:10
def GB(tag = None):
import sys
if not hasattr(GB, 'badgercount'):
GB.badgercount = 0
sys.stdout.write('Guard badger: %03d is named %s'%(GB.badgercount, 'Stanley' if not tag else tag))
sys.stdout.flush()
GB.badgercount += 1
#
# Automatically generated file; DO NOT EDIT.
# Linux/arm 4.2.0 Kernel Configuration
#
CONFIG_ARM=y
CONFIG_ARM_HAS_SG_CHAIN=y
CONFIG_MIGHT_HAVE_PCI=y
CONFIG_SYS_SUPPORTS_APM_EMULATION=y
CONFIG_HAVE_PROC_CPU=y
CONFIG_STACKTRACE_SUPPORT=y
class Blorgle(object):
@property
def incompatible(self):
import inspect
frame = inspect.currentframe()
print('Current')
print(frame.f_locals.get('self', None))
print('Previous')
print(frame.f_back.f_locals.get('self', None))
print('2Prev')
@bsmithyman
bsmithyman / JustTheNumbers
Last active December 17, 2015 17:39
Python gist to take a complicated nested object and grab a list of numbers from it.
import re
parser = re.compile('(?:[0-9\.]+)')
lambda x: [float(item) for item in parser.findall(repr(x))]
amodulename = 'modulename'
try:
import pyximport
pyximport.install()
except:
print('Cython import failed; {0} will use the legacy (pure Python) mode.'.format(amodulename))
from modulenamevanilla import class1, class2, class3
else:
try:
@bsmithyman
bsmithyman / uniquerefs.sh
Created July 30, 2013 23:49
Takes a LaTeX *.aux file as its first argument. Outputs a sorted, unique list of all citekeys from the original document. Useful for e.g., copying formatted bibliographic entries to a new document manually. Written when I was taking Chapter 5 of my PhD thesis and turning it into a paper.
#!/bin/sh
< $1 grep \\citation | cut -c 10- | sed -e "s/[{},]/\n/g" | sed -e "/^$/d" | sort -u
@bsmithyman
bsmithyman / graph_stack.py
Last active May 4, 2016 19:42
Generate a call graph for the enclosed context
import contextlib
import os.path
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
@contextlib.contextmanager
def graph_stack(filename):
'Generate a call graph for the enclosed context'
go = GraphvizOutput(output_file=filename)
go.output_type = os.path.splitext(filename)[-1][1:]
@bsmithyman
bsmithyman / LICENSE
Last active July 28, 2016 13:51
Pure Python implementation of SEG-Y file input; originally from https://github.com/bsmithyman/pygeo.
Licensed under GNU Lesser General Public License
Originally part of 'pygeo' (also by Brendan Smithyman).
https://www.gnu.org/licenses/lgpl.html
@bsmithyman
bsmithyman / resumable.py
Created October 5, 2016 21:44
Generate a resumable upload URL for Google Cloud Storage
import json
import os
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
GCP_CREDENTIALS_FILE = os.getenv('GCP_CREDENTIALS_FILE', 'client-secret.json')
GCS_UPLOAD_URL_PATTERN = 'https://www.googleapis.com/upload/storage'+ \
'/v1/b/{bucket}/o?uploadType=resumable'
def get_upload_url(bucket, filename, content_length, content_type='application/octet-stream'):
@bsmithyman
bsmithyman / keybase.md
Created May 7, 2017 23:30
Verification post for Keybase

Keybase proof

I hereby claim:

  • I am bsmithyman on github.
  • I am bsmithyman (https://keybase.io/bsmithyman) on keybase.
  • I have a public key ASBOa1GAD4sXYNqt3C8cl8KaXBx0A4erRUGsaYDCE_3j0Ao

To claim this, I am signing this object: