Skip to content

Instantly share code, notes, and snippets.

View wedens's full-sized avatar

wedens wedens

  • the middle of nowhere
View GitHub Profile
@viktorklang
viktorklang / CQRS_ES_Actor.scala
Created February 1, 2011 15:05
CQRS and EventSourcing using Akka Actors
import scala.collection.mutable.ListBuffer
import akka.actor.{Actor,ActorRef}
import akka.actor.Actor._
import akka.routing.{ Listeners, Listen }
//Represents a domain event
trait Event
//A builder to create domain entities
trait EntityBuilder[Entity] {
@eLod
eLod / gist:1384566
Created November 22, 2011 01:09
Add submodules from .gitmodules when the submodules are not committed to the repo (just the .gitmodules file, leading to git submodule init/update doing nothing).
for i in `git config -f .gitmodules --get-regexp path | cut -d" " -f2` ; do git submodule add $(git config -f .gitmodules --get submodule."$i".url) $i ; done
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@aloiscochard
aloiscochard / Action.scala
Created December 1, 2013 10:39
Slick monadic Actions
package slick
/**
* This is some code extracted from TimeOut codebase, demonstrating:
* - Use of tag typed to avoid mixing session of different DB
* - The use of the Reader Monad to compose Actions together and defer the choice of async/sync computation
*
* I remove the part where we can say if our operation are read only or not (to use different connection), in order to
* make things easier.
**/
// optionally filter on a column with a supplied predicate
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) {
def filter[T](data: Option[T])(f: T => X => scala.slick.lifted.Column[Boolean]) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
def find(id: Option[Int], createdMin: Option[Date], createdMax: Option[Date], modifiedMin: Option[Date], modifiedMax: Option[Date]) = {
@markhibberd
markhibberd / argonaut.scala
Created January 3, 2014 03:05
argonaut union type example
package argonaut.example
import argonaut._, Argonaut._
import scalaz._, Scalaz._
object UnionExample extends {
sealed trait Thing
final case class One(n: String, i: Int) extends Thing
final case class Two(n: String) extends Thing
/**
* Original source:
* [[https://gist.github.com/oxbowlakes/970717]]
*
* Modifications:
* - use scala 7.0.5
* - use toValidationNel
* - use sequenceU and traverseU instead of the lambda trick
*
* Part Zero : 10:15 Saturday Night
@joseraya
joseraya / CorsSupport.scala
Created July 1, 2014 21:24
CORS directive for Spray
package com.agilogy.spray.cors
import spray.http.{HttpMethods, HttpMethod, HttpResponse, AllOrigins}
import spray.http.HttpHeaders._
import spray.http.HttpMethods._
import spray.routing._
// see also https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
trait CORSSupport {
this: HttpService =>
@pchiusano
pchiusano / Json.scala
Last active November 7, 2023 12:53
Simple JSON parser combinator library that does not use zippers
// WARNING! totally untested, I have only compiled the code! :)
package json
import collection.immutable.Map
import scalaz.{\/, MonadPlus}
import scalaz.\/._
import scalaz.std.vector._
import scalaz.std.map._
import scalaz.std.list._
// Suggested Wartremover errors to improve inference rules and avoid partial methods which throw
wartremoverErrors ++= Seq(
Wart.Any,
Wart.Any2StringAdd,
Wart.EitherProjectionPartial,
Wart.OptionPartial,
Wart.Product,
Wart.Serializable,
Wart.ListOps,
Wart.Nothing