Skip to content

Instantly share code, notes, and snippets.

@mshock
mshock / restart_services.pl
Created May 15, 2012 14:55
restart Windows services
# /usr/bin/perl
# child process to background
# poll windows services and re-enable + start them
use Win32::Service;
use Win32::OLE;
use strict;
# set logfile location
my $logfile = 'log.txt';
@mshock
mshock / choose.pl
Created May 15, 2012 15:04
golf - n choose p
# current solution:
<>=~/,/;$r=++$_+$`;while($c++-$'){$_=$r/$c*$_-$_}print
######################################################
=pod
All of my scratch getting to this point:
<>=~/,/;$r=++$_+$`;while($c++-$'){$_=$_*$r/$c-$_}print
while
@mshock
mshock / grep_regex.pl
Created May 15, 2012 15:15
regex grep
#!/usr/bin/perl
$/ = undef;
$file = <DATA>;
$/ = "\n";
$lines_up = 2;
$lines_down = 1;
$pattern = 'bbb';
@mshock
mshock / tab.pl
Created May 15, 2012 15:18
shell tab emulation
#! /usr/bin/perl -w
use Term::ReadKey;
# make STDOUT hot
$| = 1;
$string = '';
$done = 0;
# get your dir listing
opendir($dh, '.');
@mshock
mshock / doc_vars.pl
Created May 15, 2012 15:21
neat documentation variables hack
my %const = map { s/\s+//; $_ }
map { split /\s*=>\s*/ }
grep { /=>/ }
map { split /\n/ } << '=cut';
=pod
This module uses the following constants:
bang_eth => 1
@mshock
mshock / csv_compare.sh
Created May 15, 2012 15:25
CSV column compare, one liner
perl -F, -ape'$_<($x=length$F[i])and$_=$x' file.csv
@mshock
mshock / SendEmail.pm
Last active October 4, 2015 21:37
module for sending e-mail with built-in example
#! perl -w
# framework for e-mail module for importing
package SendEMail;
use strict;
use Net::SMTP;
use Exporter 'import';
our @EXPORT = qw(send_email);
@mshock
mshock / copyfiles.pl
Created May 15, 2012 16:34
generate remote copy batch files
#! /usr/bin/perl -w
# chop up list of all files into several batch scripts for xfers
$remote_dir = $ARGV[1];
$local_temp = $ARGV[3];
$local_target = $ARGV[2];
if(scalar(@ARGV)){
@mshock
mshock / filter_sort.pl
Created May 15, 2012 16:47
filter and sort by value file containing rows of key = value
#! /usr/bin/perl
# filter rows to ones containing search_value
# sort the rows by search_value
# usage: filter_sort.pl file search_value
$search_value = $ARGV[1];
open (F, '<', $ARGV[0]);
@lines;
for(<F>) {
if (m/$search_value\s*=\s*(\d+)/) {
@mshock
mshock / alarm_sched.pl
Created May 15, 2012 17:01
alarm scheduling framework
#! /usr/bin/perl
$SIG{ALRM} = \&ten_min_task;
alarm (600);
while (1) {
# run in between task here
#sleep 1; print "foo\n";
}