Skip to content

Instantly share code, notes, and snippets.

View natbusa's full-sized avatar

Nat Busa natbusa

View GitHub Profile
@natbusa
natbusa / testAuthController.scala
Last active December 10, 2015 10:28
An example of authentication using chained action in Play
// Natalino Busa
// twitter.com/natalinobusa
// linkedin.com/in/natalinobusa
// www.natalinobusa.com
import org.apache.commons.codec.binary.Base64.decodeBase64
object Test extends Controller {
@natbusa
natbusa / buddyentity.scala
Created January 4, 2013 22:45
Example of jpa annotated entity in scala
package com.natalinobusa.jpa
import javax.persistence._
@Entity
@Table(name = "buddy")
class Buddy(first: String, last: String) {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
var id: Int = _
@natbusa
natbusa / persistance.xml
Created January 4, 2013 22:48
jpa settings for scala and hibernate
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="com.natalinobusa.jpa.HibernateJpaScalaTutorial">
<description>
Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide
</description>
@natbusa
natbusa / main.scala
Created January 4, 2013 22:50
wrapping up scala and hibernate. Main method/object
package com.natalinobusa.jpa
import javax.persistence.EntityManager
import javax.persistence.EntityManagerFactory
import javax.persistence.Persistence
import scala.collection.JavaConversions._
object HibernateJpaScalaTutorial {
@natbusa
natbusa / build.sbt
Created January 4, 2013 22:52
sbt settings for scala and hibernate
import sbt._
import Keys._
object BuildSettings {
val buildOrganization = "http://natalino.busa.nl"
val buildVersion = "1.0.0"
val buildScalaVersion = "2.9.2"
val buildSettings = Defaults.defaultSettings ++ Seq (
organization := buildOrganization,
@natbusa
natbusa / chainedaction.scala
Created January 5, 2013 09:39
How to chain action in Play! Framework
import play.api._
import play.api.mvc._
sealed trait ChainedAction[A] extends Action[A]
object ChainedAction {
def apply[A](bodyParser: BodyParser[A])(block: Request[A] => Action[A]): ChainedAction[A] =
new ChainedAction[A] {
def parser = bodyParser
def apply(request: Request[A]) = {
@natbusa
natbusa / chainedcontroller.scala
Last active December 10, 2015 16:28
Chained Action in Play! Framework: controller example
object Collection extends Controller {
def v1Index(path: String) = ChainedAction {
request =>
println("v1Index" + ' ' + request.queryString.toString())
if (1>0)
v1Next(path, "foo")
else
Action(Ok("never here"))
}
@natbusa
natbusa / markov.gameofthegoose.py
Last active December 11, 2015 01:58
The game of the goose and markov chains.
# Natalino Busa
# twitter.com/natalinobusa
# linkedin.com/in/natalinobusa
# www.natalinobusa.com
import numpy as np
from matplotlib import pyplot
def special(p, pos_start, pos_end):
@natbusa
natbusa / markov.snakesandladders.py
Created January 25, 2013 10:13
Snakes and Ladders. Game analysis using stationary markov chains. Written in python. It uses the numpy for matrix operations and matplotlib for graph visualization
# Natalino Busa
# twitter.com/natalinobusa
# linkedin.com/in/natalinobusa
# www.natalinobusa.com
import numpy as np
from matplotlib import pyplot
size=100
CREATE TABLE followers (
key text,
created timestamp,
messages_count int,
likes_count int,
PRIMARY KEY (key)
);