Skip to content

Instantly share code, notes, and snippets.

View pbkwee's full-sized avatar

Peter Bryant pbkwee

View GitHub Profile
Using a Consumer pattern vs. a constructor to populate an Enum instance. Handy if you
have a good number of fields and don't want long argument lists. Or if you need to do
some processing/method calling.
final fields would cause issues and would need to be done via a constructor without a callback.
public enum SomeEnum {
A((c)->{c.someField="A";}),
B((c)->{c.lotsMoreFields="B";}),
/*Syntax error
#!/bin/bash
# when triggered by server patch code, will also include our sysinfo.sh script . A version of which is at https://gist.github.com/pbkwee/996a0c11f6d29281e58d3c42f869ef86
if [ "$1" == "--fix-vuln" ]; then
# tag needed
echo "dss:attemptingfix:"
echo "dss:info: checking fix options."
[ ! -x /usr/bin/pkexec ] && echo "dss:info: no /usr/bin/pkexec, nothing to do." && return 0
APT_GET_INSTALL_OPTIONS=' -y -o APT::Get::AllowUnauthenticated=yes -o Acquire::Check-Valid-Until=false -o Dpkg::Options::=--force-confnew -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confmiss '
#!/bin/bash
echo "dss:hostname: $(hostname)"
echo "dss:date: $(date -u)"
echo "dss:shell: $SHELL"
echo "dss:dates: $(date -u +%s)"
echo "dss:uptimes:$([ -f /proc/uptime ] && cat /proc/uptime | awk '{print $1}')"
echo "dss:uptime: $(uptime)"
echo "dss:kernel: $(uname -a)"
echo "dss:bittedness: $(getconf LONG_BIT)"
df -m | awk '{print "dss:dfm:" $0}'
#!/bin/bash
#
# Copyright Rimuhosting.com
function usage {
echo "
$0 Creates a backup of a Linux server. It has options to let you download that via http (else you can scp it from the source). It has options to encrypt the backup file (e.g. via openssl or zip).
Usage: $0
--encrypt openssl (default if using --http) | zip (not so secure) | none (default if not using --http)
@pbkwee
pbkwee / tripp-lite-pdu-model-decoder
Created September 6, 2021 23:49
Tripp lite PDU model decoder
PDU3EVN10L2130
PDU3EVN6L2130
10,6 = cord length in feet (freedom units)
PDU3EVN10L2130
PDU3EVN6L2130
PDUMNH20HV
PDU3 = three phase, PDU = single
PDUV30
@pbkwee
pbkwee / opendkim-postfix
Created March 25, 2019 00:56
dkim setup
apt-get install opendkim
/etc/opendkim.conf use settings like:
Domain domainname.com
Selector mail
# sign, no need to verify
Mode s
# rsa private key
KeyFile /etc/ssl/private/dkimproxy.key
Socket inet:8892@localhost
openssl s_client -connect $ip:110 -starttls pop3
openssl s_client -connect $ip:465 | openssl x509 -text
@pbkwee
pbkwee / bulkspamban.sh
Last active October 11, 2023 19:45
Find emails (spam) sent from /24 IP blocks. Optionally block those IP ranges and bulk expunge emails from those ranges
#!/bin/bash
# Copyright 2018 Peter Bryant
# Licensed as https://www.apache.org/licenses/LICENSE-2.0
[ ! -z "$1" ] && [ "$1" != "--drop" ] && cat << EOJ && exit 0
Create a folders (SPAM_FOLDER=${SPAM_FOLDER:-unset} variable). Load it up with spam.
This script searches spam folders to find IP subnets (/24s) that have a sent a good amount of spam.
Output commands to move those away and to block those IP ranges.
java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlRootElement
=>
--add-modules java.xml.bind
-Djava.endorsed.dirs=/usr/local/tomcat/endorsed is not supported. Endorsed standards and standalone APIs
in modular form will be supported via the concept of upgradeable modules.
Error: Could not create the Java Virtual Machine.
=>
root@ri:/usr/local/tomcat# find . | grep endors
./endorsed
@pbkwee
pbkwee / gist:30bcd344906ca4106f2d241e2cab44e1
Created November 29, 2017 21:53
PTY allocation request failed on channel 0
Older distro (e.g. lenny) and newer kernel may result in this when ssh-ing in:
PTY allocation request failed on channel 0
You can run ssh $serverip 'bash -i' to get one off access.
You can 'fix' things with:
ssh $server 'echo "none /dev/pts devpts gid=5,mode=620 0 0" >> /etc/fstab; mount /dev/pts; cat /etc/fstab'