Skip to content

Instantly share code, notes, and snippets.

def fibonacci(n: Int): Int =
if (n == 0) 0
else if (n == 1) 1
else fibonacci(n - 1) + fibonacci(n - 2)
@scala.annotation.tailrec
def tailFibonacci(n: Int, prev: Int = 0, acc: Int = 1): Int =
if (n == 0) prev
else if (n == 1) acc
else tailFibonacci(n - 1, acc, acc + prev)
def factorial(n: Int): Int = if (n > 1) n * factorial(n - 1) else 1
@scala.annotation.tailrec
def tailFactorial(n: Int, acc: Int = 1): Int =
if (n == 1) acc
else tailFactorial(n - 1, n * acc)

A short journey through types in Scala

(based on the Jon Pretty's "Advanced Type Mechanics" workshop)

Type

It is a named collection of method signatures. Those method signatures are called properties.

Classes and traits vs types

We should be careful not to confuse classes or traits and types, because they are different things. Every class and trait gives rise to a type with the same name, but in itself is not a type. Many types also exist which do not solely correspond to a trait or a class.

Terminal tricks

Agenda

  1. navigation tricks with cd, pushd, popd
  2. some keyboard shortcuts
  3. using history as turbo
  4. source vs sh
  5. running processes in background, nohup
export CLICOLOR=1
PS1="\[\033[0;33m\][\!]\`if [[ \$? = "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi\`[\u.\h: \`if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then echo "\\W"; else echo "\\w"; fi\`]\$\[\033[0m\] "; echo -ne "\033]0;`hostname -s`:`pwd`\007"
@Hoobie
Hoobie / PagingWithBackpressure.java
Created October 12, 2017 15:00
rxjava-paging-with-backpressure
package com.example.rx;
import rx.*;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;