Skip to content

Instantly share code, notes, and snippets.

View nkcmr's full-sized avatar

nick comer nkcmr

View GitHub Profile
@nkcmr
nkcmr / ntfy-exec.sh
Created November 20, 2026 09:42
A simple script with minimal dependencies to exec a command for each message on a `ntfy.sh` topic.
#!/bin/bash
#
# Subscribe to an ntfy topic and run a command for each message published
# after this script starts, using ntfy's streaming JSON endpoint. Reconnects
# (with a short replay window) if the connection drops.
#
# The command is run once per message, in order, with the message's raw JSON
# on stdin and these environment variables set (same names as `ntfy subscribe`):
# NTFY_ID NTFY_TIME NTFY_TOPIC NTFY_MESSAGE NTFY_TITLE NTFY_PRIORITY
# NTFY_TAGS (comma-separated) NTFY_CLICK
package main
import (
"encoding/base64"
"fmt"
"io"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
package chanutil
import (
"context"
"sync"
)
func fanIn[T any](ctx context.Context, size int, chans ...<-chan T) <-chan T {
var wg sync.WaitGroup
copy := func(i <-chan T, o chan<- T) {
@nkcmr
nkcmr / webfinger-cf-worker.js
Created December 20, 2022 12:32
A Cloudflare worker that allows you to make your domains or email addresses aliases to your Fediverse account
// add your domain to CF and assign this worker to a route: example.com/.well-known/webfinger*
export default {
async fetch(request, env) {
return await handleRequest(request);
},
};
const lookupmap = {
"acct:me@example.com": {
#!/bin/bash
# should rename it just "git-newbranch" and put it in your path somewhere.
# once that is done it should be invokable as "git newbranch JIRA-123"
set -euo pipefail
JIRA_NUMBER="${1:-}"
if ! [[ "$JIRA_NUMBER" =~ ^[A-Z]{2,}-[0-9]+$ ]] ; then
echo "$(basename $0): error: invalid Jira number"
@nkcmr
nkcmr / example.ts
Last active November 16, 2022 15:02
Dynamic HTTP Request Router for Cloudflare Workers
import { Router } from './router.ts'
export interface Env {
// holds things like KV namespaces and Durable Objects
}
const r = Router.create<Env>((handle) => {
handle('GET', '/users/:username', (request, env, ctx, { username }) => {
return new Response(`hello, ${username}!`);
});
@nkcmr
nkcmr / matrix.go
Last active August 24, 2021 12:15
package main
import (
"errors"
)
// stringMatrix will iterate through every combination of each row of the matrix
// it is initialized with. while most of the time, there is a static number of
// rows in a particular matrix and it is trivial to just write something like
// this:
@nkcmr
nkcmr / proposal.md
Last active July 17, 2019 14:15
Informal Golang Proposal: `catch` block as an alternative to `if err != nil`

Informal Golang Proposal: catch block as an alternative to if err != nil

PLEASE NOTE: I am not a language designer or have any experience in implementing or mainting a language or compiler. So, I would love to write out the EBNF syntax for what I am about to propose, but alas, I wouldn't know where to start. So, please forgive the informal nature of the proposal and feel free to ask questions; hopefully I'll be able to keep up with actual experts in this field and if not I apologize for my naivety in advance!

When the try() proposal was closed, I was relieved. There is a problem to be solved here, but try, to me at least, created more problems while trying to solve one.

The main problems, I think it created were the following:

  • try reduced the visiblility of failures. For example:
package main
import (
"fmt"
"io/ioutil"
"math"
"os"
"strconv"
"strings"
"text/template"

Keybase proof

I hereby claim:

  • I am nkcmr on github.
  • I am nkcmr (https://keybase.io/nkcmr) on keybase.
  • I have a public key whose fingerprint is BBCA B79B BD4A 436E DA81 E4CF DD79 7F0B 1769 BCA1

To claim this, I am signing this object: