Skip to content

Instantly share code, notes, and snippets.

View heathermiller's full-sized avatar

Heather Miller heathermiller

View GitHub Profile
@heathermiller
heathermiller / clojure-to-scala.scala
Created November 6, 2011 14:08
Clojure to Scala, line by line
def slow = Thread.sleep(700)
def fast = Thread.sleep(100)
def threadDeliver[T](fun: => T, prom: SyncVar[T]) =
actor { prom set fun }
def main[T](a: => T, aw: Long, b: => T, overall: Long, default: T): T = {
val p = new SyncVar[T]
threadDeliver(a, p)
@heathermiller
heathermiller / clojure-to-scala-clean.scala
Created November 6, 2011 14:10
Clojure to Scala, cleaned up
def slow = Thread.sleep(700)
def fast = Thread.sleep(100)
def threadDeliver[T](fun: => T, prom: SyncVar[T]) =
actor { prom set fun }
def tryDeliver[T](promise: SyncVar[T], a: => T, timeout: Long)(otherwise: => T): T = {
threadDeliver(a, promise)
promise.get(timeout) match {
@heathermiller
heathermiller / so-try.scala
Created June 27, 2012 15:07
Illustrative use case for transform on scala.util.Try
def result(i: Int, d: Double, b: Boolean) = {
if (b) d else i
}
def fA(s: String) = 7
def fB(s: String, i: Int) = 1.0
def fC(s: String, i: Int, d: Double) = true
import scala.util.{Try, Success, Failure}
@heathermiller
heathermiller / try-transform.scala
Created June 27, 2012 15:46
Try.transform implementation
/** Completes this `Try` by applying the function `f` to this if this is of type `Failure`, or conversely, by applying
* `s` if this is a `Success`.
*/
def transform[U](f: Throwable => Try[U], s: T => Try[U]): Try[U] = this match {
case Success(v) => s(v)
case Failure(e) => f(e)
}

Scala Project & Developer Guidelines

These guidelines are meant to be a living document that should be changed and adapted as needed. We encourage changes that make it easier to achieve our goals in an efficient way.

General Workflow

This is the process for committing code to the Scala project. There are of course exceptions to these rules, for example minor changes to comments and documentation, fixing a broken build etc.

  1. Make sure you have signed the Scala CLA, if not, sign it.
  2. Before starting to work on a feature or a fix, it's good practice to ensure that:
@heathermiller
heathermiller / EdnPickleFormat.scala
Created June 11, 2013 20:09
A sample simplified edn PickleFormat for Scala Pickling. That's right, transfer data to a Clojure app! (Edn stands for "extensible data notation" and is Clojure's data transfer format.)
import scala.pickling._
import scala.reflect.runtime.universe._
import scala.util.parsing.json._
import scala.collection.mutable.{StringBuilder, Stack}
package object edn {
implicit val pickleFormat: EdnPickleFormat = new EdnPickleFormat
}
@heathermiller
heathermiller / gist:9158658
Last active December 11, 2018 06:35
A more beautiful Terminal experience.

A nicer Terminal experience.

Just add the following to your bash profile.

export PS1='\[\033[38;5;202;48;5;0m\]⏣ \[\033[38;5;134;48;5;0m\]\w \[\033[38;5;112;48;5;0m\]`git branch 2> /dev/null | grep -e ^* | sed -E  s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`\[\033[00m\]'

(The green bit there is the current branch you're on if you're in a directory that has a git repository within it)

/** @constructor */
ScalaJS.c.example_ScalaJSExample$ = (function() {
ScalaJS.c.java_lang_Object.call(this)
});
ScalaJS.c.example_ScalaJSExample$.prototype = new ScalaJS.inheritable.java_lang_Object();
ScalaJS.c.example_ScalaJSExample$.prototype.constructor = ScalaJS.c.example_ScalaJSExample$;
ScalaJS.c.example_ScalaJSExample$.prototype.main__V = (function() {
var paragraph = ScalaJS.g["document"]["createElement"]("p");
paragraph["innerHTML"] = "<strong>It works!</strong>";
ScalaJS.c.example_ScalaJSExample$.prototype.main__V = (function() {
var paragraph = ScalaJS.g["document"]["createElement"]("p");
var l = ScalaJS.modules.scala_collection_immutable_List().apply__Lscala_collection_Seq__Lscala_collection_immutable_List(ScalaJS.modules.scala_Predef().wrapIntArray__AI__Lscala_collection_mutable_WrappedArray(ScalaJS.makeNativeArrayWrapper(ScalaJS.data.scala_Int.getArrayOf(), [1, 2, 3])));
var l2 = ScalaJS.as.scala_collection_immutable_List(l.$$colon$plus__O__Lscala_collection_generic_CanBuildFrom__O(ScalaJS.bI(4), ScalaJS.modules.scala_collection_immutable_List().canBuildFrom__Lscala_collection_generic_CanBuildFrom()));
paragraph["innerHTML"] = (("<strong>Here's a list" + l2) + "</strong>");
ScalaJS.g["document"]["getElementById"]("playground")["appendChild"](paragraph)
});
Scala
/** @constructor */
ScalaJS.c.example_Person = (function() {
ScalaJS.c.java_lang_Object.call(this);
this.name$1 = null;
this.age$1 = 0
});
ScalaJS.c.example_Person.prototype = new ScalaJS.inheritable.java_lang_Object();
ScalaJS.c.example_Person.prototype.constructor = ScalaJS.c.example_Person;
ScalaJS.c.example_Person.prototype.name__T = (function() {
return this.name$1