Skip to content

Instantly share code, notes, and snippets.

View wrunk's full-sized avatar

Warren Runk wrunk

View GitHub Profile
@wrunk
wrunk / simplejson2.3.0_encode_issue.py
Created December 29, 2011 16:53
Simplejson 2.3.0 object dictionary encode issue
from simplejson import JSONEncoder
class ObjectDictWorks(dict):
""" Makes a dictionary behave like an object. """
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
@wrunk
wrunk / simple_urllib2_example.py
Created February 27, 2012 19:11
Simple python web page get using urllib2
#! /usr/bin/env python
'''
Super dumb example of getting the contents of a web page.
'''
import urllib2
page_contents = urllib2.urlopen('http://www.python.org/').read()
print page_contents
@wrunk
wrunk / sha224_digest.py
Last active October 1, 2015 06:08
Quick python sha224 digest example
#!/usr/bin/env python
'''
Example of a way you could hash a password with a salt.
Pass the password as the first and only parameter.
WARNING this is just an example. NEVER put a real password in the clear
on the command line like this.
'''
@wrunk
wrunk / print_call_stack.py
Created April 11, 2012 22:49
Printing a python call stack independent of an exception
import traceback
for line in traceback.format_stack():
print line.strip()
@wrunk
wrunk / simple_iter_class.py
Created October 2, 2012 22:19
Simple python iterator class
class TestIter(object):
def __init__(self):
self.i = 0
self.l = [1,2,3,4]
def __iter__(self):
return self
@wrunk
wrunk / py_re.py
Created December 3, 2012 22:11
Python regular expressions cheatsheet
import re
# ---------------------------------------------------------------------------- #
# Regex sting substitution
#
# As a first example, lets say we have a jinja2 template that needs
# a particular section(s) replaced
LEFT_NAV = re.compile(r'{{\s*left_nav\s*}}')
@wrunk
wrunk / wsgi_proxy.py
Created December 10, 2012 21:30
Python WSGI Proxy
# A simple example of using the simple wsgiproxy as a nudge fallback app.
# We used this to proxy unfinished requests from appengine, back to our
# ec2 app
from nudge.publisher import ServicePublisher
from wsgiproxy.app import WSGIProxyApp
PROTO = 'http'
FALLBACK_HOST = 'example.com'
@wrunk
wrunk / curl_json_post.sh
Created December 12, 2012 17:47
curl: POST a json body to a server
# POST a json body.
curl -v -H "Content-Type: application/json" -X POST \
-d '{"action": "Say Hello"}' \
http://example.com/say/hello
@wrunk
wrunk / mysql5_to_sqlite3.py
Created June 12, 2011 08:03
A base for coverting a mysql5 dump to sqlite
#!/usr/bin/env python
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@wrunk
wrunk / shellpers.sh
Last active February 10, 2018 02:38
Shellpers
# Prepend something to the beginning of each line
cat .gitignore| while read line; do echo "[ERROR] $line"; done > somefile.txt
# Delete all the GD pyc files starting in this dir
find . -name '*.pyc' -exec rm -f {} \;
#
# ** Below are some SHELLpers to deal with removing crap from a go vendor dir
# NOTE cgo stuff might not like this process ^_^