Skip to content

Instantly share code, notes, and snippets.

View terjesb's full-sized avatar
🎯
Focusing

Terje Sten Bjerkseth terjesb

🎯
Focusing
View GitHub Profile
@eltimn
eltimn / PasswordField
Created February 8, 2011 13:33
Lift-Record Password Field
import java.util.regex._
import scala.xml._
import org.mindrot.jbcrypt.BCrypt
import net.liftweb._
import common._
import http.S
import http.js._
import json.JsonAST.{JNothing, JNull, JString, JValue}
// ###########################################################
//
// Demonstrates how to supervise an Akka consumer actor.
//
// The consumer consumes messages from a file endpoint:
// - successful message processing by the consumer will
// positively acknowledge the message receipt, causing
// the file endpoint to delete the file.
// - an exception during message processing will cause a
// supervisor to restart the consumer. Before restart,
@momania
momania / gist:858476
Created March 7, 2011 13:05
Akka AMQP Loadbalance
import akka.amqp.AMQP._
import akka.amqp._
import akka.actor._
import java.util.concurrent.{TimeUnit, CountDownLatch}
import util.Random
object LoadBalancingDemo {
def main(args: Array[String]) {
require 'rubygems'
require 'json'
require 'redis'
class RedisComments
def initialize(redis,namespace,sort_proc=nil)
@r = redis
@namespace = namespace
@sort_proc = sort_proc
end
@etorreborre
etorreborre / gist:958304
Created May 6, 2011 01:29
A great configuration trick with implicits and default values!
case class Config(name: String="none")
def methodNeedingAConfig(implicit config: Config = Config()) = config.name
// by default there is no config
methodNeedingAConfig === "none"
// just add one in the current scope
implicit val myConfig = Config("some")
@jboner
jboner / SBT.sublime-build
Created May 6, 2011 09:47
Sublime Editor SBT build setup
{
"cmd": ["sbt-no-color compile"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true"
}
@oxbowlakes
oxbowlakes / 3nightclubs.scala
Created May 13, 2011 15:14
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@softprops
softprops / scala.html
Created May 30, 2011 03:55
data uris
<html>
<head></head>
<body>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoYAAABdCAYAAAA47Ke8AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAIABJREFUeF7tnQlgU1XWx1+2ZmvTpm2S7vu+Q8GybwIiihvijOM26jg68o3bqOPMqLgrbozO6IjruA+KCCgICLKVRaBAoXTfk6bZk6ZpsyfffelCWpo0aV7apD1v5pkm79xzz/3dm/bPfe+eS3rmk08Y0eRENodpZzNC6aFhLAabQWeyOehnJpPBZjEZoRjBB2W4v0s+GDBweeGSiMhExuihs0uj8yBeD0w8acrQED0M2JVjFBNBYY1cwyXh9dXmjzrdk+i/6o+KndvjY3fgbPpcEBColy68NB+hvz1ovAsTD0q6+Wo4RT628Wzvdz7wOlCX83u7Ff/U8R/M6XOruzLOtm59OzXOpR2q2tW1vs/7YhsWn6syDuNBf3Z0DAPc/57q4nOLy7oGwkAFR+RK7f8ceXDPzikmJ1/D67Vjg6GgS9SRfV5S3uxs56rt/VX1+7QPKTOE89B2UC/6c1NmSDvsNKd4TI6uGTL2Bo3t7pgNbQd61+cjZGgZu9F12+1DbUcdH67HzeBAHNHHkP4YNvaG+xywZbi3G9IHAz7sdpbT5z2IqvN7B2XH9eF12myuvxu2sIucbU4xOf+M+4zov2az2UaMDbcZfm34e6u17/eLxWIZ4sP5vcmUMXhNnze0r0uHfsfc//7oH2S+/S4e9lsE3gIBIAAEgAAQAAJAAAgELwEQhiP0nfXMWW7wdilEDgSAABAAAkAACACBsREAYTiMG8lmIxlee+2GseGEUkAACAABIAAEgAAQCF4CIAyd+s7W1sbq/t3Nf7Q21M8O3i6FyIEAEAACQAAIAAEgMDYC6BlgOHBB2Lthw+WWipNLSSYTmwRIgAAQAAJAAAgAASAwBQlMWWFIMptJv
@jramb
jramb / excel_core.clj
Created June 13, 2011 14:24
Creating and updating Excel files with Clojure/poi.apache.org
((ns excel.core
(:import [org.apache.poi.hssf.usermodel HSSFWorkbook HSSFSheet HSSFRow
HSSFRichTextString HSSFFont HSSFDataFormat
HSSFCellStyle HSSFCell])
(:import [java.io FileOutputStream FileInputStream IOException])
#_(:import [org.apache.poi.ss.util CellRangeAdrress]))
(defn make-excel [file-name]
(let [wb (HSSFWorkbook.)
@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get