Skip to content

Instantly share code, notes, and snippets.

var StringExpressionParser = function () {
this.operators = [
'+', '-', '*', '/', '^'
];
this.priorities = [
['*', '/'],
['+', '-']
];
};
@eed3si9n
eed3si9n / sbt-plugin-ranking-2017-08-05.md
Last active June 8, 2018 09:15 — forked from xuwei-k/sbt-plugin-ranking-2014-02-25
List of sbt plugins sorted by GitHub stars. This was generated using https://gist.github.com/eed3si9n/ea4ceef0c5e5c07d6e62c87bea029f88, then augmented by hand.
@rudogma
rudogma / TestNewtypes.scala
Last active January 1, 2019 17:24
Newtype upgrading for implicits & implicit conversions without imports
import scala.language.higherKinds
import scala.language.implicitConversions
object TestNewtypes extends App {
/**
Changed lines:
type NewType = Newtype[T, Tag0] with superduper.Tag[T, this.type]
def apply[TagIn, Sub, C](c: C)(implicit tagger: Tagger[TagIn, Type, Tag, Sub, C]): NewType = c.asInstanceOf[T with NewType]
// allows converting one class to another by providing missing fields
object convert {
@annotation.implicitNotFound("""
You have not provided enough arguments to convert from ${In} to ${Out}.
${Args}
""")
trait Convertible[Args, In, Out] {
def apply(args: Args, in: In): Out
}
@kubukoz
kubukoz / Playground.scala
Created August 30, 2019 01:47
TCP server dumping input to stdout with fs2
import cats.effect._
import java.net.InetSocketAddress
import java.nio.channels.AsynchronousChannelGroup
import java.util.concurrent.Executors
import fs2.Stream
import cats.implicits._
@non
non / sizes.txt
Last active October 16, 2019 10:09
Size of various JVM data structures in bytes (top column is number of elements).
COLLECTION 0 1 5 10 50 100 500 1000
Array[Int] 16 24 40 56 216 416 2016 4016
immutable.BitSet 24 24 24 24 24 32 96 160
immutable.IntMap[Int] 16 40 328 688 3568 7168 35968 71968
immutable.List[Int] 16 56 216 416 2016 4016 20016 40016
immutable.Map[Int,Int] 16 40 304 720 4856 9680 53504 111760
immutable.Queue[Int] 40 80 240 440 2040 4040 20040 40040
immutable.Set[Int] 16 32 264 480 3016 5840 27696 57952
immutable.SortedMap[Int,Int] 40 88 280 520 2440 4840 30008 62008
immutable.SortedSet[Int] 40 104 296 536 2456
@cmalven
cmalven / cmal-fresh-mac-setup.md
Last active November 17, 2019 19:03
Fresh Mac Setup

New Computer Setup

Last tested using Mac OS X 10.8 Mountain Lion

Setup Dropbox

Copy Dropbox folder from previous drive to user folder

@duarten
duarten / HashMapBenchmark.java
Created October 30, 2014 18:33
Concurrent maps benchmarks
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import scala.collection.concurrent.TrieMap;
import org.openjdk.jmh.annotations.*;
@BenchmarkMode(Mode.AverageTime)
sealed trait Path
case class Field(name: String, child: Option[Path]) extends Path {
override def toString: String = child match {
case None => name
case Some(path) => s"$name.$path"
}
}
@johnynek
johnynek / almosttailrec.scala
Last active February 29, 2020 17:11
A generalization of tail recursion for stack safety in scala
/*
* Consider a simple recursive function like:
* f(x) = if (x > 1) f(x - 1) + x
* else 0
*
* This function isn't tail recursive (it could be, but let's set that aside for a moment).
* How can we mechanically, which is to say without thinking about it, convert this into a stack safe recursion?
* An approach is to model everything that happens after the recursion as a continuation, and build up that
* continuation in a stack safe manner. Here is some example code:
*/