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 / provision.sh
Last active November 13, 2015 13:57
Generic provisioning script for a setting up a 64 bit Ubuntu box. (built with Trusty in mind)
#!/bin/sh
function install_packages {
sudo apt-get install -y nginx build-essential python3-dev libssl-dev openssl python3-pip fail2ban git mysql-server
sudo pip3 install -r requirements.txt
}
@pcote
pcote / gist:b434193ac3fefe539e2f
Created November 13, 2015 00:35
General Starter Script for 64 bit Ubuntu Linux provisioning
#!/bin/sh
function install_packages(){
sudo apt-get install -y nginx build-essential python3-dev libssl-dev openssl python3-pip fail2ban git mysql-server
sudo pip3 install -r requirements.txt
}
class count_limiter(object):
def __init__(self, count_limit):
pass
def __call__(self, func):
def wrapper(*args, **kwargs):
res = func(*args, **kwargs)
return res
@count_limiter(3)
def hello(person):
print("hi there {}".format(person))
if __name__ == '__main__':
hello("fred")
hello("george")
hello("jane")
hello("jim") # exception thrown here because it's the 4th call
from threading import Thread
from random import random, seed
from time import time, sleep
from functools import wraps
def concurrent(func):
@wraps(func)
def wrapper(*args, **kwargs):
Thread(target=func, args=args).start()
for soup, file_name in soup_line("sources"):
print(file_name, soup("title"))
@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
@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 / 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 / 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)
)