Skip to content

Instantly share code, notes, and snippets.

View samclane's full-sized avatar

Sawyer McLane samclane

View GitHub Profile
@samclane
samclane / pretty_print.py
Last active February 7, 2016 18:42
Pretty print a nested dictionary into a RichTextCtrl(self)
def pretty_print(self, elem, level=0):
"""
Adds indentation to output of an ElementTree based on depth of element. Recursive.
"""
# Todo: Write to be compliant with a dictionary
i = "\r\n" + 2 * level * " "
for item in elem:
(attr, val) = item
if not type(val) is dict:
self.BeginBold()
@samclane
samclane / led_aliases.sh
Created February 5, 2016 16:09
backup copy of aliases that control led functionality by sending hex bytes as commands to arduino through serial port
# LED Control Aliases
alias led_green="echo -e -n '\x10' > /dev/ttyACM1"
alias led_dim="echo -e -n '\x20' > /dev/ttyACM1"
alias led_blue="echo -e -n '\x50' > /dev/ttyACM1"
alias led_off="echo -e -n '\x60' > /dev/ttyACM1"
alias led_red="echo -e -n '\x90' > /dev/ttyACM1"
alias led_bright="echo -e -n '\xA0' > /dev/ttyACM1"
alias led_smooth="echo -e -n '\xC8' > /dev/ttyACM1"
alias led_white="echo -e -n '\xD0' > /dev/ttyACM1"
alias led_fade="echo -e -n '\xD1' > /dev/ttyACM1"
@samclane
samclane / script1.sh
Created February 7, 2016 01:20
display all processes with me as owner
ps -ef | awk '$1 ~ /sawyer/ { print }'
@samclane
samclane / extract_datetime.py
Created April 17, 2017 18:04
Code for extracting date information from schedule format
WEEKDAY_CODES = {
'U': 6,
'M': 0,
'T': 1,
'W': 2,
'R': 3,
'F': 4,
'S': 5
}
@samclane
samclane / weapon_scrape.py
Created April 28, 2017 04:03
Scrape weapon names from roll20
from lxml import html
import requests
from collections import namedtuple
import json
def unique(list):
seen = set()
seen_add = seen.add
return [x for x in list if not (x in seen or seen_add(x))]
@samclane
samclane / FixedFloat.c
Created September 21, 2017 19:43
A special struct for floating point numbers which allows higher accuracy
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define DISPLAY_BUFFER_SIZE 5
typedef struct FixedFloat
{
int upper;
int lower;
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")
@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):
@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 / 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: