Skip to content

Instantly share code, notes, and snippets.

View samclane's full-sized avatar

Sawyer McLane samclane

View GitHub Profile
@samclane
samclane / flatten.py
Created January 1, 2019 21:28
Flatten a container that is arbitrarily nested
def flatten(container):
"""
>>> list(flatten([1, 2, 3, [1, 2, 3, [5, 6], 8], 5, 6]))
[1, 2, 3, 1, 2, 3, 5, 6, 8, 5, 6]
"""
for i in container:
if isinstance(i, (list,tuple)):
for j in flatten(i):
yield j
else:
aliceblue
antiquewhite
cyan
aquamarine
azure
beige
bisque
black
blanchedalmond
blue
@samclane
samclane / Giant List of Color Names
Created January 1, 2019 20:19
List of color names and their hex representations. Thanks to http://chir.ag/projects/ntc/.
names: [
["000000", "Black"],
["000080", "Navy Blue"],
["0000C8", "Dark Blue"],
["0000FF", "Blue"],
["000741", "Stratos"],
["001B1C", "Swamp"],
["002387", "Resolution Blue"],
["002900", "Deep Fir"],
["002E20", "Burnham"],
@samclane
samclane / cifar10.py
Created November 23, 2018 22:20
From Learning TensorFlow A Guide to Building Deep Learning Systems By Itay Lieder, Yehezkel Resheff, Tom Hope
import os
import pickle as cPickle
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import mnist
DATA_PATH = "./cifar-10-batches-py/"
img = PhotoImage()
color_string = ''
for y in range(img.height()):
color_string += '{'
for x in range(img.width()):
color_string += GET_PIXEL_COLOR(x,y) + ' ' # GET_PIXEL_COLOR is whatever function you want to apply to the image
color_string += '} '
img.put(color_string, (0, 0, img.height(), img.width()))
@samclane
samclane / SocialAnalysisTest.py
Created October 5, 2018 00:23
Test ML processing for social data acquired from Discord. Just a snapshot to backup; will probably make a new repo for this.
import pandas
import time
import random
import networkx as nx
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB, MultinomialNB, BernoulliNB
from sklearn.preprocessing import MultiLabelBinarizer
df = pandas.DataFrame({"member": [], "present": []})
@samclane
samclane / gui.spec
Created June 9, 2018 20:25
Full spec file for main binary
# -*- mode: python -*-
import datetime
bd = datetime.datetime.now().isoformat()
auth = "Sawyer McLane"
vers = "1.3.4"
is_debug = False
# Write version info into _constants.py resource file
with open('_constants.py', 'w') as f:
@samclane
samclane / BulbIconList.py
Last active May 30, 2018 18:48
My nice canvas for drawing bulb icons manually.
class BulbIconList(Frame):
def __init__(self, *args):
self.window_width = 285
self.icon_width = 50
self.icon_height = 75
super().__init__(*args, width=self.window_width, height=self.icon_height)
self.pad = 5
self.scrollx = 0
self.scrolly = 0
self.bulb_dict = {}
@samclane
samclane / truncate_args.py
Created May 26, 2018 22:25
Decorator that truncates all decimal arguments of wrapped function to n digits
def truncate(f, n):
'''Truncates/pads a float f to n decimal places without rounding'''
s = '{}'.format(f)
if 'e' in s or 'E' in s:
return '{0:.{1}f}'.format(f, n)
i, p, d = s.partition('.')
return float('.'.join([i, (d+'0'*n)[:n]]))
def truncate_args(digits):
def decorator(func):
import os
import time
from slackclient import SlackClient
import smartsheet
import re
from tkinter import *
# starterbot's ID as an environment variable
BOT_ID = os.environ.get("BOT_ID")