Skip to content

Instantly share code, notes, and snippets.

package com.ever10.phonewords;
import java.util.*;
import java.util.stream.Collectors;
/**
* Find possible words in a phone number using the standard keypad letter mapping, and a given dictionary of words (Set<String>).
* <p>
* Algorithm: Recursively discovers all matches by exhaustively finding all letter
* combinations and matching against a word in the specified dictionary.
@raelg
raelg / Collage.scala
Last active February 28, 2017 16:46
Create a Photomosaic (https://en.wikipedia.org/wiki/Photographic_mosaic) from a directory of source images, and a given master image.
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.{File, FilenameFilter}
import java.net.URL
import javax.imageio.ImageIO
import scala.collection.immutable.IndexedSeq
import scala.io.Source
import scala.sys.process._
@raelg
raelg / NumberToString.scala
Last active July 1, 2016 12:54
Number to string
import scala.collection.immutable.TreeMap
val NUMBERS = TreeMap(
1 -> "one", 2 -> "two", 3 -> "three", 4 -> "four", 5 -> "five", 6 -> "six", 7 -> "seven", 8 -> "eight", 9 -> "nine",
10 -> "ten", 11 -> "eleven", 12 -> "twelve", 13 -> "thirteen", 14 -> "fourteen", 15 -> "fifteen", 16 -> "sixteen",
17 -> "seventeen", 18 -> "eighteen", 19 -> "nineteen", 20 -> "twenty", 30 -> "thirty", 40 -> "forty",
50 -> "fifty", 60 -> "sixty", 70 -> "seventy", 80 -> "eighty", 90 -> "ninety"
)
val HUNDREDS = TreeMap(
@raelg
raelg / gist:e12d731ba01ba58f0006
Created January 20, 2015 16:44
Scala Gson Serializer
package services
import java.lang.reflect.Type
import com.google.gson._
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.{DateTime, DateTimeZone}
object Serializers {