Skip to content

Instantly share code, notes, and snippets.

View pallas's full-sized avatar

Derrick Lyndon Pallas pallas

View GitHub Profile
#!/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 / mac_to_ipv6network.py
Created August 9, 2019 23:12
Inject MAC address into IPv6 Network
# SPDX-License-Identifier: Unlicense
from ipaddress import IPv6Network
from binascii import unhexlify
network = IPv6Network("2001:DB8::/32")
mac = "12:34:56:78:9a:bc"
mac_bytes = b''.join(map(unhexlify, mac.split(':')))
address = network[int.from_bytes(mac_bytes, byteorder='big')]
print(network, mac, mac_bytes, address)
@pallas
pallas / fancy_debug.h
Created August 28, 2019 21:33
Simple but powerful debugging primitive
// SPDX-License-Identifier: Unlicense
bool global_debug = false;
#define DEBUG(format, ...) do { \
if (global_debug) \
fprintf(stderr, "%s:%d %s " format "\n", __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \
} while(false)
@pallas
pallas / intrusive_stack.hh
Last active March 26, 2020 03:11
C++ intrusive stack
// All rights reserved,
// Derrick Pallas
// License: zlib
#ifndef INTRUSIVE_STACK_H
#define INTRUSIVE_STACK_H
#include <cassert>
#include <cstddef>
@pallas
pallas / keybase.md
Last active May 7, 2020 19:30
Keybase proof

Keybase proof

I hereby claim:

  • I am pallas on github.
  • I am pallas (https://keybase.io/pallas) on keybase.
  • I have a public key ASCsQ6NtBDpKhw9f2MArRunk8lTLxLjfIFaFVpzO79Pqtwo

To claim this, I am signing this object:

@pallas
pallas / gdb-bt.sh
Last active July 15, 2020 20:40
GDB wrapper to produce backtrace automatically
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
[ $# -gt 0 ] &&
exec gdb "$1" --return-child-result --silent --batch \
--ex "run $([ $# -gt 1 ] && printf '%q ' "${@:2}")" \
--ex bt \
2>/dev/null
#
@pallas
pallas / spring-cleaning.sh
Last active July 15, 2020 20:40
Spring clean memory on Linux systems
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
sync &&
echo 3 > /proc/sys/vm/drop_caches &&
echo 1 > /proc/sys/vm/compact_memory &&
true
#
@pallas
pallas / git-me.sh
Last active July 15, 2020 20:41
git-me: show how the local repo differs from the upstream tracking branch
#!/bin/sh
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
exec git log --oneline "$@" @{u}..
#
@pallas
pallas / tmux.conf
Last active August 21, 2020 22:17
tmux.conf
unbind C-b
set -g prefix C-a
bind-key a send-prefix
bind-key C-c new-window
bind-key C-a last-window
bind-key C-n next-window
bind-key C-p previous-window
bind-key C-d detach-client
setw -g aggressive-resize on
@pallas
pallas / kiosk.sh
Last active October 15, 2020 00:50
Raspberry Pi screensaver (feedback) + Pandora (pianobar) + AirPlay (rpiplay) kiosk
#!/bin/bash
# SPDX-License-Identifier: Unlicense
# Author: Derrick Lyndon Pallas <derrick@pallas.us>
#
# /etc/rc.local: xinit /usr/lib/kiosk.sh &
#
# http://rss-glx.sourceforge.net/
# https://github.com/PromyLOPh/pianobar
# https://github.com/FD-/RPiPlay