Skip to content

Instantly share code, notes, and snippets.

View russmatney's full-sized avatar

Russell Matney russmatney

View GitHub Profile
@jackrr
jackrr / distinct-p.clj
Created February 5, 2022 20:34
Lazily remove duplicate members of list, by predicate "hashing" function on members
(defn distinct-p
([pred coll]
(distinct-p pred coll #{}))
([pred coll seen]
(if (empty? coll)
'()
(lazy-seq
(let [next (first coll)
key (pred next)
is-dup (contains? seen key)
@IGJoshua
IGJoshua / reload.clj
Last active January 28, 2022 21:00
Reloadable function vars
(require '[clojure.spec.alpha :as s])
(s/def ::defreloadable-args
(s/cat :name simple-symbol?
:doc (s/? string?)
:attr-map (s/? map?)
:fn-tails (s/+ any?)))
(defmacro defreloadable
"Defines a new function as [[defn]], but old references will refer to new versions when reloaded.
#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System.IO;
using System.Text;
public class EditorFontResizer : EditorWindow {
#!/usr/bin/env bash
# temp file
t=/tmp/bipe.$$.txt
touch $t
# read from stdin
if [ ! -t 0 ]; then
cat > $t
@just-sultanov
just-sultanov / bb.edn
Last active January 8, 2022 18:18
Typical project tasks using babashka
{:min-bb-version "0.6.1"
:tasks
{:requires ([babashka.fs :as fs]
[babashka.process :as proc]
[clojure.string :as str]
[clojure.pprint :as pprint])
;; Helpers
@oliyh
oliyh / debounce.clj
Last active February 17, 2025 19:56
Debounce in Clojure on the JVM
(import '[java.util Timer TimerTask])
(defn debounce
([f] (debounce f 1000))
([f timeout]
(let [timer (Timer.)
task (atom nil)]
(with-meta
(fn [& args]
(when-let [t ^TimerTask @task]
@sjvnnings
sjvnnings / better_jumping_character_example.gd
Last active April 17, 2025 20:26
An easy to work with jump in Godot
extends KinematicBody2D
export var move_speed = 200.0
var velocity := Vector2.ZERO
export var jump_height : float
export var jump_time_to_peak : float
export var jump_time_to_descent : float
@hugcis
hugcis / publish.el
Created June 16, 2021 14:08
Elisp script with functions to export my notes to Hugo-markdown with ox-hugo
;;; publish --- Summary
;;; Commentary:
(require 'find-lisp)
;;; Code:
(defun hugcis/publish-note (file)
"Publish a note in FILE."
(with-current-buffer (find-file-noselect file)
(projectile-mode -1)
(setq org-hugo-section "notes"
@stelcodes
stelcodes / bb-postgresql-backup-restore.edn
Last active July 1, 2022 05:20
Babashka Tasks for PostgreSQL Backups
; run `bb backup` to backup database
; run `bb restore` to restore latest backup
{:min-bb-version "0.4.0",
:tasks {; CONSTANTS
db-name "dev_blog",
backup-dir "backups",
now (str (java.time.LocalDateTime/now)),
; TASKS
create-backup-dir {:depends [backup-dir], :task (babashka.fs/create-dirs backup-dir)},
@borkdude
borkdude / transit_arrays.clj
Created May 19, 2021 17:20
Handling arbitrary array types with transit
;; clojure -Sdeps '{:deps {com.cognitect/transit-clj {:mvn/version "RELEASE"}}}' -M /tmp/transit_arrays.clj
(require '[cognitect.transit :as transit])
(def default-write-handler
(transit/write-handler (fn [x]
(when (.isArray (class x))
"java.array"))
(fn [x]
(when (.isArray (class x))