Skip to content

Instantly share code, notes, and snippets.

@petrovg
petrovg / gist:dbdaf451901ff0bef2e3
Created May 13, 2014 16:43
Scala future error recovery/handling
object TMP extends App {
import scala.concurrent.{Future, Await}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
def b1 = {
val f: Future[Int] = scala.concurrent.future { 100 }
val r = Await.result(f, 1.second)
println(":> " + r)
}
@petrovg
petrovg / gist:6323747
Last active December 21, 2015 14:59
Consuming a twitter feed with OAuth
object twitter {
import play.api.libs.ws._
import play.api.libs.iteratee._
import play.api.libs.oauth._
import scala.concurrent.ExecutionContext.Implicits.global
val key = ConsumerKey("XXXX", "XXXX")
val twitter = OAuth(ServiceInfo(
"https://api.twitter.com/oauth/request_token",
@petrovg
petrovg / gist:6322197
Last active December 21, 2015 14:49
Consuming a web resource in chunks with a Play framework Iteratee
import play.api.libs.ws._
import play.api.libs.iteratee._
import scala.concurrent.ExecutionContext.Implicits.global
WS.url("http://www.bbc.co.uk").get( resp => Iteratee.fold(0) { (i:Int, el:Array[Byte] ) => println(el); i + 1} )
@petrovg
petrovg / gist:6018105
Last active December 19, 2015 21:09
Zsh colour theme
PROMPT='%{$fg_bold[green]%}➜ %{$fg_bold[green]%}%p %{$fg[green]%}%c %{$fg_bold[green]%}$(git_prompt_info)%{$fg_bold[green]%} % %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}) %{$fg[green]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%})"
<html>
<head></head>
<body>
<script>
var A = {who: "A"};
A.sine = function(x) { return Math.sin(x); }
A.cube = function(x) { return x*x*x; }
A.compose = function(f, g) {
return function(x) { return f(g(x)); }
@petrovg
petrovg / Noddy.js
Last active December 19, 2015 00:29
A noddy little REST test server, that allows you to set up a bunch of resources using PUT requests and then serves them back at you. This makes setting up test cases for REST consumers very simple. Run using 'node Noddy.js'. Default port is 9210 - look at the bottom to change that
var http = require('http')
var respond = function(res, s) {
res.writeHead(200);
res.write(s);
res.end();
}
var makeService = function(resources) {