Skip to content

Instantly share code, notes, and snippets.

@joshenders
joshenders / reload-vcl.patch
Last active December 11, 2016 10:34
reload-vcl patch for config discards and safe stop
--- reload-vcl 2011-10-29 13:24:10.000000000 +0000
+++ /usr/share/varnish/reload-vcl 2016-12-11 09:51:08.696300339 +0000
@@ -1,9 +1,13 @@
#!/bin/sh
-
+#
# reload-varnish: Script to reload varnishd from VCL defined in
# /etc/default/varnish.
#
# Stig Sandbeck Mathisen <ssm@debian.org>
@joshenders
joshenders / cache_gzip.c.patch
Last active November 3, 2016 06:52
Ticket #1220: Temporary gzip issue: Invalid Gzip data: incorrect header check
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -646,9 +646,6 @@
bytes -= w;
VGZ_Ibuf(vg, st->ptr + st->len, w);
st->len += w;
- sp->obj->len += w;
- if (sp->wrk->do_stream)
- RES_StreamPoll(sp);
@joshenders
joshenders / varnishncsa.c.patch
Last active October 28, 2016 08:10
Varnish 3.0.3 (9e6a70f) Time to Last Byte varnishncsa patch
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index ff07ed5..3af1367 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -98,6 +98,7 @@ static struct logline {
struct tm df_t; /* %t, Date and time */
char *df_u; /* %u, Remote user */
char *df_ttfb; /* Time to first byte */
+ char *df_ttlb; /* Time to last byte */
const char *df_hitmiss; /* Whether this is a hit or miss */
@joshenders
joshenders / certchain.sh
Last active August 26, 2021 18:19
Simple Bash function to visualize PKI chain-of-trust
function certchain() {
# Usage: certchain
# Display PKI chain-of-trust for a given domain
# GistID: https://gist.github.com/joshenders/cda916797665de69ebcd
if [[ "$#" -ne 1 ]]; then
echo "Usage: ${FUNCNAME} <ip|domain[:port]>"
return 1
fi
local host_port="$1"
@joshenders
joshenders / ylint.sh
Created December 14, 2015 11:10
YAML syntax checker
function ylint() {
if [[ "$#" -ne 1 ]]; then
echo "Usage: ${FUNCNAME} <infile>"
return 1
fi
ruby -e "require 'yaml'; YAML.load_file('$1')"
}
@joshenders
joshenders / mitmproxy.md
Last active July 23, 2023 14:49
mitmproxy configuration for iPad

Successful mitmproxy-3.7 setup tested on OS X 10.13.6 and iPhone X running 12.1.4

Enable IP forwarding and disable ICMP redirects to keep the iPad sending traffic to the proxy

sudo sysctl -w net.inet.ip.forwarding=1
sudo sysctl -w net.inet.ip.redirect=0

net.inet.ip.forwarding
Enable IP forwarding between interfaces

@joshenders
joshenders / smokeping.sh
Last active July 26, 2022 18:43
Poor man's smokeping for OS X
#!/bin/bash
# https://gist.github.com/joshenders/52cb78bedaea6787faac
# This script uses the BSD variants of commands and is intended to
# be run on an unmodified installation of OSX.
pmset noidle &
now=$(date +%s)
duration=$((86400*3)) # 3days
jenders@jenders-mba threadedfractals :) $ make
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 -c -o utils.o utils.c
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 pngify.c utils.o -o pngify -lz
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 resample.c utils.o -o resample
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 render.c utils.o -o render -lm
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 palette.c utils.o -o palette -lm
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 -c -o circularlist.o circularlist.c
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 -c -o loader.o loader.c
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 -c -o mapper.o mapper.c
cc -Ofast -Wall -Wextra -Wshadow -Werror -ansi -pedantic -std=c99 threaded.c circularlist.o loader.o mapper.o utils.o -o threaded -lm -lpthread -ldl
$ var=$(echo ' ab')
$ echo $var
ab
$ echo $var | xxd
0000000: 6162 0a ab.
$ if [[ "$var" =~ ^a ]]; then echo match; else echo not match; fi
not match
$ var=$(echo 'ab')
$ echo $var | xxd
@joshenders
joshenders / recover.sh
Last active January 5, 2016 23:37
ddrescue recovery script
#!/bin/bash
function exit_with_usage() {
# usage: exit_with_usage
echo "Usage: ${0##*/} <src> <dest>" >&2
exit 1
}
function prompt() {