Skip to content

Instantly share code, notes, and snippets.

View JulianNorton's full-sized avatar
🔒

Julian Norton JulianNorton

🔒
View GitHub Profile
@JulianNorton
JulianNorton / genetic-algo-tutorial.py
Last active December 7, 2016 18:26
genetic-algorithm-tutorial
print 'test'
import random
def chromosome():
gene = ""
for i in xrange(8):
gene += str(random.randint(0,1))
return gene
@JulianNorton
JulianNorton / task-estimate.py
Created February 12, 2017 14:51
calculating task time estimates
# What's the best guess?
tm = float(input("Most probable Time (Tm) = "))
# If everything goes well, how long would it take?
to = float(input("Optimistic Time (To) = "))
# If everything bad happens, how long would it take?
# Probable time
tp = float(input("Pessimistic Time (Tp) = "))
@JulianNorton
JulianNorton / 170324_baby_riddle.py
Last active March 31, 2017 14:50
Riddler Express 538 20170324
# results https://docs.google.com/spreadsheets/d/1q3YD0AlzynouZmyBJqCWTnxAClhHoagoEGcHH3OncAc/edit?usp=sharing
# This video would have been super helpful to watch BEFORE trying this problem
# https://www.youtube.com/watch?v=stgYW6M5o4k
# SOLUTION!
# https://fivethirtyeight.com/features/what-are-the-chances-well-meet-for-lunch/
# [This program is wrong.]
import random
max_time = 10000
@JulianNorton
JulianNorton / 170331_538riddler_lunchtime.py
Last active March 31, 2017 18:10
If we both arrive at the fountain at an independently random time between noon and 1, what are the chances our picnic actually happens?
# https://fivethirtyeight.com/features/what-are-the-chances-well-meet-for-lunch/
# On a lovely spring day, you and I agree to meet for a lunch picnic at the fountain in the center of our favorite park.
# We agree that we’ll each arrive sometime from noon and 1 p.m.,
# and that whoever arrives first will wait up to 15 minutes for the other.
# If the other person doesn’t show by then, the first person will abandon the plans and spend the day with a more punctual friend.
# If we both arrive at the fountain at an independently random time between noon and 1, what are the chances our picnic actually happens?
import random
# Seed makes the result identical for every run
@JulianNorton
JulianNorton / human_date.py
Last active June 26, 2017 23:53
Convert UNIX timestamp to human readable date
from datetime import datetime as dt
# timestamp microseconds
timestamp = '1490871689000'
# String to remove miliseconds or it'll break
converted_timestamp = int(timestamp[:-3])
# I want a timestamp that's human readable!
converted_timestamp = dt.fromtimestamp(converted_timestamp)
# https://fivethirtyeight.com/features/work-a-shift-in-the-riddler-gift-shop/
# riddler express
# https://docs.google.com/spreadsheets/d/1n2WNPOeR2iOeWf5pUpHU6P92MDH7sk3rsUtvdFUsmHM/edit#gid=0
import random
random.seed(0)
# what if the half pills fall out of your hands back into the bottle?
# let p stand for probablity between 0 and 1.
def sample_pills_extra_credit(i, p):
@JulianNorton
JulianNorton / calculate_bs.py
Created September 1, 2017 18:19
170901 Riddler Express
'''
https://fivethirtyeight.com/features/is-your-friend-full-of-it/
Riddler Express
From Shaun Raviv, a tall tale on the basketball court:
You’re hanging out with some friends, shooting the breeze and talking sports.
One of them brags to the group that he once made 17 free throws in a row after years of not having touched a basketball.
You think the claim sounds unlikely, but plausible. Another friend scoffs, thinking it completely impossible.
Let’s give your bragging friend the benefit of the doubt and say he’s a 70-percent free-throw shooter.
@JulianNorton
JulianNorton / 170908_riddler-nation-goes-to-war.py
Last active September 11, 2017 14:10
170908_riddler-nation-goes-to-war
# https://fivethirtyeight.com/features/riddler-nation-goes-to-war/
# http://www.bicyclecards.com/how-to-play/war/
import random
# https://docs.python.org/3/library/random.html
random.seed(0)
# Ace is 14
def deck_of_aces():
return [(14,'club'),(14,'diamond'),(14,'heart'),(14,'spade')]
@JulianNorton
JulianNorton / encrypt.py
Last active September 24, 2017 21:07
script to sanitize data to unique hashes
import hashlib
from hashlib import blake2b
log_file = open("ip_addresses.txt", "r").read().splitlines();
new_file = open("new.csv", 'w')
for line in log_file:
h = blake2b(key=b'secret_key_change_this!', digest_size=10)
h.update((line).encode())
parsed_line = h.hexdigest()
@JulianNorton
JulianNorton / pi_installation.sh
Last active April 5, 2018 13:48
Raspberry pi installation script alexa
# change change password, keyboard layout, enable ssh, enable wifi
sudo raspi-config
# update
sudo apt-get update
# install git
sudo apt-get install git -y
# vim