Skip to content

Instantly share code, notes, and snippets.

View t3hnar's full-sized avatar
🎯
Focusing

Yaroslav Klymko t3hnar

🎯
Focusing
View GitHub Profile
@t3hnar
t3hnar / Entity.scala
Created October 5, 2011 12:32
Squeryl Entity
package org.squeryl
import annotations.Transient
import java.lang.reflect.Field
/**
* @author Yaroslav Klymko
*/
trait HasValues {
protected def values: List[Any]
@t3hnar
t3hnar / pom.xml
Created October 7, 2011 10:01
run.mode=test in maven
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8</version>
<configuration>
<systemProperties>
<property>
<name>run.mode</name>
@t3hnar
t3hnar / BasicAuthentication.scala
Created October 24, 2011 13:13
BasicAuthentication in Akka
trait BasicAuthentication extends Loggable{
self: Actor =>
protected def authorize(rec: Receive): Receive = if (Props.testMode) rec
else new Receive {
def apply(v: Any) {
v match {
case method: RequestMethod => method.request.getHeader("Authorization") match {
case BasicAuth(login, password) if (authorized_?(login, password)) =>
package scala
/**
* @author Yaroslav Klymko
*/
object StringOption {
def apply(s: String): Option[String] = s match {
case null | "" => None
case _ => Some(s)
}
package com.thenewmotion.chargenetwork.server.services.proto
import akka.actor._
import akka.actor.Actor._
import akka.routing._
import akka.event.EventHandler
/**
* @author Yaroslav Klymko
*/
@t3hnar
t3hnar / JavaClass.java
Created February 7, 2012 10:47
Scala types with java classes
public class JavaClass {
public String toString() {
return ""
}
public boolean getBool() {
return false
}
}
@t3hnar
t3hnar / gist:2374796
Created April 13, 2012 07:25
Akka Http processing
val func = (req: HttpServletRequest) => {
// ASYNC SCOPE
// heavy scope, actually this is a place async is needed for
// async request might expire
(res: HttpServletResponse) => {
// RESPONSE SCOPE
// lite scope for putting collected data to response, called if not expired
(result: Boolean) => {
// CALLBACK SCOPE
// called to notify whether response sent successfully
object ConnectorTypes extends Table[(String, ConnectorType.Value)]("connector_type") {
implicit val ConnectorTypeMapper = new EnumMappedTypeMapper(ConnectorType)
def chargerId = column[String]("charger_id")
def connectorType = column[ConnectorType.Value]("connector_type")
def * = chargerId ~ connectorType
def ux = index("ux_connector_type", chargerId ~ connectorType, unique = true)
def fkCharger = foreignKey("fk_connector_types_charger", chargerId, Charger)(_.id)
@t3hnar
t3hnar / blog.scala
Created September 4, 2012 18:52
Very simple example of event sourcing
object blog {
object events {
sealed trait PostEvent
case class PostCreated(title: String) extends PostEvent
case class PostRenamed(id: Long, name: String) extends PostEvent
class EventStream() {
@t3hnar
t3hnar / Primes.scala
Created November 2, 2012 17:20
Primes
/**
* @author Yaroslav Klymko
*/
object Primes {
val naturals = {
def loop(n: Long): Stream[Long] = n #:: loop(n + 1)
loop(1)
}
val primes: Stream[Long] = {