This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Monoid | |
import cats.syntax.monoid._ | |
case class Order(products: List[String], topay: Double) | |
//This could be done with higher abstraction cats tools | |
implicit val orderMonoidInstance: Monoid[Order] = new Monoid[Order] { | |
def empty: Order = Order(Nil, 0.0) | |
def combine(x: Order, y: Order): Order = Order(x.products ++ y.products, x.topay + y.topay) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
curl https://www.eventbrite.es/e/lambda-world-2017-tickets-35032894330\#tickets \ | |
| awk -F "collection : " '{print $2}' \ | |
| python -m json.tool \ | |
| grep number_of_tickets_remaining |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.pfcoperez.dailyalgorithm.datastructures.graphs.undirected._ | |
val ug = UndirectedGraph(Set(1,2,3,4), Edge(1,2)::Edge(2,3)::Edge(3,4)::Edge(4,1)::Nil) | |
ug.adjacentTo(1) | |
ug.adjacentTo(2) | |
ug.adjacentTo(3) | |
ug.adjacentTo(4) | |
(ug - Edge(1,4)).adjacentTo(1) | |
(ug - Edge(1,4)).adjacentTo(4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tailrec | |
def permutations[T](alphabet: Set[T], s: Seq[Seq[T]] = Seq(Seq.empty[T])): Seq[Seq[T]] = | |
if(s.head.size == alphabet.size) s else { | |
val updatedSolutions = for { | |
partial <- s | |
chosen <- (alphabet -- partial) | |
} yield chosen +: partial | |
permutations(alphabet, updatedSolutions) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function launchIteration { | |
CMD=$1 | |
STOP_OUTPUT_PATTERN=$2 | |
OUTPUT_DIR=$3 | |
REMAINING_ITERATIONS=$4 | |
if [[ $REMAINING_ITERATIONS == "0" ]]; then | |
echo "Completed launch chain" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.parsing.combinator._ | |
object RobotCommands extends App { | |
object Entities { | |
trait MovementDirection | |
case object Up extends MovementDirection | |
case object Down extends MovementDirection | |
case object Left extends MovementDirection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://www.eventbrite.es/e/lambda-world-2017-tickets-35032894330\#tickets \ | |
| awk -F "collection : " '{print $2}' \ | |
| jq '.[] | {ticket_type: .ticket_name, price: .cost.display, remaining: .number_of_tickets_remaining}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val upperBound = 100 | |
val candidates = sc.range(1, upperBound) | |
val factors = sc.range(1, math.sqrt(upperBound).toLong+1) | |
val primes = { | |
candidates.cartesian(factors) filter { | |
case (candidate, factor) => candidate % factor == 0L | |
} | |
}.aggregateByKey(0L)((counter, _) => counter+1L, _ + _).filter(_._2 <= 2L).keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript"> | |
/*! jQuery v2.0.0 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license | |
//@ sourceMappingURL=jquery.min.map | |
*/ | |
(function(e,undefined){var t,n,r=typeof undefined,i=e.location,o=e.document,s=o.documentElement,a=e.jQuery,u=e.$,l={},c=[],f="2.0.0",p=c.concat,h=c.push,d=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=f.trim,x=function(e,n){return new x.fn.init(e,n,t)},b=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^-ms-/,N=/-([\da-z])/gi,E=function(e,t){return t.toUpperCase()},S=function(){o.removeEventListener("DOMContentLoaded",S,!1),e.removeEventListener("load",S,!1),x.ready()};x.fn=x.prototype={jquery:f,constructor:x,init:function(e,t,n){var r,i;if(!e)return this;if("string"==typeof e){if(r="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:T.exec(e),!r||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Caesar extends App { | |
private lazy val pos2symbol: Vector[Char] = (('A' to 'Z') ++ ('a' to 'z') :+ ' ' ).toVector | |
private lazy val symbol2pos: Map[Char, Int] = pos2symbol.zipWithIndex.toMap | |
def encode(msg: String)(implicit key: Int): String = | |
msg collect { case c if symbol2pos contains c => | |
pos2symbol((symbol2pos(c) + key) % symbol2pos.size) | |
} | |