Skip to content

Instantly share code, notes, and snippets.

View jsilva's full-sized avatar

Joao Da Silva jsilva

View GitHub Profile
case object transaction {
import java.sql.Connection
def apply[T](query: => T):Option[T] = {
val conn:Connection = play.db.DB.getConnection
val auto:Boolean = conn.getAutoCommit
try {
conn.setAutoCommit(false)
Some(query)
} catch {
@jsilva
jsilva / UserModel.scala
Created August 27, 2011 14:12
some snippet i found on the web. for Play Scala Anorm
package models
import externals.BCrypt
import play.db.anorm._;
class User (protected var _id: Int, protected var _email: String, protected var _name: String,
protected var _password: String, protected var _permissions: Set[String]) extends ActiveModel {
private val BCRYPT_WORK_FACTOR: Int = 6
@jsilva
jsilva / Shell
Last active December 11, 2015 02:09
# to install the latest stable version:
brew install play
# to install play-2.1-RC1:
brew install https://raw.github.com/gist/4528959/play.rb
# to switch versions (from https://github.com/mxcl/homebrew/wiki/External-Commands):
brew switch play 2.0.4
brew switch play 2.1-RC1
@jsilva
jsilva / deploy.sh
Last active December 11, 2015 07:08
#!/bin/bash -e
if [ -f /etc/cron.d/initialrunner ]; then
rm /etc/cron.d/initialrunner
fi
echo "10.181.8.179 salt salt.fffflash.com" >> /etc/hosts
mkdir -p /srv/src && cd /srv/src && wget -O - http://bootstrap.saltstack.org | sudo sh
reboot
// The "classic" Repository interface
trait BoatRepository {
def find(uid: String): Future[Boat]
}

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

@jsilva
jsilva / springer-free-maths-books.md
Created December 29, 2015 08:48 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
@jsilva
jsilva / about.md
Created May 14, 2016 05:35 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
trait Subscriber[A] {
def send(message: A)
}
def dispatch(message: T) = F.start(subscriber.send(message)
def chunkProcessor(messages: Chunk[CommittableMessage[F, K, V]]): F[Chunk[CommittableOffset[F]]] =
messages.map { message =>
deserializer(message).flatMap {
case Some(m) => dispatch(m) >> F.delay(message.committableOffset)
@jsilva
jsilva / rpc.md
Created September 15, 2019 13:24 — forked from creationix/rpc.md
Simple RPC design

I've designed a lot of RPC protocols in my career. One pattern that's worked well basically goes as follows:

// Client calls: print('Hello World\n')
-> [1, "print", "Hello World!\n"]
// Server sends return value (or lack of return vvalue)
<- [-1]

// Client calls: add(1, 2)
-> [2, "add", 1, 2]