Skip to content

Instantly share code, notes, and snippets.

@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 \
@lionello
lionello / protogen.go
Last active July 5, 2024 02:39
Generate protobuf schema file from a Go type
package main
import (
"fmt"
"reflect"
"regexp"
"strings"
compose "github.com/compose-spec/compose-go/v2/types"
)
@lionello
lionello / transfer-repos.sh
Last active June 12, 2024 22:45
Shell script to bulk-transfer repositories from one org to another
#!/usr/bin/env bash
set -e # Exit on error
ORG=DefangLabs
OWNER=$ORG
NEW_OWNER=DefangSamples
TOKEN=ghp_… # REPLACE
repos=$(curl -sL \
-H "Accept: application/vnd.github+json" \
@lionello
lionello / go.mod
Created May 25, 2024 15:05
Simplest Loki query example in Go
module github.com/DefangLabs/GoLicenseGuard/test
go 1.22.3
require github.com/grafana/loki/v3 v3.0.0
require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
@lionello
lionello / saml2aws.sh
Last active May 2, 2024 17:36
Script to log into AWS with a SAML assertion. Must replace ACCOUNT number etc. before use!
#!/bin/bash
# Copyright 2024 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 furnished to do so, subject to
# the following conditions:
#
@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 / 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; };
}
);
}