Skip to content

Instantly share code, notes, and snippets.

@raylu
raylu / html.py
Created May 1, 2015 23:15
(x)html parser
#!/usr/bin/env python3
import html
import http.client
import re
from xml.etree import ElementTree
parser = ElementTree.XMLParser()
for entity, char in html.entities.html5.items():
parser.entity[entity[:-1]] = char
@raylu
raylu / gist:5417390
Created April 19, 2013 00:58
gist paster
#!/usr/bin/env python
import requests
import sys
rs = requests.Session()
if len(sys.argv) == 2:
filename = sys.argv[1]
f = open(filename, 'r')
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@raylu
raylu / wsgi.py
Created February 10, 2015 23:12
simplest wsgi setup
#!/usr/bin/env python3
import wsgiref.simple_server
def app(environ, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
return ['hello world'.encode('utf-8')]
def main():
server = wsgiref.simple_server.make_server('0.0.0.0', 8000, app)
@raylu
raylu / test_cron.py
Created November 18, 2015 01:38
cron
#!/usr/bin/env python3
import time
import cron
def do_stuff1():
print('stuff1!')
def do_stuff2():
#1 / 0
@raylu
raylu / README
Last active June 21, 2016 05:55
distributed job queue
Examples of distributed (job) queues:
* http://python-rq.org/
* https://github.com/twitter-archive/kestrel/wiki
* http://nsq.io/overview/quick_start.html
* http://gearman.org/
* https://kafka.apache.org/documentation.html#quickstart
* http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#application
and many more inferior queues: http://queues.io/
So you want to write a distributed job queue?
@raylu
raylu / keybase.md
Created February 8, 2017 21:12
keybase.md

Keybase proof

I hereby claim:

  • I am raylu on github.
  • I am raylu (https://keybase.io/raylu) on keybase.
  • I have a public key whose fingerprint is 86AD 8A28 B07B 3DC8 19EA D5E0 8AE5 9930 FEFD 609B

To claim this, I am signing this object:

#!/usr/bin/env python3
# vim: set sw=4 ts=4:
import eventlet
eventlet.monkey_patch()
import socket
import _thread
def main():
#!/usr/bin/env python3
import ctypes
import ctypes.util
import errno
import os
import signal
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
#!/usr/bin/env python3
import ctypes
import ctypes.util
import enum
import os
import sys
def main():
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)