Skip to content

Instantly share code, notes, and snippets.

View ndunn219's full-sized avatar

Nat Dunn ndunn219

View GitHub Profile
# import modules
import re
def sort_streets(street_list):
"""
Sort streets alphabetically, ignoring cardinal direction prefixes such as North, South, East and West
:param street_list: list of street names
"""
prefix = re.compile('^North|South|East|West|N\.?|S\.?|E\.?|W\.$', re.IGNORECASE)
@ndunn219
ndunn219 / monty_hall.py
Last active October 23, 2015 17:05
This is a Python model for the Monty Hall problem. See comment below for credit.
import random
class MontyHall:
def __init__(self):
self._prize_door = random.randint(1,3)
self._selected_door = random.randint(1,3)
self._removed_door = self.remove_door()
def remove_door(self):
doors = [1,2,3]
@ndunn219
ndunn219 / FixMarkDownHeaders.ipynb
Last active November 6, 2015 15:08
Adds a space after series of hash marks at the beginning of lines. The purpose is to fix markdown headers that didn't include a space after heading hash marks. USE AT YOUR OWN RISK.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ndunn219
ndunn219 / adventure.py
Created February 3, 2016 17:46
This script was created as part of a series of training videos based on Python projects created by Shelly Tan of Northwestern University's Knight Lab. The video explaining the code is at https://youtu.be/8uJFN7OZ2Yo
import random
def msg(room):
if room['msg'] == '': #There is no custom message
return "You have entered the " + room['name'] + '.'
else:
return room['msg']
def get_choice(room,dir):
if dir=='N':
@ndunn219
ndunn219 / StackExchange PY2 v. PY3.ipynb
Created March 10, 2016 16:10
IPython Notebook creating plots showing trend in StackExchange posts tagged Python 2 and Python 3
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import os, re
dir = 'path-to-your-directory'
i=0
results = [] #Store changed files so you can look into it later
for dirname, dirnames, filenames in os.walk(dir):
for filename in filenames:
ext = filename.split('.')[-1] #Get Extension
if ext in ('cfc','cfm'): #Limit search to specific file types
from bs4 import BeautifulSoup
import requests
import pandas as pd
url = "https://www.akc.org/reg/dogreg_stats.cfm"
r = requests.get(url)
data = r.text
soup = BeautifulSoup(data, "lxml")
@ndunn219
ndunn219 / combo_lock.py
Created October 5, 2019 23:08
How to pick a combo lock.
# based on https://youtu.be/w4wkCcsWs4c
def guess_numbers(num1, num2):
nums = [num1, num1+10, num1+20, num1+30,
num2, num2+10, num2+20, num2+30]
return nums
def main():
print('''The first step is to find the "Sticky number"
by applying pressure to the shackle and turning clockwise
@ndunn219
ndunn219 / cloudSettings
Last active December 24, 2020 09:25
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-12-24T09:25:39.702Z","extensionVersion":"v3.4.3"}
@ndunn219
ndunn219 / .gitignore
Last active April 25, 2021 13:03
Webucator VS Code Courseware Settings
.DS_Store