Skip to content

Instantly share code, notes, and snippets.

View danieldietrich's full-sized avatar
💭
📡 working from space

Daniel Dietrich danieldietrich

💭
📡 working from space
View GitHub Profile
@danieldietrich
danieldietrich / README.md
Last active January 14, 2019 01:34
Coursier Artifact Fetching

Java

import static io.vavr.API.*;

class Main {
    public static void main(String... args) {
        println("Hello Vavr!");
    }
}
@danieldietrich
danieldietrich / README.md
Created January 6, 2019 11:58
Hello world (Node.js)
  1. Download npm and node
  2. echo "console.log('Hello world');" > index.js
  3. node index.js
@danieldietrich
danieldietrich / index.js
Last active November 15, 2018 22:52
Node require
const f = require('./module.js');
const g = require('./module.js');
console.log("f()", f()); // = f() 0
console.log("g()", g()); // = g() 1
const path = require('path');
delete require.cache[path.resolve(__dirname, 'module.js')];
const h = require('./module.js');
console.log("h()", h()); // = h() 0
var fizzbuzz = Stream.of("", "", "Fizz").cycle()
.zipWith(Stream.of("", "", "", "", "Buzz").cycle(), String::concat)
.zipWith(Stream.from(1), (s, i) -> s.isEmpty() ? i.toString() : s);

Array<T>

Legend:

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

Array<T>.prototype.*:

  • concat(...items: Array): T[] 🔒 ES3
@danieldietrich
danieldietrich / split-url.js
Last active December 7, 2017 14:05
Split an URL into { protocol, host, port, path } using Javascript
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 September 20, 2017 19:01
Who has the fastest machine? 😄
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 August 21, 2017 23:57
Lukas' palindrome challenge solved using Vavr
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 April 4, 2017 22:07 — forked from citrusui/dropdown.md
"Dropdowns" in Markdown
How do I dropdown? This is how you dropdown.
<details>
<summary>How do I dropdown?</summary>
This is how you dropdown.
Verifying that "danieldietrich.id" is my Blockstack ID. https://onename.com/danieldietrich