Skip to content

Instantly share code, notes, and snippets.

Derrick Lyndon Pallas pallas

View GitHub Profile
View dblock-update.sh
#!/bin/bash
# Author: Derrick Pallas
# License: zlib
BASE='dblock-set'
TEMP=${BASE}$$
ipset create -exist "$BASE" hash:ip --netmask 24 || exit 1
iptables -nL INPUT | grep -q "$BASE" ||
(
( iptables -N "$BASE" || iptables -F "$BASE" ) &&
View abuse-ch-update.sh
#!/bin/bash
# Author: Derrick Pallas
# License: zlib
BASE='feodo-set'
TEMP=${BASE}$$
ipset create -exist "$BASE" hash:ip --netmask 32 || exit 1
iptables -nL INPUT | grep -q "$BASE" ||
(
( iptables -N "$BASE" || iptables -F "$BASE" ) &&
@pallas
pallas / gdb-bt.sh
Last active Dec 8, 2018
GDB wrapper to produce backtrace automatically
View gdb-bt.sh
#!/bin/bash
[ $# -gt 0 ] &&
exec gdb "$1" --return-child-result --silent --batch \
--ex "run $([ $# -gt 1 ] && printf '%q ' "${@:2}")" \
--ex bt \
2>/dev/null
#
@pallas
pallas / courier-pem.mk
Created Jan 14, 2017
Will regenerate courier.pem & restart mail daemons when Let's Encrypt certificate renews.
View courier-pem.mk
BASE?=/etc/letsencrypt
DOMAIN?=mx.example.com
DHBITS:=4096
LIVE:=$(BASE)/live/$(DOMAIN)
PRIVKEY:=$(LIVE)/privkey.pem
FULLCHAIN:=$(LIVE)/fullchain.pem
.PHONY: default
@pallas
pallas / try.hh
Created Nov 21, 2016
C++ macros for trying libc calls, throwing std::runtime_error on errno
View try.hh
#ifndef TRY_H
#define TRY_H
#include <cstdio>
#include <cstring>
#include <stdexcept>
#include <errno.h>
#define TRY(f, ...) ({ \
@pallas
pallas / magic_mask.h
Created Jul 19, 2015
C++ template to generate a magic mask with alternating runs of 0s & 1s
View magic_mask.h
#include <cstdint>
template <typename T>
inline T magic_mask(int_fast8_t n) {
T base = T(1)<<(int_fast16_t(1)<<n);
return (~T(0))/(base*base-1)*(base-1);
}
@pallas
pallas / keybase.md
Created Aug 19, 2014
Keybase proof
View keybase.md

Keybase proof

I hereby claim:

  • I am pallas on github.
  • I am pallas (https://keybase.io/pallas) on keybase.
  • I have a public key whose fingerprint is C60C 81A1 B453 C8D8 2F29 AB74 C85D 4A38 DD52 468D

To claim this, I am signing this object:

@pallas
pallas / intrusive_tree.hh
Last active Feb 17, 2019
C++ intrusive red-black tree
View intrusive_tree.hh
// All rights reserved,
// Derrick Pallas
// License: zlib
#ifndef INTRUSIVE_TREE_H
#define INTRUSIVE_TREE_H
#include <cassert>
#include <cstddef>
#include <algorithm>
@pallas
pallas / intrusive_order.hh
Last active Aug 29, 2015
C++ intrusive ordered queue + fast tail inserts
View intrusive_order.hh
// All rights reserved,
// Derrick Pallas
// License: zlib
#ifndef INTRUSIVE_ORDER_H
#define INTRUSIVE_ORDER_H
#include <cassert>
#include <cstddef>
#include <algorithm>
@pallas
pallas / container_of.hh
Last active Nov 22, 2016
C++ member-to-object for classes with standard layout
View container_of.hh
// All rights reserved,
// Derrick Pallas
// License: zlib
#ifndef CONTAINER_OF
#define CONTAINER_OF
#include <cstddef>
template <class T, typename M>
You can’t perform that action at this time.