Skip to content

Instantly share code, notes, and snippets.

View abehmiel's full-sized avatar

Abraham Hmiel abehmiel

View GitHub Profile
@abehmiel
abehmiel / FOXNEWS_scrape.py
Last active August 9, 2017 14:47
Script to download all fox news press releases. Prints verbose output to console and file.
from bs4 import BeautifulSoup
from glob import glob
from os import makedirs
from os.path import join
from urllib.parse import urljoin
import requests
FOX_HOME_URL = 'http://press.foxnews.com/press-archive/'
YEARS = ['2011', '2012', '2013', '2014', '2015', '2016', '2017']
MONTHS = ['january', 'february', 'march', 'april', 'may', 'june',
@abehmiel
abehmiel / CBS_scrape.py
Last active August 9, 2017 14:47
Script to download all the CBS press releases. Prints verbose output to console and to file.
from bs4 import BeautifulSoup
from glob import glob
from os import makedirs
from os.path import join
from urllib.parse import urljoin
import requests
CBS_HOME_URL = 'https://www.cbscorporation.com/'
YEARS = {'2009': '7', '2010': '4', '2011': '11', '2012': '9',
'2013': '9', '2014': '9', '2015': '4', '2016': '6', '2017': '5'}
@abehmiel
abehmiel / f1_optimize.py
Created August 3, 2017 17:25
Optimize F1 score in O(n^2)
# -*- coding: utf-8 -*-
"""
@author: Faron
"""
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
from datetime import datetime
'''
@abehmiel
abehmiel / image_augmentation.py
Created August 3, 2017 13:06
configure random transformations and normalization operations to be done on your image data during training
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
datagen = ImageDataGenerator(
rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest')
@abehmiel
abehmiel / ohe.py
Created August 3, 2017 02:56
One hot encode function (for model-building, keras, etc)
import numpy as np
def one_hot_encode_object_array(arr):
'''One hot encode a numpy array of objects (e.g. strings)'''
uniques, ids = np.unique(arr, return_inverse=True)
return np_utils.to_categorical(ids, len(uniques))
train_y_ohe = one_hot_encode_object_array(train_y)
test_y_ohe = one_hot_encode_object_array(test_y)
@abehmiel
abehmiel / memoize_decorator.py
Created July 29, 2017 19:53 — forked from eriwen/memoize_decorator.py
Memoize Decorator in Python
def memoize(fn):
cache = {}
def wrapper(*args):
try:
return cache[args]
except:
result = fn(*args)
cache[args] = result
return result
return wrapper
@abehmiel
abehmiel / test.py
Created July 28, 2017 23:59
AAA test sketch
# from http://jamescooke.info/arrange-act-assert-pattern-for-python-developers.html
# from x import *
def test_reverse():
"""
list.reverse inverts the order of items in a list, in place
"""
greek = ['alpha', 'beta', 'gamma', 'delta']
result = greek.reverse()
@abehmiel
abehmiel / ssh-auth.bashrc
Created July 28, 2017 19:38
Prompt for ssh-auth on the first time using terminal after reboot (add to .bashrc)
# from https://unix.stackexchange.com/questions/90853/how-can-i-run-ssh-add-automatically-without-password-prompt
if [ ! -S ~/.ssh/ssh_auth_sock ]; then
eval `ssh-agent`
ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
fi
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
ssh-add -l > /dev/null || ssh-add
@abehmiel
abehmiel / streaming_boy.py
Last active July 18, 2017 19:31
Simple streaming twitter bot with phrase matching
import tweepy
# from time import sleep
from creds import *
from random import randint
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
matches = ["Hello world!","Hello, world","Hello, World!","hello world"]
@abehmiel
abehmiel / cursor_bot.py
Created July 18, 2017 16:15
Super-simple cursor twitter bot framework
import tweepy
from time import sleep
from creds import *
from random import randint
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
matches = ['Hello world',