Skip to content

Instantly share code, notes, and snippets.

View jrjames83's full-sized avatar

Jeff James jrjames83

View GitHub Profile
-- want to get counts of people who's last name starts with a vowel (AEIOU)
-- case, substring
-- SUM(CASE WHEN x.thing = 'whatever' THEN 1 ELSE 0 END) as counts_of_whatever
SELECT t.my_case_outcome, count(*) FROM (
SELECT c.*, substring(c.last_name, '^[AEIOUaeiou]') as x,
CASE
WHEN substring(c.last_name, '^[AEIOUaeiou]') IS NOT NULL THEN 'last_starts_vow'
@jrjames83
jrjames83 / euler42.ipynb
Created February 3, 2018 21:31
Project Euler 42 in Python / Pandas (at the end of the notebook)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jrjames83
jrjames83 / find_area_of_circle.py
Created February 3, 2018 20:41
Simulating the area of a circle with radius R by throwing darts at a square of length 2*r
# Finding the area of a circle through simulation?
import math
import random
def dart_throw_simulator(radius, runs):
hits = 0
for run in range(runs):
rand_x = random.uniform(-2,2)
rand_y = random.uniform(-2,2)
c_squared = (rand_x ** 2) + (rand_y ** 2)
@jrjames83
jrjames83 / central_limit_theorem.py
Created February 1, 2018 03:55
Python Central Limit Theorem
import numpy as np
import random
# Create a parent distribution, from the gamma family
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
s = np.random.gamma(shape, scale, 100000)
print(np.mean(s))
import matplotlib.pyplot as plt
import scipy.special as sps
@jrjames83
jrjames83 / max_subarray_python.ipynb
Created January 30, 2018 03:18
Python Maximium Subarray - Greedy Solution With Algorithmic Complexity via %time
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jrjames83
jrjames83 / python_sample_size_estimator_simulation.py
Created January 24, 2018 03:53
Python - Estimate Distribution of a Population Category through Randomly Sampling From it and find the number of samples to arrive at a decent approximation of the pop distribution.
# How to determine sample size through simulation
import random
from collections import Counter
things = ['camel', 'horse', 'donkey', 'mule', 'bulldozer', 'chain', 'machete', 'tool' ,'border collie', 'widget']
weights = [random.random() * 1000 for _ in range(10)]
assert(len(things) == len(weights))
universe = random.choices(things, weights=weights, k=100000)
# YouTube Walk Through: https://www.youtube.com/watch?v=8JwdenBGmEo&feature=youtu.be
def return_change(to_return, coins = [.01, .05, .10, .25, 1.0, 5.0]):
flag = None
for c in coins:
if c == to_return: return c
if c < to_return:
flag = c
temp_balance = round(to_return - flag, 2)
return [flag] + [return_change(temp_balance)]
@jrjames83
jrjames83 / python_binomial_cointoss.py
Created January 14, 2018 03:29
Python Coin Toss Simulation of Binomial Theorem
# python 3.6
### 10 heads in a row, 10 tails in a row
from collections import Counter
from itertools import groupby
print(1 / (.50 ** 11))
# 1024 tosses to get 1 string of heads or tails consecutive
outcomes = ''
@jrjames83
jrjames83 / python_gamblers_ruin.ipynb
Created January 13, 2018 00:27
Gambler's ruin python for youtube video
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jrjames83
jrjames83 / roman_numerals.py
Created January 9, 2018 14:26
Roman Numerals Kata - Python 3.6 Dict keys retain input ordering
numerals = {"I":1, "V":5, "X":10, "L": 50, "C": 100, "D": 500, "M": 1000 }
def convert_roman(input_number):
range_flag = None
for symbol, integer in numerals.items():
if integer == input_number: return symbol
if input_number > integer:
range_flag = symbol
remaining = input_number - numerals[range_flag]