Skip to content

Instantly share code, notes, and snippets.

View yoeluk's full-sized avatar

Yoel Garcia Diaz yoeluk

  • Toronto
View GitHub Profile
@yoeluk
yoeluk / Jms.scala
Created March 3, 2016 04:41 — forked from cjjavellana/Jms.scala
Scala Akka Camel Weblogic JMS Sample
import java.util.Properties
import org.apache.camel.component.jms.{ JmsComponent, JmsConfiguration }
import org.springframework.jms.support.destination.JndiDestinationResolver
import org.springframework.jndi.{ JndiObjectFactoryBean, JndiTemplate }
import akka.actor.{ ActorSystem, Props }
import akka.camel.CamelExtension
#!/bin/bash
declare -r TRUE=0
declare -r FALSE=1
# takes a string and returns true if it seems to represent "yes"
function isYes() {
local x=$1
[ $x = "y" ] && echo $TRUE; return
[ $x = "Y" ] && echo $TRUE; return
@yoeluk
yoeluk / streams-tutorial.md
Created November 21, 2015 10:20 — forked from djspiewak/streams-tutorial.md
Introduction to scalaz-stream

Introduction to scalaz-stream

Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.

The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca

$ ./amm
Loading...
Welcome to the Ammonite Repl 0.4.7
(Scala 2.11.7 Java 1.8.0_45)
@ load.ivy("com.typesafe" % "config" % "1.3.0")

@ val configString = """
					 |app {
					 |  root = "baseDir"
object StateApply {
import scalaz._
implicit def applyState[F[_], A](implicit F: Applicative[F], S: Semigroup[A]): Applicative[({ type l[a] = StateT[F, A, a]})#l] = new Applicative[({ type l[a] = StateT[F, A, a]})#l] {
def point[B](b: => B): StateT[F, A, B] = StateT[F, A, B]((a:A) => F.point((a,b)))
def ap[B, C](fa: => StateT[F, A, B])(f: => StateT[F, A, B => C]): StateT[F, A, C] = {
StateT[F, A, C]((s: A) => {
val sa = fa.run(s)
val sb = f.run(s)
@yoeluk
yoeluk / Manager.scala
Last active August 29, 2015 14:18
a queue manager for submitting jobs containing parallel computations
package extra.queuemanager
import akka.actor._
import scala.collection.mutable
import scala.collection.immutable
import scala.util.Failure
/**
* Created by yoelusa on 31/03/15.
*/
// immutable cycle
class Node[T]( val value: T, _next: => Node[T] ){
lazy val next = _next
}
val cycle: Node[Int] = new Node( 1, new Node( 2, cycle ) )
// prints List(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)
println(cycle.iterator.take(10).map(_.value).toList)
implicit class NodeIterator[T](node: Node[T]){
@yoeluk
yoeluk / InstaBT.scala
Last active August 29, 2015 14:08
InstaBT Integration
package com.instabt
/**
* Created by yoelusa on 30/10/14.
*/
import org.apache.commons.codec.binary.Base64
import play.api.data.Form
import play.api.data.Forms._
import play.api.libs.ws._
@yoeluk
yoeluk / PineTree.scala
Last active August 29, 2015 14:08
PineTree Traversables
package data.pinetree
trait Pine[+A] {
def inOrderTrav[B](f: A => (B => B))(ac: B): B = this match {
case End(a) => f(a)(ac)
case Fork(a,l,r) =>
r.inOrderTrav (f) (f(a) (l.inOrderTrav (f) (ac) ))
}
@yoeluk
yoeluk / ListMap.scala
Created November 1, 2014 05:37
ListMap Implementation
package data.listmap
/**
* Created by yoelusa on 30/10/14.
*/
trait ListMap[+A, +B] {
def allKeys: List[A] = {
def go(m: ListMap[A, B], ac: List[A]): List[A] = m match {