Skip to content

Instantly share code, notes, and snippets.

@mbesida
mbesida / foldRightFoldLeft.md
Last active February 18, 2021 15:56
foldRight in terms of foldLeft puzzle

Task: implement foldLeft function and then foldRight in terms of foldLeft

def foldLeft[A, B](list: List[A], z: B)(op: (B, A) => B): B = {
  def loop(currentList: List[A], acc: B): B = {
    currentList match {
      case Nil          => acc
      case head :: next => loop(next, op(acc, head))
    }
  }
  loop(list, z)
@mbesida
mbesida / lazyList.md
Last active February 19, 2021 12:50
LazyList puzzles

Task: Define factorial and fibonacci sequences as LazyLists

Factorials
val factorials: LazyList[BigInt] =
  BigInt(1) #:: factorials.zip(LazyList.from(2).map(BigInt.apply)).map {
    case (a, b) => a * b
  }
Fibs
@mbesida
mbesida / kubectl_merge.md
Last active March 2, 2021 17:18
Merge kubectl config files

To merge existing kubectl config with a new one we can use following script:

cp ~/.kube/config ~/.kube/config.old && \
KUBECONFIG=~/.kube/config:/path_to_new_config kubectl config view --flatten > /tmp_config && \
mv /tmp_config ~/.kube/config

/tmp_config and /path_to_new_config are just random names which could be changed. The script will create a file ~/.kube/config.old with old version of kubectl config

KUBECONFIG is an env variable that could be used to set the config file for kubectl, kubectl looks into this env variable and if not found uses the default config from ~/.kube/config. Elements in KUBECONFIG should be divided by : for UNIX based systems where each element is a path to a file with kubectl config