Skip to content

Instantly share code, notes, and snippets.

View fedesilva's full-sized avatar
👁️‍🗨️

federico silva fedesilva

👁️‍🗨️
View GitHub Profile
@fedesilva
fedesilva / bash.generate.random.alphanumeric.string.sh
Last active December 13, 2016 00:02 — forked from earthgecko/bash.generate.random.alphanumeric.string.sh
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@fedesilva
fedesilva / play2.service
Created August 24, 2016 20:52 — forked from dkhenry/play2.service
Systemd script for the Play Framework
[Unit]
Description=Play2 Server for <site>
After=network.target
 
[Service]
Type=simple
PIDFile=<path>/RUNNING_PID
 
ExecStartPre=/bin/sh -c 'cd <path> ;/bin/rm RUNNING_PID ; sbt clean compile stage'
ExecStart=<path>/target/start
@fedesilva
fedesilva / IO.scala
Created August 11, 2016 18:43 — forked from jdegoes/IO.scala
A pedagogical implementation of the IO monad in Scala in 14 LOC
case class IO[A](unsafePerformIO: () => A) {
def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO()))
def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO())
def tryIO(ta: Throwable => A): IO[A] =
IO(() => IO.tryIO(unsafePerformIO()).unsafePerformIO() match {
case Left(t) => ta(t)
case Right(a) => a
})
}
object IO {
@fedesilva
fedesilva / gist:3b9ca0448de3fbf6c43c79e406a08d95
Created July 2, 2016 14:44 — forked from colestanfield/gist:fac042d3108b0c06e952
sbt-assembly merge strategy for aop.xml files
// Create a new MergeStrategy for aop.xml files
val aopMerge: MergeStrategy = new MergeStrategy {
val name = "aopMerge"
import scala.xml._
import scala.xml.dtd._
def apply(tempDir: File, path: String, files: Seq[File]): Either[String, Seq[(File, String)]] = {
val dt = DocType("aspectj", PublicID("-//AspectJ//DTD//EN", "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"), Nil)
val file = MergeStrategy.createMergeTarget(tempDir, path)
package test.zipper
object TreeZipper extends App {
println("hello")
// exp 2 * 3 + 4 * 6
val _2 = Node("2", Nil)
val _3 = Node("3", Nil)
@fedesilva
fedesilva / 0introduction.md
Created April 5, 2016 19:48 — forked from djspiewak/0introduction.md
Scala Collections Proposal

Collections Redesign Proposal

I'm going to start off by motivating what I'm doing here. And I want to be clear that I'm not "dissing" the existing collections implementation or anything as unproductively negative as that. It was a really good experiment, it was a huge step forward given what we knew back in 2.8, but now it's time to learn from that experiment and do better. This proposal uses what I believe are the lessons we can learn about what worked, what didn't work, and what is and isn't important about collections in Scala.

This is going to start out sounding really negative and pervasively dismissive, but bear with me! There's a point to all my ranting. I want to be really clear about my motivations for the proposal being the way that it is.

Problems

Generic Interfaces

object ToFromMap {
implicit def materialize[T]: ToFromMap[T] = macro impl[T]
def impl[T: c.WeakTypeTag](c: Context): c.Expr[ToFromMap[T]] = {
import c.universe._
val wt = weakTypeOf[T]
// Gets the type parameters, eg Holder[T, J] => List(T, J)
val baseTypes = wt.baseClasses.head.asType.typeParams.map{ _.asType.toType }
// Gives a Map(T -> Int, J -> Double) if we are extracting Holder[Int, Double]
val myTypes = baseTypes zip wt.typeArgs toMap;
@fedesilva
fedesilva / keybase.md
Created February 9, 2016 22:47
keybase.md

Keybase proof

I hereby claim:

  • I am fedesilva on github.
  • I am fedesilva (https://keybase.io/fedesilva) on keybase.
  • I have a public key ASDem0Fuocr5gGIqgl7dUj-Fo-qj_7v2GQKmn9Rioj3SlQo

To claim this, I am signing this object:

@fedesilva
fedesilva / Zipper.scala
Created February 8, 2016 20:37 — forked from rcherrueau/Zipper.scala
Scala implementation of Gérard Huet's The Zipper
/** Scala implementation of Gérard Huet's The Zipper.
*
* The Zipper is a kind of Iterator for Tree. The Zipper offers
* navigation and edition primitives in constant time.
* [[http://www.dblp.org/rec/bibtex/journals/jfp/Huet97 The Zipper]]
*/
/** Tree data structure. */
sealed abstract class Tree[T]
case class Item[T] (val item: T) extends Tree[T]
@fedesilva
fedesilva / con-y-sin-println.scala
Last active January 26, 2016 15:35
Con y sin println
// The t function takes times and puts data points in an arraybuffer.
// I use that data to compute mean, stddev, variance ...
//
// The Walker just recursively walks a jsoup document feeding the elements to the parser
// or the parsers it returns and accumulating the new ast nodes.
// Lot's of work for the GC
//
// On one run there are two printlns, on the other none.
//