Skip to content

Instantly share code, notes, and snippets.

@slor
slor / gist:1019683
Created June 10, 2011 20:21
Grep like a boss
# grep current directory recursively for foo
# case-insensitive
# ignore binary files
# show line numbers
# ignore svn cruft
# force color
grep -rIin --color=force foo . | grep -v svn
@slor
slor / gist:1171311
Created August 25, 2011 18:04
Add your pydev workspace projects to your pythonpath when activating with virtualenvwrapper
# Assuming your workspace is called "workspace" and at the root of your virtualenv
# In $WORKON_HOME/postactivate
###############################
export PREACTIVATE_PYTHONPATH=$PYTHONPATH
for f in $VIRTUAL_ENV/workspace/*
do
export PYTHONPATH=$PYTHONPATH:$f
done
@slor
slor / decorator_with_param.py
Created December 21, 2011 23:09
An example and explaination of a Python decorator that takes a non-optional parameter.
""" 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):
@slor
slor / mint-12-installs-django-heroku-cedar.sh
Created January 15, 2012 19:14
Mint 12 installs for Django app on Heroku Cedar
# 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 / gist:3561826
Created September 1, 2012 00:30
OSX-style EOL/BOL bindings for sublime text 2
[
{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol"} },
{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol"} }
]
@slor
slor / xorg.conf
Created September 1, 2012 15:23
TwinView xorg.conf file for dual 23" LEDs created via NVidia settings
# 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 / mock_file_open.py
Created January 16, 2013 03:55
Mock the open() builtin as a context manager.
# 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 / pytest.py
Last active December 16, 2015 11:19 — forked from garrypolley/ch.html
# -*- coding: utf-8 -*-
import sys
import datetime
import base64
import requests
def main():
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">