Skip to content

Instantly share code, notes, and snippets.

View cdcme's full-sized avatar
🤓
I may be slow to respond.

@cdcme cdcme

🤓
I may be slow to respond.
View GitHub Profile
@cdcme
cdcme / environs.c
Created July 3, 2020 13:47
Print out C development environment info
// prints local development environment information
void environs() {
#ifdef __clang_major__
printf ("clang detected version %d.%d\n", __clang_major__, __clang_minor__);
#endif
#ifdef __GNUC__
// note that clang 3.7 declares itself as a gcc 4.2"
printf ("gcc detected version %d.%d\n", __GNUC__, __GNUC_MINOR__);
#endif
@cdcme
cdcme / gcp-netblocks.sh
Created November 12, 2018 20:42
Get GCP netblocks for firewall rules
for name in $(nslookup -q=TXT _spf.google.com 8.8.8.8 | grep -oe '_netblocks[1-9]*.google.com'); do nslookup -q=TXT $name 8.8.8.8 | grep -oe '[0-9]*.[0-9]*.[0-9]*.[0-9]/[0-9]*'; done
@cdcme
cdcme / checkdns.sh
Last active November 12, 2018 22:53
Gist for checking zone configuration
checksigned() {
ZONE=`basename "$1" .`.
if [ "$ZONE" = .. ]
then
ZONE=.
fi
NAME=`basename "$ZONE" .`
NO_NS=true
NO_SEC=false
OPTS="+cd +noall +answer +nocl +nottl"
@cdcme
cdcme / sysctl.conf
Last active March 1, 2022 08:02
Some sysctl settings for performance and hardening on FreeBSD
# $FreeBSD: releng/11.1/etc/sysctl.conf 112200 2003-03-13 18:43:50Z mux $
#
# see https://calomel.org/freebsd_network_tuning.html
# https://www.c0ffee.net/blog/freebsd-server-guide
# https://en.wikipedia.org/wiki/TCP_tuning
# https://en.wikipedia.org/wiki/TCP_window_scale_option
# https://en.wikipedia.org/wiki/Bandwidth-delay_product
# https://www.freebsd.org/doc/handbook/configtuning-sysctl.html
# https://www.freebsd.org/cgi/man.cgi?query=sysctl&sektion=8&manpath=freebsd-release-ports
#
@cdcme
cdcme / pcurl.sh
Last active December 27, 2018 10:08
Using GNU Parallel with cUrl
seq 20 | parallel -n0 -j2 "curl -X "POST" "https://foo.bar.com/webhooks/doStuff" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer FOOTOKEN' \
-d $'{
\"stripe_customer_id\": \"blah\",
\"api_version\": \"2017-06-05\"
}'"
@cdcme
cdcme / loader.conf.local
Last active November 12, 2018 22:56
FreeBSD loader.conf.local w/custom tuning
virtio_balloon_load="YES"
virtio_blk_load="YES"
virtio_load="YES"
virtio_pci_load="YES"
virtio_scsi_load="YES"
virtio_console_load="YES"
if_vtnet_load="YES"
aesni_load="YES"
@cdcme
cdcme / service-pf.conf
Last active November 12, 2018 22:58
FreeBSD pf.conf ideas for services
# See pf(4) and pf.conf(5)
#
#
# Author: Carlo DiCelico, June 2018
#
# Notes:
# Required order is options, normalization, queuing, translation, filtering
# Translation rules match first, filtering rules match last
# Update IPs for your instance and customize rules for your service
@cdcme
cdcme / roman_numerals.py
Last active February 20, 2017 21:54
Roman numerals multiplication & division using the halve-and-double algorithm
def roman_to_arabic(roman_numeral):
"""
Note: Does not support shorthand notation yet!
Use IIII instead of IV, VIIII instead of IX, etc.
Args:
roman_numeral (str): the Roman numeral to convert
Returns:
int: the number, in Arabic number system
"""
@cdcme
cdcme / fib.js
Last active December 22, 2015 02:59
Fast fibonacci in nodejs using caching
/* in routes/fib.js */
var cache = new Array();
function fib(n) {
if(n.toString() in cache)
return cache[n.toString()];
if(n < 2) { return 1; }