Skip to content

Instantly share code, notes, and snippets.

View thmsmlr's full-sized avatar

Thomas Millar thmsmlr

View GitHub Profile
@thmsmlr
thmsmlr / README.md
Last active February 7, 2025 10:37
cmd+k for any terminal

These three scripts can provide you a cursor style CMD+K Like experience in any terminal.

How it works

  1. Set logged-shell to be your default shell for your terminal emulator. shell = /path/to/logged-shell in ~/.config/kitty/kitty.conf for kitty users.
  2. This will stream both the inputs and outputs of your terminal session into a file defined at $SHELL_LOG_FILE
  3. The ai-bash-command will take a user prompt, add the shell as context, and call OpenAI (with the ai command) to get the bash command that satisfies the prompt.
  4. It will type the results back into your terminal using wtype for wayland users.
@thmsmlr
thmsmlr / wait_for.ex
Created December 26, 2024 21:20
ExUnit helper function to wait up to a timeout to determine whether a set of assertions completes. Perfect for testing async code
@default_timeout 100
@check_interval 10
# Test Helpers
defp wait_for(fun, timeout \\ @default_timeout) do
start_time = System.monotonic_time(:millisecond)
ref = make_ref()
try do
@thmsmlr
thmsmlr / app.js
Created February 14, 2024 16:54
Code Splitting for Phoenix LiveView Hooks
// assets/js/app.js
window._lazy_hooks = window._lazy_hooks || {};
let lazyHook = function(hook) {
return {
mounted() { window._lazy_hooks[hook].mounted(...arguments) },
beforeUpdate() { window._lazy_hooks[hook].beforeUpdate(...arguments) },
updated() { window._lazy_hooks[hook].updated(...arguments) },
destroyed() { window._lazy_hooks[hook].destroyed(...arguments) },
disconnected() { window._lazy_hooks[hook].disconnected(...arguments) },
@thmsmlr
thmsmlr / kino_daemon.exs
Created January 14, 2024 21:59
Kino Background Daemon
child_spec = Task.child_spec(fn ->
IO.puts("""
I am doing daemon things for my Livebook.
If I re-evaluate the cell, this task will be terminated and restart with the new version of the code.
If the task ever terminates, the Supervisor will automatically restart it.
Useful for running things in the background that don't need to directly interact with your notebook.
""")
@thmsmlr
thmsmlr / google-vim-hotkeys.js
Last active April 20, 2022 18:25
[Tampermonkey] Google VIM Hotkeys
// ==UserScript==
// @name Google VIM Hotkeys
// @namespace https://gist.github.com/ccjmne
// @version 0.0.1
// @description Navigate results from Google using j/k vim bindings
// @author Thomas Millar <[email protected]> (https://github.com/thmsmlr)
// @match *://www.google.com/*
// @grant none
// ==/UserScript==
@thmsmlr
thmsmlr / killport
Created February 1, 2022 19:01
killport
#!/bin/sh
usage() {
cat >&2 << EOF
killport: kill -9 any process that is bound to a local port
Usage:
killport <port>
EOF
}
@thmsmlr
thmsmlr / bash-compose-up
Created July 1, 2020 05:59
A simple way to spin up many blocking bash commands at once, killing all on SIGINT
#!/usr/bin/env bash
#
# This is a basic script to launch multiple programs and kill them
# all at the same time. It does this by launching the first n-1 jobs as
# background jobs, then running the nth job as a foreground job.
#
# It traps the exist signal produced by doing `CTRL-C` on the CLI and
# iterates through the PIDs of the background jobs and runs kill -9 on them.
#
@thmsmlr
thmsmlr / deploy.sh
Created August 17, 2016 17:17
GitHub Pages deploy script
#!/bin/sh
set -e
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "jekyll" ]; then
echo "ERROR! You can only deploy from jekyll branch"
exit 1
fi
CLEAN_REPO=$(git status --porcelain)
@thmsmlr
thmsmlr / cached_property.py
Created June 18, 2015 16:56
Cached Property
def cached_property(func):
property_name = '_' + func.__name__
@functools.wraps(func)
def wrapped(self, *args, **kwargs):
private_property = getattr(self, property_name, None)
if kwargs.get('force', False) or private_property == None:
val = func(self, *args, **kwargs)
setattr(self, property_name, val)
return val
else: