Skip to content

Instantly share code, notes, and snippets.

@adam12
adam12 / memory-allocated.sh
Last active January 10, 2018 03:21
Libvirt memory allocated
#!/bin/sh
(for i in $(ls /etc/libvirt/qemu/*.xml); do xml2 < $i | grep 'memory='; done) | awk -F= '{ sum += $2 } END { print sum / 1024^2 " GB" }'
@adam12
adam12 / orphaned-images.sh
Created January 8, 2018 17:53
List qcow2 images that have been orphaned
#/bin/sh
# vim:ts=4:sts=4:sw=4:et
for d in $(ls /var/lib/libvirt/images/*.qcow2); do
grep $d /etc/libvirt/qemu/*.xml >/dev/null || echo $d
done
@adam12
adam12 / cgi.go
Created February 17, 2018 20:04 — forked from icholy/cgi.go
package main
import (
"fmt"
"net/http"
"net/http/cgi"
"os"
)
type Handler func(http.ResponseWriter, *http.Request)
package main
import (
"bufio"
"fmt"
"io"
"log"
"os/exec"
)
@adam12
adam12 / build.py
Created August 15, 2018 18:29 — forked from icholy/build.py
#!/usr/bin/env python
import errno
import os
import subprocess
import sys
import shutil
import glob
import tarfile
import os.path
@adam12
adam12 / jail.conf
Created October 18, 2018 14:48 — forked from paulc/jail.conf
FreeBSD ZFS Jail
interface = "lo1";
host.hostname = "$name";
ip4.addr = "172.16.0.$n";
path = "/jail/run/$name";
exec.prestart = "/sbin/zfs clone zroot/jail/template/10.2-RELEASE/[email protected] zroot/jail/run/$name &&
/usr/sbin/sysrc -f /jail/run/$name/etc/rc.conf hostname=$name &&
/usr/sbin/sysrc -f /jail/run/$name/etc/rc.conf sshd_enable=YES &&
/usr/sbin/sysrc -f /jail/run/$name/etc/rc.conf sshd_flags=\"-o ListenAddress=172.16.0.$n\" &&
/usr/sbin/pw -R /jail/run/$name useradd -n u01 -m -w random &&
/usr/sbin/pw -R /jail/run/$name lock root &&
@adam12
adam12 / async.rb
Created April 1, 2019 15:44 — forked from paul/async.rb
Implementations of useful step adapters for dry-transaction
# frozen_string_literal: true
module Tesseract
module Transaction
module Steps
# Executes the step in a background job. Argument is either an ActiveJob
# or another Transaction (or anything that implements `#perform_later`.
#
# If the provided transaction implements a `validate` step, then that
# validator will be called on the input before the job is enqueued. This
@adam12
adam12 / lazy.rb
Created April 23, 2019 13:53 — forked from localhostdotdev/lazy.rb
Lazy: fetch deep values only when you need to
# Example: Lazy.new(lambda { |id| API::HackerNews.item(id) }, 0)
class Lazy
attr_reader :value
def initialize(function:, value:)
@function = function
@value = value
@cached = nil
@is_cached = false
@adam12
adam12 / accounts.txt
Created May 8, 2019 00:22 — forked from simonmichael/accounts.txt
a sample *ledger chart of accounts (first 3 levels): combined personal & business, eg for a freelancer
assets
business
accounts receivable
bank
personal
accounts receivable
bank
cash
gifts
online
@adam12
adam12 / cron_helper.sh
Created August 23, 2019 02:08 — forked from liquidgecka/cron_helper.sh
Cron helper
#!/bin/bash
usage() {
cat << EOF
Usage: $0 [OPTION]... COMMAND
Execute the given command in a way that works safely with cron. This should
typically be used inside of a cron job definition like so:
* * * * * $(which "$0") [OPTION]... COMMAND
Arguments: