Skip to content

Instantly share code, notes, and snippets.

@eatnumber1
eatnumber1 / langf-hand-scanner.sml
Created August 4, 2013 07:18
SML Implementation of Regular Expressions
(* langfc-src/scanner-parser/langf-hand-scanner.sml
*
* COPYRIGHT (c) 2011-2013 Matthew Fluet (http://www.cs.rit.edu/~mtf)
* All rights reserved.
*
* Rochester Institute of Technology
* 4005-711
* Q20112,Q20122
*
* COPYRIGHT (c) 2009 Matthew Fluet (http://tti-c.org/fluet)
@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 / 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 / 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 / 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 / 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 / sls.c
Created January 14, 2013 18:49
A awesome^H^H^H^H^H^H^Hdisgusting use of the stack in C.
#include <stdio.h>
#include <setjmp.h>
#include <stddef.h>
#include <string.h>
#define NORETURN __attribute__((noreturn))
typedef void (*AllocCont)( void * );
void NORETURN longjmp_on_return( AllocCont f, jmp_buf env, void *mem ) {
@eatnumber1
eatnumber1 / README
Created September 30, 2010 22:43
Object-Oriented C
Your compiler must support blocks.
To compile, run ONE of the following:
gcc -o ooc -std=c99 -fblocks ooc.c
clang -o ooc ooc.c
The output looks like this:
Integer: 1337
String: "Hello World!"
@eatnumber1
eatnumber1 / struct-vla.c
Created October 28, 2013 09:12
An example of the use of VLA's in structs. A GNU C extension.
int main() {
int n = 1;
struct foo {
char a;
int b[n];
};
struct foo a;
a.a = 'a';
a.b[0] = 1;
n = 2;