This file contains hidden or 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
def get_data(func, message): | |
while True: | |
try: | |
tmp = input(message) | |
tmp = func(tmp) | |
except: | |
print(f"Input not of type: {func.__name__}") | |
else: | |
return tmp |
This file contains hidden or 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
# Create classes based on csv file data | |
with open("file.csv", 'r') as f: | |
header = f.readline().split(',') | |
metaclass = type('csv', (object,), {h:None for h in header}) | |
for line in f.readlines(): | |
m = metaclass() | |
line = line.split(',') | |
for i in range(len(header)): | |
setattr(m, header[i], line[i]) | |
yield m # Return as generator |
This file contains hidden or 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
# Stolen from the docker website | |
FROM ubuntu | |
RUN apt-get update && apt-get install -qq openssh-server python | |
RUN mkdir /var/run/sshd | |
RUN echo 'root:testpass' | chpasswd | |
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config | |
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd | |
ENV NOTVISIBLE "in users profile" |
This file contains hidden or 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
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) |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
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: |
This file contains hidden or 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
rmn = {1000 : 'M', | |
900 : 'CM', | |
500 : 'D', | |
400 : 'CD', | |
100 : 'C', | |
90 : 'XC', | |
50 : 'L', | |
40 : 'XL', | |
10 : 'X', | |
9 : 'IX', |
This file contains hidden or 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 | |
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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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+' |
OlderNewer