Skip to content

Instantly share code, notes, and snippets.

Dmitriy Kostyuchenko thedmitriyk

Block or report user

Report or block thedmitriyk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@thedmitriyk
thedmitriyk / JVMOpcodeLookup.scala
Created Oct 20, 2015
JVM Opcode Mnemonic Lookup Map
View JVMOpcodeLookup.scala
val opcodeLookup = Map(
0 -> "nop",
1 -> "aconst_null",
2 -> "iconst_m1",
3 -> "iconst_0",
4 -> "iconst_1",
5 -> "iconst_2",
6 -> "iconst_3",
7 -> "iconst_4",
8 -> "iconst_5",
@thedmitriyk
thedmitriyk / JVMParamParser.scala
Last active Nov 11, 2015
Parse JVM-style method parameter strings (e.g. "I[[BLjava/lang/String;") into separate components (e.g. Seq("I", "[[B", "Ljava/lang/String;"))
View JVMParamParser.scala
object JVMParamParser {
def parse(sig: String) = {
def parseRec(acc: Seq[String], sig: List[Char]): Seq[String] = {
val drop = sig.dropWhile(_ == '[')
val fill = Seq.fill(sig.length - drop.length)('[').mkString
drop match {
case head :: tail if jvmTypeLookup.contains(head) =>
parseRec(acc :+ s"$fill${head.toString}", tail)
case head :: tail if head == 'L' =>
@thedmitriyk
thedmitriyk / SpellCheck.scala
Created Jul 15, 2015
A naïve Scala implementation of Peter Norvig's Spelling Corrector from http://norvig.com/spell-correct.html Optimized for neither readability nor brevity nor performance.
View SpellCheck.scala
object SpellCheck {
val alpha = "abcdefghijklmnopqrstuvwxyz"
val model = scala.io.Source.fromFile("big.txt")
.getLines()
.flatMap(_.toLowerCase.split("\\W+"))
.foldLeft(Map.empty[String, Int].withDefaultValue(1)) { (acc, word) =>
acc + (word -> (acc.getOrElse(word, 0) + 1))
}
@thedmitriyk
thedmitriyk / FlickrBase58Coder.scala
Last active Nov 3, 2016
Flickr Base58 encoder and decoder written in Scala.
View FlickrBase58Coder.scala
object FlickrBase58Coder {
val alpha = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
val base = alpha.length
def apply(encodedInput: String) = decode(encodedInput)
def apply(decodedInput: Long) = encode(decodedInput)
def encode(input: String): String = encode(input.toLong)
def encode(input: Long) = {
def enc(in: Long, acc: String): String = if (in < 1) acc else enc(in / base, alpha((in % base).toInt) + acc)
You can’t perform that action at this time.