Skip to content

Instantly share code, notes, and snippets.

View martinklepsch's full-sized avatar
💭
Hacking on something new ⚡️

Martin Klepsch martinklepsch

💭
Hacking on something new ⚡️
View GitHub Profile
@martinklepsch
martinklepsch / README.md
Last active November 30, 2023 02:42
A small babashka script to convert HTML from stdin to hiccup and pretty print it.

A small babashka script to convert HTML from stdin to hiccup and pretty print it.

I use this inside NeoVim with this config line

command PasteAsHiccup r !pbpaste | html2hiccup

And then whenever I want to paste some HTML as Hiccup I'll do :PasteAsHiccup.

@martinklepsch
martinklepsch / karabiner.json
Created November 14, 2022 09:35
karabiner.json rule to "press" cmd, shift, control and option when pressing caps lock
{
"description": "Change caps_lock to command+control+option+shift.",
"manipulators": [
{
"from": {
"key_code": "caps_lock",
"modifiers": {
"optional": [
"any"
]
@martinklepsch
martinklepsch / xstate.cljs
Created November 15, 2021 14:44
Semi-idiomatic wrapper around XState for ClojureScript
(ns icebreaker.xstate
"Convenience methods for working with XState in a ClojureScript app.
This namespace does not attempt to fully cover every feature of XState.
Automatically enables the XState inspector when ?xstate-debug URL param is present"
(:refer-clojure :exclude [send])
(:require ["@xstate/inspect" :as xstate-inspect]
["@xstate/react" :as xstate-react]
["xstate" :as xstate]
[applied-science.js-interop :as j]
(ns acme.react-spring
(:require [rum.core :as rum]
["react-spring" :as rs]))
(rum/defc AnimatedDiv < rum/static
[style child]
(js/React.createElement rs/animated.div (clj->js style) child))
(defn use-spring
[config-map]
@martinklepsch
martinklepsch / README.md
Last active November 17, 2022 09:59
`deps.lua` is an all-in-one script containing your declarative list of dependencies and installing any missing ones.

deps.lua is an all-in-one script containing your declarative list of dependencies and installing any missing ones.

Kind of like Clojure's deps.edn except that the dependencies and code to download them are bundled in one package.

  • add link from file to gist so people can find back to here
  • add entries to .gitignore if available
  • ? if file ends in .fnl, download fennel.lua and compile to respective .lua file location

Usage in a fennel script

(defn log-lifecyle [component-name]
(into {}
(map (fn [lifecycle]
[lifecycle (fn [state] (js/console.log component-name lifecycle) state)]))
[:will-mount :will-unmount :did-mount :did-unmount]))
(rum/defc A < (log-lifecyle :A)
[]
[:span "A"])

Conjure Cheat Sheet

All prefixed by local leader, which is \ in my case.

:disconnect "cd"
:connect-port-file "cf"
:interrupt "ei"
:last-exception "ex"
:view-source "es"
@martinklepsch
martinklepsch / boot_sentry.clj
Created May 15, 2019 05:32
Boot tasks and helper functions to create Sentry releases and attach source maps to them
(ns dev.boot-sentry
(:require [boot.util :as util]
[boot.core :as boot]
[clojure.data.json :as json]
[org.httpkit.client :as http]))
(def sentry-key "abc")
(def org "my-org")
(def project "frontend")
(def test-release "test-release-delete-me")
@martinklepsch
martinklepsch / README.md
Last active November 12, 2018 15:58
Notes about fixing https://cljdoc.org analysis issues with ClojureScript 1.10.439 https://github.com/cljdoc/cljdoc/issues/201

How to analyze-file with foreign-lib dependencies?

  • I'm trying to figure out how to analyze a file that depends on react (via CLJSJS)
  • Previously cljdoc.org would analyze with *analyze-deps* set to false
  • With 1.10.439 this no longer works. (Dynamic vars can't be resolved, see old description below)
  • With *analyze-deps* set to true I need to properly supply the foreign lib information but I can't figure out how.

Solution

When calling cljs.analyzer.api/analyze-file with the state-as-first-arg arity it calls cljs.env/with-compiler-env which shadowed my own binding described in Current Approach section. I was unaware that analyzer.api/empty-state is actually just a compiler env as well so creating the right compiler env and passing it to analyze-file solved all issues:

SQLite version 3.24.0 2018-06-04 14:10:15
Enter ".help" for usage hints.
sqlite> .schema
CREATE TABLE stats (
 date TEXT,