Skip to content

Instantly share code, notes, and snippets.

View skimbrel's full-sized avatar

Sam Kimbrel skimbrel

View GitHub Profile
{"res":0,"hash":"52829d29e9a09","btype":0,"barg":0,"fp":10,"waves":[{"seq":"1","monsters":[{"type":0,"num":"476","lv":3,"item":"476","inum":3,"pval":0},{"type":0,"num":"479","lv":3,"item":0,"inum":0,"pval":0}]},{"seq":"2","monsters":[{"type":0,"num":"220","lv":8,"item":0,"inum":0,"pval":0}]},{"seq":"3","monsters":[{"type":0,"num":"412","lv":3,"item":0,"inum":0,"pval":0}]},{"seq":"4","monsters":[{"type":0,"num":"284","lv":5,"item":0,"inum":0,"pval":0}]},{"seq":"5","monsters":[{"type":0,"num":"215","lv":5,"item":"33","inum":5,"pval":0}]},{"seq":"6","monsters":[{"type":0,"num":"596","lv":4,"item":"596","inum":4,"pval":0}]}]}
In [1]: class Foo(object):
...: def bar(self):
...: print 'hi'
...:
In [2]: f = Foo()
In [3]: f.__dict__['bar']()
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
In [31]: def create_counter():
....: def _counter():
....: global count
....: count += 1
....: return count
....: return _counter
....:
In [32]: f = create_counter()
>>> def create_counter():
... count = 0
... def _counter():
... nonlocal count
... count += 1
... return count
... return _counter
...
>>> f = create_counter()
>>> f()
In [16]: def counter_factory():
....: count = [0]
....: def _counter():
....: count[0] += 1
....: return count[0]
....: return _counter
....:
In [17]: f = counter_factory()
In [13]: def counter_factory():
....: count = 0
....: def _counter():
....: count += 1
....: return _counter
....:
In [14]: f = counter_factory()
In [15]: f()
In [1]: class Foo(object):
...: pass
...:
In [2]: def bar(self):
...: pass
...:
In [3]: bar.__get__
Out[3]: <method-wrapper '__get__' of function object at 0x10fdc6398>
@skimbrel
skimbrel / gist:6732288
Last active December 24, 2015 02:39
twiml dial example
from twilio import twiml
r = twiml.Response()
with r.dial() as d:
d.number('+14155551234', url='http://example.com')
unicode(r) # u'<?xml version="1.0" encoding="UTF-8"?><Response><Dial><Number url="http://example.com/">+14155551234</Number></Dial></Response>'
@skimbrel
skimbrel / gist:6732130
Created September 27, 2013 17:35
OS X paste shortcuts for vim
" Dump things into OS X paste buffer
vmap <leader>c :w !pbcopy<CR><CR>
nnoremap <leader>c :.w !pbcopy .<CR><CR>
@skimbrel
skimbrel / gist:6544078
Created September 12, 2013 21:32
Node's REPL needs some work
$ node
> process.nextTick(function() {null.lol;})
undefined
>
repl:1
(process.nextTick(function() {null.lol;})
^
TypeError: Cannot read property 'lol' of null
at repl:1:35
at process._tickCallback (node.js:415:13)