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 / animals.scala
Created June 25, 2015 16:09
Feeding animals
package misc
// Animal
abstract class Animal {
def name: String
def eat(food: Food): Animal =
this
case class Match(cols: Column[_]*) {
def against(what: Column[_], modifier: SearchModifier.Value*) =
SimpleExpression[Boolean]{ case (nodes, qb) =>
import qb._
qb.sqlBuilder += "MATCH("
qb.sqlBuilder.sep(nodes, ", ")(expr(_))
qb.sqlBuilder += ") AGAINST("
qb.expr(what.toNode)
qb.sqlBuilder += " "
qb.sqlBuilder.sep(modifier, " ")(_.toString)
akka {
loggers = [akka.event.slf4j.Slf4jLogger]
loglevel = "DEBUG"
actor {
provider = akka.remote.RemoteActorRefProvider
}
remote {
enabled-transports = [akka.remote.netty.tcp]
@tbje
tbje / pre-commit
Last active August 29, 2015 14:01
if test $(sbt test | grep -c -E "Reformatted|Failed") != 0
#if test $(sbt compile | grep -c -E "Reformatted|Failed") != 0
#if test $(sbt ";scalariformFormat;test:scalariformFormat" | grep -c -E "Reformatted|Failed") != 0
then
echo "Sbt detected problems"
exit 1
fi
object Trond {
val age = 25 // value - immutable variable - final in java
def sayHi = println(s"My name is Trond and I'm $age years old!") // definition - method
}
// Trond.age = 27 does not compile as age is immutable (val)
Trond.sayHi
object Eli { // singleton object - only one of these in the JVM
var age = 22 // variable (mutable)
case class User(name: String, email: String)
object User {} // <--- Notice this part here
// https://groups.google.com/forum/#!topic/scala-user/jyWBMz5Qslw
class Users(tag: Tag) extends Table[User](tag, "User") {
def name = column[String]("name", O.NotNull, O.PrimaryKey)
def email = column[String]("first", O.NotNull)
def * = (name, email) <> (User.tupled, User.unapply)
// Compile complains here ---^
}
@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