Skip to content

Instantly share code, notes, and snippets.

@eatnumber1
eatnumber1 / watch-spark-dirty-pages.sh
Created June 21, 2023 20:01
Draw a sparkline of dirty pages over time on Linux.
#!/bin/bash
set -e
set -o pipefail
statefile="$(mktemp --tmpdir=/run spark-dirty-pages.XXXXX)"
trap 'rm -f $statefile' INT HUP QUIT
function watch_iter {
declare -a dirty
readarray -t dirty < "$statefile"
@eatnumber1
eatnumber1 / cookieauth.conf
Last active July 28, 2023 21:09
Stateless Nginx Cookie Authentication
# Simple Cookie Authorization (SCA)
#
# SCA sets up an auth scheme which uses a secure cookie, presenting basic
# auth if the cookie isn't supplied.
#
# Put this file in /etc/nginx/conf.d
#
# To use it, put a stanza like the following in a server section:
#
# set $sca_realm "My Website";
@eatnumber1
eatnumber1 / get_all_hostnames.js
Last active August 21, 2022 22:07
Bitburner utility function to create a generator that yields all hostnames.
/**
* Create a generator that yields all hostnames.
*
* @param {NS} ns
* @param {String} hostname the host to start traversal at
* @param {Set} seen used for internal recursion
* @yields {String} a hostname
*/
export function* getAllHostnames(ns, hostname = "home", seen = new Set()) {
seen.add(hostname);
@eatnumber1
eatnumber1 / pathto.js
Last active August 21, 2022 21:14
Bitburner CLI tool to print the path to a given host
/**
* Pathto finds the path of servers between a source and destination.
*
* @param {NS} ns
* @param {String} dest the hostname to try to find a path to
* @param {String} src the hostname to start at
* @param {Array} tosrc used for internal recursion
* @param {Set} seen used for internal recursion
* @returns {Array} the path from src to dest, or null if no path exists
*/
@eatnumber1
eatnumber1 / wait-with-timeout.c
Created March 28, 2017 02:05
wait(2) with timeout using a timer
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdbool.h>
#include <limits.h>
@eatnumber1
eatnumber1 / plex.conf
Created December 6, 2015 20:44
fluentd config for plex
<source>
type tail
path /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/*.log
pos_file /var/lib/google-fluentd/pos/plex.pos
read_from_head true
tag plex
format multiline
format_firstline /^[^ ]+ \d{1,2}, \d{4} \d{2}:\d{2}:\d{2}/
format1 /^(?<time>^[^ ]+ \d{1,2}, \d{4} \d{2}:\d{2}:\d{2}) [^ ]+ (?<severity>[^ ]+) - (?<message>(?:(?:Request|Completed): \[(?<remotehost>[^:]+):[^\]]+\] (?<method>[^ ]+) (?<path>[^? ]+)(?:\?(?<querystring>[^ ]+))? \([^\)]+\)(?: (?:TLS|GZIP))*(?: [0-9]+ms (?<bytes>[0-9]+) bytes (?<status>[0-9]+))?.*|.+))$/
</source>
@eatnumber1
eatnumber1 / renameat2.c
Last active November 3, 2023 17:24
Command-line tool to call renameat2(2)
/*
* Copyright (c) 2023 Russell Harmon
*
* 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:
*
@eatnumber1
eatnumber1 / good.c
Last active August 29, 2015 14:09
The result of a challenge to write in C code that will do the following when run in Python: "good " * 2. I think I got a little carried away.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
for (char *s = "good ", l = strlen(s), z = 2 * l, d[z], *p = d; p == d + z ? *--p = 0, !puts(d) : 1; p = memcpy(p, s, l) + l);
}
@eatnumber1
eatnumber1 / a.c
Last active August 29, 2015 14:09
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
int wins = 2;
char *s = "good ";
char *p = malloc(wins * strlen(s) + 1);
for (int i = 0; i < wins; i++) p = strcat(p, s);
printf("%s\n", p);
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
Domain Name: CAPICUE.COM
Registrar: GOOGLE INC.
Whois Server: whois.rrpproxy.net