Skip to content

Instantly share code, notes, and snippets.

View bencord0's full-sized avatar

Ben Cordero bencord0

View GitHub Profile
@bencord0
bencord0 / system_uuid.sh
Last active August 31, 2023 11:51
Unique id for a linux system
#!/bin/bash
cat /var/lib/dbus/machine-id && exit
# Provided by dbus, hence available on all systemd systems.
# Any user can read it and it is persistent accross boots.
# It is unique per installation, and works well in VMs.
# Not all systems (i.e. stage3 gentoo/handbook install)
# have dbus installed by default.
cat /sys/class/dmi/id/product_uuid && exit
@bencord0
bencord0 / lb.py
Created October 9, 2016 00:08
asyncio (dumb TCP) load balancer
#!/usr/bin/env python3
"""
usage: lb.py [listening_port] [backend_host] [backend_port]
Only specify one backend host/port. It is expected that
other backends can be discovered by DNS at connect time.
Useful if, say, your backends are on fully dynamic addresses,
but you have a sensible DNS server in front of them.
"""
import argparse
import asyncio
@bencord0
bencord0 / listeningsockethandler.py
Created December 12, 2012 23:36
ListeningSocketHandler ====================== A python logging handler. logging.handlers.SocketHandler is a TCP client that sends log records to a TCP server. This class is the opposite. When a TCP client connects (e.g. telnet or netcat), new log records are sent through the tcp connection.
#!/usr/bin/env python
"""
ListeningSocketHandler
======================
A python logging handler.
logging.handlers.SocketHandler is a TCP Socket client that sends log
records to a tcp server.
This class is the opposite.
@bencord0
bencord0 / provider.tf
Created June 20, 2022 18:22
Extracting secret environment variables from Terraform Cloud
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "secret-org"
workspaces {
name = "secret-workspace"
}
}
@bencord0
bencord0 / reset.sh
Last active June 7, 2022 01:32
Reset branch
#!/bin/bash
# Resets the `staging` branch to the contents of the `production` branch,
# all while maintaining history of both trees, harshly.
PRODUCTION="${1}"
STAGING="${2}"
if [ -z "${PRODUCTION}" -o -z "${STAGING}" ]; then
echo "Usage: reset.sh <production> <staging>"
@bencord0
bencord0 / appsync.py
Last active February 2, 2022 23:02
Accessing AppSync GraphQL APIs from python
import json
import requests
from boto3.session import Session as AWSSession
from gql_py import Gql
from requests import Session
from requests_aws4auth import AWS4Auth
aws = AWSSession()
session = Session()
@bencord0
bencord0 / sealvalue.go
Created December 27, 2021 16:44
Seal a value for a github action secret
package main
import (
"encoding/base64"
"fmt"
"golang.org/x/crypto/nacl/box"
)
func main() {
plaintext := "hello"
@bencord0
bencord0 / openstack.guestfs
Last active September 30, 2021 21:26
Custom Gentoo Openstack Images
#!/usr/bin/guestfish -f
!echo "Modifying gentoo-openstack.qcow2"
# Fetch the image from the mirrors.
# wget -O gentoo-openstack.qcow2 \
# https://distfiles.gentoo.org/experimental/amd64/openstack/gentoo-openstack-amd64-systemd-latest.qcow2
add gentoo-openstack.qcow2
!echo "Starting libguestfs"
@bencord0
bencord0 / update_typora.py
Last active September 29, 2021 11:51
A script to update VSCode on linux (which has no autoupdater)
import os
import re
import requests
import tarfile
from pathlib import Path
from tqdm import tqdm
from urllib.parse import urlparse
INDEX_URL = "https://nodejs.org/dist/index.json"
FETCH_URL = 'https://nodejs.org/dist/{version}/node-{version}-linux-x64.tar.xz'
@bencord0
bencord0 / Dockerfile
Created June 16, 2021 08:55
Dockerfail
FROM ubuntu
RUN exit 1 | cat
RUN echo "Hello World"