Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Futrelle joefutrelle

  • Falmouth, MA
View GitHub Profile
@joefutrelle
joefutrelle / python_sqlite.ipynb
Created Jun 1, 2021
Working with SQLite in Python
View python_sqlite.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@joefutrelle
joefutrelle / binpack2.py
Last active Sep 15, 2021
Numba implementation of Guillotine bin packing
View binpack2.py
import numba as nb
from numba.typed import List
NO_ID = -1
DOESNT_FIT = 99999999
NO_SECTION = (0, 0, 0, 0, DOESNT_FIT)
@nb.jitclass([
('x', nb.int32),
('y', nb.int32),
@joefutrelle
joefutrelle / class_scores.py
Last active Dec 12, 2019
save/load IFCB class scores
View class_scores.py
import h5py as h5
import numpy as np
from scipy.io import savemat
def save_class_scores(path, bin_id, scores, roi_numbers, class_labels):
assert scores.shape[0] == len(roi_numbers), 'wrong number of ROI numbers'
assert scores.shape[1] == len(class_labels), 'wrong number of class labels'
with h5.File(path,'w') as f:
ds = f.create_dataset('scores', data=scores, compression='gzip', dtype='f4')
@joefutrelle
joefutrelle / tpj.pl
Last active Sep 27, 2019
Obfuscated Perl contest winner from 1997 (note: no longer works)
View tpj.pl
package S2z8N3;{
$zyp=S2z8N3;use Socket;
(S2z8N3+w1HC$zyp)&
open SZzBN3,"<$0"
;while(<SZzBN3>){/\s\((.*p\))&/
&&(@S2zBN3=unpack$age,$1)}foreach
$zyp(@S2zBN3){
while($S2z8M3++!=$zyp-
30){$_=<SZz8N3>}/^(.)/|print $1
;$S2z8M3=0}s/.*//|print}sub w1HC{$age=c17
@joefutrelle
joefutrelle / wide_to_long.py
Last active Mar 1, 2019
utility for wide to long conversion of Pandas dataframes
View wide_to_long.py
def wide_to_long(df, wide_cols_list, value_cols, long_col, long_labels):
"""converts selected columns from wide to long format. params:
- df: the input dataframe
- wide_cols_list: for each set of wide columns, a list of their names
- value_cols: for each set of wide columns, the name of the long column to hold the values
- long_col: the name of the column to indicate which set of wide columns the value comes from
- long_labels: for each set of wide columns, what to call it in the long_col values.
For example if I have the following DataFrame:
@joefutrelle
joefutrelle / install-docker.sh
Last active Feb 1, 2019
Install Docker in Debian
View install-docker.sh
# current as of 2018-12-10
# install docker-ce: https://docs.docker.com/install/linux/docker-ce/debian/#install-docker-ce-1
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
sudo apt-get update
@joefutrelle
joefutrelle / parse_btl_file.ipynb
Last active May 2, 2018
Parse Seabird CTD .btl file
View parse_btl_file.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@joefutrelle
joefutrelle / dataset.xml
Last active Apr 13, 2018
Convert nutrient data from mat export fmt to NetCDF
View dataset.xml
<dataset type="EDDTableFromNcCFFiles" datasetID="lter-nutrient" active="true">
<reloadEveryNMinutes>10080</reloadEveryNMinutes>
<updateEveryNMillis>10000</updateEveryNMillis>
<fileDir>/home/vagrant/lter-poc/output/</fileDir>
<fileNameRegex>.*\.nc</fileNameRegex>
<recursive>true</recursive>
<pathRegex>.*</pathRegex>
<metadataFrom>last</metadataFrom>
<preExtractRegex></preExtractRegex>
<postExtractRegex></postExtractRegex>
@joefutrelle
joefutrelle / aaa_nut_reps2netcdf.py
Last active May 1, 2018
create CF compliant NetCDF files from MVCO nutrient data
View aaa_nut_reps2netcdf.py
import os
from scipy.io import loadmat
import pandas as pd
from pocean.dsg.timeseriesProfile.om import OrthogonalMultidimensionalTimeseriesProfile as OMTP
MAT_FILE = '/vagrant/nut_data_reps.mat'
OUT_DIR = './output'
mat = loadmat(MAT_FILE, squeeze_me=True)
@joefutrelle
joefutrelle / proteomz.py
Last active Sep 30, 2017
bokeh plotting of proteomics data (checkpointing)
View proteomz.py
# coding: utf-8
import pandas as pd
import numpy as np
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models.widgets import Select, Slider, TextInput
from bokeh.models import HoverTool, CustomJS