Skip to content

Instantly share code, notes, and snippets.

View nosamanuel's full-sized avatar

Noah Seger nosamanuel

View GitHub Profile
# Check how many users are *still* on IE6
# Also check the other IE versions out of curiosity
ip_agents = {}
ip_counts = {}
for l in open('nginx_access.log'):
try:
ip, event = l.split(' - - ')
except ValueError:
continue
var session = FB.getSession();
var query = FB.Data.query("select uid2 from friend where uid1 = {0}", session.uid);
var friend_ids = new Array();
FB.Data.waitOn([query], function() {
FB.Array.forEach(query.value, function(row) {
friend_ids.push(row.uid2);
});
console.log(friend_ids);
});
<A HREF="/HeartLand-Gaien/7211/kudos10/okurimono.html">
<P ALIGN="CENTER">
<LI>心からの贈り物J
</A>
</LI>
</P>
@nosamanuel
nosamanuel / gist:5180376
Created March 17, 2013 06:23
Curiosity about garbage collection and generator.send
state = {}
def generator():
state['generator'] = yield None
yield None
def main():
g = generator()
import inspect
class Selfless(type):
def __new__(cls, name, bases, attrs):
# Detect any methods without `self` as the first argument
selfless_methods = {}
for k, v in attrs.items():
if callable(v):
try:
@nosamanuel
nosamanuel / fail_in_exception.py
Created November 24, 2013 03:35
try/finally in a bare except block can safely re-raise the original error.
def do_something():
raise RuntimeError('do_something')
def clean_up():
raise RuntimeError('clean_up')
def fail_in_exception():
try:
<snippet>
<content><![CDATA[
@property
def ${1:name}(self):
${2:pass}
]]></content>
<tabTrigger>prop</tabTrigger>
<scope>source.python</scope>
<description>New Property Decorator</description>
</snippet>
@nosamanuel
nosamanuel / gist:8888183
Last active August 29, 2015 13:56
Python has a record of variables defined after the current frame
import inspect
frame = inspect.currentframe()
assert 'asdf' in frame.f_code.co_names
assert "asdf = 'asdf'" not in inspect.getsource(frame)
asdf = 'asdf'
@nosamanuel
nosamanuel / destructure.py
Created February 9, 2014 00:04
Destructuring bind in Python
import ast
import inspect
class destructure(object):
def __init__(self, target):
self.target = target
def __enter__(self):
# 1. Get the stack frame that called `destructure`
@nosamanuel
nosamanuel / pep380.py
Created April 21, 2014 17:40
PEP 380
def foo():
yield 1
yield 2
yield 3
def bar():
yield 'a'
yield 'b'
yield 'c'