Skip to content

Instantly share code, notes, and snippets.

View OleTraveler's full-sized avatar
🤷‍♂️
Dunno

Travis Stevens OleTraveler

🤷‍♂️
Dunno
View GitHub Profile
@OleTraveler
OleTraveler / JmsControl.java
Created February 21, 2011 17:37
Wrapper around JMS to commit messages after a threshold has been met in order to commit messages in blocks.
package com.gaiam.gcsi.util;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
class WiredUser {
val userToWire = (Users.userForDisplay or userDetail.currentValue).get
private object User {
val entity = ValueCell(userToWire)
val edit = ValueCell(false)
val email = edit.lift(b => entity.lift(_.getEmail.asScala.headOption).get)
}
/*
* Created by IntelliJ IDEA.
* User: tstevens
* Date: 4/30/11
* Time: 3:50 PM
*/
package com.oletraveler.bmapz
import xml.{NodeSeq, Elem}
@OleTraveler
OleTraveler / mvn2sbt.scala
Created June 23, 2011 16:30 — forked from retronym/mvn2sbt.scala
mvn2sbt: updated to convert to 0.10.0 build.sbt file
val xml = <dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sf.oval</groupId>
<artifactId>oval</artifactId>
def lineToOffer(line: String, headers: List[String]) : Validation[NonEmptyList[String], Offer] = {
({commaSplit(_)} andThen {extractFields(_: List[String], headers)} apply line) :->
{(v) => Offer(v._1, v._2, v._3, v._4)}
}
def commaSplit(l: String): String => List[String] = l.split(",").toList
def extractFields(x: List[String], headers: List[String]): Validation[NonEmptyList[String], (String, String, String, String)] = {
notEmpty(x(headers.indexOf("offer_name")), "No offer name specified on line:" + x.mkString(","))) <|***|> (
notEmpty(x(headers.indexOf("email")), "No email specified on line:" + x.mkString(",")),
val validInt: String => ValidationNEL[String, Int] = s =>
for {
validStr <- (allDigits(s) |@| maxSizeOfTen(s))((_,x) => x)
i <- toInt(validStr)
} yield(i)
@OleTraveler
OleTraveler / TypeOf
Last active December 23, 2015 13:39
trait A {
def a: String => String
}
trait B {
//TypeOf is something magical
def b: TypeOf[A.a]
}
@OleTraveler
OleTraveler / gist:525ba037ae94625ba822
Created July 20, 2014 20:48
Code Written for blog entry:
package com.czarism.blog
import scalaz._
import Scalaz._
/**
* Created by tstevens on 7/18/14.
*/
object FavorValidation {
def maxTen(i: Int) =
if (i <= 10) \/-(i)
else "Must be less than ten"
def divisibleByTwo(i: Int) =
if (i % 2 == 0) == 0 \/-(i)
else "Must be divisable by two"
def whatType(input: Int): ???[NonEmptyList[String], Int] =
( parseInt(input) |@| divisibleByTow(input) )
@OleTraveler
OleTraveler / gist:04fe8eacd3326f250c9c
Created August 13, 2014 06:10
Hibernate Inheritance and Using Pattern Matching
trait PaymentSource {
def accept[T](visitor: PsVisitor[T]) : T
}
class CreditCard extends PaymentSource{
override def accept[T](visitor: PsVisitor[T]) = {
visitor.visit(this)
}
}