Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
// | |
// Regular Expression for URL validation | |
// | |
// Author: Diego Perini | |
// Created: 2010/12/05 | |
// Updated: 2018/09/12 | |
// License: MIT | |
// | |
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it) | |
// |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
git filter-branch --tree-filter 'git ls-files -z | xargs -0 dos2unix' -- --all |
#!/bin/bash | |
echo "Generating an SSL private key to sign your certificate..." | |
openssl genrsa -des3 -out myssl.key 1024 | |
echo "Generating a Certificate Signing Request..." | |
openssl req -new -key myssl.key -out myssl.csr | |
echo "Removing passphrase from key (for nginx)..." | |
cp myssl.key myssl.key.org | |
openssl rsa -in myssl.key.org -out myssl.key |
""" Use watchdogs to make your code safer. (http://en.wikipedia.org/wiki/Watchdog_timer) | |
Usage: | |
with watchdog.Watchdog(duration = 1.0): | |
# Some code which takes less than 1s | |
# If it takes more, the exception Watchdog.Reset will be raised | |
# To notify the watchdog the section is still alive, call the method | |
# 'tick' to reset its internal timer. |
import struct | |
import SocketServer | |
from base64 import b64encode | |
from hashlib import sha1 | |
from mimetools import Message | |
from StringIO import StringIO | |
class WebSocketsHandler(SocketServer.StreamRequestHandler): | |
magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11' |
""" | |
Theres a gevent pool of 4 greenlets. Jobs are spawned continuously, blocking | |
until a free greenlet is available (default gevent.pool behaviour). Say, | |
a unit of work takes rougly a second. Then, at any moment, there are likely | |
4 jobs mid-execution. | |
The Goal | |
-------- | |
I want to catch both SIGINT/KeyboardInterrupt _and_ SIGTERM in | |
the main loop, and in a nondestructive way. By nondestructive, I mean (1) |
import json, datetime | |
class RoundTripEncoder(json.JSONEncoder): | |
DATE_FORMAT = "%Y-%m-%d" | |
TIME_FORMAT = "%H:%M:%S" | |
def default(self, obj): | |
if isinstance(obj, datetime.datetime): | |
return { | |
"_type": "datetime", | |
"value": obj.strftime("%s %s" % ( |
import weakref, new | |
class Proxy(object): | |
''' | |
Our own proxy object which enables weak references to bound and unbound | |
methods and arbitrary callables. Pulls information about the function, | |
class, and instance out of a bound method. Stores a weak reference to the | |
instance to support garbage collection. | |
@organization: IBM Corporation |