Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco Sardo frankiesardo

View GitHub Profile
@frankiesardo
frankiesardo / count_coins.pl
Created Oct 3, 2013
Count the coins kata in prolog
View count_coins.pl
value(1, 1).
value(2, 5).
value(3, 10).
value(4, 25).
value(5, 50).
count_coins(Amount, Ways) :- cc(Amount, Ways, 5).
cc(X, 0, _) :- X < 0.
cc(_, 0, 0).
@frankiesardo
frankiesardo / gist:7254813
Created Oct 31, 2013
Harrt Potter Kata desc
View gist:7254813
To try and encourage more sales of the 5 different Harry
Potter books they sell, a bookshop has decided to offer
discounts of multiple-book purchases.
One copy of any of the five books costs 8 EUR.
If, however, you buy two different books, you get a 5%
discount on those two books.
If you buy 3 different books, you get a 10% discount.
View CustomMatchers.java
public class CustomMatchers {
public static Matcher<View> withBackground(final int resourceId) {
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
return sameBitmap(view.getContext(), view.getBackground(), resourceId);
}
@Override
View percolation.clj
(ns percolation.core
"Currently working for non-recursive, fully specified (no [:*]), attributes only (no limit, defaults etc.) pull api queries."
(:require [datomic.api :as d]))
(def schema
"Percolation specific schema"
[{:db/id #db/id[:db.part/db]
:db/ident :percolator/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
View project-version.clj
(require '[clojure.java.shell :as shell]
'[clojure.string :as str])
(defn- current-tag []
(let [{:keys [exit out]} (shell/sh "git" "describe" "--tags")]
(when (zero? exit)
(str/trim out))))
(def version
(if-let [tag (current-tag)]
View backup.clj
#!/usr/bin/env boot
(set-env!
:dependencies '[[com.datomic/datomic-pro "0.9.5302"]
[com.datomic/datomic-transactor-pro "0.9.5302"]]
:repositories {"my.datomic.com"
{:url "https://my.datomic.com/repo"
:username "..."
:password "..."}})
View find-in.clj
(defn find-in [m ks]
(loop [path []
ks (seq ks)
m m]
(if ks
(when-let [[k m] (find m (first ks))]
(recur (conj path k) (next ks) m))
[path m])))
View log.clj
(ns example.log)
(defprotocol Logger
(log [this msg]))
(defn map* [f logger]
(reify Logger
(log [this msg] (log logger (f msg)))))
View tinylog.clj
(ns tinylog.core
(:require [clj-http.client :as http]
[cheshire.core :as json]
[clojure.core.async :as async]))
(defprotocol Logger
(log [this msg]))
(defn map* [f logger]
(reify Logger