Skip to content

Instantly share code, notes, and snippets.

View nelix's full-sized avatar
🎯
Focusing

Nathan Hutchision nelix

🎯
Focusing
View GitHub Profile
#!/usr/bin/env python
"""
Regex for URIs
These regex are directly derived from the collected ABNF in RFC3986
(except for DIGIT, ALPHA and HEXDIG, defined by RFC2234).
They should be processed with re.VERBOSE.
"""
import asyncore, socket
from dns import resolver, rdatatype, rdataclass, message
# Stolen from here:
# http://glyphy.com/asynchronous-dns-queries-python-2008-02-09
class AsyncDNS(asyncore.dispatcher):
def __init__(self):
asyncore.dispatcher.__init__(self)
import threading, os, sys, time
class autolock(threading._RLock):
__enter__ = threading._RLock.acquire
__leave__ = threading._RLock.release
def __except__(self, type, value, traceback):
self.release()
if type is KeyboardInterrupt:
self.interrupt = value
scheme, host, path, params, query, fragment = urlparse.urlparse(uri)
define ppystack
while $pc < Py_Main || $pc > Py_GetArgcArgv
if $pc > eval_frame && $pc < PyEval_EvalCodeEx
set $__fn = PyString_AsString(co->co_filename)
set $__n = PyString_AsString(co->co_name)
printf "%s (%d): %s\n", $__fn, f->f_lineno, $__n
end
up-silently 1
end
@nelix
nelix / cont.as
Created July 3, 2009 15:33 — forked from cho45/cont.as
// 同時実行されてしまう
for (var i:uint = 0; i < len; i++) {
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, fun (..._) {});
loader.load(t[i]);
}
// 順次実行
var i:uint = 0; (function cont (..._):void { if (i++ < parts) {
var loader:URLLoader = new URLLoader();
## Function
traverse("object", obj, function(key, val) {console.log(key, val)});
## Call
function traverse(key, jsonObj, func) {
if( typeof jsonObj == "object" ){
$.each(jsonObj, function(k,v) {
traverse(k,v);
})
} else {
LUAOBJECT_GRAMMAR = %q{
grammar LuaObject
rule luaobj
space value space { def to_ruby; value.to_ruby; end }
end
rule value
nil / float / number / string / table / boolean
end
@nelix
nelix / uuid.py
Created July 5, 2009 01:32 — forked from mmalone/uuid.py
import socket
def sockrecv(sock):
d = ''
while not d or d[-1] != '\n':
d += sock.recv(8192)
return d
>>> d = {k:v for k,v in enumerate('ABCD') if v not in 'CB'}
>>> print(d)
{0: 'A', 3: 'D'}
>>> type(d)
<class 'dict'>