Skip to content

Instantly share code, notes, and snippets.

View PEZ's full-sized avatar
🎯
Focusing

Peter Strömberg PEZ

🎯
Focusing
View GitHub Profile
@PEZ
PEZ / baldr.cljc
Last active November 27, 2024 12:50
Baldr, clojure.test and cljs/test with Mocha-inspired positive reporting
(ns pez.baldr
(:require #?(:cljs [cljs.test :as t]
:clj [clojure.test :as t])
[clojure.string :as string]))
(defn- default [text]
(str "\033[39m" text "\033[22m"))
(defn- gray [text]
(str "\033[90m" text "\033[39m"))
@PEZ
PEZ / fuzzy.cljs
Last active November 3, 2024 13:07
Joyride script for adding fuzzy search in files with instant previews to VS Code
(ns fuzzy
(:require ["vscode" :as vscode]
[clojure.string :as string]
[joyride.core :as joyride]
[promesa.core :as p]))
(defn- get-configured-exclude-patterns! []
(->> ["search.exclude" "files.exclude"]
(mapcat (fn [config-key]
(-> (.get (vscode/workspace.getConfiguration) config-key)
@PEZ
PEZ / highlight_thousands.cljs
Last active October 30, 2024 04:51
A highlighter for long numbers in VS Code, using Joyride
;; Joyride thousands highlighter
;; The end goal here is to help humans read long numbers by highlighting groups of thousands
;; First we need to find the groups of thousands. We only want to highlight _odd_ groups
;; of thousands, starting with the least significant group to the most significant group.
;; We also consider the most significant group of thousands when it is not three digits long.
; Here is some test data, line numbers are on the left
; The xxx are the groups of thousands we want to highlight on the numbers on the line above them.
;08 1111111222111333444 :foo 555666 :bar 123 :baz 1234
;09 x xxx xxx xxx xxx xxx
@ericnormand
ericnormand / 00 Digit search.md
Last active December 21, 2022 00:45
399 - PurelyFunctional.tv Newsletter

Digit search

This is one of those weird programming puzzles with no real point except practice. But it's considered Very Hard in JavaScript. Let's see how we do in Clojure.

Write a function that takes a sequence of integers. You're trying to get all 10 digits by looking through the numbers sequentially. When you have found one instance of every decimal digit, return whatever number you were on when you found the last one. If you get to the end of the sequence without finding all the digits (for instance, maybe there was no 9), then just return nil.

Example

(digit-search [5175 4538 2926 5057 6401 4376 2280 6137]) ;=> 5057
@ericnormand
ericnormand / 00 Wolf Sheep Cabbage.md
Created September 25, 2020 16:10
397 - PurelyFunctional.tv Newsletter

Wolf, sheep, cabbage

There's a really common problem called "Wolf, sheep, cabbage". (There are other names for it as well). The problem goes like this:

You own a wolf, a sheep, and a cabbage. You need to cross a river and you only have a boat big enough for you plus one other passenger (your wolf, sheep, or cabbage). The trouble is, the animals are hungry. If you leave the wolf with the sheep, the wolf will eat it. If you leave the sheep with the cabbage, it will eat it. The wolf, being a carnivore, will not eat the cabbage. How do you move them safely to the other side with nothing being eaten?

It's a fun problem and I suggest you give it a try on paper if you don't know the solution. If you can't figure it out, search for it online and you'll find solutions.

Your task is to write a function that generates solutions to this puzzle, in the form of boat crossings. Each crossing should state:

@pjstadig
pjstadig / transducers.md
Last active June 8, 2021 13:22
The secret feature of transducers that no one talks about!

The Pledge

One thing that always made me a little sad about transducers was how map lost its ability to iterate multiple collections in parallel. This is actually my favorite feature of map. For example:

(map + (range 5) (range 5 10))
=> (5 7 9 11 13)

One somewhat practical use of this is if you want to compare two sequences, pairwise, using a comparator. Though I wish that every? took multiple collections, this is an adequate substitute:

@kordano
kordano / url-param.cljs
Last active September 12, 2022 12:14
URL parameter parsing with clojurescript
(defn parse-params
"Parse URL parameters into a hashmap"
[]
(let [param-strs (-> (.-location js/window) (split #"\?") last (split #"\&"))]
(into {} (for [[k v] (map #(split % #"=") param-strs)]
[(keyword k) v]))))
/**
* Determines if the device running this
* application is Game Center ready.
*
* @return true if Game Center is available.
*/
BOOL isGameCenterAvailable();