Skip to content

Instantly share code, notes, and snippets.

View lionello's full-sized avatar
🇭🇰

Lio李歐 lionello

🇭🇰
View GitHub Profile
@lionello
lionello / extract-image.ts
Created March 11, 2024 23:49
TS file to extract a file from a container image
import * as tar from "tar-stream";
import gunzip from "gunzip-maybe";
import { pipeline } from "stream";
import { promisify } from "util";
const pipelineAsync = promisify(pipeline);
const dockerRegistryUrl = "https://registry-1.docker.io";
const imageName = "library/ubuntu"; // Replace with your image name
const tag = "latest"; // or the specific tag you want to download
@lionello
lionello / Dockerfile
Created October 21, 2023 12:18
Dockerfile for krallin/tini
FROM alpine:3 as tini
# The is automatically set by docker buildx
ARG TARGETARCH
# From https://github.com/krallin/tini#signed-binaries
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-${TARGETARCH} /tini
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-${TARGETARCH}.asc /tini.asc
RUN apk add --no-cache gnupg \
&& gpg --batch --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 595E85A6B1B4779EA4DAAEC70B588DFF0527A9B7 \
&& gpg --batch --verify /tini.asc /tini
@lionello
lionello / ECMath.sol
Last active June 11, 2023 05:44
ECDSA verification and recovery for curve secp256r1
/*
MIT License
Copyright (c) 2018 Lionello Lunesu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@lionello
lionello / jwk.go
Created March 16, 2023 20:48
JWK in Go
package pkg
import (
"crypto/ecdsa"
"crypto/elliptic"
"encoding/base64"
"errors"
"math/big"
)
@lionello
lionello / wait-for-sig.py
Last active February 11, 2023 23:10
Shell script to wait for a signal
#!/usr/bin/env python
import signal, subprocess, sys
signal.sigwait([signal.SIGTERM])
@lionello
lionello / flake.nix
Created August 30, 2022 17:53
Generic flake.nix for migrating from shell.nix
{
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}
@lionello
lionello / post-merge
Created August 26, 2022 20:38 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#!/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@lionello
lionello / stashd.d
Last active August 7, 2022 18:32
Tool to find GIT stashes containing changes to specified file(s)
#!/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;
int main(string[] args) {
import std.process : pipeProcess, wait, Redirect;
@lionello
lionello / base64url
Last active August 6, 2022 17:37
base64url: wrapper script for base64
#!/usr/bin/env bash
# Source: https://gist.github.com/lionello/6bb597fc600932c6c737aab3b402147c
ignore=0
decode=0
dashdash=0
args=()
files=()
while [ $# -gt 0 ]; do
@lionello
lionello / writevt.c
Last active August 1, 2022 21:49
Forked writevt from console-tools
/*
* Mostly ripped off of console-tools' writevt.c
*/
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>