Skip to content

Instantly share code, notes, and snippets.

View zelark's full-sized avatar

Aleksandr Zhuravlёv zelark

View GitHub Profile
@zelark
zelark / pg_test.types.clj
Last active February 2, 2024 19:47
Support json and jsonb Postgres types in Clojure.
;; For supporting more PG types, see https://github.com/remodoy/clj-postgresql
(ns pg-test.types
(:require [cheshire.core :as json]
[clojure.java.jdbc :as jdbc])
(:import [org.postgresql.util PGobject]
[java.sql PreparedStatement]))
;; Writing
(defn- to-pg-json [data json-type]
@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 / easy-web-scrap-skeleton.py
Created April 24, 2014 13:42
easy web scraping with python
import bs4
import requests
import argparse
import re
from multiprocessing import Pool
root_url = 'http://pyvideo.org'
index_url = root_url + '/category/50/pycon-us-2014'
@zelark
zelark / .gitignore
Last active February 13, 2023 10:35
#config #mac
.vscode/
.lsp/
.calva/
.clj-kondo/cache/
@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 / 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 / simple-life.clj
Last active January 7, 2021 12:29
#gameoflife #life #game
(ns zelark.small-life
(:require [clojure.pprint :refer [pprint]]))
(defn empty-board
"Creates a rectangular empty board of the specified width
and height."
[w h]
(vec (repeat w (vec (repeat h nil)))))
(defn populate
@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"
},
@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