Skip to content

Instantly share code, notes, and snippets.

View tbje's full-sized avatar

Trond Bjerkestrand tbje

View GitHub Profile
@tbje
tbje / Shell.scala
Last active September 26, 2017 07:56
Running a shell command in scala native capturing output
import scalanative.native._, stdlib._, stdio._
@extern
object Pipe {
def popen(cmd: CString, mode: CString): Ptr[FILE] = extern
def pclose(file: Ptr[FILE]): Unit = extern
}
object Shell {
def runCommand(cmd: String, cwd: Option[String] = None): Option[String] =
@tbje
tbje / addition.sbt
Last active February 28, 2017 08:18
addition.sbt
import com.typesafe.training.sbtkoan.SbtKoan
SbtKoan.autoImport.configurations := Set(Configurations.Test, Configuration("multi-jvm", "Multi-jvm dir", true, Nil, true))
@tbje
tbje / keybase.md
Last active July 28, 2016 12:28
keybase.md

Keybase proof

I hereby claim:

  • I am tbje on github.
  • I am tbje (https://keybase.io/tbje) on keybase.
  • I have a public key ASAKaaSO1Y7nE_TfyvDf1raxzYEXDxvW3vKzeg74psA_Lgo

To claim this, I am signing this object:

@tbje
tbje / ensimeWithSources.scala
Last active December 27, 2015 11:59
Allows you to look at sources of dependencies in ensime. Feel free to transform this into a sbt plugin.
// After having run eclipse with-sources=true from sbt (with sbteclipse) .classpath should contain sourcepaths:
val eclippseCp = scala.xml.XML.load(".classpath")
val entries = eclippseCp.child filter { _.label == "classpathentry" }
val sources = entries flatMap { _.attributes filter { _.key=="sourcepath" }} map { _.value.text }
val destDir = "~/ensime-sources" // feel free to modify this
def fileName(file: String) = new java.io.File(file).getName.replace("-sources.jar", "")
import java.io.File
@tbje
tbje / Outilne.scala
Created December 11, 2012 13:00
Phone Mnemonics
package misc
class PhoneMnemonics(words: Set[String]) {
val codeToChars: Map[Char, String] =
Map(
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ"
)
import sbt._
import sbt.Keys._
import com.typesafe.sbtscalariform.ScalariformPlugin._
object Build extends Build {
lazy val scalatrain = Project(
"scalatrain",
file("."),
settings =
@tbje
tbje / TestData.scala
Created January 31, 2012 08:04
TestData
package org.scalatrain
object TestData {
val List(munich, nuremberg, essen, cologne) =
List("Munich", "Nuremberg", "Essen", "Cologne") map { Station(_) }
val (t722, t724) = ("722", "724")
val times: Map[String, Map[Station, Time]] = Map(
t722 -> Map(
@tbje
tbje / TestData.scala
Created December 16, 2011 09:05
Test data
/*
* Copyright 2011 Typesafe Inc.
*
* This work is based on the original contribution of WeigleWilczek.
*
* Unless otherwise agreed, training materials may only be used for
* educational and reference purposes by individual named participants
* in a training course offered by Typesafe or a Typesafe training partner.
* Unauthorized reproduction, redistribution, or use of this material is prohibited.
*/
@tbje
tbje / plugins.sbt
Created November 23, 2011 12:09
Different versions of sbt and global plugins
import sbt._
import Defaults._
libraryDependencies <++= (scalaVersion, sbtVersion) {
case (scalaVersion, sbtVersion @ "0.11.0") => Seq(
sbtPluginExtra("name.heikoseeberger.groll" % "groll" % "0.4.0-SNAPSHOT", sbtVersion, scalaVersion), // corresponds to addSbtPlugin("name.heikoseeberger.groll" % "groll" % "0.4.0-SNAPSHOT")
sbtPluginExtra("com.typesafe.sbteclipse" % "sbteclipse" % "1.5.0-SNAPSHOT", sbtVersion, scalaVersion)
)
case (scalaVersion, sbtVersion @ "0.11.1") => Seq(
@tbje
tbje / plugins.sbt
Created November 23, 2011 11:26
Different versions of sbt and global plugins
import sbt._
import Default._
libraryDependencies <++= (scalaVersion, sbtVersion) {
case (scalaVersion, sbtVersion @ "0.11.0") => Seq(
sbtPluginExtra("name.heikoseeberger.groll" % "groll" % "0.4.0-SNAPSHOT", sbtVersion, scalaVersion),
sbtPluginExtra("com.typesafe.sbteclipse" % "sbteclipse" % "1.5.0-SNAPSHOT", sbtVersion, scalaVersion)
)
case (scalaVersion, sbtVersion @ "0.11.1") => Seq(