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 / 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 / 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 / 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 / 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 / expando.py
Created November 15, 2011 12:13
Minimal Python expando class
class Expando(object):
def __init__(self, *args, **kw):
self.__dict__.update(kw)
@jacob414
jacob414 / test_cmsplug_init.py
Created November 15, 2011 12:16
Test registry and instantiation of DjangoCMS plugin objects
from cms.plugin_pool import plugin_pool
# ..in production code: class YourPlugin(CMSPlugin)...
# This ensures that the system is aware of your plugin:
YrPluginCls = plugin_pool.plugins.get('YourPlugin', None)
# ..instantiate:
plugin = YrPluginCls()
@jacob414
jacob414 / fix_links_firing_twice.js
Created December 1, 2011 14:34
Fix undecorated links firing twice in Sencha Touch (only tested on 1.x yet)
@jacob414
jacob414 / both.coffee
Created January 24, 2012 09:45
Writing CoffeeScript Modules for Browser and Node
# See http://braintostring.blogspot.com/2012/01/writing-javascript-modules-for-browser.html
foo = exports? and @ or @foo = {}
class foo.ExampleClass
method: -> 1
foo.func = -> 2
@jacob414
jacob414 / indented_both.coffee
Created January 24, 2012 20:49
CoffeeScript for Browser and Node but indented
foo = exports? and exports or @foo = {}
do(foo) ->
# Being at indent level 1 here makes me uneasy!
class foo.Cls
meth: -> 1
foo.func = -> 2
@jacob414
jacob414 / fakeJq.coffee
Created February 9, 2012 17:40
Pico jQuery faking
# Doesn't work yet, have patience..
fakeJqOb = new class FakeJqOb
constructor: (@els=[]) ->
append: (content) =>
@ap or= []
console.log "Adding #{content}"
@ap.push content
@