Skip to content

Instantly share code, notes, and snippets.

View mtorchiano's full-sized avatar

Marco Torchiano mtorchiano

View GitHub Profile
@mtorchiano
mtorchiano / gglikert.py
Created March 17, 2026 13:22
Plotnine extension for likert-like plotting using divergent bar charts
from plotnine import *
import pandas as pd
class geom_likert(geom_col):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def __radd__(self, other):
if isinstance(other, ggplot):
df = other.data
mapping = other.mapping
@mtorchiano
mtorchiano / FlatMapExplained.java
Last active April 29, 2021 13:21
Source code for the video example of Stream.flatMap() available at: <https://youtu.be/ouinDyk-H0c>
import java.util.Arrays;
import java.util.stream.Stream;
import it.polito.po.data.Lyrics;
/**
* Explaining how Stream.flatMap() works
* with a simple code example...
* @author mtk
*
*/
@mtorchiano
mtorchiano / PROFES2020_Timeline.R
Last active April 28, 2020 11:59
PROFES2020 Timeline diagram (post-COVID-19)
library(tidyverse)
library(scales)
schedule <- data.frame(Date = c("2020-07-13", "2020-07-20", "2020-07-27", "2020-07-31",
"2020-09-07", "2020-09-14", "2020-09-14", "2020-09-14", "2020-10-05",
"2020-10-12"),
Event = c("Abstracts", "Submission", "Submission", "Submission",
"Notification", "Notification", "Notification", "Submission",
"Notification", "Camera Ready"),
Track = c("Full", "Full", "Industry", "Short", "Full", "Industry",
@mtorchiano
mtorchiano / eligendo.js
Last active June 3, 2019 13:46
Bookmarklet for scraping Italian election official website
javascript:(function() {
let res = [];
let table = $('#superTable tr');
let headings = table.eq(0).children().map( (i,x) => x.innerText ).get();
let dups = {};
headings = headings.map( e => {
let n = dups[e] | 0;
let ee = n ? e + n : e;
dups[e] = n + 1;
return ee;
@mtorchiano
mtorchiano / FibonacciStream.java
Last active September 26, 2024 15:21
Fibonacci sequence generation using Java Stream API
package streams;
import java.util.stream.LongStream;
import java.util.stream.Stream;
public class FibonacciStream {
public static LongStream fibonacciGG() {
class FibonacciGenerator{
int prev=0;
@mtorchiano
mtorchiano / _README.md
Created April 23, 2018 11:33
Replacing Observer-Observable (inheritance vs. composition)

Replacing Observer-Observable (inheritance vs. composition)

Since Java 9 the pair Observer-Observable have been declared deprecated.

They don't provide a rich enough event model for applications. 
For example, they support only the notion that something has changed, 
but they don't convey any information about what has changed. 
There are also some thread-safety and sequencing issues that cannot be fixed compatibly. 
@mtorchiano
mtorchiano / Java idioms for exposing properties.md
Last active April 3, 2017 09:28
Java idioms for exposing properties

Java idioms for exposing properties

Creative Commons License
This work by Marco Torchiano is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.


In several application where a general purpose container needs to access specific objects, properties represent a common technique.

We can loosely define a property as an attribute of an object that can be accessed programmatically based on run-time only information.

@mtorchiano
mtorchiano / README.md
Last active May 30, 2016 19:10
Where we donate vs. Diseases that kill us

Where we donate vs. Diseases that kill us - Slopegraph

This gist reports a redesign of the graph shown in the August 20, 2014 article by Vox.

The original diagram uses two paired bubble charts with categorical levels encoded in colors.

The re-design presented here makes use of a slopegraph.

@mtorchiano
mtorchiano / README.md
Last active May 30, 2016 19:08
Where we donate vs. Diseases that kill us

Where we donate vs. Diseases that kill us - Paired Barchart

This gist reports a redesign of the graph shown in the August 20, 2014 article by Vox.

The original diagram uses two paired bubble charts with categorical levels encoded in colors.

The re-design presented here makes use of two paired opposed bar charts.