This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
def get_raw_gist(raw_gist_url): | |
return urllib2.urlopen(raw_gist_url).read() | |
def python_anywhere_gist_url(gist_num, gist_file, py_version="python2"): | |
return "https://www.pythonanywhere.com/gists/{0}/{1}/{2}".format(gist_num, gist_file, py_version) | |
print get_raw_gist("https://gist.github.com/calebmadrigal/5504352/raw/pythonanywhere_gist.py") | |
print python_anywhere_gist_url(5504352, "pythonanywhere_gist.py") |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSString *)base64String:(NSString *)str | |
{ | |
NSData *theData = [str dataUsingEncoding: NSASCIIStringEncoding]; | |
const uint8_t* input = (const uint8_t*)[theData bytes]; | |
NSInteger length = [theData length]; | |
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4]; | |
uint8_t* output = (uint8_t*)data.mutableBytes; |
NewerOlder