In urls.py
# urls like "articles/2011/tutorial03" or "articles/2011/tutorial03.html"
urlpatterns = patterns('',
(r'articles/(?P<year>\d+)/(?P<item>\w+)(\.htm(l)?)?$', 'articles.views.detail'),
)
| # Scrapuje Respekt.cz, aby to shráblo aktuální číslo v HTML. | |
| # Nestahuje to obrázky, ale vidět jsou, protože maj absolutní URL, | |
| # tohle se dá spravit pomocí pář řádků. | |
| # | |
| # Bohužel hapruje diakritika, bude tam někde potřeba pořešit přes iconv nebo tak něco. | |
| import mechanize | |
| from pyquery import PyQuery as pq | |
| usr = "username" |
| import logging | |
| from rpclib.application import Application | |
| from rpclib.decorator import srpc | |
| from rpclib.service import ServiceBase | |
| from rpclib.model.primitive import String | |
| from rpclib.model.primitive import Integer | |
| from rpclib.model.complex import Iterable | |
| from rpclib.interface.wsdl import Wsdl11 | |
| from rpclib.protocol.soap import Soap11 |
| import simplejson as json | |
| import lxml | |
| class objectJSONEncoder(json.JSONEncoder): | |
| """A specialized JSON encoder that can handle simple lxml objectify types | |
| >>> from lxml import objectify | |
| >>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>") | |
| >>> objectJSONEncoder().encode(obj) | |
| '{"price": 1.5, "author": "W. Shakespeare"}' | |
| """ |
| // Simple proof of concept for PHP bug (CVE-2012-0830) described by Stefan Esser (@i0n1c) | |
| // http://thexploit.com/sec/critical-php-remote-vulnerability-introduced-in-fix-for-php-hashtable-collision-dos/ | |
| // Generate 1000 normal keys and one array | |
| function createEvilObj () { | |
| var evil_obj = {}; | |
| for (var i = 0; i < 1001; i++) { | |
| evil_obj[i] = 1; | |
| } | |
| evil_obj['kill[]'] = 'kill'; |
| #! -*- Coding: utf-8 -*- | |
| from gevent import monkey | |
| monkey.patch_all() | |
| import gevent | |
| import time | |
| from envoy import run | |
| from sys import exit, argv | |
| import subprocess | |
| import pip |
| #compdef hg | |
| # Zsh completion script for mercurial. Rename this file to _hg and copy | |
| # it into your zsh function path (/usr/share/zsh/site-functions for | |
| # instance) | |
| # | |
| # If you do not want to install it globally, you can copy it somewhere | |
| # else and add that directory to $fpath. This must be done before | |
| # compinit is called. If the file is copied to ~/.zsh.d, your ~/.zshrc | |
| # file could look like this: |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| def NewTorIP(): | |
| s = socket.socket() | |
| s.connect(('localhost', 9051)) | |
| s.send("AUTHENTICATE\r\n") | |
| r = s.recv(1024) | |
| if r.startswith('250'): | |
| s.send("signal NEWNYM\r\n") | |
| r = s.recv(1024) | |
| if r.startswith('250'): | |
| return True |
| import re | |
| # sada regularnich vyrazu pro lepsi typosku | |
| # zdroj: texy-2.1/texy/modules/TexyTypographyModule.php | |
| TEXY_CHARS = ur'A-Za-z\u00C0-\u02FF\u0370-\u1EFF' | |
| TEXY_TYPO_PATTERNS = [ | |
| (re.compile(ur'(?<![.\u2026])\.{3,4}(?![.\u2026])', re.M | re.U), u"\u2026"), # ellipsis ... | |
| (re.compile(ur'(?<=[\d ])-(?=[\d ]|$)'), u"\u2013"), # en dash 123-123 | |
| (re.compile(ur'(?<=[^!*+,/:;<=>@\\\\_|-])--(?=[^!*+,/:;<=>@\\\\_|-])'), u"\u2013"), # en dash alphanum--alphanum |