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 / CommonSettingsPlugin.scala
Created April 26, 2016 02:32
Using Maven style dependencies in SBT as raw XML. No need to convert stuff about.
import sbt._
import sbt.Keys._
object CommonSettingsPlugin extends AutoPlugin {
override def trigger = allRequirements
object autoImport {
implicit class elemAdder(elem: scala.xml.Elem) {
def asModule: sbt.ModuleID = {
(elem \ "groupId").text % (elem \ "artifactId").text % (elem \ "version").text
}
@ScalaWilliam
ScalaWilliam / load.sql
Last active April 26, 2016 01:39
Load actionfps games in h2-sql
CREATE TABLE GAMES
AS SELECT * FROM CSVREAD('https://actionfps.com/all/', STRINGDECODE('ID\tJSON'), STRINGDECODE('fieldSeparator=\t'));
#!/usr/bin/env node
var EventSource = require('eventsource');
var cfgPath = require('confortable')('stream.json', process.cwd());
if (!cfgPath) {
throw new Error("Could not load stream.json");
}
var cfg = require(cfgPath);
var ircStream = require('irc-stream')(cfg.irc.server, cfg.irc.name, {
(ac_arid,15)
(ac_stellar,17)
(ac_industrial,20)
(ac_douze,20)
(ac_avenue,23)
(ac_lainio,32)
(ac_power,51)
(ac_desert,62)
(ac_outpost,97)
(ac_werk,116)
case class RetryFuture(times: Int) {
def apply[T](f: => Future[T])(implicit executionContext: ExecutionContext): Future[T] = {
f.toTryFuture.flatMap {
case failure@Failure(_) if times > 0 =>
RetryFuture(times - 1)(f)
case other =>
Future.fromTry(other)
}
}
}
@ScalaWilliam
ScalaWilliam / BindingModule.scala
Created January 3, 2016 12:03
Caching Play data in development with Hazelcast. Decreased reload times by about 5x so well worth it.
val binding = if ( environment.mode == Mode.Dev ) {
List(bind[FullProvider].to[CachedProvider])
} else Nil
@ScalaWilliam
ScalaWilliam / output.json
Created December 22, 2015 12:21
json transform with xquery 3.1 (saxon 9.7) and xslt. Only doing it in xquery because want it self contained
{"stuff":{"more":["more stuff!",{"thing":"more stuff!"}]}}
vim /c/Program\ Files\ \(x86\)/sbt/conf/sbtconfig.txt
@ScalaWilliam
ScalaWilliam / output.txt
Last active December 13, 2015 13:35
I truly can't imagine how many lines of code it would take to do this in Java/Scala/Clojure.
Got message ID 62.210.131.155:1999, type server-status:
Server: 62.210.131.155:1999
Got message ID aura.woop.ac:1999, type current-game-status:
Got message ID 62.210.131.155:4999, type server-status:
Server: 62.210.131.155:4999
Got message ID aura.woop.ac:4999, type current-game-status:
Got message ID aura.woop.ac:1999, type current-game-status-fragment:
Got message ID aura.woop.ac:4999, type current-game-status-fragment:
Got message ID 104.236.35.55:1111, type server-status:
Server: 104.236.35.55:1111
@ScalaWilliam
ScalaWilliam / for-sbt.sbt
Last active November 26, 2015 16:45
Play 2.4: making scalaxb-based requests & making them reportable via ErrorHandler e.g. https://www.playframework.com/documentation/2.4.x/ScalaErrorHandling The main use case was to log requests which failed to parse against the scalaxb parser and emit detail on that generally via the standard handler.
https://github.com/scala/async