Skip to content

Instantly share code, notes, and snippets.

View rafd's full-sized avatar
🐃
yak-shaving

Rafal Dittwald rafd

🐃
yak-shaving
View GitHub Profile
@rafd
rafd / flowstorm.md
Last active November 12, 2024 09:36
Ideal FlowStorm Setup

FlowStorm Quickstart

FlowStorm is a time-travelling debugger for clojure.

IMO, Clojure has the best development experience with its REPL-driven workflow. FlowStorm makes it even better.

Most notably:

  • "time-traveling" retrospective debugger (walk forward and backward, search for values)
  • zero-config tap> destination
  • retroactively add print statements to previous evaluations
@rafd
rafd / probability.clj
Created February 2, 2023 01:18
2023-02-01 clojure meetup
;; 2 blue balls, 6 yellow balls
;; opt a - take 3, win if there are not 2 blue
;; opt b - take 1, win if it isn't blue
;; which option better?
;;(def bag {:blueballs #{'x 'y} :yellow-balls #{'a 'b 'c 'd 'e 'f}})
;;(def bag [1 1 0 0 0 0 0 0])
(def prototype-bag
@rafd
rafd / core.clj
Created December 8, 2022 02:17
2022-12-07 clojure workshop leaky bucket
(ns demo.core)
;; inputs are "litres/s"
;; bucket is leaking 1 l/s
;; bucket has capacity of 10
;; does the input overflow the bucket?
(defn leaky-bucket-overflowing?
[limit list]
(->> list
@rafd
rafd / tic-tac-toe.cljs
Created October 6, 2022 01:06
clojodojo-2022-10-05-tic-tac-toe
(ns demo.ui
(:require
[reagent.core :as r]))
(defonce state (r/atom {:game-board [[:x :o :x] [:o nil nil] [nil nil nil]]
:current-player :x}))
;; "how can i represent any moment of my app as a dictionary"
(defn flip0 [player]
(if (= player :x)
(ns exercises.core
(:require
[clojure.walk :as walk]))
;; trie
; "hello"
; "hi"
; "he"
@rafd
rafd / september.clj
Created September 2, 2021 01:09
Clojure Meetup September
(ns exercises.september
(:require [criterium.core :as criterium]))
#_(+ 1 2 3)
#_(println "asdasd")
(defn clamp [v min max]
(cond
(< v min) min
@rafd
rafd / marketplace.clj
Created August 5, 2021 01:11
ClojoDojo 2021-07-04
(ns exercises.marketplace)
;; there is marketplace of vendors
;; each offering a certain amount of foos for bars
;; want to be able to convert from foos to bars
;; function 1 - show cost of converting some number of foos to bars, via multiple trades in marketplace (ex. 2 foo => 5 bars)
;; function 2 - path to achieve that conversion 1 foo => 4 cats => 2 zigs => 25 bars
(def offers
[{:from [4 :banana]
@rafd
rafd / cleave.clj
Created July 21, 2021 00:53
clojure meetup 2021-07-20
(cleave 5 [#(* % 2) dec #(* % %)])
;; => [10 4 25]
(defn cleave [x fs]
((apply juxt fs) x))
(defn cleave2 [x fs]
(map #(% x) fs))
@rafd
rafd / livecode.clj
Created September 14, 2020 21:11
clojodojo-2020-09-14
(ns demo)
(defn hello []
"sagasgd x")
(defonce run? (atom true))
(defn run []
(future
(Thread/sleep 1000)
@rafd
rafd / gist:a5e78d8d70859a659cff8b732319d69e
Created July 4, 2017 15:51
Graphing with Reagent + SVGs
(ns dota2viz.client.graph
(:require
[clojure.string :as string]))
(defn interpolate
[x [x0 x1] [y0 y1]]
(+ y0 (/ (* (- x x0)
(- y1 y0))
(- x1 x0))))