Skip to content

Instantly share code, notes, and snippets.

View will-molloy's full-sized avatar
🚀

Will will-molloy

🚀
View GitHub Profile
@will-molloy
will-molloy / .gitconfig
Last active June 22, 2023 00:00
gitconfig - sign with SSH
[user]
name = <USER>
email = <EMAIL>
signingkey = <PATH_TO_PUBLIC_KEY>
[gpg]
format = ssh
[commit]
gpgsign = true
[tag]
gpgsign = true
@will-molloy
will-molloy / patternmatching.hs
Last active December 22, 2019 02:33
Pattern matching in Haskell (and how it may look in future version of Java)
allTrue :: [Bool] -> Bool
allTrue [] = True
allTrue (head:tail) = head && allTrue tail
anyTrue :: [Bool] -> Bool
anyTrue [] = False
anyTrue (head:tail) = head || anyTrue tail
noneTrue :: [Bool] -> Bool
noneTrue = not . anyTrue
@will-molloy
will-molloy / curry.hs
Last active December 22, 2019 02:25
Currying (partial function application) in haskell
add :: Int -> Int -> Int
add x y = x + y
add3 :: Int -> Int
add3 = add 3
main = print (add3 4) -- 7
@will-molloy
will-molloy / ZonedDateTimes.java
Last active August 12, 2019 08:52
Java time API (JSR 310) is smarter than initially thought
public static void main(String[] args) {
ZonedDateTime auckland = ZonedDateTime.of(LocalDateTime.of(2019, Month.AUGUST, 12, 20, 45), ZoneId.of("Pacific/Auckland"));
ZonedDateTime london = ZonedDateTime.of(LocalDateTime.of(2019, Month.AUGUST, 12, 9, 45), ZoneId.of("Europe/London"));
System.out.println(auckland.equals(london)); // false
System.out.println(auckland.isEqual(london)); // true
auckland = ZonedDateTime.of(LocalDateTime.of(2019, Month.DECEMBER, 12, 20, 45), ZoneId.of("Pacific/Auckland"));
london = ZonedDateTime.of(LocalDateTime.of(2019, Month.DECEMBER, 12, 7, 45), ZoneId.of("Europe/London"));
System.out.println(auckland.equals(london)); // false
System.out.println(auckland.isEqual(london)); // true
@will-molloy
will-molloy / ZippedListMap.java
Last active July 27, 2019 08:24
Zipping two Lists into a Map (resulting map has O(n) get, mainly used for iterating pairs)
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
public class ZippedListMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
@will-molloy
will-molloy / GroupingByAlternative.java
Created July 27, 2019 08:05
Grouping By alternative (Guava Multimaps)
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Multimap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
class GroupingByAlternative {
@will-molloy
will-molloy / ChainingOptional.java
Last active July 27, 2019 08:07
Chaining Optional (Java 9 Optional#or)
import java.util.Optional;
class ChainingOptional {
static Optional<Integer> get1() {
return Optional.empty();
}
static Optional<Integer> get2() {
return Optional.empty();
@will-molloy
will-molloy / Sealed.java
Last active June 28, 2019 11:09
Java sealed class (abstract enum)
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
/**
* Example 3. Sealed
*
* <p>Now sealed. Outsiders cannot implement the root abstraction.
*
* <p>(i.e. {@code extends Sealed} is forbidden).