Skip to content

Instantly share code, notes, and snippets.

View eqhmcow's full-sized avatar

Daniel S. Sterling eqhmcow

View GitHub Profile
@eqhmcow
eqhmcow / tictactoe.c
Last active October 18, 2023 18:20
compute all possible tic tac toe games
#include <stdio.h>
#include <stdbool.h>
#define SIZE 9
// Winning combinations
const int WINNING_COMBINATIONS[8][3] = {
{0, 1, 2}, {3, 4, 5}, {6, 7, 8},
{0, 3, 6}, {1, 4, 7}, {2, 5, 8},
{0, 4, 8}, {2, 4, 6}
@eqhmcow
eqhmcow / hfsc-shape.sh
Last active August 2, 2023 11:59
HFSC - linux traffic shaping's best kept secret
#!/bin/bash
# As the "bufferbloat" folks have recently re-discovered and/or more widely
# publicized, congestion avoidance algorithms (such as those found in TCP) do
# a great job of allowing network endpoints to negotiate transfer rates that
# maximize a link's bandwidth usage without unduly penalizing any particular
# stream. This allows bulk transfer streams to use the maximum available
# bandwidth without affecting the latency of non-bulk (e.g. interactive)
# streams.
@eqhmcow
eqhmcow / gist:a8b234ef4791769671c95c3ac7909d81
Last active July 18, 2023 00:52
build new kernel for CentOS 7
# something like this...
docker run -it oraclelinux:7
yum install rpm-build git wget vim oracle-softwarecollection-release-el7 scl-utils oraclelinux-developer-release-el7 oracle-epel-release-el7
yum-config-manager --enable ol7_software_collections
yum-config-manager --enable ol7_latest ol7_optional_latest
yum-config-manager --enable ol7_developer
git clone https://git.centos.org/rpms/kernel.git
cd kernel
@eqhmcow
eqhmcow / unzip.pl
Last active December 31, 2022 18:49
Perl unzip example with IO::Uncompress::Unzip
#!/usr/bin/perl
# example perl code, but this should now actually work properly, even on
# Windows
# thanks to everyone who tested this, reported bugs and suggested or
# implemented fixes!
# this code is licensed under GPL 2 and/or Artistic license;
# aka free perl software
@eqhmcow
eqhmcow / twitter-format.pl
Last active August 28, 2022 23:10
re-format text from e.g. rainbowstream twitter output
#!/usr/bin/perl
use strict;
use warnings;
$|++;
use Text::Format;
use IO::Select;
use Time::HiRes;
@eqhmcow
eqhmcow / bash-caps
Last active July 18, 2022 11:11
SYNTAX ERROR: UNEXPECTED END OF FILE
cp /bin/bash ./bash.caps; echo "this will take a while, be patient..."; strings -n 10 bash.caps | egrep -e '^.* .* .* .*$' | grep -Pv '^(_|\s)|\$|\[|;|@|\s\s' | while read i; do perl -pi -e "$/=\"\\0\";next if/ function\S|binding|^(case|select|for|trap|builtin)|_.*_/;next unless m@\\Q$i\\E@;sub b{return\$_ if/%/;uc}\$_=join' ',map{b()}split/ /" bash.caps; done; chmod a+x bash.caps; ./bash.caps
@eqhmcow
eqhmcow / README
Last active July 9, 2022 12:54 — forked from anonymous/README
docker wrapper
slightly-less-insecure-docker
wrapper around docker that perhaps makes it slightly less insecure
example usage:
DOCKER=/path/to/docker-wrapper
sudo $DOCKER run -it -v /etc/passwd:/etc/passwd -v /tmp:/tmp ubuntu
NOTE:
@eqhmcow
eqhmcow / logger.pl
Created March 22, 2011 21:10
logger.pl reimplements (most of) logger(1). Thanks to Perl, this logger hasn't got arbitrary message length limits; so you can syslog(3) messages bigger than the default logger(1) buffer (usually 1k) -- as long as your syslogd supports doing that.
#!/usr/bin/perl
use strict;
use warnings;
=pod
=head1 NAME
B<logger.pl> - a shell command interface to the syslog(3) system log module
@eqhmcow
eqhmcow / cake
Last active December 16, 2020 03:15
let me eat cake
### section 1
# disable CPU mitigations, disable CPU sleep (C states), disable CPU throttling (frequency scaling)
# edit /boot/grub/grub.cfg
# mitigations=off intel_idle.max_cstate=0 processor.max_cstate=1
echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo performance > /sys/devices/system/cpu/cpufreq/policy1/scaling_governor
@eqhmcow
eqhmcow / apache-preconnect-workaround-README
Last active April 12, 2020 19:41
version 2 of a script to kill apache 1.3 / 2.x prefork httpd processes serving preconnect connections, in an attempt to prevent chrome from causing a DoS against the httpd
script to kill apache 1.3 / 2.x prefork httpd processes serving preconnect connections, in an attempt to prevent chrome from causing a DoS against the httpd
This is version 2 of https://gist.github.com/eqhmcow/4774549
The major change is the use of two processes instead of one:
One process makes server-status requests, the other kills idle prefork processes.
This allows the kill script to continue killing idle processes even when Chrome has effectively DoS'd the apache server. When this happens, the check script can't get an updated status response back immediately, but the kill script can hopefully free up a slot by killing some processes. Having an uninterrupted request in the socket queue allows us to get an updated response after killing the Chrome preconnections are killed.