Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Osheim non

  • Providence / Philly
View GitHub Profile
@non
non / massdel.py
Created Jan 9, 2020
Script to delete all issues for a repo. This is different than just closing all of them. It uses the v4 GraphQL Github API.
View massdel.py
#!/usr/bin/env python
#
# by Erik Osheim
#
# STEPS TO USE
#
# 0. install deps
# - pip install requests
#
# 1. generate personal access token
@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 Apr 9, 2020
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 Dec 2, 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 {
You can’t perform that action at this time.