Skip to content

Instantly share code, notes, and snippets.

(defn naive-fibonacci [n]
(condp = n
0 1
1 1
(+ (naive-fibonacci (- n 1))
(naive-fibonacci (- n 2)))))
(defn fibonacci-draft
([n]
(fibonacci-draft n 0 1))
(ns fourclojure.problem)
(comment Maximum Value 38)
(defn max-of [& positive-numbers]
(let [max-acc
(fn [ns acc]
(if (empty? ns)
acc
(recur (rest ns) (if (> (first ns) acc) (first ns) acc))))]
@thieux
thieux / ArrayCovarianceTest.java
Last active January 2, 2017 08:48
How Java array covariance is bad
import org.junit.Test;
public class ArrayCovarianceTest {
@Test(expected = ArrayStoreException.class)
public void cat_should_not_be_set_in_dog_list() {
Animal[] animals = new Dog[1]; // array covariance
// Java compiler allows the assignment because Dog extends Animal
// But the Java runtime throws a "java.lang.ArrayStoreException: Cat"
(ns clojure-brave-true-exercises.crashcourse-test
(:require [clojure.test :refer :all]))
(deftest map-empty
(testing "empty"
(is (= #{} (mapset inc [])))))
(defn mapset [f list] #{})
(deftest map-singleton
; CIDER 0.8.1 (package: 20141120.1746) (Java 1.8.0_111, Clojure 1.8.0, nREPL 0.2.12)
clojure-brave-true-exercises.core> (str nil)
""
clojure-brave-true-exercises.core> (str)
""
clojure-brave-true-exercises.core> (str "hello")
"hello"
clojure-brave-true-exercises.core> (str "A" "B")
"AB"
clojure-brave-true-exercises.core> (str :x :y)

Chai Assertion Library

Create a workspace so that chai will be visible by node REPL.

~/workspace/test/node-chai$ npm install chai
~/workspace/test/node-chai$ node

Import Chai:

React Hello World

I prepare an environment with the last version of nodejs.

In /home/m/opensource/react-hello-world/nodepath.bash

#!/bin/bash

PATH="/home/m/node-v6.2.1-linux-x64/bin:$PATH"

IntelliJ Advanced Shortcuts

Editing

Shift+Enter Ctrl+Alt+Enter

Alt+J

Ctrl+Shift+Down

package com.mathieupauly.selectionsort;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class SelectionSortTest {
private SelectionSort selectionSort = new SelectionSort();

Method or constructor parameters?

Consider passing parameter through a method:

class Fibo {
  int fibo(int n) {...}
}