Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# Use this script with sudo to install multiple golang
# installations.
if [[ $(id -u) -ne 0 ]] ; then echo "This script should be run using
sudo or as the root user" ; exit 1 ;
fi
# Ensure the user wants to rm the contents of /opt/golang!
@langley
langley / Play Framework 2.2.x Enumerator Example
Last active August 29, 2015 14:06
Play Framework 2.2.x Enumerator Example
// Start play, go into the console and copy & paste these lines
import scala.concurrent._
import scala.concurrent.duration._
import scala.language.postfixOps
import play.api.libs.iteratee._
import play.api.libs.concurrent.Execution.Implicits._
val enumerateUsers: Enumerator[String] = {
Enumerator("Guillaume", "Sadek", "Peter", "Erwan")
}
@langley
langley / Base64EncodeDecode_Play2.2.scala
Created February 2, 2014 18:59
Base64 Encode/Decode using the org.apache.commons.codec included in Play2.2 from scala. This works in the "console" from the play app.
// Works in the console from a Play 2.2 project
import org.apache.commons.codec.binary.Base64
val encoded: Array[Byte] = Base64.encodeBase64("text to be encoded".getBytes)
val decoded: Array[Byte] = Base64.decodeBase64(encoded)
println(new String(decoded))
// Code snippets to illustrate working with the
// Enumeratee api from Play Framework
// http://www.playframework.com/documentation/2.2.x/Iteratees
// You should create a play app and then launch the scala console from it.
// Then you can paste these snippets in to experiment with iteratees
// in the scala REPL.
import play.api.libs.iteratee._
import play.api.libs.concurrent.Execution.Implicits._
@langley
langley / Find an Akka 2.0 Actor in the REPL
Last active May 7, 2017 23:53
Determine whether an akka actor exists or not in the repl. Play 2.2.1 implies Akka 2.2.0 Using this trick means you don't need to maintain your own list of existing actors. However you'll need to actually use it from w/in an actor (notice that the the answer is a message)
import akka.actor._
// need an actor system, make it implicit to it's used by all our repl based actors
implicit val system = ActorSystem("replActorSystem")
// this gives us an easy way to define simple actors
import ActorDSL._
// make an actor that can be used to receive responses... just a good practice
implicit val sender = actor(new Act { become { case msg => println(s"Console sender recvd: $msg") } } )
@langley
langley / Iteratee-Enumerator-Enumeratee.scala
Last active January 2, 2016 03:39
Iteratee / Enumerator / Enumeratee code snippets
// Code snippets to illustrate working with
// Iteratee / Enumerator / Enumeratee api from Play Framework
// http://www.playframework.com/documentation/2.2.x/Iteratees
// You should create a play app and then launch the scala console from it.
// Then you can paste these snippets in to experiment with iteratees
// in the scala REPL.
import play.api.libs.iteratee._
import play.api.libs.concurrent.Execution.Implicits._
@langley
langley / SimpleActorsFromTheRepl
Last active March 31, 2016 07:25
Use simple Akka actors from the REPL. I should probably also illustrate a simple sbt project that just depends on Akka to make starting a repl with akka easy
import akka.actor._
// need an actor system, make it implicit to it's used by all our repl based actors
implicit val system = ActorSystem("replActorSystem")
// this gives us an easy way to define simple actors
import ActorDSL._
// here's a simple example of creating an actor
// Also, this will give us a simple actor that is used to print the
// results sent back to us from the other actors.
@langley
langley / UofArecs.cpp
Created August 26, 2013 18:53
UofARecs illustrates an attempt to create an avro specification for an array of values which can hold either an array of longs or an array of doubles
#include "UofARecs.hpp"
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
int
main()
{
std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
@langley
langley / Simple Play 2.1 Scala JsonService Example
Last active December 14, 2015 03:59
Simple Play 2.1 Scala Json Service
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.json._
// you need this import to have combinators
import play.api.libs.functional.syntax._
// Add this to your conf/routes
// POST /JsSayHello controllers.JsonServices.sayHello
@langley
langley / Play2.1 Web "Proxy Service" Example
Created February 24, 2013 19:29
A universal "Web Proxy Service" action for Play 2.1 Scala
# Add this to your conf/routes file
# Universal Proxy
GET /proxyGet/*urlToProxy controllers.Application.proxyGet(urlToProxy)
# Add this to a Controller class, e.g. Application
import play.api.libs.ws.WS
import play.api.libs.concurrent.Execution.Implicits._