Skip to content

Instantly share code, notes, and snippets.

//quick hack to pretty-print some text:
(a,b)=> {
var indent=a;
b match {
case '('=> println("("); indent=a+2; print(" "*indent);
case ')'=>println;indent=a-2;println(" "*indent + ")");print(" "*indent)
case x => print(x);
daniel-trinh / prettyPrint.scala
Last active November 11, 2016 09:39
Pretty Print method for formatting case class (as a string input)
def pp(tree: String, indentSize: Int = 2): String = {
var indentLevel = 0
var outputTree = ""
tree foreach { char => char match {
case '(' =>
indentLevel += 1
outputTree += char.toString+'\n'+indents
case ')' =>
indentLevel -= 1
outputTree += "\n" + indents + char.toString
adriaanm / nightly.sbt
Created December 11, 2016 19:13
How to use the latest Scala nightly build from your sbt build by @SethTisue
// originally by @SethTisue, see
resolvers += "nightlies" at ""
scalaVersion := {
val propsUrl = new URL("*view*/")
val props = new java.util.Properties
scalaBinaryVersion := "2.12"
milessabin / trait-instances.scala
Last active June 23, 2020 08:40
Constraining a trait type parameter via a super class type parameter constraint
import cats.{Applicative, Monad}
import cats.implicits._
abstract class Foo[+M[_[_]], F[_]](implicit val M: M[F])
trait Bar[F[_]] extends Foo[Applicative, F] { def bar = Applicative[F] }
trait Baz[F[_]] extends Foo[Monad, F] { def baz = Monad[F] }
class User[F[_]: Monad] extends Bar[F] with Baz[F]
object Test {
package webm
import scala.collection.{GenMap, GenTraversableOnce}
import scala.language.experimental.macros
import scala.reflect.macros.blackbox
import scala.scalajs.js
import scala.scalajs.js.|
object FunctionMacro {
gijsbotje / display-utilities.csv
Last active January 22, 2021 04:15
bootstrap v4 migration table for hidden-* and visible-*
Old New
.hidden .d-none
.hidden-xs-up .d-none
.hidden-xs .d-none .d-sm-[value]
.visible-xs .d-sm-none
.visible-xs-block .d-block .d-sm-none
.visible-xs-inline .d-inline .d-sm-none
.visible-xs-inline-block .d-inline-block .d-sm-none
.hidden-xs-down .d-none .d-sm-[value]
.hidden-sm .d-sm-none .d-md-[value]
terlar /
Last active January 31, 2021 04:11
Kubernetes fish completions
# kubernetes - is an open source system for managing containerized
# applications across multiple hosts, providing basic mechanisms for
# deployment, maintenance, and scaling of applications.
# See:
function __kubectl_no_command
set -l cmd (commandline -poc)
if not set -q cmd[2]
return 0
nafg / toVDOM.scala
Last active November 20, 2022 02:53
HTML to scalajs-react VDOM
#!/usr/bin/env amm
import scala.xml.{Elem, Node, Text, XML}
def quoteString(s: String) =
'"' +
s.replace("\n", "\\n").replace("\"", "\\\"") +
djspiewak /
Last active November 28, 2023 15:03
Scala Collections Proposal

Collections Redesign Proposal

I'm going to start off by motivating what I'm doing here. And I want to be clear that I'm not "dissing" the existing collections implementation or anything as unproductively negative as that. It was a really good experiment, it was a huge step forward given what we knew back in 2.8, but now it's time to learn from that experiment and do better. This proposal uses what I believe are the lessons we can learn about what worked, what didn't work, and what is and isn't important about collections in Scala.

This is going to start out sounding really negative and pervasively dismissive, but bear with me! There's a point to all my ranting. I want to be really clear about my motivations for the proposal being the way that it is.


Generic Interfaces

indygreg /
Created June 17, 2012 20:17
Find oldest lines in git repository
# This script parses Git blame's "porcelain" output format and
# ascertains the oldest lines of code seen.
# If you want to perform a custom report, just define your own callback
# function and invoke parse_porcelain() with it.
# The expected input format is slightly modified from raw `git blame
# -p`. Here is an example script for producing input: