Skip to content

Instantly share code, notes, and snippets.

import socket
SOCKET_SIZE = 4096
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("localhost", 8009))
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, SOCKET_SIZE)
while True:
try:
msg, host = sock.recvfrom(SOCKET_SIZE)
# Captures are a slightly modified version of logstash "grok" patterns, with
# the format %{<capture syntax>[:<semantic name>][:<modifier>]}
# By default all named captures are converted into string fields.
# Modifiers can be used to convert captures to other types or tags.
# Timestamp modifiers can be used to convert captures to the timestamp of the
# parsed metric.
# View logstash grok pattern docs here:
# https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html
# All default logstash patterns are supported, these can be viewed here:
127.0.0.1 - - [22/Aug/2011:10:02:00 +0900] "GET / HTTP/1.1" 200 902 "-" "Python-urllib/2.7"
127.0.0.1 - - [22/Aug/2011:10:02:00 +0900] "GET / HTTP/1.1" 200 572 "-" "okhttp/2.4.0"
127.0.0.1 - - [22/Aug/2011:10:02:00 +0900] "GET /large.jpg HTTP/1.1" 200 714 "-" "okhttp/2.4.0"
127.0.0.1 - usera [22/Aug/2011:10:02:00 +0900] "GET /large.jpg HTTP/1.1" 200 926 "-" "Firefox/5.0"
127.0.0.1 - userb [22/Aug/2011:10:02:00 +0900] "GET / HTTP/1.1" 200 862 "-" "Firefox/5.0"
127.0.0.1 - - [22/Aug/2011:10:02:00 +0900] "GET / HTTP/1.1" 200 306 "-" "Firefox/5.0"
127.0.0.1 - - [22/Aug/2011:10:02:00 +0900] "POST / HTTP/1.1" 200 579 "-" "okhttp/2.4.0"
127.0.0.1 - - [22/Aug/2011:10:02:00 +0900] "POST / HTTP/1.1" 200 988 "-" "Python-urllib/2.7"
127.0.0.1 - - [22/Aug/2011:10:02:00 +0900] "GET /large.jpg HTTP/1.1" 200 115 "-" "Firefox/5.0"
127.0.0.1 - userb [22/Aug/2011:10:02:00 +0900] "GET / HTTP/1.1" 200 359 "-" "Firefox/5.0"
@sparrc
sparrc / statfs.go
Created January 25, 2016 23:54
Golang statfs
package main
import (
"fmt"
"syscall"
)
func main() {
stat := syscall.Statfs_t{}
err := syscall.Statfs("/", &stat)
@sparrc
sparrc / delete-old-remote-branches.sh
Last active March 10, 2022 22:36
Delete old remote branches in git using `git push --delete origin`
#!/usr/bin/env bash
# if the most recent commit on the branch is older than MAX_AGE_DAYS, then the branch
# will be deleted.
MAX_AGE_DAYS=180
# if DRY_RUN=1, then only print the names of the branches that would be deleted.
if [ -z "$DRY_RUN" ]; then
DRY_RUN=0
fi
#!/usr/bin/env bash
# if the most recent commit on the branch is older than MAX_AGE_DAYS, then the branch
# will be deleted.
MAX_AGE_DAYS=180
# if DRY_RUN=1, then only print the names of the branches that would be deleted.
if [ -z "$DRY_RUN" ]; then
DRY_RUN=0
fi
@sparrc
sparrc / get-all-cgroup-data.sh
Last active April 21, 2023 21:11
cats all cgroup files in ecs and docker cgroups (for cgroups v1 system)
#!/usr/bin/env bash
set -x
rm -rf /tmp/cgroup-ecs && touch /tmp/cgroup-ecs
rm -rf /tmp/cgroup-docker && touch /tmp/cgroup-docker
for f in $(find /sys/fs/cgroup -type f | grep "/ecs/" | sort -h); do
echo $f >>/tmp/cgroup-ecs
cat $f >>/tmp/cgroup-ecs
@sparrc
sparrc / install-ffmpeg.sh
Last active November 14, 2023 13:24
Installs ffmpeg with libaom and libx265 enabled for av1 and hevc encoding (tested on Ubuntu 16.04)
#!/usr/bin/env bash
# Installs ffmpeg from source (HEAD) with libaom and libx265, as well as a few
# other common libraries
# binary will be at ~/bin/ffmpeg
sudo apt update && sudo apt upgrade -y
mkdir -p ~/ffmpeg_sources ~/bin
export PATH="$HOME/bin:$PATH"
@sparrc
sparrc / phabricator_readme.md
Last active March 25, 2024 05:59
Phabricator Ubuntu Installation Guide

Phabricator Ubuntu Installation Guide

This is a supplement to the official Phabricator Installation Guide, because their guide will leave you with all kinds of permission and config errors and ~15,000 setup issues on startup.

Install bonus packages:

# apt-get install mercurial subversion python-pygments sendmail imagemagick

Create necessary users and add phd-user to sudoers: