Skip to content

Instantly share code, notes, and snippets.

//quick hack to pretty-print some text:
"((hi)(bye(yeah))((x)))".foldLeft(0){
(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
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
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 http://stackoverflow.com/questions/40622878/how-do-i-tell-sbt-to-use-a-nightly-build-of-scala-2-11-or-2-12/40622879#40622879
resolvers += "nightlies" at "https://scala-ci.typesafe.com/artifactory/scala-release-temp/"
scalaVersion := {
val propsUrl = new URL("https://scala-ci.typesafe.com/job/scala-2.12.x-integrate-bootstrap/lastSuccessfulBuild/artifact/jenkins.properties/*view*/")
val props = new java.util.Properties
props.load(propsUrl.openStream)
props.getProperty("version")
}
scalaBinaryVersion := "2.12"
@milessabin
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
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
terlar / kubectl.fish
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: https://kubernetes.io
function __kubectl_no_command
set -l cmd (commandline -poc)
if not set -q cmd[2]
return 0
end
@nafg
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
djspiewak / 0introduction.md
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.

Problems

Generic Interfaces

@ppurang
ppurang / README.md
Last active February 18, 2024 04:11 — forked from keynmol/README.md
Scala example of using htmx