Skip to content

Instantly share code, notes, and snippets.

Nat Dunn ndunn219

Block or report user

Report or block ndunn219

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
@ndunn219
ndunn219 / combo_lock.py
Created Oct 5, 2019
How to pick a combo lock.
View combo_lock.py
# 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 / srt_to_txt.py
Last active Sep 15, 2019
Simple Python Script for Extracting Text from an SRT File
View srt_to_txt.py
"""
Creates readable text file from SRT file.
"""
import re, sys
def is_time_stamp(l):
if l[:2].isnumeric() and l[2] == ':':
return True
return False
View tabs_to_spaces.py
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
View web-scraping.py
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 / sitemap_checker.py
Last active Feb 13, 2019
This code shows how to check a sitemap to make sure there are no links pointing to missing pages and to see if 301s are working correctly. It is explained at https://www.webucator.com/blog/2016/05/checking-your-sitemap-for-broken-links-with-python/
View sitemap_checker.py
import requests
from bs4 import BeautifulSoup
sitemap = 'http://www.nasa.gov/sitemap/sitemap_nasa.html'
r = requests.get(sitemap)
html = r.content
soup = BeautifulSoup(html, 'html.parser')
links = soup.find_all('a')
@ndunn219
ndunn219 / StackExchange PY2 v. PY3.ipynb
Created Mar 10, 2016
IPython Notebook creating plots showing trend in StackExchange posts tagged Python 2 and Python 3
View StackExchange PY2 v. PY3.ipynb
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 Feb 3, 2016
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
View adventure.py
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 / FixMarkDownHeaders.ipynb
Last active Nov 6, 2015
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.
View FixMarkDownHeaders.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ndunn219
ndunn219 / monty_hall.py
Last active Oct 23, 2015
This is a Python model for the Monty Hall problem. See comment below for credit.
View monty_hall.py
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]
View sort_streets.py
# 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)
You can’t perform that action at this time.