Skip to content

Instantly share code, notes, and snippets.

View thomasjpfan's full-sized avatar

Thomas J. Fan thomasjpfan

View GitHub Profile
@thomasjpfan
thomasjpfan / optimized_metro.py
Last active December 29, 2015 09:59
Script to obtain optimized Metrocard rides.
# number of optimized prices
num = 15
price_per_ride = 250 #cents
percentage = 5
min_price = 500 #cent
incease_percent = (100+percentage)/100.0
new_price_per_ride = price_per_ride/incease_percent
# Calculate lowest number of rides to satisfy low price
@thomasjpfan
thomasjpfan / orgphotos
Last active December 29, 2015 12:19
Command line util to organize photos in folders with the format: '{year}/{year} - {month} - {month_name}'
#!/usr/bin/env python
import os
import argparse
from datetime import datetime
from calendar import month_name as months
import shutil
EXTENSIONS = ['.jpg', '.png', '.mov', '.mp4', '.tif', '.jpeg', '.raw']
OUTPUT_TEMPLATE = '/{year}/{year} - {month} - {month_name}'
@thomasjpfan
thomasjpfan / Makefile
Created January 4, 2014 17:39
Makefile for cpp
CXX = g++
CXXFLAGS=-g -O2 -Wall -Wconversion
SOURCES=$(wildcard src/**/*.cpp src/*.cpp)
OBJECTS=$(patsubst src/%.cpp,bin/%.o,$(SOURCES))
EXECUT=build/test.exe
MAIN=src/main.cpp
LIB_SOURCES=$(filter-out $(MAIN), $(SOURCES))
@thomasjpfan
thomasjpfan / postit
Last active August 29, 2015 13:57
Simple script for posting to social pages
#!/usr/local/bin/python3
import argparse
import re
import subprocess
def is_valid_link(link):
match = re.compile(r"^https?://.+")
link_match = match.findall(link)
if link_match:
@thomasjpfan
thomasjpfan / damped_oscillator_plot.py
Created May 2, 2014 21:05
Generate plots for free damped oscillators
import matplotlib.pyplot as plt
from numpy import exp, cos, pi, linspace
from scipy.optimize import minimize
eta = 0.5
omega = 2 * pi
def damped_os(t):
return exp(-eta * t) * cos(omega * t)
@thomasjpfan
thomasjpfan / swift_challenge_3
Last active August 29, 2015 14:05
Swift Challenge #3
// Takes into account of multiple matching substrings and returns an array of String.Indexes
extension String {
func findIndexOf(subString: String) -> [String.Index]?{
let selfLength = countElements(self)
let subStringLength = countElements(subString)
if subStringLength == 0 || selfLength == 0 || selfLength < subStringLength {
return nil
@thomasjpfan
thomasjpfan / post-checkout
Created January 8, 2016 16:48
Workaround for Carthage - place in .git/hooks/
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import hashlib
import subprocess
import shutil
from pathlib import Path
def main():
set -g base-index 1
setw -g pane-base-index 1
unbind x
bind x kill-pane
bind X kill-session
set -g prefix C-a
unbind C-b
unbind-key j
bind-key j select-pane -D
unbind-key k
@thomasjpfan
thomasjpfan / karabiner.json
Created July 26, 2017 13:59 — forked from ttscoff/karabiner.json
Example Karabiner Elements setup for Vim navigation keys using Hyper+h/j/k/l
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
@thomasjpfan
thomasjpfan / how_to_run.md
Last active August 23, 2018 02:24
skorch performance testing
python -m cProfile -o skorch.prof skorch_bm.py

Install and run snackviz

pip install snakeviz
snackviz skorch.prof