This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#stupid_metaclass_tricks.py | |
def howard(self): | |
print("fizz") | |
that_method = lambda : print("buzz") | |
def foo(self): | |
print("foo") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reddit27_samp.py | |
# http://docs.python.org/release/2.5.2/lib/httplib-examples.html | |
import httplib | |
url_string = "www.reddit.com" | |
header_stuff = {"User-Agent":"blah blah blah"} | |
reddit_feed = "/r/skydiving.json" | |
conn = httplib.HTTPConnection(url_string) | |
conn.request(method="GET", url=reddit_feed, headers=header_stuff) | |
res = conn.getresponse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from pdb import set_trace | |
# quick handy little lambdas | |
first = lambda l : l[0] | |
last = lambda l : l[-1] | |
def chunks(lst, n): | |
for i in range(0, len(lst), n): | |
yield lst[i:i+n] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import urllib.request as request | |
import json | |
import time | |
user_name = "" | |
my_url = "https://api.github.com/users/%s/gists" % user_name | |
json_ob = json.loads(request.urlopen(my_url).read().decode("utf-8")) | |
gist_set = [x['files'] for x in json_ob] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_step(width, base_level, step_height, num_sides): | |
axis = [0,0,-1] | |
PI2 = pi * 2 | |
rad = width / 2 | |
init_vector = Vector([rad, 0, base_level]) | |
quat_angles = [(cur_side/num_sides) * PI2 | |
for cur_side in range(num_sides)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pin_shuffler.py - quick 4 digit pin generator written out of boredom. | |
# slightly revised | |
from itertools import permutations | |
from random import seed, shuffle | |
from time import time | |
from operator import concat | |
from functools import reduce | |
all_pins = [x for x in permutations(range(10), 4)] | |
seed(time()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#worlds_worst_fizzbuzz.py | |
print(type("",(),{"__call__": | |
lambda self, start, end: | |
[(n, (lambda x: ("fizz" if x % 3 == 0 else "") + ("buzz" if x % 5 == 0 else ""))(n)) | |
for n in range(start,end+1)] | |
})()(1,50) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# meta_troll.py | |
# This is me messing around with Python type constructors just for fun. | |
# Try and see what happens if you uncomment the __metaclass__ line in Foo. | |
class TrollType(type): | |
def __new__(meta, classname, bases, clssDict): | |
class MyTroll(object): | |
def say_stuff(self): | |
print("you mad bro?") | |
return MyTroll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import _bpy | |
from collections import defaultdict | |
def make_operator_dict(): | |
submod_op_pairs = [entry.split("_OT_") for entry in _bpy.ops.dir()] | |
submod_op_pairs = [(k.lower(), v) for k,v in submod_op_pairs] | |
op_dict = defaultdict(list) | |
for key, val in submod_op_pairs: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def soup_line(dir_name, *exclusions): | |
""" | |
Pair up soups with the files they're based on. | |
:param dir_name: Directory with the html files needed. | |
:param exclusions: Don't include these files. | |
:return: A tuple of soup file name pairs. | |
""" | |
import os | |
from collections import namedtuple |