Skip to content

Instantly share code, notes, and snippets.

@mshock
mshock / keep_awake.ahk
Created May 31, 2016 22:07
AutoHotkey script to keep Windows from sleeping
SetTimer,KeepAwake,480000 ;run every 8 minutes
return
KeepAwake:
{
MouseMove,0,0,0,R ; mouse pointer stays in place but sends a mouse event
}
return
^0::
@mshock
mshock / host_ports.pl
Created November 28, 2012 16:17
Perl test host port connectivity
#! perl -w
# test ports 80 and 1433 on given IP
# HTTP and SQL
# for new NAT addresses
use strict;
use IO::Socket::PortState qw(check_ports);
my $timeout = 10;
@mshock
mshock / flair_parse.cfg
Last active March 26, 2018 18:35
scrape user flair to sqlite db from posts within a subreddit
[reddit]
client_id = XXX
client_secret = XXX
unique_key = XXX
@mshock
mshock / refresh_desktop.bat
Created March 10, 2016 00:48
get rid of annoying stuck context menu items in W2000-W7
tskill dwm
@mshock
mshock / pig_latin.rb
Created March 7, 2016 08:18
Pig Latin
def translate(str)
words = str.split(" ")
result_array = Array.new
words.each do |word|
if ( word.match(/^[aeiou]/) )
result_array.push( word + 'ay' )
else
done = false
consonants = ''
@mshock
mshock / sleepseconds.pl
Created November 22, 2013 16:38
get number of seconds to sleep for once a day scheduling by hour
sub getsleep {
my ($thour) = @_;
return 0 unless $thour;
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst )
= localtime(time);
my $dif = $thour - $hour - $min / 60 - $sec / 3600;
if ( $dif >= 0 ) {
return $dif * 3600;
@mshock
mshock / gdate.pl
Created August 21, 2013 17:55
Julian date number (JDN) to Gregorian calendar date Source: http://aa.usno.navy.mil/faq/docs/JD_Formula.php
sub gdate {
my $jdn = shift;
my $l= $jdn+68569;
my $n= int(4*$l/146097);
$l= int($l-(146097*$n+3)/4);
my $i = int(4000*($l+1)/1461001);
$l= int($l-1461*$i/4+31);
my $j = int(80*$l/2447);
my $k = int( $l - 2447 * $j/80);
$l = int($j/11);
@mshock
mshock / pascal.pl
Last active December 18, 2015 12:19
golf - Pascal's Triangle (34 rows) - 61 chars
$z='1';
$r=$z;
for(0..32){
@d=split' ',$z;
unshift@d,0;
@n=();
while($#d!=-1){
push@n,($d[0]||0)+($d[1]||0);
shift@d
}
@mshock
mshock / switchboard.pl
Created June 14, 2013 13:47
golf - switchboard - 141 characters
#!perl -n
@z=/[^\n]/sg if/A/;
while(1) {
$i=index$_,'X';
($p,$t)=$i%2?($i-1,$i+1):($i-2,$i+2);
($z[$p],$z[$t])=($z[$t],$z[$p]);
s/X/ /
}
}{print@z
__DATA__
@mshock
mshock / switch_simple.pl
Created April 29, 2013 21:26
most basic CLI arg parsing for Perl scripts which use warnings and/or strict: perl -s script.pl -test
#! perl -ws
use strict;
our $test ||= '';
print $test;