Skip to content

Instantly share code, notes, and snippets.

View mathcass's full-sized avatar
👋

Cass mathcass

👋
View GitHub Profile
@mathcass
mathcass / equivalence.py
Last active February 14, 2016 02:58
A simple brute-force algorithm to create equivalence classes of a collection based on an equivalence relation.
def build_equivalence_classes(a_collection, comparer):
"""Given a collection of items that can be compared,
and a comparer for those items, return a new collection
of sublists that are equivalence classes of items in the
original collection.
"""
classes = []
accounted_for = [False] * len(a_collection)
@mathcass
mathcass / Makefile
Last active February 14, 2016 02:57
This is a simple Makefile spec that allows you to transform every .tsv file in your current directory to a .csv with a given tsv2csv python script
# You can call this with:
# make -j N all_csv
# where N can be the number of processors you wish to use in parallel
# This Make rule uses the Python script `tsv2csv.py` to turn the first argument (the .tsv file) and dumps it to the output file
%.csv: %.tsv
python tsv2csv.py $< > $@
# This gets all files in this directory that end in .tsv
@mathcass
mathcass / run.py
Created February 14, 2016 02:56
A simple example demonstrating how to use the Python memory_profiler package.
#!/usr/bin/env python
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
@profile
def infinite_loading():
"""Exceeds available memory"""
train = pd.read_csv('big.csv')

I hereby claim:

  • I am mathcass on github.
  • I am mathcass (https://keybase.io/mathcass) on keybase.
  • I have a public key ASBURwDb_4-jp5hUjLFgtQbaLz9CbS1fMxQL3pNEFfZO2go

To claim this, I am signing this object:

{
@mathcass
mathcass / aedeploy.sh
Created January 19, 2018 22:01
A generic AppEngine deploy script
#!/bin/bash
# Deploys application to default service setting version to current time, thus
# mimicking how `gcloud app deploy` works
APP="$PROJECT_NAME" # Or, just replace with your project
VERSION=$(date +%Y%m%dt%H%M%S) # ${year}${month}${day}t${24hour}${minute}${second}
gcloud config set project "$APP"
@mathcass
mathcass / aliases.sh
Created March 17, 2018 15:07
Default aliases for Ubuntu
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
@mathcass
mathcass / notebook-name.js
Created March 23, 2018 20:50
Creates a bookmarklet to automatically name your Jupyter notebook according to https://www.svds.com/jupyter-notebook-best-practices-for-data-science/
// javascript:(function(){// your code here })();
// document.activeElement.value = '2018-03-23-cp-.ipynb'
javascript:(function () {
initials = 'cp';
d = new Date();
dateStr = d.toISOString().slice(0, 10);
notebookTpl = dateStr + '-' + initials + '-.ipynb';
@mathcass
mathcass / uninstall_pip.sh
Created March 26, 2018 01:01
Within a Python virtualenv, remote all instlled packages
pip freeze | xargs -L1 pip uninstall -y
@mathcass
mathcass / json_marshal_example.go
Created April 15, 2018 20:12
Example of unmarshalling a JSON string in Go "lazily" to ensure that you at least decode some of the items in the event of an error.
// Demonstrates how to do "lazy" JSON Unmarshaling if you suspect that the main
// JSON container is formatted correctly but some sub-items may not be formatted
// correctly.
package main
import (
"encoding/json"
"log"
)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.