Skip to content

Instantly share code, notes, and snippets.

@keithshep
keithshep / csv_to_hdf5.py
Created November 5, 2014 17:33
convert CSV file to HDF5 using h5py
#!/usr/bin/env python -O
import argparse
import sys
import numpy
import h5py
import csv
class ColType:
UNKNOWN = 1
@keithshep
keithshep / bash-cheats.sh
Last active February 13, 2022 02:39
bash shell cheats
#!/bin/bash
# exit on error and don't allow the use of unset variables
set -o errexit
set -o nounset
#NOTE: you can find a list of special variables at http://tldp.org/LDP/abs/html/internalvariables.html
# quietly execute GUI applications
function quietly() {
@keithshep
keithshep / scrollproblem.dart
Created June 13, 2021 04:03
scrollproblem.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
@keithshep
keithshep / python-cheats.md
Last active October 13, 2020 16:53
python cheats

Angle between two vectors

Note that this doesn't give you the direction the angle sweeps in

def angle_deg_between_vecs(vec1, vec2):
    """
    Computes an angle in degrees between two vectors
    :param vec1: the first vector (numpy array of length n >= 2)
    :param vec2: the second vector (numpy array of length n >= 2)

:return: the angle in radians

@keithshep
keithshep / git-cheats.sh
Last active September 29, 2020 15:26
git cheats
# grep through git history
for i in {1..20}
do
echo "### check master~$((i - 1)) vs master~${i} diff ###"
git diff "master~$((i - 1))" "master~${i}" | grep -i 'sample-index'
done
# merge logs across several projects
(echo "commit time,author,project,message"; \
(for i in `"ls" -d */`; do (cd $i; git log "--pretty=tformat:%ai,%an,$i,%s") 2>/dev/null; done \
@keithshep
keithshep / h5pyexample.py
Created March 5, 2019 14:32
h5py examples for mandy
# first open the file in read/write mode
with h5py.File('/path/to/file.h5', 'r+') as gait_h5:
# loop through all the videos. Here we assume current video is:
# LL1-B2B/2018-08-22_SPD/LL1-2_003890-F-AX11-5.28571428571429-43291-2-K1808155.avi
# ... somehow get your residual values into a numpy array for current video. This has to be
# done for all variables you're correcting for. Here using step_width as an example.
@keithshep
keithshep / Numpy Distance from Center Map.ipynb
Last active March 28, 2018 15:31
Create a 2D "Distance from Center" Map with numpy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import requests
import json
# a helper function that returns the error message in case there is one and
# None otherwise
def get_err_msg(x):
if 'errorMessage' in x:
return x['errorMessage']
else:
return None
@keithshep
keithshep / rhmm-example.R
Created June 14, 2010 19:57
Example use of R HMM package
library("RHmm")
sunProb <- c(0.6, 0.2, 0.15, 0.05)
cloudProb <- c(0.25, 0.25, 0.25, 0.25)
rainProb <- c(0.05, 0.10, 0.35, 0.50)
weatherDist <- distributionSet(dis="DISCRETE", proba=list(sunProb, cloudProb, rainProb), labels =c("DRY", "DRYISH", "DAMP", "SOGGY"))
weatherTransitions <- rbind(c(0.5, 0.375, 0.125), c(0.25, 0.125, 0.625), c(0.25, 0.375, 0.375))
weatherHmm <- HMMSet(initProb=c(0.63, 0.17, 0.20), transMat=weatherTransitions, distribution=weatherDist)
weatherPath <- viterbi(HMM=weatherHmm, obs=c("DRY", "DAMP", "SOGGY", "SOGGY", "DRYISH"))
@keithshep
keithshep / tree-table.component.ts
Created July 20, 2017 19:16
Tree-Table implemented with Angular
import {
Component,
ContentChildren,
Input,
QueryList,
TemplateRef,
} from '@angular/core';
@Component({
selector: 'pxa-tree-table',