Skip to content

Instantly share code, notes, and snippets.

View defndaines's full-sized avatar

Michael S. Daines defndaines

View GitHub Profile
@defndaines
defndaines / auc.clj
Created December 29, 2016 19:16
Area Under the Curve [AUC]
(defn auc [lines]
(let [[a _ n fp' p tp'] (reduce iter [0 Double/NEGATIVE_INFINITY 0 0 0 0] lines)]
(/ (+ a (trap-area n fp' n tp'))
(* p n))))
@defndaines
defndaines / auc-iter.clj
Last active December 29, 2016 19:17
Area Under Curve [AUC] reduce function
(defn iter
"Area Under Curve [AUC] reduce function.
The element is a vector of three elements: the ID of the model,
whether the classifier example is positive (pos),
and the probabilistic value (f).
The accumulator tracks six values, aggregated area, the last f value (f'),
negative examples (fp and fp'), and positive examples (tp and tp')."
[[area f' fp fp' tp tp'] [_ pos f]]
(if (= f' f)
[area
@defndaines
defndaines / trap-area.clj
Created December 29, 2016 18:54
Trapezoid Area
(defn trap-area
"Trapezoid area."
[x1 x2 y1 y2]
(* (Math/abs (- x1 x2))
(/ (+ y1 y2) 2)))
movie = Store.insert_movie(movie_map)
movie_list = Eiga.Movie |> select([movie], movie.title) |> Eiga.Repo.all
assert Enum.find(movie_list, &(&1 == movie_map["title"]))
assert movie == Store.insert_movie(movie_map)
assert Enum.filter(movie_list, &(&1 == movie_map["title"])) == [Enum.find(movie_list, &(&1 == movie_map["title"]))]
movie = Store.insert_movie(movie_map)
movie_list = Eiga.Movie |> select([movie], movie.title) |> Eiga.Repo.all
assert Enum.find(movie_list, &(&1 == movie_map["title"]))
^movie = Store.insert_movie(movie_map)
assert Enum.filter(movie_list, &(&1 == movie_map["title"])) == [Enum.find(movie_list, &(&1 == movie_map["title"]))]
Eiga.Repo.delete(movie)
warning: variable movie is unused
test/eiga/store_test.exs:22
@defndaines
defndaines / idempotent_insert.exs
Created December 4, 2016 11:36
Elixir test case with variable warning
test "inserting movies is idempotent" do
movie_map = %{"title" => "The Goonies",
"short_title" => "goonies",
"year" => 1985,
"country" => "U.S."}
movie = Store.insert_movie(movie_map)
movie_list = Eiga.Movie |> select([movie], movie.title) |> Eiga.Repo.all
assert Enum.find(movie_list, &(&1 == movie_map["title"]))
import java.util.LinkedList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public final class Throttler {
private final List<Throttle> throttles = new LinkedList<>();
public void addThrottle(Throttle throttle) { throttles.add(throttle); }
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
List<Double> doubles = Arrays.asList(3.0, 3.0, 3.0);
Optional<Double> pow = doubles.stream().reduce(Math::pow);
List<String> words = Arrays.asList("/a/", "b", "c");
Optional<String> result = words.stream().reduce(""::replaceFirst);
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
List<Long> numbers = Collections.emptyList();
Optional<Long> result = numbers.stream().reduce(Math::max);
// result.orElse(-1L) == -1L;
numbers = Arrays.asList(52L, 127L, 1337L);