Skip to content

Instantly share code, notes, and snippets.

View ivanopagano's full-sized avatar

Ivano Pagano ivanopagano

View GitHub Profile
@ivanopagano
ivanopagano / HuffmanViz.scala
Created October 15, 2012 21:04
Huffman Jit Visualizer
package patmat
/*
* This file should be used to generate an easy visualization of huffman trees implemented
* during the course of the Coursera "Principles of Functional Programming" class, held by prof.M.Odersky.
*
* It's intended as an aid to the students.
* Take notice that you need to have access to the course material, so it's almost useless for any other purpose.
*
* To correctly compile you need to have the patmat.Huffman object visible in your class-path.
@ivanopagano
ivanopagano / Counts.scala
Created November 12, 2012 11:19
Simple word counting with parallel collections and scala-io
import scalax.io._
import scalax.file._
import scalax.file.defaultfs._
import scalax.file.LinkOption.NoFollowLinks
import scalax.file.PathMatcher.IsDirectory
object Counts {
type Counter = Map[String, Int]
package org.iainhull.akka
import scala.concurrent.duration._
import akka.actor._
import akka.event.Logging
import akka.pattern.ask
import akka.util.Timeout
import akka.persistence.{PersistentView, AtLeastOnceDelivery, PersistentActor}
@ivanopagano
ivanopagano / App.java
Created October 22, 2014 11:12
Person vs PersonBean
package it.pagoda5b;
import java.util.HashMap;
import java.util.Map;
/**
* Hello world!
*
*/
public class App {
@ivanopagano
ivanopagano / Joiner.java
Created March 17, 2015 13:43
joining strings in java 8
import java.util.*;
public class Joiner {
public static void main(String[] args) {
System.out.println(String.join("\n", Arrays.asList(args)));
System.out.println(String.join("\n", testArgs()));
}
@ivanopagano
ivanopagano / FluentFunctionalValidation.java
Last active August 29, 2015 14:19
Example of functionaljava lifting to a Validation result
import fj.*
import fj.data.*
import static LiftingMiaClasse.*
class UsaClasse {
//ho importato staticamente i metodi di lifting a funzione per una sintassi piu' scorrevole
public static void usa() {
Validation<String, Risultato> risultato = faiQuesto()
@ivanopagano
ivanopagano / OpenMovie.java
Created February 26, 2016 00:11
Infamous Scala Requirements
package omdb.client;
/**
* Created by Ivano Pagano on 09/02/16.
*
* Espone i valori presenti nella risposta json delle API
*/
public interface OpenMovie {
public String title();
public String year();

Keybase proof

I hereby claim:

  • I am ivanopagano on github.
  • I am ivanopagano (https://keybase.io/ivanopagano) on keybase.
  • I have a public key whose fingerprint is B69F 549F 2B42 DB94 2BD3 4749 0754 4458 C605 E71A

To claim this, I am signing this object:

@ivanopagano
ivanopagano / majority-split-brain+redeploy.md
Last active March 29, 2017 09:14
redeploy scenario on 3-instance cluster and split-brain happens. keep-majority strategy

Base scenario

The policy is keep-majority, new instances are started one by one, on redeploy newest instances are downed first (YOUNGEST_FIRST)

  • 3 nodes up: N1, N2, N3

Redeploy

  1. a redeploy is started, so a new node is spun (N+)
  2. N+ is acked by all the nodes, so the Leader (L) is about to set the node to UP
@ivanopagano
ivanopagano / nested-for.scala
Created December 4, 2017 09:44
desugaring of a for comprehension for the herding-cats either example
//refers to http://eed3si9n.com/herding-cats/stacking-future-and-either.html
def isFriends1(user1: Long, user2: Long)
(implicit ec: ExecutionContext): Future[Either[Error, Boolean]] =
for {
a <- followers(user1)
b <- followers(user2)
} yield for {
x <- a.right
y <- b.right