Skip to content

Instantly share code, notes, and snippets.


Aleksandr Zhuravlёv zelark

View GitHub Profile
View grumpy.clj
(defn posts-after [post-id]
(slurp (str "" post-id)))
(defn get-post-ids [posts]
(->> posts
(re-seq #"data\-id=\"(.+?)\"")
(map second)))
(defn post-ids [start-id]
(loop [post-ids [start-id]
zelark / take-first-sorted-by.clj
Created Nov 26, 2020 — forked from Ivana-/take-first-sorted-by.clj
Lazysecs efficient reducer, which returns n first elements of sequence, sorted by keyfn & comp
View take-first-sorted-by.clj
(defn take-first-sorted-by
"Performs the same result as (take n (sort-by keyfn comp coll))
but more efficient in terms of time and memory"
([n keyfn coll] (take-first-sorted-by n keyfn compare coll))
([n keyfn ^java.util.Comparator comp coll]
(if (pos? n)
(let [m ^java.util.TreeMap (java.util.TreeMap. comp)
m-size (volatile! 0)
;; if it is guaranteed that (keyfn v) will be unique for all v in coll
;; we can attach :unique? key to keyfn meta and algorythm will use single val map
zelark / torrent-viewer.clj
Last active Jul 13, 2021
babashka script for viewing torrents files
View torrent-viewer.clj
#!/usr/bin/env bb
(require '[ :as io])
(require '[bencode.core :refer [read-bencode]])
(require '[clojure.walk :refer [prewalk]])
(require '[clojure.pprint :refer [pprint]])
(import '
(defn bytes->strings [coll]
(prewalk #(if (bytes? %) (String. % "UTF-8") %) coll))
View fizzbuzz.clj
(defn fizzbuzz [n]
(let [fizzes (cycle ["" "" "Fizz"])
buzzes (cycle ["" "" "" "" "Buzz"])
pattern (map str fizzes buzzes)
numbers (map str (rest (range)))]
(take n (map #(some not-empty %&) pattern numbers)))) ;; another option would be `(partial max-key count)`
(run! println (fizzbuzz 100))
zelark / .gitignore
Last active Jan 6, 2021
#config #mac
View .gitignore
zelark / keybindings.json
Last active Dec 10, 2020
#vscode #settings
View keybindings.json
// Place your key bindings in this file to overwrite the defaults
"key": "cmd+enter",
"command": "clojureVSCode.evalAndShowResult"
"key": "cmd+k cmd+e",
"command": "clojureVSCode.eval"

Lessons learned; The nice and accurate counsel of Alex Miller, programmer


  • Be intentional
  • Stay connected to the problem
  • Use tables to explore alternatives
  • Make a picture

1. Read the docs!

View lazyness.clj
(defn eager-map [f coll]
(when-first [x coll]
(println "iteration")
(cons (f x)
(eager-map f (rest coll)))))
(defn lazy-map [f coll]
(when-first [x coll]
(println "iteration")
zelark / hashmap.c
Last active Apr 5, 2020
You can find the original example here
View hashmap.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HASHMAP_SIZE 16
typedef struct entry_t {
char *key;
char *value;
struct entry_t *next;