Skip to content

Instantly share code, notes, and snippets.

View dfa1's full-sized avatar

Davide Angelocola dfa1

View GitHub Profile
@dfa1
dfa1 / git-autosquash
Last active March 21, 2020 19:24
inattentively squash all commits of a topic branch (i.e. no need to open an editor as in rebase -i)
#!/bin/bash
set -euo pipefail
target_branch=$1
current_branch=$(git rev-parse --abbrev-ref head)
squash_branch=${current_branch}_work
git checkout -B ${squash_branch} ${target_branch}
git merge --squash ${current_branch}
git commit -am "squashed"
git checkout ${current_branch}
git reset --hard ${squash_branch}
@dfa1
dfa1 / Refined.java
Last active November 26, 2019 15:58
(run-time) Refined types in Java https://kwark.github.io/refined-in-practice/
import java.util.function.Predicate;
public class Refined<T> {
private final T value;
public Refined(Predicate<T> validator, T value) {
if (validator.test(value)) {
throw new IllegalArgumentException();
}
@dfa1
dfa1 / wc.java
Last active October 16, 2019 19:08
Rewriting https://github.com/ChrisPenner/wc in Java11
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.concurrent.ArrayBlockingQueue;