Wednesday, December 17, 2014

Javascript jQuery Scroll Event Listener Print Scroll Position to Console Log

$(window).scroll(function (event) {
    var scroll = $(window).scrollTop();
    console.log(scroll);
});

Save scroll position for reload or ajax call for new content

var scroll = 0;
scroll = $(window).scrollTop();
console.log(scroll); 
location.reload();
$(window).scrollTop(scroll);

Thursday, December 4, 2014

Iterating over all cookies and local storage

console.log('COOKIES LIST BEGIN');
var theCookies = document.cookie.split(';');
 for (var i = 1 ; i <= theCookies.length; i++) {
        console.log(theCookies[i-1]);
    }
console.log('COOKIES LIST END');
console.log('localStorage LIST BEGIN');
for(var i in localStorage) {
       console.log(localStorage[i]);
        }

 for(var i=0, len=localStorage.length; i " + value);
    if(key == 'GetSystemStatus') {
            var bill = value.search(/ bill=\"8\" /);
            console.log(bill);
            bill != -1 ? console.log('did NOT find') : console.log('found it'); }
        }
        } 

Wednesday, November 12, 2014

jQuery. Get ID of each element in a class using .each

$('.myClassName').each(function() {
    console.log( this.id );
});

Monday, November 3, 2014

Find Apache Services in .Net

sc query state= all | findstr /i apache
Also: find all services already started
net start

Thursday, October 2, 2014

Using simpleXML to edit a known node attribute

    $file = 'c:\db\server.xml';         
  try {           
   $xml = simplexml_load_file($file);
   $oStorage = $xml->xpath('/body/storage');
   $xmlElement = $oStorage[0]->attributes();
          $xmlElement['mysql_use_backup']='0';
   file_put_contents($file, $xml->asXml()); 
                               
          } catch(Exception $e){ die($e); }


Thursday, September 4, 2014

Javascript counter and location.reload


 var interval = "";
 var incrementVar = 0;
 function increment(){
        incrementVar++;
        console.log(incrementVar);
        if(incrementVar>30) {
    location.reload(); 
    window.clearInterval(interval);
    incrementVar = 0;
         }
          
    }

   $(document).ready(function(){
    interval = setInterval( increment, 1000);
   }) 

Wednesday, July 16, 2014

Listen to TCPDUMP output as spoken word on OS X

say `sudo tcpdump -s 1514 -vvvv -c 20 -c2 icmp` 

# listens for ping traffic, so in another terminal issue a ping command

Tuesday, May 20, 2014

Python FTPLIB Simple Example

#!/usr/bin/python
from ftplib import FTP
import sys

print "hello world"
site = 'ftp.example.com'
ftp = FTP(site)
print 'Logging in to '+site
print ftp.login('myname', 'passwd')
directory = '~/public_html/'
print 'Changing to ' + directory
print ftp.cwd(directory)
for myfile in sys.argv:
ftp.storbinary("STOR " + myfile, file(myfile, "rb"))
print ftp.retrlines('LIST')
print ftp.close()

Monday, April 28, 2014

HTML5 FOR IE

https://code.google.com/p/html5shiv/

Get City State from Hostip.info

$test=false;
$ip='63.172.12.36';
$ip='12.215.42.19';
$test ? $ip='12.215.42.19' : $ip=$_ENV['REMOTE_ADDR'] ;
$lines = explode("\n", str_replace("\r", "", file_get_contents("http://api.hostip.info/rough.php?ip=".$ip)));
$city=explode(':',$lines[2]);
preg_match('/Unknown/i', $city[1], $matches);
count($matches)==0 ? $print=true : $print=false;
if($print) { print "Hello ".$city[1]; }


Thursday, January 2, 2014

Strip newlines from entries in MySQL

update `org` set `orgName` = replace(`orgName`,"\n","");

org is the table, orgName is the column.