This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from altered import state | |
org = {'foo': 'foo'} | |
@state(org, foo='bar') | |
def fn(): | |
return org['foo'] | |
# prints 'bar' | |
print fn() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counter = (start) -> | |
n = start | |
-> n++ | |
c = counter(0) | |
while 2 >= i = c() | |
alert i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Doesn't work yet, have patience.. | |
fakeJqOb = new class FakeJqOb | |
constructor: (@els=[]) -> | |
append: (content) => | |
@ap or= [] | |
console.log "Adding #{content}" | |
@ap.push content | |
@ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('touchend', | |
function (e) { e.preventDefault() if e.target.localName == 'a') }, | |
true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Expando(object): | |
def __init__(self, *args, **kw): | |
self.__dict__.update(kw) |