Skip to content

Instantly share code, notes, and snippets.

Caleb Madrigal calebmadrigal

Block or report user

Report or block calebmadrigal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View output.txt
Prediction for [1, 1, 1, 1]: [[0.16937022 0.83062978]]
Prediction for [1, 2, 3, 4]: [[0.25071094 0.74928906]]
The maximum opset needed by this model is only 6.
The maximum opset needed by this model is only 1.
INPUT NAME: float_input
OUTPUTS: ['output_label', 'output_probability']
Prediction with ONNX for [1. 1. 1. 1.]: [[{0: 0.16937017440795898, 1: 0.830629825592041}]]
Prediction with ONNX for [1. 2. 3. 4.]: [[{0: 0.2507109045982361, 1: 0.7492890954017639}]]
View parse_trackerjacker_wifi_map.py
import sys
import yaml
def parse_wifi_map(map_path):
with open(map_path, 'r') as f:
data = f.read()
wifi_map = yaml.load(data)
devices = set()
View calculate_xkcd_2018.py
import sys
from datetime import date,timedelta
def is_xkcd_day(d):
return d.weekday() in {0, 2, 4}
def find_date_by_xkcd_number(xkcd_num, current_xkcd=1964, start_date=date(2018, 3, 7)):
if not is_xkcd_day(start_date):
View get_milwaukee_traffic_cams.py
import sys
from urllib.request import urlopen
CAM_RANGE = range(188)
CAM_URL_TEMPLATE = 'http://content.dot.wi.gov/travel/milwaukee/cameras/cam{}.jpg'
def get_camera_pic(cam_num, verbose=True):
if type(cam_num) != str or len(cam_num) != 3:
cam_num = str(cam_num).zfill(3)
@calebmadrigal
calebmadrigal / rewrite_strings.py
Created Aug 24, 2017
Example of changing the python AST
View rewrite_strings.py
import ast
class StringWrapper(ast.NodeTransformer):
"""Wraps all strings in 'START ' + string + ' END'. """
def visit_Str(self, node):
return ast.Call(func=ast.Name(id='wrap_string', ctx=ast.Load()),
args=[node], keywords=[])
def wrap_string(s):
return 'START ' + s + ' END'
@calebmadrigal
calebmadrigal / example_run.txt
Last active Aug 25, 2017
Python timeout function with ast
View example_run.txt
cmadrigal-MBP:ast_stuff caleb.madrigal$ python3 wrap_function_test.py
Wrapping function: range
Wrapping function: do_sleep
check_timeout_proxy()
check_timeout_proxy()
check_timeout_proxy()
check_timeout_proxy()
Traceback (most recent call last):
File "wrap_function_test.py", line 34, in <module>
run_code_string_with_timeout(code, 3)
@calebmadrigal
calebmadrigal / for_loop.py
Last active Sep 24, 2015
Python for loop vs list comprehension speed test. This is just testing the speed of performing a particular operation in both a for loop and list comprehension. Note that the list comprehension version uses more memory because it is storing the results. This could be partially responsible for it being slower.
View for_loop.py
import sys
num = int(sys.argv[1])
def test(i):
return i+1
for i in range(num):
t = test(i)
@calebmadrigal
calebmadrigal / evil_child.py
Last active Sep 1, 2015
evil_child() kills all parents and siblings, leaving only itself alive to do what it pleases (like cleaning things up)
View evil_child.py
import os
import signal
import time
from multiprocessing import Process
def kill_all(parent_pid):
os.killpg(os.getpgid(parent_pid), signal.SIGKILL)
def evil_child(parent_pid):
print("Killing my parents and siblings...")
@calebmadrigal
calebmadrigal / tkinter_example.py
Created Jun 20, 2015
Drawing individual pixels with Tkinter.
View tkinter_example.py
import random
import math
from tkinter import Tk, Canvas, PhotoImage, mainloop
width = 1000
height = 600
window = Tk()
canvas = Canvas(window, width=width, height=height, bg="#000000")
canvas.pack()
img = PhotoImage(width=width, height=height)
@calebmadrigal
calebmadrigal / log_example.py
Created Jun 18, 2015
Basic python logging example
View log_example.py
import logging
config = { 'logfile': 'log_example.log', 'loglevel': 'DEBUG' }
logger = logging.getLogger('log_example')
log_handler = logging.FileHandler(config['logfile'])
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
log_handler.setFormatter(formatter)
logger.addHandler(log_handler)
logger.setLevel(logging.getLevelName(config['loglevel']))
You can’t perform that action at this time.