Skip to content

Instantly share code, notes, and snippets.

@jkrasnay
jkrasnay / AutoHotkeyU64.ahk
Created February 17, 2023 14:57
AutoHotKey script for window management
; This is my AutoHotKey script for window management
; Each keystroke involves a "mash": holding the Ctrl, Alt, and Windows keys together,
; then pressing on of the keys centered around the K key
; E.g. Ctrl-Alt-Windows-J moves the current window to the left half of the screen.
;
; GetCurrentMonitor is from https://www.autohotkey.com/board/topic/85457-detecting-the-screen-the-current-window-is-on/
GetCurrentMonitor()
{
SysGet, numberOfMonitors, MonitorCount
@jkrasnay
jkrasnay / turing.clj
Last active May 3, 2022 21:28
Turing machine implementation from Clojure TO 2022-04-19
(ns turing)
(def dirs
{:l dec
:r inc})
(defn move
[machine dir]
(update machine :pos (dirs dir)))
@jkrasnay
jkrasnay / re-frame-subs.adoc
Last active June 17, 2022 08:59
Re-frame Subscription Helpers

Re-frame Subscription Helpers

There are a couple of common problems with Re-frame subscriptions that I’d like to solve:

  1. Because subscriptions are registered via keywords, the ClojureScript compiler does nothing to help check that we haven’t made a typo when subscribing.

  2. We often need to use the same logic to access a value in the app DB in both a subscription and in events.

I’ve come up with the following structure. First we create the accessor function, which can be used by both the subscription and any events. (This of course implies that the namespace where we implement our events must refer to the namespace where we define our subscriptions.)

@jkrasnay
jkrasnay / m5stack-core2-getting-started.adoc
Last active June 7, 2022 15:28
Getting Started on the M5Stack Core2

Getting Started on the M5Stack Core2

This is a short guide to getting the M5Stack Core2 running on MacOS Catalina.

Setting Up the Environment

The following commands get us set up with arduino-cli

brew install arduino-cli
@jkrasnay
jkrasnay / foo.js
Created June 28, 2018 15:29
Tiny move-based game engine in Node
var name = "Bar!";
var dirs = {
n: [0,1],
s: [0,-1],
e: [1,0],
w: [-1,0]};
function vadd(v1, v2) {
return v1.map((x,i) => x + v2[i]);
@jkrasnay
jkrasnay / .inputrc
Created October 5, 2017 20:47
.inputrc file for Vi-mode editing
set editing-mode vi
set keymap vi
$if mode=vi
set keymap vi-insert
"jj": vi-movement-mode
$endif
@jkrasnay
jkrasnay / core.clj
Created September 28, 2017 18:45
Clojure Topo Sort
(ns topo-sort.core)
;; Graph Topological Sort
;;
;; The topo-sort function here performs a toplogical sort of the graph. A
;; topological sort returns a list of nodes in dependency order. In our case, a
;; graph is represented as a collection of directed edges, each of which is a
;; two element vector with the "from node" and the "to node":
;;
;; (topo-sort #{[:a :b] [:b :c] [:a :c]})
@jkrasnay
jkrasnay / swagger-jq.sh
Last active July 19, 2023 02:49
Processing Swagger with jq
# Convert to TSV
# Note -r flag
# to_entries creates an array of key,value maps, the trailing [] converts this array to stream items
cat api-docs.json | jq -r '.paths | to_entries[] | .key as $path | .value | to_entries[] | [.key,$path,.value.tags[0]] | @tsv'
# Transform into different JSON...
cat api-docs.json | jq '[ .paths | to_entries[] | .key as $path | .value | to_entries[] | { path:$path, method:.key, tag:.value.tags[0] } ]'
{
"features": [
{
"id": "schedule1",
"type": "feature-schedule",
"name": "Schedule 1",
"icon": "15",
"settings": {
"type": "schedule-settings",
"timeFormat": "12",
@jkrasnay
jkrasnay / keybase.md
Created August 29, 2014 18:37
Keybase.io proof

Keybase proof

I hereby claim:

  • I am jkrasnay on github.
  • I am jkrasnay (https://keybase.io/jkrasnay) on keybase.
  • I have a public key whose fingerprint is 43FF 0EEB D26E D264 3C35 A992 01CB 791D F272 A4CE

To claim this, I am signing this object: