Skip to content

Instantly share code, notes, and snippets.

View dreid's full-sized avatar
💭
Archived

dreid dreid

💭
Archived
View GitHub Profile
from zope.interface import Interface
from twisted.python.components import proxyForInterface
class IResolver(Interface):
def callback(result):
pass
def errback(reason):
pass
import json
from klein import Klein
app = Klein()
_collections = {}
@app.route('/collections/')
def collections(request):
@dreid
dreid / itemstore1.output.txt
Created February 26, 2013 19:16
klein implicit branches and werkzeug route ordering.
(klein)thomasina dreid:klein (master=)> python itemstore1.py
Map([<Rule '/items/' -> items>,
<Rule '/items/<name>/<__rest__>' (PUT) -> save_item_branch>,
<Rule '/items/<name>/<__rest__>' (HEAD, GET) -> get_item_branch>,
<Rule '/items/<name>/' (PUT) -> save_item>,
<Rule '/items/<name>/' (HEAD, GET) -> get_item>,
<Rule '/items/<__rest__>' -> items_branch>])
2013-02-26 11:14:26-0800 [-] Log opened.
2013-02-26 11:14:26-0800 [-] Site starting on 8080
2013-02-26 11:14:26-0800 [-] Starting factory <twisted.web.server.Site instance at 0x10ab59488>
from klein import route
@route('/'):
def accept_some_work(request):
reactor.callLater(0, do_some_work, request)
return 'OK'
@dreid
dreid / zoomzero.py
Created August 23, 2012 02:28
sublime text 2 plugin for zooming to an original font size.
import sublime
import sublime_plugin
settings = sublime.load_settings('Preferences.sublime-settings')
orig_font_size = settings.get('base_font_size', settings.get('font_size'))
settings.set('base_font_size', orig_font_size)
sublime.save_settings('Preferences.sublime-settings')
class ZoomzeroCommand(sublime_plugin.WindowCommand):
def run(self):
-> if (('close' in connHeaders) or self._state != "QUIESCENT" or
(Pdb) connHeaders
['Close']
@dreid
dreid / ufw.py
Created July 15, 2012 05:56
beginning of a ufw salt state.
"""
'22':
ufw.allow:
- enabled: true
- proto: tcp
- from: 127.0.0.1
- to: any
"""
<doctype !html>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="https://raw.github.com/mbostock/d3/master/d3.v2.min.js"></script>
<script src="https://raw.github.com/shutterstock/rickshaw/master/rickshaw.min.js"></script>
<div id="chart"></div>
<script>
var graph = new Rickshaw.Graph( {
>>> (foo, bar) = xrange(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
>>> (foo, bar) = xrange(19)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
"""
twistd -n web --class=hello.resource
"""
from klein import route, resource
@route('/')
def home(request):
return 'Hello, world!'