Skip to content

Instantly share code, notes, and snippets.

@jasonk
jasonk / Reolink API.md
Last active November 30, 2025 15:09
Simple Bash Examples for Reolink API
@jasonk
jasonk / Home Assistant - Mass delete devices.md
Last active November 13, 2025 17:30
Home Assistant - Mass delete devices

After running rtl_433 with the MQTT Discovery add-on for a while, I ended up with hundreds of my neighbors devices in my Home Assistant instance. This was when I found out there was no easy way to delete them and was faced with the prospect of going to each one in the GUI, picking "delete" from a menu and the confirming it hundreds of times.

I'm too lazy for that, so I did this instead, based on some code from the forums I came up with this.

How to use it

To use this:

  1. Create a new Area in your Home Assistant (I called mine "Garbage"), and change the GARBAGE_ID variable in the code to have the ID of your new area.
  2. In the devices list you can hit the "select" button and put checkmarks next to all the devices you want to get rid of. Then use the menu in th
@jasonk
jasonk / Home Assistant template functions in pyscript
Last active May 11, 2025 18:55
Import template functions from Home Assistant into pyscript
Inspired by [pyscript#251](https://github.com/custom-components/pyscript/issues/251) and [pyscript#568](https://github.com/custom-components/pyscript/issues/568).
This is a module that you can put in your [pyscript](https://github.com/custom-components/pyscript) modules directory and then import from any pyscript script and have access to all the template functions that Home Assistant provides.
Features:
* It automatically determines what functions Home Assistant is providing to templates, so when new functions get added by a Home Assistant update (like labels and areas did recently) they get included automatically.
* It even includes things added by extensions, like the template functions added by [spook](https://spook.boo/).
* It automatically figures out which functions need the `hass` instance passed to them and wraps the ones that do.
## Usage ##
@jasonk
jasonk / README.md
Last active March 23, 2025 22:39
MongoDB Update Pipeline Tricks

Starting with MongoDB 4.2, you can use [aggregation pipelines to update documents][$pipelines]. Which leads to some really cool stuff.

For example, prior to this you could easily add sub-documents to an array using [$addtoSet][$addtoSet], and you could remove documents from an array using [$pull][$pull], but you couldn't do both in the same operation, you had to send two separate update commands if you needed to remove some and add some.

With 4.2, now you can, because you can format your update as a pipeline, with multiple $set and $unset stages, which makes those things possible. However, since this is so new I had a really hard time finding examples of many of the things I wanted to do, so I started to collect some here for my reference (and yours).

See also:

@jasonk
jasonk / setup.sh
Last active February 12, 2025 16:56
Setup script for Minecraft Bukkit, ScriptCraft, and MQTT
#!/bin/bash
cd "$(dirname "$0")"
# CraftBukkit download URL
CBURL="http://repo.bukkit.org/content/groups/public/org/bukkit/craftbukkit/1.7.2-R0.3/craftbukkit-1.7.2-R0.3.jar"
# ScriptCraft download URL
SCURL="http://scriptcraftjs.org/download/2014-02/v2.0.4/scriptcraft.jar"
# Install CraftBukkit
if [ ! -f craftbukkit.jar ]; then
@jasonk
jasonk / patch-meteor.sh
Last active February 12, 2025 16:56
Monkey patch Meteor to use CA certs from the OS X keychain.
#!/bin/bash
set -e
# This script monkey-patches MeteorJS to allow it to work from behind a MITM
# proxy that forges SSL keys. You may need this to get through a corporate
# content-inspection proxy, for example, since Meteor doesn't allow you to
# specify the CA certs to use.
cd "$HOME/.meteor"
cd "$(dirname "$(readlink meteor)")"
cd tools
@jasonk
jasonk / TamperMonkey Utilities.md
Last active February 12, 2025 16:56
TamperMonkey Utility Scripts

TamperMonkey Utility Scripts

To use, include them in your TamperMonkey script, like so:

// @require https://gist.githubusercontent.com/jasonk/24bd00ff72b686f0b8a098290ef754bf/raw/tampermonkey-utils.js
// @require https://gist.githubusercontent.com/jasonk/24bd00ff72b686f0b8a098290ef754bf/raw/tampermonkey-cleanup.js

Note that tampermonkey-utils.js must be loaded before any of the others are loaded.

@jasonk
jasonk / Jenkinsfile
Last active February 12, 2025 16:56
Docker credential helper for authenticating from environment variables
pipeline {
environment {
DOCKER_REGISTRY = 'https://my-docker-registry.example.com'
DOCKER_CREDS = credentials( 'my-docker-credentials' )
}
}
@jasonk
jasonk / lazy-developer-branch-tickets.md
Last active February 12, 2025 16:56
Lazy developers use branch names to keep track of their tickets

On my team we like to put ticket numbers in commit messages, so that Jira finds them and puts links to the commits in the ticket. The problem is that I have a really hard time remembering my ticket numbers. What I've been doing is creating a branch for each ticket, but while that helps me remember the numbers, it still doesn't help me remember which ticket is which. I had tried posting comments to myself in Slack to keep track of them, but then it occurred to me that I didn't need to be using just the ticket number as the branch name, so now I'm trying something new.

Instead of creating branches with just the ticket number, I'm using ticket/short-description. The length of the branch name doesn't affect much, thanks to tab completion, and having that information available at a glance right in the repo is huge, especially since I have the branch name as part of my prompt.

[me@my-machine:dir PROJ-1234/fix-ci ]$ git branch
  PROJ-1234/fix-ci
  PROJ-1233/remove-stupid-widgets
  PROJ-1232/fix-brok
@jasonk
jasonk / README.md
Last active February 12, 2025 16:56
Pull request message hooks for hub

I'm a big fan of hub, but I found myself wishing for the ability to use git hooks on pull-request messages the same way you can on commit messages with prepare-commit-msg and commit-msg hooks. People have been asking for hub to be able to do this for a while, but until that happens, here is a way you can do it yourself, right now.

To use this, just drop the script below into your $PATH somewhere, and make sure you have your $EDITOR environment variable set to whatever command runs your real editor, and then set your $GIT_EDITOR environment variable to run the hub-editor script.

The way this works is that when hub-editor is invoked with a file named PULLREQ_EDITMSG (which is the filename hub uses for editing pull requests) then it will run the prepare-pull-request-msg and pull-request-msg scripts from your .git/hooks directory (if they exist and are executable). If hub-editor is invoked with any other file