Skip to content

Instantly share code, notes, and snippets.

View abehmiel's full-sized avatar

Abraham Hmiel abehmiel

View GitHub Profile
@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 / 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 / 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 / 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 / PRP_scrape.py
Last active August 12, 2017 16:57
Press release scrape for pressreleasepoint.com - verbose output to console and saves to text file
"""
Because this code take so long to run as-coded below, I recommended to follow it
up with a check for file duplicates (fdupes -dN in linux seems to work)
After downloading, you can combine them into a single corpus file by concatenating:
find . -name "*.txt" -exec cat '{}' ';' > dirty.txt
Then you can use whatever means you wish to clean up the text and remove unicode symbols
and so on
"""
@abehmiel
abehmiel / test_prime.py
Last active August 10, 2017 17:23
Even better parameterized pytest boilerplate
# test_prime.py
# from James Routley's blog: https://jamesroutley.co.uk/tech/2017/08/09/parameterise-python-tests.html
import pytest
from prime import is_prime
@pytest.mark.parametrize("x,output", [
(-1, False),
(0, False),
@abehmiel
abehmiel / beautiful_idiomatic_python.md
Created August 11, 2017 21:44 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@abehmiel
abehmiel / prepare_yr_library.py
Created August 12, 2017 01:50
Library for hackerrank challenges
""" GCD/ LCD """
# greatest common divisor
from fractions import gcd
gcd(x,y)
# least common multiple
def lcm(x, y):
""" This function takes two
integers and returns the L.C.M. """
@abehmiel
abehmiel / sbuzz.py
Last active October 24, 2017 05:03
Buzzfeed article scraper for NLP
from bs4 import BeautifulSoup
import requests
# for cleaning:
import re
import string
import nltk
from itertools import chain
def scrape_buzzfeed_article(url):
@abehmiel
abehmiel / keybase.md
Created October 11, 2017 17:07
Keybase proof

Keybase proof

I hereby claim:

  • I am abehmiel on github.
  • I am abehmiel (https://keybase.io/abehmiel) on keybase.
  • I have a public key whose fingerprint is 9268 F147 2D66 ED22 5564 4480 AB82 9B94 356E D366

To claim this, I am signing this object: