Skip to content

Instantly share code, notes, and snippets.

@sbz
sbz / aws-policies.md
Last active July 24, 2024 16:50
List all existing AWS policies with services and actions
% curl \
  -s 'https://awspolicygen.s3.amazonaws.com/js/policies.js' \
  | sed 's#app.PolicyEditorConfig=##' \
  | jq -r '.serviceMap[]|.StringPrefix as $prefix|.Actions[] | "\($prefix):\(.)"' \
  | sort -u
a2c:GetContainerizationJobDetails
a2c:GetDeploymentJobDetails
a2c:StartContainerizationJob
a2c:StartDeploymentJob
@sbz
sbz / wdate.sh
Created July 17, 2024 16:17
wdate: worldwide timezone date
#!/bin/bash
# date --date='TZ="UTC+4" 2016-08-22 10:37:44' "+%Y-%m-%d %H:%M:%S"
# Show date and time in other time zones
search=$1
format='%a %F %T %z'
zoneinfo=/usr/share/zoneinfo
@sbz
sbz / pypi-requires.py
Created June 13, 2024 06:05
pypi-requires.py: List packages dependencies using pypi API
import sys
import json
import requests
from pprint import pprint
def main() -> int:
if sys.argv[0] == 1:
print(f"Usage: {sys.argv[0]} <package==version>|<package>|<package> <version>")
return 1
@sbz
sbz / ansible-filter-fact-with-jq.sh
Last active April 17, 2023 20:51
Get FreeBSD ansible facts using jq script function to pick selected facts
$ cat <<EOF > reduce.jq
def pick($paths):
. as $root | reduce $paths[] as $path ({}; . + { ($path): $root[$path] });
.ansible_facts | pick(["ansible_kernel", "ansible_distribution", "ansible_kernel_version"])
EOF
$ ansible -m setup localhost | sed '1 s/^.*|.*=>.*$/{/g' | jq -f reduce.jq
{
"ansible_kernel": "13.1-RELEASE-p3",
@sbz
sbz / lsdev.gdb
Created April 17, 2023 20:02
FreeBSD kernel list devices in kgdb
define lsdev
set $dev = bus_data_devices->tqh_first
while ($dev != 0)
printf "%-20s ", $dev->nameunit
printf " %p", $dev->softc
print "\n"
set $dev = $dev->devlink.tqe_next
end
end
@sbz
sbz / elf-compiler-section
Last active April 14, 2025 18:21
Add ELF section .sbz using compiler __attribute__((section))
$ cat test.c
#include <stdio.h>
void
test() __attribute__ ((section (".sbz")))
{
printf("Test called located in %p and section .sbz\n", &test);
}
int
@sbz
sbz / go.mod
Created June 8, 2021 14:15
Test go pf FreeBSD
module github.com/sbz/pf-test
go 1.16
require (
github.com/go-freebsd/kld v0.0.0-20170326221633-78f2bd4a5544 // indirect
github.com/go-freebsd/pf v0.0.0-20190318053615-719aae74de40
github.com/stretchr/testify v1.7.0 // indirect
)
@sbz
sbz / gist:3c23c52d6817246b3682922944a9c3ba
Created March 25, 2021 13:32
crowdsec patch uuid for BSD systems
diff --git c/cmd/crowdsec-cli/machines.go w/cmd/crowdsec-cli/machines.go
index bbdf11c..33e87e9 100644
--- c/cmd/crowdsec-cli/machines.go
+++ w/cmd/crowdsec-cli/machines.go
@@ -7,6 +7,7 @@ import (
"io/ioutil"
"math/big"
"os"
+ "runtime"
"strings"
@sbz
sbz / ntp.py
Created February 13, 2020 00:06
tcollector ntp
#!/usr/bin/env python
import sys
import subprocess
import socket
import shlex
NTPQ_BIN='/usr/bin/ntpq'
METRICS=[
@sbz
sbz / tf-init.sh
Last active August 19, 2019 15:19
Initialize terraform environment
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
readonly TF_VERSION="v0.11"
output_line() {