Skip to content

Instantly share code, notes, and snippets.

@AndrewRussellHayes
AndrewRussellHayes / clearScreen.pl
Created November 20, 2013 16:40
clear screen in any major system
sub clearScreen{
system $^O eq 'MSWin32' ? 'cls' : 'clear';
}
@AndrewRussellHayes
AndrewRussellHayes / getSwitchState.pl
Last active December 28, 2015 21:39
Code to get the value of a switch (in this case the switch is a single line file with a boolean value on it)
my $switchName = "Debug Switch";
open($switchFileHandle,'<',$switchFile) || warn "cant open switch file $!";
$switch = <$switchFileHandle>;
close($switchFileHandle);
chomp($switch);
if($switch){$switch = "ON";}
else{$switch = "OFF";}
$switchString = "$switchName($switch)";
@AndrewRussellHayes
AndrewRussellHayes / updateGitSubmodules.sh
Last active December 28, 2015 19:09
update submodule to their current head status in git
# get the submodule initially
git submodule add ssh://bla submodule_dir
git submodule init
# time passes, submodule upstream is updated
# and you now want to update
# change to the submodule directory
cd submodule_dir
@AndrewRussellHayes
AndrewRussellHayes / dataDumperSort.pl
Last active December 28, 2015 19:09
perl Data Dumper Sort Order
use Data::Dumper;
$Data::Dumper::Sortkeys =1;
#$Data::Dumper::Sortkeys = sub { [reverse sort keys %{$_[0]}] }; #reverse order
@AndrewRussellHayes
AndrewRussellHayes / arrayByRef.pl
Created November 19, 2013 16:22
messing around with passing a perl array by reference
@arr = qw(1 2 3 4 5 6 7 8 9 10);
use Data::Dumper;
#print Dumper(@arr);
printme(1,2,\@arr,4);
use strict;
use warnings;
use Time::Local;
my $sec = 0;
my $min = 0;
my $hours = 0;
my $day = 28; #(days are 1-31)
my $month = 5; #(months are 0-11)
my $year = 2013;
@AndrewRussellHayes
AndrewRussellHayes / shellOneLiners.sh
Last active December 28, 2015 19:08
List of commands I find useful, changes over time
#grep recursively
find . -type f -exec grep -n "stuff" {} \; -print
#count files in directory
ls -1 <targetdir> | wc -l
#put contents of one file at end of another
cat ./this-file >> ./into_this-file
# remove results of ls
@AndrewRussellHayes
AndrewRussellHayes / perlCmdLineOneLiners.pl
Last active December 28, 2015 19:08
replace file with file name and the entire contents get printed with line numbers to screen
#replace file with file name and the entire contents get printed with line numbers to screen
perl -n -e 'print "$. - $_"' file
#or
perl -p -e '$_ = "$. - $_"' file
@AndrewRussellHayes
AndrewRussellHayes / phpDBdump.php
Last active December 28, 2015 17:59
PHP quick db table dump. May have issues, storing for later use. Definitely connects and pulls data from a simple table.
<?php
// Connects to your Database
mysql_connect("db.host", "uname", "pwd") or die(mysql_error());
mysql_select_db("ectmenu") or die(mysql_error());
$data = mysql_query("SELECT * FROM pizza") or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{ // here is the menu code below
print"<p>
@AndrewRussellHayes
AndrewRussellHayes / recAdd.pl
Last active December 20, 2015 19:18
Wrote this when I was learning perl. Putting it here jus to play with git.
#!/usr/bin/perl
#recAdd.pl By: Andrew Hayes <http://AndrewHay.es/>
#Copyright (c) 2012 Andrew Hayes
#
# This perl script recursively adds a given number to every number between it and zero.
#
use strict;
use warnings;
use Scalar::Util qw(looks_like_number);