Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am stepheweffie on github.
  • I am savantlab (https://keybase.io/savantlab) on keybase.
  • I have a public key ASDk8RYspeKagwvOjFUG8wqHOfDDZWU_nDgqvjHJyXPJOQo

To claim this, I am signing this object:

@stepheweffie
stepheweffie / screenshots.py
Last active March 22, 2018 11:36
Takes screenshots of a live drawing and saves the recording then moves the clips (shots) into a clips directory. Needs to maximize browser.
'''
Takes a screen shot of user completing a drawing in the browser at
http://mrdoob.com/projects/harmony/#shaded, searches for a Phash of screenshot as a repeat drawing.
'''
import subprocess
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
import shutil
import os.path
@stepheweffie
stepheweffie / creation_dates.py
Created March 22, 2018 11:25
Get the sorted directory by file creation dates
import os
directory = "/dir/"
os.chdir(directory)
files = filter(os.path.isfile, os.listdir(directory))
files = [os.path.join(directory, f) for f in files] # add path to files
files.sort(key=lambda x: os.path.getmtime(x))
@stepheweffie
stepheweffie / long_factorial.py
Last active March 20, 2018 16:18
The factorial function without the factorial module in python
n = input('Please provide a number n: ')
def factor_ial(number):
count = 1
arr = list()
num = number + 1
for i in range(int(num)):
if i == 1:
count += 1
#print(i, i * count)
@stepheweffie
stepheweffie / code_crackle_pop.py
Last active March 22, 2018 11:26
The application code question for the Recurse Center
'''
Write a program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle instead of the number.
If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop.
'''
def main():
for i in range(1, 101):
if i % 3 == 0:
print('Crackle')
elif i % 5 == 0:
print('Pop')
@stepheweffie
stepheweffie / adjacent_product.py
Last active March 22, 2018 11:27
returns the max product of two items for all adjacent items in the list
# the long way
def main(a, l):
for i in a:
if a.index(i) < a.index(a[-1]):
n = i * a[a.index(i) + 1]
l.append(n)
print(max(l))
return max(l)
if __name__ == '__main__':
@stepheweffie
stepheweffie / binary_searches.py
Created March 8, 2018 11:32
a simple binary search
def binary_search(array, target):
lower = 0
upper = len(array)
while lower < upper:
x = lower + (upper - lower) // 2
value = array[x]
if target == value:
return x
elif target > value:
if lower == x:
@stepheweffie
stepheweffie / first_dupe.py
Last active March 8, 2018 11:19
first complete duplicate pair of a list, not the fastest
def firstDupe(a):
"""
Finding the first occurrence of any duplicates with the first second occurrence of a value
as long as params are met.
Returns -1 if outside params.
"""
if len(a) == len(set(a)):
return -1