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 / 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
@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 / 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 / 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 / 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 / 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 / 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 / wulf-quote.txt
Created July 14, 2010 14:02
Common quote on computing sins.
"More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason-including blind stupidity."
--W. A. Wulf
@metasim
metasim / c-ify.sh
Created June 23, 2011 13:28
Poor man's resource compiler
#!/bin/bash
# Poor man's resource compiler
# Converts given file into compilable byte stream via
# C code header and implementation files.
# Based on original by http://www.linuxjournal.com/users/mitch-frazier
#
if [[ $# -ne 1 ]]; then
echo "Usage: $0 FILENAME"
exit 1
@metasim
metasim / ant-build-frag.xml
Created January 2, 2012 21:20
Disk image creation fragment
<!-- Fragment from an Ant build.xml file for creating a disk image with bells and whistles. -->
<property name="dmgname" value="${build.dir}/install-${name}.dmg" />
<property name="tmpdmg" value="/tmp/${app.name}-installer-tmp.dmg" />
<property name="volname" value="${app.name}-${VERSION}-Install" />
<delete file="${tmpdmg}" quiet="yes" failonerror="false" />
<!-- Create the temporary image -->
<echo>Making initial image...</echo>