Skip to content

Instantly share code, notes, and snippets.

View pcote's full-sized avatar
🏠
Working from home

Emma Cote pcote

🏠
Working from home
View GitHub Profile
@pcote
pcote / stupid_metaclass_tricks.py
Created August 28, 2012 02:08
This is me having some mindless fun with Python metaclasses
#stupid_metaclass_tricks.py
def howard(self):
print("fizz")
that_method = lambda : print("buzz")
def foo(self):
print("foo")
@pcote
pcote / reddit27_samp.py
Created August 28, 2012 18:19
Sample for interacting with Reddit using Python 2.7
# 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()
@pcote
pcote / keyframe_point_swapper.py
Created September 2, 2012 02:58
Blender test script that swaps pairs of selected keyframe points.
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]
@pcote
pcote / gist_blender.py
Created September 19, 2012 00:29
Gist File Loader Idea for Blender
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]
@pcote
pcote / create_step.py
Created September 21, 2012 17:49
An example of list comprehensions in action for solving a linear algebra problem for making a set of verts.
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)]
# 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())
@pcote
pcote / worlds_worst_fizzbuzz.py
Created March 18, 2013 23:15
Inspired by FizzBuzz Enterprise Edition found here: https://github.com/Mikkeren/FizzBuzzEnterpriseEdition This is my version using overengineered Python.
#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)
)
@pcote
pcote / meta_troll.py
Created April 8, 2013 19:49
Playing around with custom class construction just to see how it works. Good dumb fun.
# 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
@pcote
pcote / blender_ops_dict.py
Created August 15, 2014 18:08
Makes a dictionary of names with respect to submodules for Operators Within Blender
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:
@pcote
pcote / soup_line.py
Last active August 29, 2015 14:11
Snippet for soup_line
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