Skip to content

Instantly share code, notes, and snippets.

View bradmontgomery's full-sized avatar

Brad Montgomery bradmontgomery

View GitHub Profile
@bradmontgomery
bradmontgomery / index_server.py
Created August 26, 2015 16:37
Subclass of python's built-in SimpleHTTPRequestHandler that only serves a single file.
import http.server
import socketserver
PORT = 5555
class IndexHandler(http.server.SimpleHTTPRequestHandler):
"""Always show the index no matter what the requested path."""
def parse_request(self, *args, **kwargs):
Python 2.7.5 (default, Jul 17 2013, 17:11:57)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> timeit.timeit("dict()")
0.3571889400482178
>>> timeit.timeit("{}")
0.04683995246887207
#!/bin/bash
source ~/.profile; workon p3; unset PYTHONPATH; ipython3
$ python temp.py
in try
in exceptky
$ history | grep git | awk '{print $3}' | sort | uniq -c | sort -rn | head
127 st
53 dif
46 add
33 co
23 commit
16 push
12 pull
12 merge
10 br
Date & Time, Trans, Elap Time, Data Trans, Resp Time, Trans Rate, Throughput, Concurrent, OKAY, Failed
2012-01-31 09:40:15, 1000, 4.47, 0, 0.08, 223.71, 0.00, 19.00, 1000, 0
2012-01-31 09:58:08, 344, 1.32, 0, 0.14, 260.61, 0.00, 35.61, 344, 1154
2012-01-31 09:58:55, 5000, 9.62, 1, 0.14, 519.75, 0.10, 74.46, 5000, 0
2012-02-27 16:28:57, 5349, 186.81, 0, 0.01, 28.63, 0.00, 0.30, 5349, 0
2012-02-27 16:42:54, 0, 109.37, 0, nan, 0.00, 0.00, 0.00, 0, 46
2012-02-27 17:20:42, 9408, 364.87, 0, 0.02, 25.78, 0.00, 0.51, 9408, 15
2012-02-27 17:56:04, 12188, 426.62, 1, 0.01, 28.57, 0.00, 0.24, 12188, 0
2012-03-19 10:48:34, 293, 11.73,
#! usr/bin/env python
x = '10-10-10-10-10-72-97-112-112-121-32-66-105-114-116-104-100-97-121-33-10-10-10-10'
print(''.join(chr(int(i)) for i in x.split('-')))
@bradmontgomery
bradmontgomery / timing.py
Last active August 29, 2015 14:01
Timing some things in python 2 and python 3. You should use a list comprehension instead of map + lambda, and/or a list comprehension with sum instead of reduce + lambda (python 2), but that's no necessarily the case in python 3!
#!/usr/bin/env python
# Run this in python 2
from timeit import timeit
# Use a list comprehension instead of map & lambda
# ------------------------------------------------
code = "map(lambda x: {'id': x}, range(100))"
print(code)
print("--> {0}\n".format(timeit(code))) # ~ 21.14860200881958
@bradmontgomery
bradmontgomery / dev.conf
Created May 29, 2014 00:20
My nginx config for development. I use this in a vagrant vm (ubuntu), to proxy to the django development server (which runs on port 8888). Based on http://www.peterbe.com/plog/local-django-development-with-nginx
server {
listen 8000;
root /vagrant/MY_PROJECT/static;
# My vm's host name is 'appserver'
server_name appserver;
access_log /var/log/nginx/access.log;
gzip off;
location /static {
DATA = {u'makesCount': 39, u'makes': [{u'models': [{u'years': [{u'id': 200471908, u'year': 2014}], u'id': u'Acura_ILX', u'niceName': u'ilx', u'name': u'ILX'}, {u'years': [{u'id': 200493809, u'year': 2014}], u'id': u'Acura_ILX_Hybrid', u'niceName': u'ilx-hybrid', u'name': u'ILX Hybrid'}, {u'years': [{u'id': 200465929, u'year': 2014}], u'id': u'Acura_MDX', u'niceName': u'mdx', u'name': u'MDX'}, {u'years': [{u'id': 200467168, u'year': 2014}], u'id': u'Acura_RDX', u'niceName': u'rdx', u'name': u'RDX'}, {u'years': [{u'id': 100539511, u'year': 2014}], u'id': u'Acura_RLX', u'niceName': u'rlx', u'name': u'RLX'}, {u'years': [{u'id': 200488448, u'year': 2014}], u'id': u'Acura_TL', u'niceName': u'tl', u'name': u'TL'}, {u'years': [{u'id': 200490517, u'year': 2014}], u'id': u'Acura_TSX', u'niceName': u'tsx', u'name': u'TSX'}, {u'years': [{u'id': 200673755, u'year': 2014}], u'id': u'Acura_TSX_Sport_Wagon', u'niceName': u'tsx-sport-wagon', u'name': u'TSX Sport Wagon'}], u'id': 200002038, u'niceName': u'acura', u'name': u'Ac