This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
val reverseLetters = ( ('a' to 'z') zip ('a' to 'z').reverse ).toMap.withDefault(identity) | |
val words = Source.fromFile("/usr/share/dict/words").getLines.toVector | |
def isWordMatch(word: String) = { | |
val reverseLetterWord = word.toLowerCase.map(reverseLetters) | |
reverseLetterWord.reverse == word | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RESET="\[\017\]" | |
NORMAL="\[\033[0m\]" | |
YELLOW="\[\033[33;1m\]" | |
function colour256() { | |
echo "\[\033[38\;5\;$1m\]"; | |
} | |
# Alternative to \W. \W works in $PS1, but bash can not interpret it | |
function pwdbn() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
httpProxy = require('http-proxy'); | |
// | |
// A node http-proxy application to sit in front of a cube server (https://github.com/square/cube) | |
// and do some primitive authentication to require a password (specified in the 'cube-password' header | |
// in order call the write apis, but still allowing anyone to call the read apis. | |
// | |
httpProxy.createServer(function (req, res, proxy) { | |
if(req.method !== 'OPTIONS' && req.method !== 'GET') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="https://raw.github.com/mbostock/d3/master/d3.min.js"></script> | |
<script type="text/javascript" src="https://raw.github.com/square/cubism/master/cubism.v1.min.js"></script> | |
<style> | |
.time-series { | |
font-family: "Helvetica Neue", Helvetica, sans-serif; | |
margin: 30px auto; | |
width: 800px; | |
position: relative; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
test -f ~/.sbtconfig && . ~/.sbtconfig | |
SBT_LAUNCH=/usr/local/Cellar/sbt/0.12.1/libexec/sbt-launch.jar | |
# Take leading integer as debug port and not sbt args | |
DEBUG_PORT=$1 | |
SBT_ARGS=`echo "$@" | grep -oE "[^0-9].*"` | |
exec java -Xmx512M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT} ${SBT_OPTS} -jar $SBT_LAUNCH $SBT_ARGS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.ActorRef | |
import akka.util.Timeout | |
import concurrent.{Promise, Future, ExecutionContext} | |
import spray.http.{HttpMethods, HttpResponse, HttpRequest} | |
import spray.client.pipelining._ | |
import spray.http.StatusCodes.Redirection | |
import concurrent.Promise._ | |
import spray.http.HttpMethods._ | |
import scala.concurrent.duration._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val sets = List( | |
name.map(n => Field("name", n)), | |
share.map(s => Field("shared", s)) | |
).flatten | |
val query = sets.zipWithIndex.foldLeft(Q.u + "UPDATE wishlist SET "){ | |
case (q, (f, 0)) => q + f.col + " = " +? f.value | |
case (q, (f, _)) => q + ", " + f.col + "=" +? f.value | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Experiment trying to mimic the java syntax | |
// isTrue ? thing: otherThing | |
//NOTE: This is just for proving a point about scala's great expressivness. | |
// Don't use this for anything real. In real code use if(isTrue) thing else otherThing | |
class QuestionWithSuccess[T](cond: Boolean, success: T) { def |(fail: T) = if(cond) success else fail } | |
class Question(cond: Boolean) { def ?[T](t: T) = new QuestionWithSuccess(cond, t) } | |
implicit def boolToQuestion(b: Boolean) = new Question(b) | |
true ? "ham" | "cheese" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f recoverWith { | |
case _: TimeoutException ⇒ | |
Future.failed(new TimeoutException("Alerts API Timeout")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f recoverWith { | |
case _: TimeoutException ⇒ | |
log.error("Alerts API took too long") | |
Future.failed(new TimeoutException("Alerts API Timeout")) | |
} |
OlderNewer