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
# 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 / 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)]
@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 / 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 / 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 / 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 / image_collector.py
Created August 15, 2012 01:32
An image collecting screen scraper built as an interesting example usage of Beautiful Soup. Done with Python 2.7
"""
image_collector.py
A script to screen scrape an image archive and then download those images
one by one to a local folder. Interesting example usage of BeautifulSoup.
Modify as needed for the site you intend to scrape.
Use only with permission of site owner!!!
Geeky Note:
@pcote
pcote / post_test.py
Created August 6, 2012 19:43
Python 3 example script for sending data to a web application using the post method.
"""
post_test.py
An example script that shows how to send data by post-method from
command-line to a web application.
"""
import urllib.request as request
import urllib.response as response
import urllib.parse as parse
url_string = "http://localhost:8085/A_WebApp/targetservlet"
@pcote
pcote / hn_screen_scraper.py
Created June 28, 2012 19:52
Screen scraper that Pulls URLs and Titles from the Front Page of Hacker News
# hn_screen_scraper.py
# A screen scraper for the front page of hacker news done out of a fit of boredom.
from urllib import request
import re
# read in the data and split it into a raw list of entries
url_path = "http://news.ycombinator.com"
sock = request.urlopen(url_path)
raw_data = str(sock.read())
data_set = re.split("arrow\.gif", raw_data)
@pcote
pcote / matrix_op.py
Created June 16, 2012 03:55
A simple experimental operator for messing with matrix basics.
"""
matrix_op.py
A simple experimental operator for messing with matrix basics.
"""
import bpy
from bpy.props import FloatProperty
from math import pi
class MatrixOp(bpy.types.Operator):