Skip to content

Instantly share code, notes, and snippets.

(ns datastar.expr
(:require [clojure.string :as str]
[clojure.walk :as walk]))
;; The motivation here is to provide a *thin* syntactic veneer over constructing strings
;; representing Datastar expressions (basically JS snippets embedded in DOM attributes)
;;
;; Takes inspiration from Scriptjure, but targeted more specifically to the Datastar context,
;; and does *not* aim to implement Clojure-like truthiness / value semantics (cf. Squint, Clojurescript)
;; or to enable the writing of arbitrarily nested complex expressions (an antipattern)
@yuhan0
yuhan0 / repro.clj
Last active May 2, 2025 11:02
Datastar debounce / throttle repro
(ns app.repro
(:require [hyperlith.core :as h]
[clojure.string :as str]))
(defn render [_req]
(h/html
[:main#morph.main
[:div {:style {:display :grid
:grid-gap :1em
:justify-items :stretch
@yuhan0
yuhan0 / cljs-differences.edn
Last active September 15, 2024 23:14
Clojure vs Clojurescript core namespace differences
;; Public vars in JVM Clojure (1.11.2) which are missing from Clojurescript (1.11.60, self-hosted via Planck REPL)
;; and roughly categorized according to their purpose.
;; Note: Some manual work was involved in sorting out the macros, so there may be omissions or grouping errors
{:dynamic-vars [*agent*
*allow-unresolved-vars*
*clojure-version*
*compile-files*
*compile-path*
*compiler-options*
@yuhan0
yuhan0 / clojure-comment-block.el
Created April 21, 2021 10:29
Mark clojure comment blocks in fringes
;;; clojure-comment-block.el --- mark comment blocks in the fringe -*- lexical-binding: t; -*-
;; This is free and unencumbered software released into the public domain.
;;
;; Anyone is free to copy, modify, publish, use, compile, sell, or
;; distribute this software, either in source code form or as a compiled
;; binary, for any purpose, commercial or non-commercial, and by any
;; means.
;;
;; In jurisdictions that recognize copyright laws, the author or authors
@yuhan0
yuhan0 / evil-refresh-cursor.el
Created March 19, 2019 14:18
rate limit evil-refresh-cursor
(defvar evil--refresh-cursor-last-executed 0
"Unix time of when the evil cursor was last refreshed")
(defvar evil-refresh-cursor-delay 0.1
"Max delay in seconds between each cursor refresh")
(defvar evil--refresh-cursor-current-timer nil
"Current timer keeping track of cursor refresh changes")
(defvar evil--refresh-cursor-delayed-specs nil
"Cons pair of cursor (state . buffer) to set after the delay")
@yuhan0
yuhan0 / clojure-toggle-ignore.el
Last active April 24, 2020 11:35
Toggle Clojure #_ ignore forms in Emacs
(defun clojure--toggle-ignore-next-sexp (&optional n)
"Insert or delete N `#_' ignore macros at the current point.
Point must be directly before a sexp or the #_ characters.
When acting on a top-level form it inserts #_ on a new line
preceding the form."
(let ((rgx (rx-to-string `(repeat ,(or n 1) (seq "#_" (* (in "\r\n" blank)))))))
(backward-prefix-chars)
(skip-chars-backward "#_")
(cond
((looking-at rgx) ;; point is before #_
@yuhan0
yuhan0 / packages.el
Created December 31, 2018 16:24
Excerpt from WIP Spacemacs outshine layer
;;; Outshine
(defun outshine/init-outshine ()
(use-package outshine
:defer t
:commands (outshine-reveal-context outshine-mode)
:init
(progn
;; Enable outshine-mode for *all* programming buffers.
;; note - this enables outline-minor-mode at the same time.
(add-hook 'prog-mode-hook 'outshine-mode)
@yuhan0
yuhan0 / auto_annotate.py
Created April 4, 2018 03:51
Adds keyword-argument style parameters to Grasshopper components. Copy and paste this code into an empty GhPython component, it should automatically setup input parameters
"""
Adds annotations to internalized input parameters for all components on the canvas.
using the format `X=Y`. Completely reversible via toggling the `enable` input.
Default enabled types are Boolean, Integer, Number, String, Interval, and Plane,
connect a Value List to the `types` input to enable others.
"""
from Grasshopper.Kernel import Types, Parameters, GH_Component
from Grasshopper.Kernel.Special import GH_ValueList, GH_ValueListItem, GH_ValueListMode
this = ghenv.Component
@yuhan0
yuhan0 / fix_multiline_panels.ghx
Last active April 3, 2018 03:26
Paste directly into Grasshopper canvas to fix multiline panel number parsing issue on Mac. C# component auto-destructs after executing.
<?xml version="1.0" encoding="utf-8" standalone="yes"?><Archive name="Root"><!--Grasshopper archive--><!--Grasshopper and GH_IO.dll are copyrighted by Robert McNeel & Associates--><!--Archive generated by GH_IO.dll file utility library {0.2.0002}--><items count="1"><item name="ArchiveVersion" type_name="gh_version" type_code="80"><Major>0</Major><Minor>2</Minor><Revision>2</Revision></item></items><chunks count="1"><chunk name="Clipboard"><items count="1"><item name="plugin_version" type_name="gh_version" type_code="80"><Major>0</Major><Minor>9</Minor><Revision>80</Revision></item></items><chunks count="3"><chunk name="DocumentHeader"><items count="5"><item name="DocumentID" type_name="gh_guid" type_code="9">9a66f130-89e9-4d3d-9fb1-30aaebdeb37d</item><item name="Preview" type_name="gh_string" type_code="10">Shaded</item><item name="PreviewMeshType" type_name="gh_int32" type_code="3">1</item><item name="PreviewNormal" type_name="gh_drawing_color" type_code="36"><ARGB>100;150;0;0</ARGB></item><item name="Previe