Skip to content

Instantly share code, notes, and snippets.

View jacob414's full-sized avatar
💭
Retired but semi-active, hobby projects & activism

Jacob Oscarson jacob414

💭
Retired but semi-active, hobby projects & activism
View GitHub Profile
@jacob414
jacob414 / fake_django_req.py
Created November 14, 2011 11:02
Fake a Django HTTP request for simpler testing purposes
from StringIO import StringIO
from django.core.handlers.wsgi import WSGIRequest
def fake_get(path='/', user=None):
req = WSGIRequest({
'REQUEST_METHOD': 'GET',
'PATH_INFO': path,
'wsgi.input': StringIO()})
from django.contrib.auth.models import AnonymousUser
req.user = AnonymousUser() if user is None else user
@jacob414
jacob414 / classgen.coffee
Created November 1, 2011 10:34
Class factory in CoffeeScript
gen = (clsname, val) ->
C = class
C.prototype[val] = -> "#{clsname} says #{val}"
C
Cat = gen 'Cat', 'meow'
console.log Cat
c = new Cat
alert c.meow()
@jacob414
jacob414 / abspath.sh
Created October 13, 2011 18:18
Absolute path in shell scripts
#!/bin/sh
ME=$(dirname $0)
function abspath {
B=`basename "$1"`
echo "`cd \"$ME\" 2>/dev/null && pwd || echo \"$D\"`/$B"
}
@jacob414
jacob414 / proper_readline.sh
Created October 13, 2011 12:13
Proper readline installation in new Python on OS X
# Not a real shell file (might work, tho..). I suggest copy-and
# paste the lines one by one into a terminal. You need to have
# installed the official OS X Python 2.7 from python.org, obviously.
cd /Library/Frameworks/Python.framework/Versions/2.7
curl http://peak.telecommunity.com/dist/ez_setup.py -O
./bin/python2.7 ez_setup.py
./bin/easy_install readline
@jacob414
jacob414 / test_funcargs_combo.py
Created October 13, 2011 08:48
Minimal example of py.test funcargs where one parameter is static and the other varying.
import py
def pytest_generate_tests(metafunc):
fargs = {}
if 'static' in metafunc.funcargnames:
fargs['static'] = 'stays the same'
if 'different' in metafunc.funcargnames:
for variant in (1,2):
@jacob414
jacob414 / func_subclass.py
Created September 21, 2011 13:02
Subclass via function in Python
def subclass(Cls, name=None):
class _(Cls):pass
_.__name__ = name or 'subclass'
return _
@jacob414
jacob414 / main.coffee
Created May 27, 2011 14:55
MMMM, delicious! Green tea mixed with coffee!
class BaseScreen extends Ext.Panel
title: 'Base panel'
iconCls: 'info'
class Screen1 extends BaseScreen
title: 'First screen'
html: 'Content of one screen'
class Screen2 extends BaseScreen
title: 'Second screen'
@jacob414
jacob414 / adhoc_watcher.rb
Created March 29, 2011 20:15
Ruby FSEvents & rsync insanely easy to write directory mirror
# Just added a subprocess call to rsync to one of rb-fsevent's example
# scripts. Spookily easy.
require 'rubygems'
require 'rb-fsevent'
require 'open3'
include Open3
fsevent = FSEvent.new
@jacob414
jacob414 / log-webkit-events.js
Created March 1, 2011 09:39
Logs as many events as possible
// Log as many events as possible, with event names grabbed from
// webkit sources:
// http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/dom/EventNames.h
known = [
'abort',
'beforecopy',
'beforecut',
'beforeload',
'beforepaste',
@jacob414
jacob414 / weinre-senchatouch.html
Created February 26, 2011 22:19
Weinre/Sencha Touch edge-case
<!-- Assumes Weinre running on localhost, and the file accessed via -->
<!-- another webserver also running on localhost. Accessing this file -->
<!-- locally (file://[..] protocol) doesn't provoke the issue. -->
<!-- Tried on OS X and Linux (recent Ubuntu) -->
<!DOCTYPE html>
<html>
<head>
<title>Weinre & Sencha Touch</title>
<script src="sencha-touch-1.0.1a.js"></script>
<script src="sencha-weinre.js"></script>