Skip to content

Instantly share code, notes, and snippets.

View aishfenton's full-sized avatar

Aish aishfenton

  • Netflix
  • San Francisco
View GitHub Profile
@aishfenton
aishfenton / scopt-range-parser.scala
Created February 18, 2017 21:42
Scopt range parser
implicit val listIntRead: scopt.Read[List[Int]] =
scopt.Read.reads { str =>
val parts = str.split(",").map(_.trim).toList
parts.flatMap { p =>
if (p.contains("-")) {
val (start :: end :: Nil) = p.split("-").map(_.trim.toInt).toList
Range(start, end + 1).toList
}
else p.toInt :: Nil
}
@aishfenton
aishfenton / ArrayMap.scala
Created February 10, 2017 23:38
ArrayMap.scala
trait EnumMap[A, B] {
def apply(a: A): B
}
// Quick sketch, untested.
final class ArrayEnumMap[A, @spec B : ClassTag](xs: Seq[(A,B)]) extends EnumMap[A,B] {
val (keys, values) = mkEntries(xs)
val size = keys.length
@aishfenton
aishfenton / gist:de1d18056b0311594d792add92dca3f2
Last active October 5, 2016 03:10
Scala gaps for Machine Learning
* Actively supported linear alg library ;)
* Good optimization libraries.
* Better low-level GPU libaries. JCuda, but better.
* A feature-rich plotting library.
* Richer MCMC libaries.
@aishfenton
aishfenton / UnionType.scala
Last active December 10, 2019 22:15
Union Types for Scala
package union
/**
* Much magic. Very Lambda. Wow!
*
* These types provide union types (i.e. val a = (String or Int) within Scala. See here for good discussion on
* how to represent union types in Scala (hat tip Miles Sabin)
* http://stackoverflow.com/a/37450446/1591351
*
* Core idea is to adapt Demorgan's Law:
select regexp_extract(date_time,'[^T]*T([0-9][0-9])', 1), count(*)
from single_search
group by regexp_extract(date_time,'[^T]*T([0-9][0-9])', 1)
@aishfenton
aishfenton / to_pig_format
Created June 19, 2013 20:50
Converts file from TSV format with quoted fields into a format compatible with Hadoop Pig.
#!/usr/bin/env awk -f
BEGIN {
SEP="\t"
FS="\"" SEP "\"|^\"";
}
{
out=$2;
for (i=3;i<=NF-1;i++) {
gsub(/\t/, "_", $i);
@aishfenton
aishfenton / main.css
Last active December 18, 2015 03:08
Knitr Stylesheet
body {
font-family: sans serif;
background-color: white;
font-family: georgia;
font-size: 15px;
margin: 20px;
}
ul {
list-style-type: square;
@aishfenton
aishfenton / benchmark_bloomfilter.rb
Created December 5, 2012 23:59
Benchmark BloomFilter serialization
require "benchmark"
require "mongoid"
require "bloomfilter-rb"
module BloomFilter
class Native
def self.unpack(str)
bitstring = str.unpack("B*").first
bytes = []
@aishfenton
aishfenton / vworkapp.js
Created September 5, 2011 04:32
vWorkApp Javascript Script
// ------------------------------------------------------------------------------------------------------------------//
// vWorkApp Core Library
// ------------------------------------------------------------------------------------------------------------------//
var vWorkAppScript = vWorkAppScript || {};
vWorkAppScript.host = "api.vworkapp.com";
vWorkAppScript.apiToken = "PUT YOUR API KEY HERE"
(function() {
@aishfenton
aishfenton / broken_ssl.rb
Created June 14, 2011 00:27
evma_httpserver broken with SSL
require 'eventmachine'
require 'evma_httpserver'
class MyHttpServer < EventMachine::Connection
include EventMachine::HttpServer
def post_init
super
ssl_dir = File.join(File.dirname(__FILE__), "ssl")
server_key = File.join(ssl_dir, "server.key")