This file contains 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
def twisted_run_if_main(f): | |
from twisted.internet import reactor | |
from twisted.python import log | |
from twisted.internet.defer import maybeDeferred, inlineCallbacks | |
@inlineCallbacks | |
def run(): | |
yield maybeDeferred(f) | |
print "done" | |
reactor.stop() |
This file contains 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 MyTemplateMaker(TemplateMaker): | |
def annotate_fragment_attribute(self, index, field, attribute='content'): | |
for f in self.htmlpage.parsed_body[index::-1]: | |
if isinstance(f, HtmlTag) and f.tag_type in [HtmlTagType.OPEN_TAG, HtmlTagType.UNPAIRED_TAG]: | |
if 'data-scrapy-annotate' in f.attributes: | |
fstr = self.htmlpage.fragment_data(f) | |
raise FragmentAlreadyAnnotated("Fragment already annotated: %s" % fstr) | |
d = {'annotations': {attribute or "content": field}} | |
a = ' data-scrapy-annotate="%s"' % json.dumps(d).replace('"', '"') | |
p = self.htmlpage |
This file contains 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
server { | |
listen 80; | |
server_name yourdomain.com; | |
rewrite ^/(.*) http://www.yourdomain.com/$1 permanent; | |
} |
This file contains 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
def dbus_handler(which): | |
def inner(f): | |
@wraps(f) | |
def decorator(*args, **kwargs): | |
return f(*args, **kwargs) | |
decorator.dbus_callback = which | |
return decorator | |
return inner |
This file contains 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
def mygen(): | |
page = 1 | |
results = json.loads(requests.get("http://foo.com?p=%s" % page).content) | |
while results: | |
for r in results: | |
yield r | |
page += 1 | |
results = json.loads(requests.get("http://foo.com?p=%s" % page).content) | |
This file contains 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
dpn@dpn-linux-desktop:~$ sudo apt-add-repository ppa:versable/elementary-update | |
You are about to add the following PPA to your system: | |
A supplementary PPA for elementaryOS Luna, providing elementaryOS based apps, third party icons for the elementary icon theme, additional plank themes and more. | |
For more elementaryOS visit http://www.elementaryupdate.com/ | |
For bug reports visit https://bugs.launchpad.net/elementary-community | |
More info: https://launchpad.net/~versable/+archive/elementary-update | |
Press [ENTER] to continue or ctrl-c to cancel adding it | |
Usage: lsb_release [options] |
This file contains 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
def page_gen(): | |
from mezzanine.pages.models import Page | |
pages = Page.objects.all() | |
for page in pages: | |
yield (page.title, "page") | |
ADMIN_MENU_ORDER = ( | |
# ("Content", ("pages.Page", "blog.BlogPost", | |
# "generic.ThreadedComment", ("Media Library", "fb_browse"),)), | |
# ("Site", ("sites.Site", "redirects.Redirect", "conf.Setting")), |
This file contains 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 twisted.internet import reactor | |
from twisted.internet.protocol import Factory, Protocol | |
from twisted.internet.endpoints import TCP4ClientEndpoint | |
class MetricCollector(Protocol): | |
def send_metric(self, name, value, timestamp): | |
self.transport.write("%s %d %d\n" % (name, value, timestamp)) | |
This file contains 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 sqlalchemy import create_engine, Table | |
from sqlalchemy.schema import MetaData | |
from somewhere import settings | |
from collections import defaultdict | |
_engines = {} | |
_metadata = defaultdict(lambda: MetaData()) | |
_tables = defaultdict(dict) | |
This file contains 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 TestCase(unittest.TestCase): | |
def __call__(self, *args, **kwargs): | |
alembic_cfg = Config("../alembic.ini") | |
alembic_cfg.set_section_option( | |
"alembic", "script_location", "../alembic") | |
command.upgrade(alembic_cfg, "head") | |
r = super(TestCase, self).__call__(*args, **kwargs) | |
command.downgrade(alembic_cfg, "base") | |
return r |