Skip to content

Instantly share code, notes, and snippets.

View mgonto's full-sized avatar

Martin Gontovnikas mgonto

View GitHub Profile
@mgonto
mgonto / factorialtailrec.scala
Created September 26, 2012 04:13
Factorial Tail Rec
object factorial {
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
def factorial(n : Int) : Int = {
if (n == 0) 1 else n * factorial(n-1)
} //> factorial: (n: Int)Int
def factorial2(n : Int) : Int = {
def innerFact(n : Int, count : Int, acum : Int) : Int = {
@mgonto
mgonto / Register.scala
Last active December 9, 2015 22:48
FactoryPal Register
FactoryPal.register[Person]() { person =>
person.name.mapsTo("gonto") and
person.age.isRandom
}
@mgonto
mgonto / create.scala
Created December 19, 2012 20:06
Create
val person = FactoryPal.create[Person]
@mgonto
mgonto / Create-override.scala
Last active December 9, 2015 22:48
Create with overriders
val person = FactoryPal.create[Person]() { (person : ObjectBuilder[Person]) =>
person.age.mapsTo(45) alone
}
@mgonto
mgonto / Build.scala
Last active December 9, 2015 22:48
FactoryPal dependency
import sbt._
import sbt.Keys._
object ApplicationBuild extends Build {
lazy val root = Project(
id = "factory_pal_sample",
base = file("."),
settings = Project.defaultSettings ++ Seq(
name := "factory_pal_sample",
@mgonto
mgonto / register.scala
Created December 21, 2012 19:41
FactoryPal multiple template register
//Default template creation
FactoryPal.register[Person]() { person =>
person.name.mapsTo("gonto") and
person.age.isRandom
}
//Creating template for a certain name. This way you can create multiple templates for a certain class
FactoryPal.register[Person](Some('coolPerson)) { person =>
person.name.mapsTo("cool") and
person.age.isRandom
@mgonto
mgonto / create.scala
Last active December 10, 2015 00:59
FactoryPal multiple template per class creation
//Create a person from default template
val person = FactoryPal.create[Person]
//Creating a Person for cool template
val person = FactoryPal.create[Person](Some('coolPerson))()
@mgonto
mgonto / Build.scala
Last active December 11, 2015 03:08
FactoryPal 0.2 build
import sbt._
import sbt.Keys._
object ApplicationBuild extends Build {
lazy val root = Project(
id = "factory_pal_sample",
base = file("."),
settings = Project.defaultSettings ++ Seq(
name := "factory_pal_sample",
@mgonto
mgonto / Output.txt
Created January 23, 2013 03:18
Scanner
nfo] Compiling 2 Scala sources to /Users/gonto/repos/fp2/framework-src/target/scala-2.10/classes...
Children are List()[info]
Compiling 1 Scala source to /Users/gonto/repos/fp2/framework-src/target/scala-2.10/test-classes...
Children are List(class PalObject1, class PalObject2)Children are List(class PalObject1, class PalObject2)0Set()[info]
@mgonto
mgonto / json_controller.rb
Created February 26, 2013 03:11
Json controller
class UsersController < ApplicationController
respond_to :json
before_filter :authenticate_user!, :only => :destroy
def create
@user = User.new(params[:user])
if @user.save
respond_with @user, status: :created
else