Skip to content

Instantly share code, notes, and snippets.

View messiest's full-sized avatar
👾
beep boop

Chris Messier messiest

👾
beep boop
View GitHub Profile
@messiest
messiest / timer.py
Last active December 5, 2019 20:22
import time
from contextlib import ContextDecorator
class Timer(ContextDecorator):
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, *exc):
def camel_case(s):
s = s.split()
leading = [x.lower() for x in s[:1]]
trailing = [x.capitalize() for x in s[1:]]
return ''.join(leading + trailing)
@messiest
messiest / reinstall.sh
Created November 7, 2018 19:37 — forked from 8enmann/reinstall.sh
Reinstall NVIDIA drivers without opengl Ubuntu 16.04 GTX 1080ti
# Download installers
mkdir ~/Downloads/nvidia
cd ~/Downloads/nvidia
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/384.59/NVIDIA-Linux-x86_64-384.59.run
sudo chmod +x NVIDIA-Linux-x86_64-384.59.run
sudo chmod +x cuda_8.0.61_375.26_linux-run
./cuda_8.0.61_375.26_linux-run -extract=~/Downloads/nvidia/
# Uninstall old stuff
sudo apt-get --purge remove nvidia-*
@messiest
messiest / numeric_check.py
Last active July 3, 2018 20:26
Checking if a pandas columns are numeric
for c in df.columns:
if np.issubdtype(df[c].dtype, np.number):
# do stuff
@messiest
messiest / substring_index.py
Created June 25, 2018 14:19
Return the index of the string that contains the substring
def substring_index(strings, substring):
for i, s in enumerate(strings):
if substring in s:
return i
return False
@messiest
messiest / crypto.py
Created June 22, 2018 20:05
Get crypto prices
#!/usr/bin/env python3
import ccxt
class Coin:
price_dict = ccxt.kraken().fetchTickers()
def __init__(self, abbr, name):
self.name = name
self.pair = "{}/USD".format(abbr)
@messiest
messiest / bank_holidays.py
Created June 21, 2018 19:56
Pandas calendar for US Bank Holidays
from datetime import datetime
from pandas.tseries.offsets import DateOffset, WeekOfMonth
from pandas.tseries.holiday import sunday_to_monday, AbstractHolidayCalendar, \
Holiday, USMemorialDay, USLaborDay, USColumbusDay, USThanksgivingDay
class BankCalendar(AbstractHolidayCalendar):
rules = [
Holiday("New Year's Day", month=1, day=1, observance=sunday_to_monday),
@messiest
messiest / list_splice.py
Created May 1, 2018 23:25
Splicing lists in python
def list_splice(*args):
out = [None] * (sum(len(i) for i in args))
for i, l in enumerate(args):
out[i::len(args)] = l
return out
import gym
env = gym.make('SuperMarioBros-1-1-v0')
observation = env.reset()
done = False
t = 0
while not done:
action = env.action_space.sample() # choose random action
observation, reward, done, info = env.step(action) # feedback from environment
import gym
env = gym.make('SuperMarioBros-1-1-v0')
env.reset()