Skip to content

Instantly share code, notes, and snippets.

View zelark's full-sized avatar

Aleksandr Zhuravlёv zelark

View GitHub Profile
@zelark
zelark / server.py
Created October 3, 2024 20:19 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
License: MIT License
Copyright (c) 2023 Miel Donkers
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
@zelark
zelark / install_ruby_bundler_project_jekyll.md
Created January 31, 2024 18:37 — forked from MichaelCurrin/install_ruby_bundler_project_jekyll.md
Set up Ruby, Bundler and a project-level Jekyll on macOS Catalina and up

Set up Jekyll environment on macOS

Set p Ruby, Bundler and a project-level Jekyll on macOS Catalina and up

This guide is for macOS Catalina and is based on the Jekyll on macOS doc and my experience.

1. Install dev tools

Use the XCode CLI to install dev tools. Recommended so that you can install native extensions when installing gems.

@zelark
zelark / grumpy.clj
Created February 16, 2021 06:34
#grumpy
(defn posts-after [post-id]
(slurp (str "https://grumpy.website/after/" 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
zelark / take-first-sorted-by.clj
Created November 26, 2020 17:27 — forked from Ivana-/take-first-sorted-by.clj
Lazysecs efficient reducer, which returns n first elements of sequence, sorted by keyfn & comp
(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
zelark / torrent-viewer.clj
Last active July 13, 2021 13:53
babashka script for viewing torrents files
#!/usr/bin/env bb
(require '[clojure.java.io :as io])
(require '[bencode.core :refer [read-bencode]])
(require '[clojure.walk :refer [prewalk]])
(require '[clojure.pprint :refer [pprint]])
(import 'java.io.PushbackInputStream)
(defn bytes->strings [coll]
(prewalk #(if (bytes? %) (String. % "UTF-8") %) coll))
@zelark
zelark / fizzbuzz.clj
Last active October 7, 2020 10:28
#fizzbuzz
(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
zelark / .gitignore
Last active February 13, 2023 10:35
#config #mac
.vscode/
.lsp/
.calva/
.clj-kondo/cache/
@zelark
zelark / keybindings.json
Last active December 10, 2020 13:29
#vscode #settings
// 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

TL:DR

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

1. Read the docs!