Skip to content

Instantly share code, notes, and snippets.

Avatar

Elliott Hoffman slor

View GitHub Profile
View daemon_example.py
""" An example of a Linux daemon written in Python.
Based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
The changes are:
1 - Uses file open context managers instead of calls to file().
2 - Forces stdin to /dev/null. stdout and stderr go to log files.
3 - Uses print instead of sys.stdout.write prior to pointing stdout to the log file.
4 - Omits try/excepts if they only wrap one error message w/ another.
@slor
slor / test_everything.sh
Created Jun 12, 2013
Run django test on all the packages listed in a CSV file. Supports additional args too.
View test_everything.sh
#!/usr/bin/env bash
#
# Run tests on packages listed in a csv file.
#
# Usage: ./test_everything.sh [arg1 arg2 ...]
#
# Runs manage.py test on all the packages listed in what_to_test.csv. You can
# pass additional args and they will be appended to the manage command.
#
# Example:
View pytest.py
payload = {'html': ' <!doctype html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Home | Linkminded</title> <meta name="description" content="Discover like minded individuals with complementing skillset to collaborate on an idea together."> <meta name="keywords" content="link, minded, like, developers, designers, entrepreneurs, startup, collaborate, collaboration, find, discover, ideas, projects"> <meta name="author" content="link-minded.com"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="shortcut icon" href="https://d1ttgy8gd6pa2l.cloudfront.net/img/favicon.fbe95e4d6cf2.ico">
View pytest.py
# -*- coding: utf-8 -*-
import sys
import datetime
import base64
import requests
def main():
@slor
slor / mock_file_open.py
Created Jan 16, 2013
Mock the open() builtin as a context manager.
View mock_file_open.py
# http://www.voidspace.org.uk/python/mock/
from mock import MagicMock
open_name = '%s.open' % __name__
with patch(open_name, create=True) as mock_open:
mock_file = MagicMock(spec=file)
mock_file.read.return_value = 'hello'
mock_open.return_value.__enter__.return_value = mock_file
with open('/some/path', 'rU') as f:
@slor
slor / xorg.conf
Created Sep 1, 2012
TwinView xorg.conf file for dual 23" LEDs created via NVidia settings
View xorg.conf
# nvidia-settings: X configuration file generated by nvidia-settings
# nvidia-settings: version 295.33 (buildd@allspice) Fri Mar 30 13:37:33 UTC 2012
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
Option "Xinerama" "0"
EndSection
@slor
slor / gist:3561826
Created Sep 1, 2012
OSX-style EOL/BOL bindings for sublime text 2
View gist:3561826
[
{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol"} }
]
@slor
slor / mint-12-installs-django-heroku-cedar.sh
Created Jan 15, 2012
Mint 12 installs for Django app on Heroku Cedar
View mint-12-installs-django-heroku-cedar.sh
# Installs the prerequisites to set up a Django app on Heroku Cedar [2].
apt-get install python-setuptools
apt-get install python-dev
easy_install pip
pip install virtualenvwrapper
apt-get install curl
apt-get install postgresql
sudo apt-get install postgresql-server-dev-9.1
@slor
slor / decorator_with_param.py
Created Dec 21, 2011
An example and explaination of a Python decorator that takes a non-optional parameter.
View decorator_with_param.py
""" An example of writing a decorator that takes an argument.
Based on e-satis's answer at http://stackoverflow.com/questions/739654/understanding-python-decorators#1594484.
"""
from functools import wraps
# The outer-most level is the decorator factory. The middle level is the
# decorator and the inner most level is where we call the decorated function.
def decorator_maker(buzz):
You can’t perform that action at this time.