Skip to content

Instantly share code, notes, and snippets.

const { uniq, map, range, zip, mapValues, groupBy, flatMap } = require('lodash');
const expandWordToDeletions = (word) => {
const wordArray = word.split("");
const deletionList = map(
range(word.length),
i => {
const copied = [...wordArray];
copied.splice(i, 1);
return copied.join("");
package util
object FutureOption {
implicit class WithFutureOption[A](self: Future[Option[A]]) {
def flatMapOption[T](e: => Exception)(f: A => Future[T]): Future[T] = {
self flatMap {
_ map f getOrElse Future.failed(e)
}
}
@matthandlersux
matthandlersux / gist:8751399
Created February 1, 2014 12:05
possible way to make easily updatable case class objects
trait Base[T] {
val id: Option[String]
def copyId(id: String): T
}
case class Test2(id: Option[String], other: String) extends Base[Test2] {
def copyId(id: String) = copy(id=Some(id))
}
@matthandlersux
matthandlersux / spike.scala
Created October 24, 2013 18:49
showing jason my spikes
// file 1
package active_column.driver
import me.prettyprint.cassandra.serializers.ByteBufferSerializer
import me.prettyprint.cassandra.serializers.DoubleSerializer
import me.prettyprint.cassandra.serializers.DynamicCompositeSerializer
import me.prettyprint.cassandra.serializers.IntegerSerializer
import me.prettyprint.cassandra.serializers.LongSerializer
import me.prettyprint.cassandra.serializers.SerializerTypeInferer
@matthandlersux
matthandlersux / serialize.scala
Last active December 25, 2015 12:39
testing a possible way to serialize to and from a nosql database
object Serializers {
trait Serializable[T] {
def serialize(t: T): String
def fromSerialized(s: String): Option[T]
}
object Serializable {
implicit object SerializableInt extends Serializable[Int] {
def serialize(t: Int) = s"int: $t"
def fromSerialized(s: String): Option[Int] = try {
@matthandlersux
matthandlersux / fizzbuzz.erl
Created November 27, 2012 22:06
fizzbuzz in erlang
-module(fizzBuzz).
-export([fizzBuzz/0]).
fizzBuzz() ->
fizzBuzz(1,3,5).
fizzBuzz(100, _, _) ->
io:format("buzz~n");
fizzBuzz(Count, Count, Count) ->
io:format("fizzbuzz~n"),
@matthandlersux
matthandlersux / PrivateMethodCaller.scala
Created September 15, 2012 12:37 — forked from jorgeortiz85/PrivateMethodCaller.scala
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))
@matthandlersux
matthandlersux / whywrong.scala
Created August 17, 2012 20:06
pulling out types?
class Test {
def pullOutType[V](f:Map[String, V] => Unit) {
var map = Map[String, V]()
val params = Map("string" -> "string", "int" -> 20, "list" -> List("ok", "then"))
params.foreach {
case (field, value) => value match {
case v:V => map = map + (field -> v)
case _ => null
}
@matthandlersux
matthandlersux / gist:3344752
Created August 13, 2012 23:18
type matching test
object Holder {
var companions = Set[AnyRef]()
def companionFor[M](m:M) = {
companions.find {
case found:M => true
case _ => false
}
}
}
@matthandlersux
matthandlersux / unclean creator in companion.scala
Created July 6, 2012 02:01
any way to make this cleaner?
abstract class SuperClass {
var initialized = false
def initialize {
initialized = true
}
}
abstract trait SubclassCompanion {
def create:Any