Skip to content

Instantly share code, notes, and snippets.

View abehmiel's full-sized avatar

Abraham Hmiel abehmiel

View GitHub Profile
@abehmiel
abehmiel / titlecase.js
Created May 25, 2017 14:49
Title Case in JS
function toTitleCase(str)
{
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
@abehmiel
abehmiel / fitbit_clean.py
Created May 23, 2017 20:04
Fitbit cleaner
import pandas as pd
from datetime import datetime, date
"""
Cleaning time!
This script will clean data downloaded from the fitbit website.
A little bit of preprocessing is useful. First, Separate the activities
and sleep data into different csv files and make sure there's only
one header row in each. Multiple months may be concatenated together,

Monday, May 22

Weather/Transportation

Rainy. I took the 6 from GCS to Canal St and walked about 4 blocks.

Plans

General

Intense! Met a lot of people!

@abehmiel
abehmiel / API_request.py
Last active August 19, 2019 08:30
Basic Python API request
import requests
headers = {"token": "API TOKEN"}
params = {"something": "SOMETHING"}
response = requests.get("https://www.something.com", headers=headers, params=params)
json_data = response.json()
status = response.status_code
@abehmiel
abehmiel / get_max_key.py
Created May 9, 2017 20:50
Get the key with the maximum value in a dictionary
some_dict = {'one': 1, 'two':2, 'three': 3480394803840, 'four': 4}
max_key = max(some_dict, key=some_dict.get)
@abehmiel
abehmiel / csv_tools.py
Created April 18, 2017 23:23
Useful Pandas csv import functions. Original by Chris Albon
# Thanks to Chris Albon. Shamelessly lifted from: https://chrisalbon.com/python/pandas_dataframe_importing_csv.html
import pandas as pd
import numpy as np
# Create dataframe (that we will be importing)
raw_data = {'first_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'last_name': ['Miller', 'Jacobson', ".", 'Milner', 'Cooze'],
'age': [42, 52, 36, 24, 73],
'preTestScore': [4, 24, 31, ".", "."],
@abehmiel
abehmiel / starter.lua
Created April 7, 2017 05:36 — forked from byronhulcher/starter.lua
PICO-8 Starter LUA code (save this as starter.p8)
-- pico-8 starter code
-- by @hypirlink
-- _init() is called when
-- you 'run' the program
function _init()
-- states: menu, game, end
state = "menu"
end
@abehmiel
abehmiel / gifsicle-120.sh
Created April 5, 2017 05:13
Gifsicle resize & context
#!/bin/sh
gifsicle --resize 120x120 file.gif > out-120.gif
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]
@abehmiel
abehmiel / colorblind_palete.py
Created April 3, 2017 04:54
Palette for colorblind-differentiable colors for plotting with Matplotlib
col1 = (0/255.,107/255.,164/255.) # dark blue
col2 = (255/255.,128/255.,14/255.) # orange
col3 = (171/255.,171/255.,171/255.) # half-gray
col4 = (89/255.,89/255.,89/255.) # mostly gray
col5 = (95/255.,158/255.,209/255.) # sky blue
col6 = (200/255.,82/255.,0/255.) # burnt sienna
col7 = (137/255.,137/255.,137/255.) # 3/4 gray
col8 = (162/255.,200/255.,236/255.) # periwinkle
col9 = (255/255.,188/255.,121/255.) # peach
col10 = (207/255.,207/255.,207/255.) # 1/4 gray