Skip to content

Instantly share code, notes, and snippets.

View onesamblack's full-sized avatar

sam_black onesamblack

View GitHub Profile
@onesamblack
onesamblack / remove_package_from_build.py
Created May 1, 2023 07:10
Building chromiumos - lacks the ability to remove a pre-installed ebuild file from the list of ebuilds.
# found in the LICENSE file.
import os
import argparse
import re
import atexit
import signal
import yaml
import datetime
import subprocess
from functools import partial
@onesamblack
onesamblack / regex_ebuild.py
Created April 26, 2023 09:41
ebuild-parsing-regex
import re
import os
def read_content(filepath):
with open(filepath, "r") as f:
return f.read()
ebuild_special_chars = ["*", "?", "+", "(", ")", "[", "]", ":", "=", ">", "<", "-",".","_","/"]
def compose_regex(parts=[], group="", compile=True):
@onesamblack
onesamblack / watcher.py
Created November 11, 2021 08:23
watch files
#!/usr/bin/python3
import sys
import os
import re
import psutil
import subprocess
import socket
from dotenv import load_dotenv
from twilio.rest import Client
@onesamblack
onesamblack / keras_bidirectional_lstm.py
Created March 31, 2021 04:13
bidirectional LSTM in keras
# this was a rough cut that I used in a small project, but thought it would be useful to have in case I need to refer back
# to a keras version of this. I've since switched to pytorch
# define the model object (subclass model)
# initial params
window = 30
num_cells_lstm = 32
learning_rate = 1e-6
layer_dropout = 0.5
cell_dropout = 0.2
batch_size = 16
@onesamblack
onesamblack / weighted_categorical_cross_entropy.py
Created March 31, 2021 04:09
weighted categorical cross entropy for keras
# I have since lost the original author of this -> but I've made a few edits
def weighted_categorical_crossentropy(weights):
"""
A weighted version of keras.objectives.categorical_crossentropy
Variables:
weights: numpy array of shape (C,) where C is the number of classes
@onesamblack
onesamblack / cos_sin_time.py
Created March 31, 2021 04:06
time according to the unit circle
def circular_time(ts, start_cycle=None, end_cycle=None, interval='s', as_series=True):
"""
returns a tuple (sin,cos) representing the timestamp as a coordinate in a unit circle
the calculation is 2*pi*(ratio of interest)
e.g. for a time on a 24hour clock, you have 2*pi*(seconds since midnight/seconds in day)
this cycle can be abstracted to days by using (days elapsed /days in year)
or custom cycles such as (days elapsed since start of cycle / days in cycle)
:param ts: a pandas datetime object representing the time in a 24 hour clock
"""
@onesamblack
onesamblack / apply_measures.py
Created March 31, 2021 04:01
apply_measures_to_df
"""
this is a really rough function that I use to organize applying multiple calculations to a df - it caches in a way,
in that it doesn't recalculate the measure if it exists. It also can be used in the case of dependencies.
I think there are better libraries that exist for this now - but it's handy just in case
"""
@onesamblack
onesamblack / velocityestimationnet.ipynb
Created December 24, 2020 23:51
VelocityEstimationNet.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@onesamblack
onesamblack / video_preprocessing.ipynb
Created December 23, 2020 22:42
video_preprocessing.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@onesamblack
onesamblack / mann_kendall_consensus.ipynb
Created December 17, 2020 22:33
mann_kendall_consensus.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.