Monday, January 9, 2017

Javascript misterClean string cleaner

function misterClean(x) {
   x = x.replace(/^\s+|\s+$/gm,''); // remove end whitespace
   x = x.replace(/(\r\n|\n|\r)/gm,""); // remove line breaks
   return x;
}

Thursday, December 29, 2016

No width parameter for SPAN tags, so limit width with javascript

$('span').each(function(index, value) {
  var limit = 30;
  var myID = $(this).attr('id');
  if(myID=='decoderip') {
   limit=60;
  }
  var mytext = $(this).text();
  if (mytext.length > limit) {
   // console.log('span text: '+mytext);
   $(this).text(mytext.slice(0, limit) + '...');
  }
 });

Monday, December 19, 2016

Time seconds increment on class of elements


function updateAge() {
 $('.age').each(function(){
  var age=$(this).text();
  age++;
  $(this).text(age);
 })
}

$(document).ready(function(){
  console.log('document ready'); 
  setInterval(updateAge, 1000); 
})

Thursday, December 1, 2016

Debian Package Creator and Installer

I made this for a particular "product", change the directory variables and final archived .deb filename per your needs.

debian.build.install.sh
#!/usr/bin/env bash
# this.is.lance.miller@gmail.com
clear;
basedir='/home/';
microdir=$basedir"micro/";
chmod 0775 $microdir'DEBIAN/postinst';
myfile=$microdir'DEBIAN/control';
echo $myfile;
myversion=`cat $myfile | grep Version | cut -d' ' -f2`;
echo $myfile' declares version '$myversion;
dpkg-deb --build $microdir;
ls -l $basedir*.deb;
sleep 5;
dpkg -i $basedir'micro.deb';
ls -l $basedir*.deb;
newfile='our_product_name_'$myversion'_all.deb';
echo 'creating this versioned deb archive: '$newfile;
mv $basedir'micro.deb' $basedir$newfile;
ls -l $basedir*.deb;

Monday, November 14, 2016

Kill process

target='Encoder'
kill `ps -x | grep $target | cut -d" " -f2`

Friday, October 28, 2016

CPU Analysis PHP

<?php 
header("Content-Type:text/plain") ;

$free = shell_exec('free');
$free = (string)trim($free);
$free_arr = explode("\n", $free);
$mem = explode(" ", $free_arr[1]);
$mem = array_filter($mem);
$mem = array_merge($mem);
$memory_usage = $mem[2]/$mem[1]*100;


print "Report for host: ".gethostname()." ".$_SERVER['SERVER_ADDR']."   timestamp: ".date("Y:m:d:h:i:s a")." year/month/date/hour/minute/seconds ".PHP_EOL.PHP_EOL;
$loadArray = sys_getloadavg();
$cpu = $loadArray[2];
$memoryMsg = "Memory ".$memory_usage." percent in use.".PHP_EOL;
print PHP_EOL."++++++++++++ operating system profile +++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL;
print         "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL;
 echo 'Operating System: '.php_uname('s').PHP_EOL;
 echo 'Release Name: '.php_uname('r').PHP_EOL;
 echo 'Version: '.php_uname('v').PHP_EOL;
 echo 'Machine Type: '.php_uname('m').PHP_EOL;
print         "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL;


if(file_exists('/proc/cpuinfo')) {
 $retval=file_get_contents('/proc/cpuinfo');
 $mycount=explode(PHP_EOL, $retval);
 $cores = round( (count($mycount)/26), 0, PHP_ROUND_HALF_DOWN);
 $load = $cpu/$cores;
 $load = $load*100;


 print PHP_EOL."++++++++++++ hardware profile +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL;
 print         "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL;
 print "CPU has ".$cores." cores".PHP_EOL;
 print PHP_EOL.'Memory:'.PHP_EOL.$free.PHP_EOL;
 print PHP_EOL."+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL.PHP_EOL;

 print "CPU load ".$load." percent averaged over last 15 minutes. [ sys_getloadavg() is ".$loadArray[0]." ".$loadArray[1]." ".$loadArray[2]." ]".PHP_EOL;
 print $memoryMsg;
 print PHP_EOL."Detailed CPU Information ( /proc/cpuinfo ) below.".PHP_EOL;
 print $retval.PHP_EOL;
} else {
 print "CPU load ".$cpu.PHP_EOL;
 print $memoryMsg;
}

print PHP_EOL."Uptime information  below.".PHP_EOL;
exec('uptime', $retval); 
foreach($retval as $ret) {
 print $ret.PHP_EOL;
}  


?>

Thursday, October 6, 2016

Unix/Linux how to run a command in background

nohup myFooCommand > /dev/null 2>&1 &