Skip to content

Instantly share code, notes, and snippets.

💭
🕉 Coding...

Daniel Dietrich danieldietrich

💭
🕉 Coding...
Block or report user

Report or block danieldietrich

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View FizzBuzz.java
var fizzbuzz = Stream.of("", "", "Fizz").cycle()
.zipWith(Stream.of("", "", "", "", "Buzz").cycle(), String::concat)
.zipWith(Stream.from(1), (s, i) -> s.isEmpty() ? i.toString() : s);
View api-cheatsheet-array.md

Array<T>

Legend:

  • ✏️ method changes this.
  • 🔒 method does not change this.

Array<T>.prototype.*:

  • concat(...items: Array<T[] | T>): T[] 🔒 ES3
@danieldietrich
danieldietrich / split-url.js
Last active Dec 7, 2017
Split an URL into { protocol, host, port, path } using Javascript
View split-url.js
function splitUrl(url) {
const parts = url.match(/^(http[s]?):\/\/([^:/]*):?(\d*)\/?(.*)$/i);
if (parts === null) {
throw Error('invalid url: ' + url);
} else {
return {
protocol: parts[1],
host: parts[2],
port: parts[3],
path: (parts[4] === '') ? '' : ('/' + parts[4])
@danieldietrich
danieldietrich / FastestMachineContest.java
Last active Sep 20, 2017
Who has the fastest machine? 😄
View FastestMachineContest.java
import io.vavr.collection.Iterator;
import io.vavr.collection.Seq;
public class Test {
public static void main(String[] args) {
int size = 10;
Iterator<String> iter = Iterator.continually(() -> (char) (Math.random() * ((122 - 48) + 1) + 48))
@danieldietrich
danieldietrich / SubstringPalindromes.java
Created Aug 21, 2017
Lukas' palindrome challenge solved using Vavr
View SubstringPalindromes.java
Seq<Tuple<Integer, Integer>> getSubstringPalindromes(String s) {
final N = s.length();
return List.range(0, N-1)
.flatMap(i -> List.of(Tuple.of(i, i+1), Tuple.of(i, i+2)))
.flatMap(t -> List.unfold(t, tt -> {
final int i = tt._1;
final int j = tt._2;
return i >= 0 && j <= N && isPalindrome(s.substring(i, j))
? Option.some(Tuple(i-1, j+1), tt)
: Option.none();
@danieldietrich
danieldietrich / dropdown.md
Created Apr 4, 2017 — forked from citrusui/dropdown.md
"Dropdowns" in Markdown
View dropdown.md
How do I dropdown? This is how you dropdown.
<details>
<summary>How do I dropdown?</summary>
This is how you dropdown.
</details>
View blockstack.id
Verifying that "danieldietrich.id" is my Blockstack ID. https://onename.com/danieldietrich
@danieldietrich
danieldietrich / FactoryTest.java
Last active Mar 2, 2017
Functional Factory Pattern in Java
View FactoryTest.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public class FactoryTest {
public static void main(String[] args) {
ListFactory immutableListFactory = new ListFactory(Arrays::asList);
@danieldietrich
danieldietrich / BigFTest.md
Last active Oct 6, 2017
Javaslang's Future: Thread creation and ExecutorService usage
View BigFTest.md

Future Test

public class BigFTest {

    public static void main(String[] args) throws Throwable {
        final long sleepMillis = 1500;

        ExecutorService executorService = Executors.newFixedThreadPool(1);
@danieldietrich
danieldietrich / Test.java
Created Jan 21, 2017
Inserting objects into a database and collecting the errors (Java vs Javaslang)
View Test.java
import javaslang.control.Try;
import java.util.ArrayList;
import java.util.Arrays;
import static javaslang.API.*;
public class Test {
public static void main(String[] args) {
You can’t perform that action at this time.