Skip to content

Instantly share code, notes, and snippets.

@ejain
ejain / gpx2geojson.py
Created January 2, 2020 20:34
Build a GeoJSON file from a collection of GPX files.
import dateutil.parser
import fiona
import glob
import json
import math
import pytz
import re
import sys
from pathlib import Path
@ejain
ejain / polylines2gpx.js
Created January 2, 2020 20:17
Build a GPX file from a CSV file exported from dashboard.automatic.com.
"use strict";
var csv = require("ya-csv");
var polyline = require("polyline");
var moment = require("moment-timezone");
var togpx = require("togpx")
var reader = csv.createCsvStreamReader(process.stdin, { columnsFromHeader : true });
var geojson = {
@ejain
ejain / emfitqs.py
Created January 31, 2017 22:00
Retrieves sleep presence records from Emfit QS, and merges the records into a single spreadsheet.
import io, re, requests, sys, time, zipfile
def get_device(token):
r = get("/api/v1/user/get", token)
device = r.json()["user"]["devices"]
print("Device: " + device, file = sys.stderr)
return device
def list_presences(token, device):
r = get("/v4/presence/{0}/latest".format(device), token)
@ejain
ejain / panel.txt
Created January 13, 2017 19:42
Arivale's clinical blood tests (as of August 2016)
Homocysteine (serum)
Total cholesterol
LDL
LDL particle number
LDL small particle number
LDL size
Oxidized LDL
HDL
HDL particle number
Triglycerides
@ejain
ejain / AV15-xxxx.otuTable.tsv
Last active January 27, 2016 17:59
Converts Second Genome data files to a uBiome taxonomy file.
dnOTU_15 AV15-1068 16733
dnOTU_16 AV15-1068 20403
dnOTU_17 AV15-1068 32939
@ejain
ejain / flights.groovy
Last active December 25, 2015 21:43
Concatenates tracklogs from FlightAware for import into Google Fusion Tables.
import groovy.xml.MarkupBuilder
new MarkupBuilder().kml(xmlns : 'http://www.opengis.net/kml/2.2') {
Document() {
new File(args?.size() ? args[0] : '.').eachFileMatch(~/.*\.flight\.kml/) { file ->
new XmlParser().parse(file).Document.Placemark.each { placemark ->
placemark.Point.each { point ->
Placemark {
name(placemark.name.text())
Point {
@ejain
ejain / LoopBenchmark.java
Last active August 29, 2015 14:27
A JMH microbenchmark comparing the performance of different looping constructs.
package benchmark;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
@ejain
ejain / SortBenchmark.java
Created December 18, 2014 03:39
A JMH microbenchmark comparing sorting performance on Ints.asList vs an actual List.
package benchmark;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
@ejain
ejain / SyncBenchmark.java
Last active August 29, 2015 14:11
A JMH microbenchmark to determine how a JVM is optimizing calls to synchronized methods.
package benchmark;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
@ejain
ejain / ArithmeticBenchmark.java
Created December 10, 2014 00:52
A JMH microbenchmark to determine if a JVM is optimizing divisions by two.
package benchmark;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;