Skip to content

Instantly share code, notes, and snippets.

View ScalaWilliam's full-sized avatar
🏠
Working from home

ScalaWilliam ScalaWilliam

🏠
Working from home
View GitHub Profile
@ScalaWilliam
ScalaWilliam / interleave.awk
Created January 7, 2017 21:46
Interleave N streams line-by-line (doesn't close!)
BEGIN {
while(1) {
ch = 0
while(++ch < ARGC)
if ( getline < ARGV[ch] )
print
}
}
#!/usr/bin/jjs
function cstTime(unixTime) {
var instant = java.time.Instant.ofEpochSecond(unixTime);
var zoned = instant.atZone(java.time.ZoneId.of("America/New_York"));
return java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.format(zoned);
}
java.nio.file.Files.lines(
java.nio.file.Paths.get("/dev/stdin")
).map(JSON.parse)
#!/usr/bin/jjs
function isoTime(unixTime) {
var instant = java.time.Instant.ofEpochSecond(unixTime);
return java.time.format.DateTimeFormatter.ISO_INSTANT.format(instant);
}
java.nio.file.Files.lines(
java.nio.file.Paths.get("/dev/stdin")
).map(function (line) line.split(",", -1))
.map(function(columns) { columns.unshift(isoTime(columns[0])); return columns })
import com.eclipsesource.v8.JavaCallback;
import com.eclipsesource.v8.NodeJS;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Mapp {
private static String NODE_SCRIPT = "var http = require('http');\n"
import com.eclipsesource.v8.JavaCallback;
import com.eclipsesource.v8.NodeJS;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Mapp {
private static String NODE_SCRIPT = "var http = require('http');\n"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import com.amazonaws.ClientConfiguration
import com.typesafe.config.{ConfigBeanFactory, ConfigFactory}
object FailApp extends App {
ConfigBeanFactory.create(ConfigFactory.empty(), classOf[ClientConfiguration])
}
@ScalaWilliam
ScalaWilliam / sample.bash
Last active February 12, 2017 00:09
Scala ScriptEngine doesn't seem to be working as before in 2.12.1/2.12.0 via SBT.
# SBT + 2.11.8 gives us an IMain
$ sbt
> set scalaVersion := "2.11.8"
> console
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
scala> new javax.script.ScriptEngineManager().getEngineByName("scala")
res0: javax.script.ScriptEngine = scala.tools.nsc.interpreter.IMain@52f09302
# Loading SBT + 2.12.1 gives us a null
$ sbt
@ScalaWilliam
ScalaWilliam / Game.scala
Last active December 28, 2016 15:08
PyTest TDD + Jython/Python (2.7)
package game
import scala.collection.JavaConverters._
case class Game(teams: List[String], winner: Option[String]) { g =>
// todo turn this into a macro
final class JythonGame {
def getWinner(): String = g.winner.orNull
def getAsScala(): Game = g
def getTeams(): java.util.List[String] = teams.asJava
def __iter__(): org.python.core.PyObject = new org.python.core.PyIterator {
class ComplexFeature(serviceA: ServiceA, serviceB: ServiceB,
advancedFeature: AdvancedFeature)
extends Feature {
def execute(inputXml: Elem): Future[Result] = {
Future(ComplexFeature.process(serviceA, serviceB))
.recoverWith {
case NonFatal(e) => advancedFeature.execute(inputXml)
}
}
}