Skip to content

Instantly share code, notes, and snippets.

View salamanders's full-sized avatar

Benjamin Hill salamanders

View GitHub Profile
@salamanders
salamanders / console_buffer.js
Created July 22, 2013 17:27
In phonegap, buffer the outputs to console.log to help hunting down errors that would otherwise be missed.
var console_buffer = {
isBuffering: false,
logBuffer: [],
preservedConsoleLog: null,
start: function() {
"use strict";
console.log('INFO: log buffer starting'); // will be lost
console_buffer.preservedConsoleLog = console.log;
console_buffer.isBuffering = true;
console.log = function() {
/*
* This script goes through your Gmail Inbox and finds recent emails where you
* were the last respondent. It applies a nice label to them, so you can
* see them in Priority Inbox or do something else.
*
* To remove and ignore an email thread, just remove the unrespondedLabelStr and
* apply the ignoreLabelStr.
*
* This is most effective when paired with a time-based script trigger.
*
@salamanders
salamanders / TryAllClassifiers.java
Last active March 31, 2016 05:32
Ultra-hacky attempt to give EdwardRaff/JSAT a workout by blindly trying every classifier
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@salamanders
salamanders / encode_vp9.sh
Created November 13, 2015 21:31
ffmpeg reasonable vp9 encoding
ffmpeg -ss 00:09:06 -i myfile.flv -c:v libvpx-vp9 -pass 1 -b:v 2000K -threads 8 -speed 4 \
-tile-columns 6 -frame-parallel 1 \
-an -to 02:43:23 -loglevel quiet -f webm /dev/null \
&& ffmpeg -ss 00:09:06 -i myfile.flv -c:v libvpx-vp9 -pass 2 -b:v 2000K -threads 8 -speed 1 \
-tile-columns 6 -frame-parallel 1 -auto-alt-ref 1 -lag-in-frames 25 \
-c:a libvorbis -b:a 128k -to 02:43:23 -loglevel quiet -f webm myfile.webm
@salamanders
salamanders / ColumnInfo.java
Created August 13, 2016 19:13
Guava Table<Long,String,String> to JSAT DataSet (Classification or Regression)
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
@salamanders
salamanders / clean.sh
Last active November 20, 2017 17:25
Laptop weekly cleaning - upgrade and update
#!/bin/bash
if hash brew 2>/dev/null; then
echo "# UPDATING BREW"
sudo chown -R $(whoami):admin /usr/local
brew update
# brew install ffmpeg --with-faac --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libquvi --with-libssh --with-libvidstab --with-libvorbis --with-libvpx --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-snappy --with-theora --with-tools --with-webp --with-x265 --without-libvo-aacenc --without-qtkit --without-xvid
# brew install git wget ffmpeg htop imagemagick jpegoptim optipng sqlite3 python python3
# brew install boost-python --with-python3
# brew install opencv3 --with-contrib --with-cuda --with-ffmpeg --with-tbb --with-qt5 --with-java --with-opengl --with-python3
package info.benjaminhill.klatbot.piconzero
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import com.google.android.things.pio.Gpio
import com.google.android.things.pio.GpioCallback
import com.google.android.things.pio.PeripheralManagerService
@salamanders
salamanders / MLWorkout2.kt
Created August 23, 2017 20:59
JSAT Workout in Kotlin
import com.google.common.collect.ImmutableSet
import com.google.common.collect.Sets
import com.google.common.reflect.ClassPath
import jsat.classifiers.ClassificationModelEvaluation
import jsat.classifiers.Classifier
import jsat.classifiers.OneVSAll
import jsat.classifiers.svm.SupportVectorLearner
import jsat.classifiers.trees.DecisionStump
import jsat.distributions.kernels.RBFKernel
import jsat.exceptions.FailedToFitException
@salamanders
salamanders / setpersist.kt
Created October 21, 2017 02:42
Kotlin functions to allow persisting a Set<Serializable> to/from zipped file (good for prototyping and restarting processes)
/** Save/load any Set<Serializable>, works easily with your simple data class */
inline fun Set<out Serializable>.save(fileName:String="persist_${javaClass.simpleName}.ser.gz") {
val tmpPath = Files.createTempFile(fileName, ".tmp")
ObjectOutputStream(GZIPOutputStream(Files.newOutputStream(tmpPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE))).use {
println("Persisting Set<${javaClass.simpleName}> to $fileName containing ${this.size} entries.")
it.writeObject(this)
}
Files.move(tmpPath, Paths.get(fileName), StandardCopyOption.REPLACE_EXISTING)
}
/**
* Read lines and get counts
*/
fun main(args: Array<String>) {
val file = File("googlebooks-eng-1M-3gram-20090715-112.csv")
val ms = measureTimeMillis {
var total = 0
file.inputStream()
.bufferedReader()