Skip to content

Instantly share code, notes, and snippets.

@p120ph37
p120ph37 / screenrotate.sh
Last active August 29, 2015 14:04
Rotate screen every 15 minutes (for 2 hours)
#!/bin/sh
#
# to fix:
# xrandr | grep \ connected | cut -f1 -d\ | xargs -I{} xrandr --output {} --rotate normal
times=2
delay=900
for y in `seq 1 $times`; do
for x in right inverted left normal; do
sleep $delay
xrandr | grep \ connected | cut -f1 -d\ | xargs -I{} xrandr --output {} --rotate $x
@p120ph37
p120ph37 / dc22_badge_human_full.spin
Created August 10, 2014 03:21
Human and Goon badge code for DC22
'' =================================================================================================
''
'' File....... dc22_badge_human_full.spin
''
'' Authors.... Jon "JonnyMac" McPhalen and Ryan "1o57" Clarke
'' Unpublished portions reverse-engineered by Aaron "P120ph37" Meriwether
'' MIT License
'' -- see below for terms of use
''
'' E-mail..... jon@jonmcphalen.com
@p120ph37
p120ph37 / gist:15efac098fcf98d9da08
Created August 22, 2014 22:21
Git Bash Prompt
# produce a colorized path string with the git branch injected at the root of the repository
PS1git='\[\e[94m\]$(git rev-parse --show-toplevel 2>/dev/null)$( \
( test -z "$(git status -s 2>/dev/null)" && __git_ps1 "\[\e[32m\](%s)" ) \
|| __git_ps1 "\[\e[91m\]{%s}" \
)\[\e[94m\]${PWD##$(git rev-parse --show-toplevel 2>/dev/null)}'
# Use where you would use "\w" in your PS1 prompt. e.g.:
PS1='${debian_chroot:+($debian_chroot)}\[\e[1;32m\]\u@\h\[\e[0m\]:'"$PS1git"'\[\e[0m\]\$'
@p120ph37
p120ph37 / rc.xml
Created August 27, 2014 20:22
openbox config file
<?xml version="1.0" encoding="UTF-8"?>
<openbox_config xmlns="http://openbox.org/3.4/rc" xmlns:xi="http://www.w3.org/2001/XInclude">
<resistance>
<strength>10</strength>
<screen_edge_strength>20</screen_edge_strength>
</resistance>
<focus>
<focusNew>yes</focusNew>
<followMouse>no</followMouse>
<focusLast>yes</focusLast>
@p120ph37
p120ph37 / seq_sed_FizzBuzz.sh
Last active April 19, 2018 10:53
seq/sed FizzBuzz
seq 100 | sed 'n;n;s/.*/Fizz/' | sed 'n;n;n;n;s/[0-9]*$/Buzz/'
@p120ph37
p120ph37 / gist:49bf890ee37087d37114
Created October 14, 2014 16:31
Minimal webserver in Perl.
socket$s,2,1,6;bind$s,pack+snN3,2,8080;listen$s,1;while(accept$c,$s){<$c>=~/\/(\S+)/;open$f,$1;print$c(<$f>);close$c}
@p120ph37
p120ph37 / gist:c0a6bd7579cb87446eeb
Last active July 15, 2020 00:38
A better one-line webserver in Perl
socket$_,2,1,6;setsockopt$_,1,2,pack"l",1;(bind$_,pack"snN3",2,pop)||die$!;listen$_,128;{accept+my($c),$_;fork&&redo;($_)=<$c>=~/(\/\S*)/;s/%([0-9a-f]{2})/pack"H2",$1/eig;s-/$-/index.html-;!/\.\./&&open$a,"<.$_"||last;syswrite$c,"HTTP/1.1 200\x0D\x0A\x0D\x0A";syswrite$c,$,until!sysread$a,$,,1024}
@p120ph37
p120ph37 / show_locks.pl
Last active August 29, 2015 14:23
Cross-reference `/proc/locks` against a particular file to show what locks are present against that file.
#!/usr/bin/perl
use warnings;
use strict;
my %pl;
open(my $fh, '<', '/proc/locks') or die $!;
for(<$fh>) {
my @f = split /\s+/;
push(@{$pl{$f[5]}}, \@f);
}
@p120ph37
p120ph37 / perl_inject.pl
Last active September 21, 2019 03:46
Inject an eval into a running Perl process using GDB and temporarily capture STDERR.
#!/usr/bin/perl
use warnings;
use strict;
use threads;
use File::Temp;
use POSIX qw/mkfifo/;
my $pid = shift @ARGV;
my $eval = shift @ARGV || 'require Carp; local $Carp::CarpLevel = 1; Carp::cluck(\'Currently\');';
my $thread = $ENV{'GDB_THREAD'} || 'all';
@p120ph37
p120ph37 / d64
Created July 7, 2015 21:20
Base64 decode purely via Bash builtins.
#!/bin/sh
((V=N=0))
while :; do
((V<<=6,++N))
IFS= read -n1 C && {
printf -vC '%d' "'$C"
((C=C>64&&C<91?C-65:C>96&&C<123?C-71:C>47&&C<58?C+4:C==43?62:C==47?63:(V>>=6,--N,0),V|=C))
}
((N==4)) && {