Skip to content

Instantly share code, notes, and snippets.

View ahmed1hsn's full-sized avatar

Ahmed Hassan ahmed1hsn

View GitHub Profile
@daveliepmann
daveliepmann / assert-or-not.md
Last active March 2, 2025 12:24
A guide to orthodox use of assertions in Clojure.

When to use assert?

In JVM Clojure, Exceptions are for operating errors ("something went wrong") and Assertions are for programmer and correctness errors ("this program is wrong").

An assert might be the right tool if throwing an Exception isn't enough. Use them when the assertion failing means

  • there's a bug in this program (not a caller)
  • what happens next is undefined
@henryw374
henryw374 / flexi_clock.clj
Created October 17, 2024 16:11
clojure java.time clock
(ns flexi-clock
(:import (java.time Clock Duration Instant ZonedDateTime)))
(defn clock
"potential library function (e.g. in tick or tempo).
This just implements the platform Clock - which works because non-test code only uses that API.
Any manipulation of time (which happens in testing code) is done via changing
what get-instant and get-zone return"
[get-instant get-zone]
@WebReflection
WebReflection / sqlite-as.md
Last active January 25, 2025 15:12
Bun sqlite `.as(Class)` alternative

This is a simple demo of how latest Bun could've implemented .as(Class) instead of using the quite jurassic Object.create which is slow, bloated due descriptors logic, if used at all, and incapable to play nicely with features introduced after Object.create was even specified.

// what `as(Class)` should return
const { assign } = Object;
const asClass = new WeakMap;
const setAsClass = Class => {
  class As extends Class {
    constructor(fields) {
      assign(super(), fields);
@rafd
rafd / flowstorm.md
Last active March 30, 2025 12:27
Ideal FlowStorm Setup

FlowStorm Quickstart

FlowStorm is a time-travelling debugger for clojure.

IMO, Clojure has the best development experience with its REPL-driven workflow. FlowStorm makes it even better.

Most notably:

  • "time-traveling" retrospective debugger (walk forward and backward, search for values)
  • zero-config tap> destination
  • retroactively add print statements to previous evaluations
@shvets-sergey
shvets-sergey / jst.clj
Created August 14, 2023 00:54
Implements a hiccup-like compiler into js templates
(ns jst
(:require [camel-snake-kebab.core :as csk]
[clojure.string :as string]
[hyperfiddle.rcf :refer [tests]]))
(hyperfiddle.rcf/enable!)
;; Implements a hiccup compiler into js-template.
;;
;; Usage: (jst cljs-symbol? template-fn? hiccup), where:
;; cljs-symbol - what symbol implements js-template in cljs (default: shadow.cljs.modern/js-template)
@WebReflection
WebReflection / esx.md
Last active October 6, 2024 12:35
Proposal: an ESX for JS implementation
@spacegangster
spacegangster / timezones.edn
Last active July 15, 2020 14:52
List of standard timezones, scraped from a popular mailing service
;; UPD hey, I'm not sure now if those zones are correct throughout the year
;; see this https://www.creativedeletion.com/2015/01/28/falsehoods-programmers-date-time-zones.html
;; Sorry for misleading you
[{:option/value "Pacific/Tarawa" :option/label "(GMT +12:00) Tarawa"}
{:option/value "Pacific/Auckland" :option/label "(GMT +12:00) New Zealand Time"}
{:option/value "Pacific/Norfolk" :option/label "(GMT +11:00) Norfolk Island (Austl.)"}
{:option/value "Pacific/Noumea" :option/label "(GMT +11:00) Noumea, New Caledonia"}
{:option/value "Australia/Sydney" :option/label "(GMT +10:00) Australian Eastern Time (Sydney)"}
{:option/value "Australia/Queensland" :option/label "(GMT +10:00) Australian Eastern Time (Queensland)"}
{:option/value "Australia/Adelaide" :option/label "(GMT +9:30) Australian Central Time (Adelaide)"}
@ataggart
ataggart / project.clj
Last active June 16, 2020 14:48
Example log4j2 project setup.
(defproject example "0.1.0"
:description "Example configuration for using log4j2 as the concrete logging
implementation. Libraries that depend on other well-known java
logging abstractions (e.g., SLF4J) will be logged with log4j2.
Also configures tools.logging to choose log4j2."
:dependencies [; Provide the log4j2 logging implementation:
[org.apache.logging.log4j/log4j-api "2.13.0"]
[org.apache.logging.log4j/log4j-core "2.13.0"]
; Provide log4j2 adapters for other java logging abstractions:
@holyjak
holyjak / Fulcr-x-Redux-talk.md
Last active December 2, 2021 10:18
Want more from your frontend framework!

Source code for my Telia Full Stack Feast talk "Want more from your frontend framework!" (slides) (6/2020), comparing Redux with REST and a Fulcro with Pathom (Graph API).

Use case we are implementing: Show “hot deals” in your webshop, loaded on-demand.

PS: For the sake of simplicity I am cheating a little and presenting the Fulcro HotDeals component as a root component. If it was used as a child, we would need to either change the a Link Query or make sure that the :deals are presented as a property on the parent component. Also, I use unqualified keys for brevity. This is not recommended in practice.

@saikyun
saikyun / zig_watch.clj
Last active April 8, 2021 09:40
babashka command to watch a folder for changes to .zig-files
#!/usr/bin/env bb
(if *command-line-args*
(def in (str (first *command-line-args*)))
(do
(println "Which bin to run?")
(def in (str *input*))))
(println "Watching" "*.zig" "->" (str "./" in))