Skip to content

Instantly share code, notes, and snippets.

View baileywickham's full-sized avatar
👓

Bailey Wickham baileywickham

👓
View GitHub Profile
@baileywickham
baileywickham / venmo.py
Created December 20, 2021 05:50
Calculate the difference between two venmo users
import csv
import sys
me = ''
them = ''
paid_to_me = 0
paid_to_them = 0
payment_from_them = 0
payment_to_them = 0
def _max(values, func=None):
if not func:
return max(values)
maybeMax = values[0]
for v in values:
if func(v, maybeMax):
maybeMax = v
return maybeMax
@baileywickham
baileywickham / fpmap.rkt
Created May 12, 2021 22:30
fixed point map
(define fpmap
(lambda args
(map (lambda (iter)
(apply (first args) iter (remove-last (rest args)))) (last args))))
(define (remove-last l)
(reverse (rest (reverse l))))
@baileywickham
baileywickham / sitemap.py
Last active May 6, 2021 05:59
wasup kelso
# https://architizer.com/sitemap-firms.xml
# Step 1: Download the above link to the file 'sitemap-firms.xml' and put it in the same directory as the python script.
# Step 2: Run the python script. It's sorta hacked together so it only half works, but it should do the basics. You can filter
# the list more if you want.
import xml.etree.ElementTree as ET
import requests
import re
email_regex = 'mailto:\S+@\S+\.\S+'
# Fixed Point Map:
# fpmap(function, fixed_point..., list)
def fpmap(*argv):
if len(argv) < 2:
# bad map paramaters
raise TypeError("fpmap must have at least two arguments")
# function to call
f = argv[0]
# List to pass to map
import sys
def sieve(N):
P = [1 if x % 2 == 1 or x == 2 else 0 for x in range(N+1)]
m = 3
n = m**2
while n <= N:
if P[m] == 1:
while n <= N:
P[n] = 0
@baileywickham
baileywickham / romans.py
Created November 4, 2020 06:36
Roman numeral converter
rmn = {1000 : 'M',
900 : 'CM',
500 : 'D',
400 : 'CD',
100 : 'C',
90 : 'XC',
50 : 'L',
40 : 'XL',
10 : 'X',
9 : 'IX',
@baileywickham
baileywickham / Maybe.py
Created November 3, 2020 03:38
Maybe monad in python
from operator import neg
class Maybe(object):
def __init__(self, v, failed=False):
self.v = v
self.failed = failed
def bind(self, f):
if self.failed:
return self
try:
@baileywickham
baileywickham / Dockerfile
Last active September 29, 2020 05:25
A Dockerfile for PEP622, pattern matching.
# A Dockerfile for PEP622, pattern matching.
# https://www.python.org/dev/peps/pep-0622/
FROM alpine:3.12
# ensure local python is preferred over distribution python
ENV PATH /usr/local/bin:$PATH
# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8
select dayofweek(checkin), count(code), sum(datediff(checkout, checkin)*rate)
from reservations
join rooms on rooms.roomcode=reservations.room
group by dayofweek(checkin)
order by dayofweek(checkin)