Skip to content

Instantly share code, notes, and snippets.

View green-coder's full-sized avatar
🌱

Vincent Cantin green-coder

🌱
View GitHub Profile
@green-coder
green-coder / html.clj
Last active March 15, 2022 08:28
Cross platform (CLJC) and hackable `html->hiccup` function.
(ns hiccdown.html
(:require [clojure.edn :as edn]
[instaparse.core :as insta :refer [defparser]]))
;; A cross-platform (CLJC) html->hiccup converter for Hiccdown's own needs.
;; For now, only used in the tests.
(defparser html-parser "
nodes = node*
<node> = text | open-close-tags | self-closing-tag
open-close-tags = opening-tag nodes closing-tag
[{:title ":clojureD 2020",
:id "PLaSn8eiZ631lrDFmUTBH9LFGzAxc3tvU4",
:items
({:title
"clojureD 2020: Lightning Talks by Mikkel Gravgaard, Daniel Slutsky, Daniel Janus and Arne Brasseur",
:id "fVtawjGbvOQ",
:duration "1363"}
{:title
"clojureD 2020: \"From Lazy Lisper to Confident Clojurist\" by Alexander Oloo",
:id "j57UbYFbI-U",
@green-coder
green-coder / screen.md
Created September 15, 2020 06:48 — forked from fredrick/screen.md
GNU Screen Cheat Sheet

#GNU Screen Cheat Sheet

##Basics

  • ctrl a c -> cre­ate new win­dow
  • ctrl a A -> set win­dow name
  • ctrl a w -> show all win­dow
  • ctrl a 1|2|3|… -> switch to win­dow n
  • ctrl a " -> choose win­dow
  • ctrl a ctrl a -> switch between win­dow
  • ctrl a d -> detach win­dow
(def my-cat
(fn [rf]
(fn ([] (rf))
([result] (rf result))
([result input]
(reduce (fn [acc val]
(cond
(or (= val :fish)
(= val :heat))
acc
(def my-cat
(fn [rf]
(fn ([] (rf))
([result] (rf result))
([result input]
(reduce (fn [acc val]
(if (or (= val :fish)
(= val :heat))
acc
(rf acc val)))
(defn debug
; Default parameters stuffs.
([] (debug 0))
([indent] (debug indent ">" "<"))
([indent in out]
(let [spaces (apply str (repeat indent \space))]
(debug (str spaces in)
(str spaces out))))
; The transducer code starts here.
([in out]
(def identity
(fn [rf]
(fn ([] (rf))
([result] (rf result))
([result input] (rf result input)))))
(into [] identity (list 1 2 3))
@green-coder
green-coder / tree-seq.clj
Last active April 8, 2018 20:43 — forked from mfikes/tree-seq.clj
Directly-reducible PoC in Clojure
(defn nth' [coll n]
(transduce (drop n) (completing #(reduced %2)) nil coll))
(defn tree-seq'
[branch? children root]
(eduction (take-while some?) (map first)
(iterate (fn [[node pair]]
(when-some [[[node' & r] cont] (if (branch? node)
(if-some [cs (not-empty (children node))]
[cs pair]
@green-coder
green-coder / 00_destructuring.md
Created January 5, 2018 01:12 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors