Skip to content

Instantly share code, notes, and snippets.

View metasim's full-sized avatar
🎹

Simeon H.K. Fitch metasim

🎹
View GitHub Profile
@metasim
metasim / pom2sbt.sbt
Created January 8, 2016 20:14
Attempt at a command to convert a pom.xml dependency specification into sbt syntax.
/** Utility command to convert in SBT a maven dependency fragment into SBT syntax. */
def Pom2SbtCommand = "pom2sbt"
def Pom2SbtHelp = " <pom.xml>"
import complete.DefaultParsers._
lazy val pomLibs2Sbt = Command(Pom2SbtCommand,
Help((Pom2SbtCommand, Pom2SbtHelp)))(_ ⇒ fileParser(new File("./"))) { (state, file) ⇒
import scala.xml.XML
@metasim
metasim / birthday-greetings.scala
Created November 12, 2015 15:41
Birthday wishes from a colleague.
scala> (1 to 4).map { i => "Happy Birthday " + (if (i == 3) "dear Simeon" else "to You") }.foreach { println }
Happy Birthday to You
Happy Birthday to You
Happy Birthday dear Simeon
Happy Birthday to You
@metasim
metasim / build.sbt
Created July 30, 2015 17:32
Example packaging aggregation build definition.
addCommandAlias("package", "collectPackages")
addCommandAlias("stage", "universal:stage")
enablePlugins(GitBranchPrompt)
enablePlugins(JavaAppPackaging)
// TODO: Need to figure out how to look this up from the outer project
version in ThisBuild := "0.2.1-SNAPSHOT"
@metasim
metasim / OpenFolderHere.scala
Created July 22, 2015 14:14
SBT AutoPlugins FTW! Put this in your global sbt plugins directory to get an "openHere" command to launch the MacOS finder in the project directory.
import sbt._
import sbt.Keys.commands
object OpenFolderHere extends AutoPlugin {
override def trigger = allRequirements
override lazy val projectSettings = Seq(
commands += Command.command("openHere") { (state: State) =>
"open .".!
state
}
)
@metasim
metasim / java2scala-recipe.md
Last active August 29, 2015 14:08
Quickly convert a bunch of Java files to Scala from the command line

Here's one way of brute-force converting a bunch of Java code to Scala without too much concern for correctness.

Hard stuff is done by scalagen.

If the project is Maven-based with an existing pom.xml, all you need to do is run the scalagen Maven plugin:

mvn com.mysema.scalagen:scalagen-maven-plugin_2.10.1:0.3.2:main -DtargetFolder=target/scala

You have to have a pom.xml file for this to work. If your project is configured with sbt (or have no project!), use the sbt makePom task to create one:

@metasim
metasim / FutureMergeTest.scala
Created August 14, 2014 14:38
Example of merging results from `Future`s created in an *akka-streams* `Flow` into another `Flow`..
import akka.actor._
import akka.stream.actor.ActorPublisher
import akka.stream.scaladsl._
import akka.stream.{ FlowMaterializer, MaterializerSettings }
import akka.testkit._
import org.scalatest.FunSpecLike
import scala.concurrent.Future
import scala.concurrent.duration._
class FutureMergeTest extends TestKit(ActorSystem()) with FunSpecLike with ImplicitSender {
@metasim
metasim / pom2sbt.scala
Last active August 29, 2015 14:04
SBT plugin fragment implementing utility command to read `pom.xml` and convert `<dependency/>` elements to SBT format.
// NB: Requires SBT >= 0.13.5
package pomhelpers
import sbt._
import Keys._
import sbt.complete.Parser
import sbt.complete.DefaultParsers._
object ExtractMvnDependencies extends AutoPlugin {
override def trigger = allRequirements
@metasim
metasim / None-vs-null-worksheet.scala
Created June 28, 2014 16:19
Explanatory example showing how `Option[T]` is much more powerful than just `null.asInstanceOf[T]`
// Comparison of using `null` vs `None` to represetn NAs
val csvtext = "1,4,5,6,,9,12"
val tokens = csvtext.split(",").toList
// Null NA Approach
val nullNAs = tokens.map(t => if(t.isEmpty) null else t)
val numFromNulled = for {
t <- nullNAs
num = if(t == null) null else t.toInt
@metasim
metasim / 1.30.14 Meeting Notes.md
Last active August 29, 2015 13:55
Virginia Scala Scholars Meeting Notes

Central Virginia Scala Scholars

Agenda

  1. Introductions
    • Name, company, kind of development, etc.
  2. Discussion
#!/usr/bin/env ruby -wKU
# -*- coding: utf-8 -*-
# Adapted from Brett Terpstra’s original “Markdown to Evernote” service (http://brettterpstra.com/a-better-os-x-system-service-for-evernote-notes-with-multimarkdown/)
# Martin Kopischke 2011 – License: Creative Commons Attribution Share-Alike (CC BY-SA) 3.0 Unported (http://creativecommons.org/licenses/by-sa/3.0/)
# Changes: – support for setting the creation date with 'Date:' MMD metadata attribute
# – create only one Evernote note per (Multi)Markdown input passed (instead of one per line)
# – do not choke on shell escape characters (use Tempfile instead of shell pipe for osascript)
# – default to MultiMarkdown 3 executable (instead of MMD 2 Perl script)
# – make smart typography processing optional (set SMARTY to 'false' to bypass processing;