Wednesday, November 4, 2015

MySQL Count Duplicates

#!/usr/bin/env bash
echo "Table to read:"
read table
echo "Column to count and display:"
read col
echo "Threshold number:"
read num
echo "SELECT $col FROM $table GROUP BY $col HAVING count(*) > $num;";

Useage

Table to read: geocodes Column to count and display: ip Threshold number: 2 SELECT ip FROM geocodes GROUP BY ip HAVING count(*) > 2;

GIT Checkout Loop

#!/usr/bin/env bash



while true
do
 git fetch --prune; 
        git branch -vvv
 echo "provide branch name to checkout:"
 read branch
        git checkout $branch;
        git pull;
        git log --decorate --pretty=tformat:'%h %d %ar %s' --first-parent --reverse -30;
        git log -1
 $1  # arg to import a command, such as 'exit'
done

Monday, November 2, 2015

GIT Log Search Source Script

#!/usr/bin/env bash
# this.is.lance.miller@gmail.com
regex="$2*$3*$4"
clear
echo "useage"
echo "$0 2 foo fab fangs"
echo "2 is the number of results"
echo  "foo fab fangs are the search terms. wildcards are placed in between them"
echo "press [Enter] to proceed"
read
echo "search string is: $regex"
for i in `git log -$1 --decorate --pretty=tformat:'%h %d %an %ar %s' --source --all -i -G $regex | cut -d" " -f1`;
do
 echo $i
 git show $i
done
exit

Use Example

searchGIT.sh 2 foo fab fangs
2 is the number of results
foo fab fangs are the search terms. wildcards are placed in between them

Friday, October 30, 2015

Javascript: If undefined or null or string length equals zero return false

function checkExists(myVar) {

 if (typeof myVar === 'undefined')  { return false;  }
 if ( myVar === null )      { return false;  }
 if ( myVar.length == 0)            { return false; } 
 
 return true;
 
}

Thursday, October 15, 2015

PHP disk_free_space

$diskFreeSpace = round(disk_free_space($data_drive) / 1024 / 1024 / 1024);
Nice little uptimeRobot alert script:
isset($_REQUEST['threshold']) ? $driveThresold=$_REQUEST['threshold'] : $driveThresold=11; 
   
function killMe($input) { 
   header('HTTP/1.1 500 Internal Server Error'); 
   die();
}

function allGood($input) { 
   header("Content-Type:text/plain") ;
   die($input);
}

$diskFreeSpace = round(disk_free_space($data_drive) / 1024 / 1024 / 1024);
$diskfreespace < $driveThresold ? killMe($diskfreespace) : allGood(strval($diskfreespace));
die();

Friday, October 2, 2015

Directory List to XML

<?php
header("Content-type: text/xml");
print "<?xml version='1.0' encoding='UTF-8'?>\n<response?>\n";
$files = glob('*.xml');
foreach($files as $file) {
 print "<file?>".$file."</file?>\n<!-- ".date("F d Y H:i:s.",filemtime($file))."--?>\n";
}
die('');
?>

Tuesday, August 11, 2015

GIT Rebase Basic with Force Push.

#!/usr/bin/env bash
echo "present working directory is:";
pwd;
echo ;
echo "enter your GIT project dir, or .(dot) followed by [ENTER]:"
read directory
cd $directory;
echo "present working directory is:";
pwd;

echo "enter name of experiment branch";
read experiment
echo $experiment
git checkout $experiment

echo "enter name of master branch";
read master
echo $master
git checkout $master
git rebase $master
echo "git push --force origin $experiment:$experiment WILL HAPPEN AFTER YOU PRESS ENTER";
read reply
git push --force origin $experiment:$experiment
exit;