Skip to content

Instantly share code, notes, and snippets.

View lionello's full-sized avatar
🇱🇸

Lio李歐 lionello

🇱🇸
View GitHub Profile
@lionello
lionello / settings.json
Last active May 20, 2026 22:15
Claude allow/deny settings with (mostly) read-only commands. Use at own risk!
{
"permissions": {
"allow": [
"Bash(aws * describe-*)",
"Bash(aws * get-*)",
"Bash(aws * list-*)",
"Bash(aws pricing:*)",
"Bash(az * list:*)",
"Bash(az * show:*)",
"Bash(az monitor diagnostic-settings list:*)",
@lionello
lionello / group.go
Created February 7, 2026 20:20
GroupAdjacentFunc in Golang
func GroupAdjacentFunc[T any, K comparable](seq iter.Seq[T], by func(item T) K) iter.Seq[[]T] {
return func(yield func([]T) bool) {
var group []T
var groupKey K
for item := range seq {
key := by(item)
if key == groupKey {
group = append(group, item)
} else {
if len(group) > 0 && !yield(group) {
@lionello
lionello / DefaultKeyBinding.dict
Created September 16, 2025 19:43
Remapped Page-Up/Down Home/End for MacOS/Darwin
{
/* Home */
"\UF729" = "moveToBeginningOfLine:";
"^\UF729" = "moveToBeginningOfDocument:";
"$\UF729" = "moveToBeginningOfLineAndModifySelection:";
"^$\UF729" = "moveToBeginningOfDocumentAndModifySelection:";
/* End */
"\UF72B" = "moveToEndOfLine:";
"^\UF72B" = "moveToEndOfDocument:";
@lionello
lionello / gh.ts
Created July 30, 2025 22:48
Convert GitHub Issue label to Issue type
import { components } from "@octokit/openapi-types";
import { Octokit } from "@octokit/rest";
const dryrun = false;
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
type Issue = components["schemas"]["issue"];
async function fetchAndMarkBugIssues(owner: string, repo: string) {
// Fetch all issues (paginated)
@lionello
lionello / wol.c
Created September 8, 2013 02:48
Wake-On-LAN
// Portable Wake-On-Lan by Lionello Lunesu, placed in the public domain
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#ifdef _MSC_VER
#pragma comment(lib, "ws2_32.lib")
#endif
#else
#include <sys/socket.h>
@lionello
lionello / delete-bucket-object-versions.py
Last active June 16, 2025 18:04
Python script to delete all versions of objects in an S3 bucket by their prefix
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3Packages.boto3
# Canonical URL: https://gist.github.com/lionello/f322e24135aef81d5ab9c6086c5604cf
import boto3
s3 = boto3.client("s3")
def delete_object_versions(bucket, prefix):
paginator = s3.get_paginator("list_object_versions")
pages = paginator.paginate(Bucket=bucket, Prefix=prefix)
@lionello
lionello / stashd.d
Last active May 22, 2025 17:23
Tool to find GIT stashes containing changes to specified file(s) https://github.com/lionello/stashd
#!/usr/bin/env rdmd
// Get rdmd from https://dlang.org/download.html (or brew, nix, apt, yum)
// Copyright Lionello Lunesu. Placed in the public Domain.
// https://gist.github.com/lionello/84cad70f835131198fee4ab7e7592fce
import std.stdio : writeln, File;
int main(string[] args) {
import std.process : environment, pipeShell, wait, Redirect;
import std.stdio : stdout;
@lionello
lionello / inspect.sh
Last active April 2, 2025 00:12
Shell script to inspect a Docker image on a remote registry
#!/bin/bash
# Canonical version: https://gist.github.com/lionello/8fb32ee065774b934ab9af62fd269e39
# Inspired by https://stackoverflow.com/a/69300514/2017049
REGISTRY="registry-1.docker.io"
ref="${1:-library/ubuntu:latest}"
repo="${ref%:*}"
tag="${ref##*:}"
token=$(curl -sSLf "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
@lionello
lionello / powFetch.html
Last active December 12, 2024 19:41
Stateless rate limiting using Proof-of-Work in JS/HTML
<script>
async function powFetch(url, options = {}) {
if (window.crypto && window.crypto.subtle) {
let bodyHash, nonceArray = new Uint32Array(1), nonce = 0;
const body = new TextEncoder().encode(options.body);
const bodyWithNonce = new Uint8Array(nonceArray.byteLength + body.byteLength);
bodyWithNonce.set(body, nonceArray.byteLength);
do {
nonceArray[0] = ++nonce;
bodyWithNonce.set(new Uint8Array(nonceArray.buffer));
@lionello
lionello / Dockerfile
Last active November 20, 2024 04:29
Minimal Compose app to upload/download a file
# Use an official Node runtime based on slim as a parent image
FROM node:20-slim
# Set the working directory to /app
WORKDIR /app
# Install curl and any other dependencies
RUN apt-get update \
\
&& apt-get install -y --no-install-recommends \