Skip to content

Instantly share code, notes, and snippets.

View louissalin's full-sized avatar

Louis Salin louissalin

View GitHub Profile
@louissalin
louissalin / gist:6486d2b9fe950a068e20
Created May 8, 2014 20:21
A test of adding validations to a domain model
import scalaz._
import Scalaz._
class InvoiceValidations {
def checkName(name: String): ValidationNel[String, String] = {
if (name.length > 100)
"name too long".failNel[String]
else
name.successNel[String]
}
@louissalin
louissalin / gist:41d05e98509998cc21e7
Last active August 29, 2015 14:01
Praask's last letter
Dear mother,
If you read this letter then I have unfortunately died. Don't believe everything you read about me,
as I'm sure not all of it is true. You knew it already; I love guns. This love is what killed me.
I dared venture out into the unknown and I guess I didn't make it back.
Ever since the day my brother was killed by a better fighter, I vowed to avenge his death. Weapons
are the best way to outmatch an opponent. They are the great equalizer. A Wookie can fall to a pistol
blast. My brother could've been saved had he carried a weapon. Fists and claws are nothing. All that
matters is the concentration of energy that is expelled from the tip of a riffle. I have spent my
@louissalin
louissalin / gist:479093b5e3a34248b09a
Created June 4, 2014 00:09
Active Record code that may or may not work
require 'sinatra'
require 'active_record'
require 'sqlite3'
require 'json'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'app.db'
)

the code that fails is below. Here's some imported code:

newtype Size = Size Int
  deriving (Eq, Ord, Show, Num)

getSize :: Size -> Int
getSize (Size i) = i
@louissalin
louissalin / gist:bec446f440fe59662c7d
Last active August 29, 2015 14:04
small git merging exercise
$ mkdir git-exercises
$ cd git-exercises
$ git init
$ touch a.txt
$ git add -A
$ git commit -m 'empty file'

##let’s work on a small feature

package test
case class Address(no: Int, street: String, city: String, state: String, zip: String)
trait LabelMaker[T] {
def toLabel(value: T): String
}
trait Plus[T] {
def plus(a1: T, a2: T): T
$ sudo gem install guard
$ sudo gem install guard-shell
links:
- https://github.com/guard/guard
- https://github.com/guard/guard-shell
Create a file named "Guardfile" in the root of the project and put the following lines in it:
guard :shell do
require 'values'
# value objects
User = Value.new(:name)
u1 = User.new("Louis")
u2 = User.new("Bob")
u3 = User.new("Louis")
main = do
config <- readDbConfig
let runAction = withConnection config
S.scotty 3000 $ do
S.get "/" $ do
res <- liftIO . runAction $ getOpportunity
S.json $ Opportunities res
S.post "/opportunities/" $ do
requestBody <- S.body
import Text.Regex
subRegex (mkRegex "\d") "some digits: 123" "*"
<interactive>:19:21:
lexical error in string/character literal at character 'd'