Skip to content

Instantly share code, notes, and snippets.

sudo sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sudo sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
@forketyfork
forketyfork / Comparison2.java
Created May 13, 2021 07:22
Code to article "Custom String Comparison in Java"
var collator = new RuleBasedCollator("< b < a");
var strings = List.of("aaa", "bbb", "ccc", "aba");
var sortedStrings = strings.stream()
.sorted(collator::compare)
.toList();
System.out.println(sortedStrings);
@forketyfork
forketyfork / Comparison.java
Created May 13, 2021 07:21
Code to article "Custom String Comparison in Java"
var strings = List.of("aaa", "bbb", "ddd", "ccc", "aba");
var sortedStrings = strings.stream().sorted().toList();
System.out.println(sortedStrings);
// => [aaa, aba, bbb, ccc, ddd]
@forketyfork
forketyfork / Concat.hs
Created May 11, 2021 07:07
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
concat = foldr mappend empty
@forketyfork
forketyfork / SumProductExample.hs
Created May 11, 2021 07:06
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
getSum ( Sum 1 `mappend` Sum 2 ) -- this returns 3
getProduct ( Product 5 `mappend` Product 10 ) -- this returns 50
@forketyfork
forketyfork / MonoidProduct.hs
Created May 11, 2021 06:57
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
instance Num a => Monoid (Product a) where
mempty = Product 1
Product x `mappend` Product y = Product (x * y)
@forketyfork
forketyfork / ProductSum2.hs
Created May 11, 2021 06:57
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
Product 1
Sum 3
@forketyfork
forketyfork / ProductSum.hs
Created May 11, 2021 06:56
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
newtype Sum a = Sum { getSum :: a }
newtype Product a = Product { getProduct :: a }
@forketyfork
forketyfork / Monoid.hs
Created May 11, 2021 06:55
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
class Monoid m where
mempty :: m
mappend :: m -> m -> m
@forketyfork
forketyfork / Person.hs
Created May 11, 2021 06:54
Code to article "Why You Should Learn Functional Programming: Type Classes vs. Interfaces"
data Person = Person {
name :: String,
surname :: String,
age :: Int
}