Skip to content

Instantly share code, notes, and snippets.

Andrew Hayes AndrewRussellHayes

Block or report user

Report or block AndrewRussellHayes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@AndrewRussellHayes
AndrewRussellHayes / copyMove.pl
Last active Dec 20, 2015
needed a quick script to monitor directory A and whenever files arrived there to copy to directory B and move to directory C. This is what I came up with. Very simple, dies if a directory is placed in A.
View copyMove.pl
#!/usr/bin/perl
#copyMove.pl By: Andrew Hayes <http://AndrewHay.es/>
#Copyright (c) 2013 Andrew Hayes
#
# This takes a file from Dir A and copies it to Dir B and moves it to Dir C.
# When the copy suceedes it prints a line to the stdout
# When a copy fails it Dies. For now. Dies if dir placed in A.
#
use strict;
use warnings;
@AndrewRussellHayes
AndrewRussellHayes / recAdd.pl
Last active Dec 20, 2015
Wrote this when I was learning perl. Putting it here jus to play with git.
View recAdd.pl
#!/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);
@AndrewRussellHayes
AndrewRussellHayes / phpDBdump.php
Last active Dec 28, 2015
PHP quick db table dump. May have issues, storing for later use. Definitely connects and pulls data from a simple table.
View phpDBdump.php
<?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 / perlCmdLineOneLiners.pl
Last active Dec 28, 2015
replace file with file name and the entire contents get printed with line numbers to screen
View perlCmdLineOneLiners.pl
#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 / shellOneLiners.sh
Last active Dec 28, 2015
List of commands I find useful, changes over time
View shellOneLiners.sh
#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
View date_time.pl
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 / arrayByRef.pl
Created Nov 19, 2013
messing around with passing a perl array by reference
View arrayByRef.pl
@arr = qw(1 2 3 4 5 6 7 8 9 10);
use Data::Dumper;
#print Dumper(@arr);
printme(1,2,\@arr,4);
@AndrewRussellHayes
AndrewRussellHayes / dataDumperSort.pl
Last active Dec 28, 2015
perl Data Dumper Sort Order
View dataDumperSort.pl
use Data::Dumper;
$Data::Dumper::Sortkeys =1;
#$Data::Dumper::Sortkeys = sub { [reverse sort keys %{$_[0]}] }; #reverse order
@AndrewRussellHayes
AndrewRussellHayes / updateGitSubmodules.sh
Last active Dec 28, 2015
update submodule to their current head status in git
View updateGitSubmodules.sh
# 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 / getSwitchState.pl
Last active Dec 28, 2015
Code to get the value of a switch (in this case the switch is a single line file with a boolean value on it)
View getSwitchState.pl
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)";
You can’t perform that action at this time.