Skip to content

Instantly share code, notes, and snippets.

@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 / client.clj
Last active November 26, 2023 20:36
A minimal Clojure client for Airtable.com's HTTP API.
(ns oxygen.client
"A minimal Clojure client for Airtable.com's HTTP API.
Supports retrieval of whole tables as well as individual records.
Dependencies: [org.clojure/data.json \"0.2.6\"] [clj-http \"2.0.0\"]"
(:require [clojure.data.json :as json]
[clojure.string :as string]
[clojure.set :as set]
[clj-http.client :as client]))
(def api-base "https://api.airtable.com/v0")
@martinklepsch
martinklepsch / fritzbox_reconnect.py
Created April 22, 2010 19:39
Simple script to reconnect your fritz.box
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Instruct an AVM FRITZ!Box via UPnP_ to reconnect.
This is usually realized with tools like Netcat_ or cURL_. However, when
developing in Python_ anyway, it is more convenient to integrate a native
implementation. This one requires Python_ 2.5 or higher.
UPnP_ (Universal Plug and Play) control messages are based on SOAP_, which is
@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

@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"
]

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 / random-color.clj
Last active April 23, 2022 20:07
Generate a random HEX color in cojure or clojurescript
(require '[clojure.string :as s])
;; My initial attempt
(def c [:0 :1 :2 :3 :4 :5 :6 :7 :8 :9 :A :B :C :D :E :F])
(str "#" (s/join (map name (repeatedly 6 #(rand-nth c)))))
;; Another option not using keywords (/ht locks in #clojure)
(def c [0 1 2 3 4 5 6 7 8 9 \A \B \C \D \E \F])
(str "#" (s/join (repeatedly 6 #(rand-nth c))))
;; the last line can be simplified even more (/ht xificurC in #clojure)
@martinklepsch
martinklepsch / README.md
Last active February 28, 2022 04:34
A very minimal Emacs configuration to get started with Emacs & Evil-mode

A Starting Point for using Emacs & Evil-mode

(I wrote a bit about why Emacs and Vim on my blog and thought it might be nice to give some starting point for people that want to try it.)

If you just want to play around with Emacs & Evil mode do the following:

  1. mkdir ~/.emacs.d/
  2. copy init.el into ~/.emacs.d/
  3. Download Emacs from http://emacsformacosx.com
@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]
(defn listen-file-drop
([el] (listen-file-drop el (chan)))
([el out & {:keys [concat]
:or {concat true}}]
(let [handler (events/FileDropHandler. el true)]
(events/listen el events/FileDropHandler.EventType.DROP
(fn [e] (let [files (event->files e)]
(.log js/console "dropped")
(.log js/console (-> (-source-event e) .-dataTransfer .-files prim-seq))
(if concat