Skip to content

Instantly share code, notes, and snippets.

View afresh1's full-sized avatar

Andrew Hewus Fresh afresh1

View GitHub Profile
@afresh1
afresh1 / c_rehash.sh
Last active September 22, 2016 16:38
This script replaces the c_rehash perl script from openssl, at least the main functionality of it. From http://man.openbsd.org/SSL_CTX_load_verify_locations
#!/bin/sh
# replaces the c_rehash perl script from openssl.
# by afresh1
rm -f *.[0-9]* *.r[0-9]*
for c in *.pem; do
[ "$c" = "*.pem" ] && continue
hash=$(openssl x509 -noout -hash -in "$c")
if egrep -q -- '-BEGIN( X509 | TRUSTED | )CERTIFICATE-' "$c"; then
suf=0
@afresh1
afresh1 / create_github_labels.js
Created June 4, 2016 23:35
Creates "Sane GitHub Labels", paste into the javascript console on the issue page for your project. https://medium.com/@dave_lunny/sane-github-labels-c5d2e6004b63
labels = [
{ "name": "Priority: Low", "color": "#009800" },
{ "name": "Priority: Medium", "color": "#fbca04" },
{ "name": "Priority: High", "color": "#eb6420" },
{ "name": "Priority: Critical", "color": "#e11d21" },
{ "name": "Status: Abandoned", "color": "#000000" },
{ "name": "Status: Accepted", "color": "#009800" },
{ "name": "Status: Available", "color": "#bfe5bf" },
{ "name": "Status: Blocked", "color": "#e11d21" },
{ "name": "Status: Completed", "color": "#006b75" },
@afresh1
afresh1 / lock_screen
Created May 15, 2016 19:16
Lock screen and dpms off monitor. I have `command lock "lock_screen"` in ~/.cwmrc and `*/5 * * * * $HOME/bin/monitors_off` in my crontab.
#!/bin/sh
if ! pgrep xlock >/dev/null 2>&1; then
xlock -lockdelay 0 &
sleep 1
fi
sudo -k
ssh-add -D
@afresh1
afresh1 / wtf.cgi
Created January 20, 2016 17:09
This simple program displays an issue with either slowcgi or httpd. It appears that the headers end after the first read instead of after the first blank line.
#!/usr/bin/perl
use strict;
use warnings;
$| = 1;
print "foo: bar\r\n" for 1 .. 15;
print "\r\n";
print "quux\r\n";
@afresh1
afresh1 / serve_this.sh
Last active June 4, 2023 22:00
A Mojolicious One Liner to serve static files from the current directory
#!/bin/sh
exec perl -Mojo -E '$m=a("/");$m->static->paths(["."]);$m->start' daemon
@afresh1
afresh1 / drop_privileges_fcgi_app.psgi
Last active July 25, 2019 03:16
This is a proof of concept for an FCGI::ProcManager that will chroot into a directory and drop privileges for each child process.
#!/usr/bin/env plackup -s FCGIDropPrivs
use strict;
use warnings;
my ($user, $group) = qw( nobody nogroup );
my $uid = getpwnam($user);
my $gid = getgrnam($group);
my $root = '/var/empty';
package Plack::Handler::FCGIDropPrivs;
@afresh1
afresh1 / tmux.rc
Created July 9, 2015 16:13
Start tmux on login. This would go in your kshrc or bashrc
if [ ! "$TMUX" ]; then
echo "Starting tmux . . ."
sleep 3
[ "$TERM" = "xterm" ] && TERM=xterm-256color
tmux -2 attach || tmux -2
exit
fi
@afresh1
afresh1 / reprove.pl
Last active June 29, 2016 14:55
This script watches your tests and your files and re-runs "prove" to help with perl TDD -- http://perldoc.perl.org/prove.html
#!/usr/bin/perl
# Copyright (c) 2015 Andrew Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@afresh1
afresh1 / post_dmesg_to_nycbug.pl
Last active December 22, 2021 22:14
This script posts an OpenBSD dmesg to the NYC*BUG archive at http://www.nycbug.org/index.cgi?action=dmesgd
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use feature 'signatures';
no warnings 'experimental::signatures';
use Sys::Hostname;
use HTTP::Tiny;
@afresh1
afresh1 / icb_twitter_bot.pl
Created February 11, 2015 02:26
An ICB bot that watches for twitter URLs and fills out the text.
#!/usr/bin/perl
use strict;
use warnings;
# On OpenBSD, I have a port for p5-Bot-ICB and p5-Net-ICB
# pkg_add p5-Bot-ICB p5-LWP-Protocol-https p5-HTML-Tree p5-Text-Unidecode
use Bot::ICB;
use LWP::Simple;
use HTML::Tree;