Skip to content

Instantly share code, notes, and snippets.

Erik Osheim non

  • Providence / Philly
Block or report user

Report or block non

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
@non
non / sizes.txt
Last active Oct 16, 2019
Size of various JVM data structures in bytes (top column is number of elements).
View sizes.txt
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
View cast.sh
#!/bin/sh
#
# simple streaming from the command line:
#
# ./cast.sh send *.mp3 # stream some files
#
# ./cast.sh recv # listen to the stream
#
# currently hardcodes localhost port 9999.
#
@non
non / Wild.scala
Last active May 21, 2019
Interesting trick to lift existentials into values, so we can later refer to them.
View Wild.scala
package demo
import cats.{Applicative, Functor, Id, Semigroupal, Traverse}
import cats.arrow.FunctionK
/**
* Type-lifting operation to replace the wildcard type (i.e. _).
*
* In some cases we end up with code like: List[Option[_]]. This is
* fine unless you later need to write code in terms of a particular
View LogicalBitSet.scala
package cats.collections
sealed abstract class LogicalBitSet { lhs =>
import LogicalBitSet.{Absent, Present}
def apply(n: Int): Boolean =
this match {
case Present(bits) => bits(n)
case Absent(bits) => !bits(n)
View ack.scala
package ack
import cats.Eval
import spire.math.SafeLong
object Ackermann {
import SafeLong.{zero, one}
// requires m >= 0 and n >= 0
def run(m: SafeLong, n: SafeLong): Eval[SafeLong] =
@non
non / seeds.md
Last active Oct 28, 2019
Simple example of using seeds with ScalaCheck for deterministic property-based testing.
View seeds.md

introduction

ScalaCheck 1.14.0 was just released with support for deterministic testing using seeds. Some folks have asked for examples, so I wanted to produce a Gist to help people use this feature.

simple example

These examples will assume the following imports:

@non
non / seethru.scala
Last active Feb 13, 2018
nested opaque types demo
View seethru.scala
package object demo {
opaque type Collection[A] = Array[A]
object Collection {
opaque type Pointer[A] = Int
object Pointer {
def first(c: Collection[A]): Option[Pointer[A]] =
if (c.length > 0) Some(0) else None
@non
non / Diagonal.scala
Last active Feb 13, 2018
Initial thoughts on creating efficient ways to index into arbitrary enumerations of all values of a type.
View Diagonal.scala
package kronecker
import spire.implicits._
/**
* Utilities for doing diagonalization in N dimensions.
*
* The goal here is to be able to support diagonalizations for
* arbitrary tuples, e.g. Tuple2, Tuple3, Tuple9, etc. The "dimension"
* (or "dim") represents the arity of the tuple: dim=2 would
@non
non / JavapPlugin.scala
Created Jan 29, 2018
Slouching toward a functioning SBT plugin.
View JavapPlugin.scala
package sbtjavap
import sbt._
import Keys._
import complete.DefaultParsers.StringBasic
import scala.sys.process.Process
object Plugin extends AutoPlugin {
object autoImport {
@non
non / analysis.md
Last active Jan 2, 2018
Some notes about the interaction of SIP-23 with specialization.
View analysis.md

introduction

I was asked to consider how specialization should interact with SIP-23. Here is a quick test I did with some thoughts on where we are now versus where we should be.

See tlc.scala for the code and tlc.bytecode for the Java bytecode that code produced (using Typelevel Scala with the -Yliteral-types flag enabled).

You can’t perform that action at this time.