Skip to content

Instantly share code, notes, and snippets.

View tmoerman's full-sized avatar
🦀
keep calm and crabulon

Thomas Moerman tmoerman

🦀
keep calm and crabulon
  • Aspect Analytics, Polymath BV
  • Belgium
View GitHub Profile
package be.webcomrades.spike.partition
object Algo {
def partition(list: List[Int], acceptedSizes: Set[Int]) : List[List[Int]] = {
def internal(list: List[Int], result: List[List[Int]]) : List[List[Int]] = list match {
case Nil => result
case i :: rest =>
result match {
My news aggregation service kept pushing this article in my face.
I decided to make a contribution.
#1 #2 #3 #4 #5 #8
TIKTAALIK
Flat headed animal, 375 million years old, transitional form between primitive fish and amphibians
- http://www.youtube.com/watch?v=x2xyrel-2vI#t=2604
- http://en.wikipedia.org/wiki/Tiktaalik
ARCHAEOPTERYX
You have a knack for prose my friend, but your science is just no good.
Example 1, I assume you wouldn’t marry your sister, right? Why would that be? Because you do not want to
procreate with genes that are too similar to yours. What does offspring of very similar parents have more
chance of having? Genetic defects. Where do you think the term “Hill Billy” come from?
Example 2, it has been shown that the sense of smell is still important for humans for selecting a mate,
because smell discloses particularities about your immune system’s genes. Which mates do people (and
animals as well) prefer according to smell? That’s right, mates with a different genetic makeup. Why?
because difference in genes strengthen your body’s defence systems against parasites and diseases.
(ns scraps
(:require [clojure.core.async :refer [go timeout alts! chan <! >! put! <!!] :as async]
[org.httpkit.client :as http]))
;; sometimes yields nil
(def c (chan))
(defn http-get [url c]
(http/get url (fn [r] (put! c r)))
(defn toggled
"Add a toggle to an input channel.
The ctrl channel accepts truthy, falsy or :toggle values.
The toggle value in the loop determines whether the input value is piped
to the output channel or not.
_____
=[in]===>| |
| alt |=[out]=>
=[ctrl]=>| |
(defn apply-all
"
=[in]=>(effect)
"
[effect in]
(go-loop []
(if-let [v (<! in)]
(do
(effect v)
(recur)))))
@tmoerman
tmoerman / gist:2d71eccf730889f3f782
Created May 21, 2014 14:37
Threading macro and core.async
(def c (chan))
(defn exception? [x] (instance? Exception x))
(defn throwable? [x] (instance? Throwable x))
(-> c
(->> (map*< #(/ 5 %))
(split (complement throwable?)))
(-< (->> (first)
(map*< (fn [x] (prn ":) " x)))
@tmoerman
tmoerman / gist:d7035032a1a1f4b15a6c
Last active August 29, 2015 14:01
Clojure core.async exception handling
(defn nil->keyword [x] (if (nil? x) :nil x))
(defn nil-safe [f] (comp nil->keyword f))
(defn lift
[f]
(fn [x]
(cond
(instance? Throwable x) x
(nil? x) :nil
@tmoerman
tmoerman / combine_latest.clj
Last active January 2, 2018 00:36
core.async combine-latest
(defn combine-latest
"Accepts a collection of channels, an optional selector function f and an option output
channel. Returns a channel with the latest values of the input values combined by the
selector function. If no selector function is specified, a vector will be returned.
The output channel closes when any of the input channels closes.
Inspired by http://rxmarbles.com/#combineLatest"
([chs] (combine-latest (chan) vector chs))
([f chs] (combine-latest (chan) f chs))
([out f chs]
(assert some? chs)
@tmoerman
tmoerman / fulcro-merge-bug-or-quirk.cljs
Last active February 8, 2021 18:37
Fulcro bug or edge case
(defn get-case-ident
[props]
(let [case-id? string?]
(cond
(-> props :nexus.case.image-annotation/id merge/nilify-not-found case-id?) [:nexus.case.image-annotation/id (:nexus.case.image-annotation/id props)]
(-> props :nexus.case.test-case/id merge/nilify-not-found case-id?) [:nexus.case.test-case/id (:nexus.case.test-case/id props)]
:else (log/error "Cannot derive a valid ident. Invalid props." props))))
(defsc AddState [_ _]
{:query [:nexus.case.image-annotation/id