Skip to content

Instantly share code, notes, and snippets.

@jonas
jonas / progresstinate.sh
Created October 24, 2012 15:31
Show progress spinner based on chatty commands
# Usage:
# progresstinate "Building $SERVER_WAR" \
# mvn clean install
progresstinate() {
msg="$1"; shift; args="$@"; symbol="-"
printf "$msg [$symbol]"
"$@" | while read line; do
symbol="$(echo "$symbol" | tr -- '-/|\\' '/|\\-')"
printf "\b\b$symbol]"
done
@jonas
jonas / build.sbt
Created November 30, 2013 23:27
Scalac test case: .../src/main/scala/not_found.scala:19: not found: value x$1
name := "Scala Test Case: not found"
@jonas
jonas / scala-js-game-2.patch
Created December 1, 2013 02:01
Scala.js Game 2 patch
diff --git a/src/main/resources/00boot.js b/src/main/resources/00boot.js
index 9f2a0bf..d8961f5 100644
--- a/src/main/resources/00boot.js
+++ b/src/main/resources/00boot.js
@@ -1,3 +1,3 @@
-function cp(){};
-function ScalaJSBundle(){};
-ScalaJS.modules.example_ScalaJSExample().main();
+function xcp(){};
+function xScalaJSBundle(){};
@jonas
jonas / BufferTest.scala
Last active August 29, 2015 13:56
Test and output for debugging scala-js/scala-js#268
//...
it("should support Buffer !! - #268") {
val a = scala.collection.mutable.Buffer.empty[Int]
for (i <- 0 to 10) {
val p : Int = a.length / 2
expect(s"${a.length} / 2 -> $p, $i").toEqual("...")
a.insert(p, i)
expect(a.mkString(", ")).toEqual("...")
}

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@jonas
jonas / Typesafe-config-settings.scala
Last active October 13, 2015 10:56
Read Typesafe config settings using approach from http://rapture.io/ 's CLI module
scala> val config = com.typesafe.config.ConfigFactory.parseString("""
| a.b.c = 42
| d.e.f = hello world
| g.h.i = 2m
| """)
config: com.typesafe.config.Config = Config(SimpleConfigObject({"a":{"b":{"c":42}},"d":{"e":{"f":"hello world"}},"g":{"h":{"i":"2m"}}}))
scala> val Alpha = Setting[Int]("a.b.c")
Alpha: commands.common.SimpleSetting[Int] = a.b.c
@jonas
jonas / DateInterval.scala
Last active June 8, 2016 14:11
WIP porting Luigi's DateInterval to Scala
import org.joda.time.DateTime
import org.joda.time.DateTimeFieldType
import org.joda.time.format.{ DateTimeFormat, DateTimeFormatter }
import scala.util.Try
object utcDateTime {
val UTC = org.joda.time.DateTimeZone.UTC
def apply(year: Int, month: Int = 1, day: Int = 1, hour: Int = 0): DateTime =
@jonas
jonas / .gitconfig
Last active October 21, 2016 00:00
[alias]
prune-remotes = "!f() { for r in $(git remote); do git remote prune $r; done; }; f"
#prune-branches = "!f() { git prune-remotes; git branch --merged | sed -n 's/.*\\(version\\|bugfix\\|feature\\|jonas\\)/\\1/p' | xargs -n 1 git branch -d $b; }; f"
prune-branches = "!f() { git prune-remotes; git branch --merged | sed -n 's/[ *]*\\([a-z].*\\)/\\1/p' | grep -v master | xargs -n 1 git branch -d ; }; f"
@jonas
jonas / build.sbt
Last active November 29, 2016 02:49
JSON templating with Typesafe Config
lazy val deployProd = taskKey[Unit]("Deploy a job to prod")
lazy val deployQA = taskKey[Unit]("Deploy a job to qa")
lazy val jobConfig = settingKey[Config]("Job configuration")
// Environments endpoints are defined via Credentials where realm contains the env name.
val qa = Credentials(...)
val prod = Credentials(...)
// Task to fetch an existing JSON document, generate a new configuration
// using per-job overrides and then use the result to deploy a job.
@jonas
jonas / StringConcatenationBenchmark.scala
Created January 2, 2017 19:08
Scala string concatenation benchmark
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations._
/**
* The following command will run the benchmarks with reasonable settings:
*
* > sbt "benchmark/jmh:run -i 10 -wi 10 -f 2 -t 1 StringConcatenationBenchmark"
*/
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))