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 / swiss_army_path.py
Created April 11, 2012 08:57
Swiss army path function
import os
def path(*segs):
"""
CWD and `~` aware path construction. Start a segment with `/` for absolute paths.
*(Example, on my machine)*
>>> path('sub', 'dir')
/Users/jacob/src/tmp/sub/dir
>>> path('~', 'src', 'project', 'pkg')
/Users/jacob/src/project/pkg
@jacob414
jacob414 / altered_states_demo2.py
Created March 1, 2012 11:26
Simple demo of Altered States decorator
from altered import state
org = {'foo': 'foo'}
@state(org, foo='bar')
def fn():
return org['foo']
# prints 'bar'
print fn()
@jacob414
jacob414 / altered_states_demo1.py
Created March 1, 2012 11:15
Simple demo of Altered States context manager
from altered import state
class A(object): pass
o = A()
o.foo = 'foo'
with(state(o, foo='bar')):
# prints 'bar'
print o.foo
# prints 'foo', o.foo now restored to previous value
@jacob414
jacob414 / pseudogen.coffee
Created February 20, 2012 10:40
CoffeeScript pseudo-generator
counter = (start) ->
n = start
-> n++
c = counter(0)
while 2 >= i = c()
alert i
@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
@
@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 / 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 / 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 / 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 / expando.py
Created November 15, 2011 12:13
Minimal Python expando class
class Expando(object):
def __init__(self, *args, **kw):
self.__dict__.update(kw)