Skip to content

Instantly share code, notes, and snippets.

View kgriffs's full-sized avatar

Kurt Griffiths kgriffs

View GitHub Profile
@kgriffs
kgriffs / inline-vs-external.md
Created August 8, 2013 17:29
Exploring the cost of defining a noop function inline, vs. calling a free noop function. Tested on a MPB Retina, Python 2.7

Exploring the cost of defining a noop function inline, vs. calling a free noop function:

In [215]: %timeit test_inline()
1000000 loops, best of 3: 261 ns per loop

In [216]: %timeit test_external()
1000000 loops, best of 3: 215 ns per loop

In [217]: %timeit y.test_inline()

1000000 loops, best of 3: 306 ns per loop

@kgriffs
kgriffs / gist:6382507
Created August 29, 2013 19:41
Quick benchmark showing the difference between using datetime and time
In [56]: %timeit datetime.datetime.utcnow()
1000000 loops, best of 3: 875 ns per loop
In [57]: %timeit time.time()
10000000 loops, best of 3: 110 ns per loop
@kgriffs
kgriffs / pip.conf
Last active December 22, 2015 00:49
Speed up pip install by using crate.io
[global]
timeout = 10
index-url = https://pypi.python.org/simple/
# This doesn't work for a few packages for some reason, but mostly works and is a little faster
;index-url = https://simple.crate.io/
# Try the standard pypi mirrors if the above times out
use-mirrors = True
@kgriffs
kgriffs / Python - Tox.sublime-build
Created August 30, 2013 17:18
Invoke Tox from Sublime Text
{
"cmd": ["tox", "-e", "py27,pep8"],
"working_dir": "${file_path}",
"env": {
"PATH": "/usr/local/bin:/usr/local/sbin:/usr/local/share/python:$PATH"
},
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
@kgriffs
kgriffs / vlc
Last active February 23, 2024 17:57
Run VLC from the command line on Mac OS X and stream internet radio (such as Radio Paradise).
#!/usr/bin/env bash
/Applications/VLC.app/Contents/MacOS/VLC -I rc "$@"
@kgriffs
kgriffs / example.py
Created October 11, 2013 00:45
Python singleton pattern
class Catalog(object):
"""Represents the mapping between queues and shard drivers."""
__slots__ = ['_shards']
_singleton = None
def __init__(self):
self._shards = {}
@kgriffs
kgriffs / bug.txt
Last active December 31, 2015 03:49 — forked from anonymous/gist:fd19f5a3895e0304dde6
bug
/ .'
.---. \/
(._.' \()
^"""^"
@kgriffs
kgriffs / relative_urls.py
Last active December 31, 2015 04:39
Relative URL Examples
# Examples demonstrating the rules for combining URLs
In [63]: urlparse.urljoin("https://marconi.example.com/v1", "/queues/foo")
Out[63]: 'https://marconi.example.com/queues/foo'
In [58]: urlparse.urljoin("https://marconi.example.com/v1", "queues/foo")
Out[58]: 'https://marconi.example.com/queues/foo'
In [59]: urlparse.urljoin("https://marconi.example.com/v1/", "queues/foo")
Out[59]: 'https://marconi.example.com/v1/queues/foo'
@kgriffs
kgriffs / magic_strings.py
Created December 13, 2013 21:28
Python 3.3 compatible magic string methods
import six
class FooError(Exception):
message = u'An unknown exception occurred.'
def __str__(self):
if six.PY3:
return self.message
@kgriffs
kgriffs / ntpd-accuracy.py
Created December 16, 2013 21:27
NTPD Accuracy Testing Tools
import time
def check(points):
indexes = []
prev = points[0]
for p, i in enumerate(points[1:]):
if p == prev:
indexes.append(i)
prev = p
return indexes