Skip to content

Instantly share code, notes, and snippets.

@xinau
xinau / main.go
Last active December 5, 2022 12:49
Update mtime and file name of Google Photos takeout
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/fs"
"log"
"os"
@xinau
xinau / README.md
Created November 25, 2022 23:56
bpftrace go programs

bpftrace go programs

go build -o server main.go
./server
objdump -t ./server | grep "main."
@xinau
xinau / main.go
Created March 24, 2022 08:53
Server-Sent Events in Go
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
)
@xinau
xinau / kata-data-collect.md
Last active September 11, 2021 00:46
kata-data-collect.sh for priviliged containerd

Meta details

Running kata-collect-data.sh version 2.2.0 (commit ) at 2021-09-11.00:46:02.252524179+0000.


Runtime

@xinau
xinau / prometheus.py
Last active July 28, 2022 00:04
Ansible callback plugin for exposing playbook execution statistics to Prometheus
# (c) 2018 xinau <felix.ehrenpfort@protonmail.com>
# GNU General Public License v3.0+ (see https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = '''
callback: prometheus
callback_type: aggregate
short_description: expose playbook stats to as Prometheus metrics.
@xinau
xinau / domain.sh
Created February 5, 2021 09:07
script for getting available domains based on the filesysetm layout
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# sudo ./domains.sh | tee domains.txt | awk '/AVAILABILITY_AVAILABLE$/ {print $1}'
structs=$(find / -maxdepth 2 -mindepth 2 \
| grep -E "^/(media|run|dev)" \
| grep -v -E "(_|\.)" \
@xinau
xinau / main.go
Last active May 22, 2020 12:04
CountFunc and SplitNFunc for byte arrays in golang
package main
import (
"bytes"
"fmt"
)
func CountFunc(s []byte, f func(rune) bool) int {
n := 0
for i := 0; i < len(s); i++ {
@xinau
xinau / tfinist.sh
Created May 20, 2020 09:42
terraform init wrapper - backend switch and environment name export.
#!/usr/bin/env bash
#
# This script is used for configuring terraform and it's remote state backend
# for a specific environment. This is done by sourcing a backend config in the
# `dev` folder under the git root directory. Note that the backend config file
# name needs to end with a `.hcl` extension and the file basename is used as
# the environment name provided. It also sets a `TF_VAR_envname` with the
# environment name as value.
#
# For distinguishing the different environments the script also sets `PS1`.
@xinau
xinau / main.go
Created May 7, 2020 11:38
script for geneareting a flat-file database on github repositories and releases
package main
import (
"context"
"fmt"
"os"
"github.com/google/go-github/v31/github"
"golang.org/x/oauth2"
)
@xinau
xinau / packer.json
Created April 13, 2020 21:17
Building docker images using packer and ansible
{
"variables": {
"host": "default",
},
"builders": [
{
"type": "docker",
"image": "debian:9.6",
"commit": true,
"run_command": [