Code Samples

Okay everyone, time to share some code. Sometimes I write what I consider to be pretty good code. Since my website is not about making money directly only indirectly in the form of getting the next killer job. Perhaps you may want to copy and paste? My only ask is you give me credit. It could be as simple as putting my website as a comment in your HTML.

Like the rest of the internet, this web page will be updated as time allows. Do not underestimate the simplicity of the code. I consider myself to have mastered computers and now as a manager working on mastering human behavior.

My expertise is web based technologies such as javascript, perl, php, python, XML, Xpath, HTML, CSS, C and curl. I do not use IDEs or programs such as Dreamweaver. I use vi or notepad and ftp. If you didn't notice, this entire website was written in php.

PHP - Using php and Google Graphs
cellular graph I did this for work. I was trying to see how hard or easy using Google Charts would be compared to some of it's competitors.

Here is a piece of the code:

    function draw850() {

      var chartDiv = document.getElementById("chart_div850");

      var data = new google.visualization.DataTable();
      data.addColumn("date", "Date");
      data.addColumn("number", "Power level");
      data.addColumn("number", "RF Signal");


    echo substr($row850, 0, -2);

    echo "

PHP - Custom webpages I love this language. It was designed for the LAMP solution, which in my humble opinion, is the best for the mid-size to small-size company. Assuming your database does not have too many rows in it.

When I see something cool on the internet, I begin reverse engineering it in my mind. One day I was doing a google search on channel names currently being used at and found this web page. I was quite impressed since I am always developing ways to avoid ads.

Here are some key pieces of code that make my code possible:

  function curl_get_file_contents($URL) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL,"$URL");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
    $contents = curl_exec($curl);

    if ($contents) return $contents;
    else return FALSE;

  $url2 = "";
  $lines2 = curl_get_file_contents($url2);
  $pattern1 = "<span class=\"small\">on <a href=\"/";
  $pattern2 = "/videos\">";
  $pattern3 = "<\/a></span>";
  $pattern4 = "/<span class=\"small\">on <a href=\"\/[^>]+>[^>]+<\/a><\/span>/i";
  preg_match_all($pattern4, $lines2, $matches2);

  foreach ($matches2 as $obj_key => $obj) {
    while (list ($key,$value)=each ($obj)) {
      $value = trim($value);
      $value = preg_replace('/[^(\x20-\x7F)\x0A]*/', '', $value);
      $start_channel = strpos($value, $pattern1) + strlen($pattern1);
      $length_channel = strpos($value, $pattern2) - $start_channel;
      $channel = substr($value, $start_channel, $length_channel);
      $start_description = strpos($value, $pattern2) + strlen($pattern2);
      $length_description = strpos($value, $pattern2) - $start_description;
      $description = substr($value, $start_description, $length_description);
      array_push($justinChannels, $channel . "|" . $description);
      $channel = NULL;
      $description = NULL;

PHP - http headers
Here is two different functions that do similiar things. get_http_response_code is used when you need to know the exact http status code. url_exists is used when you just need to know if the http response code is 200.

  function get_http_response_code($theURL) {
    $headers = get_headers($theURL);
    return substr($headers[0], 9, 3);

  function url_exists($url) {
    $h = get_headers($url);
    $status = array();
    preg_match('/HTTP\/.* ([0-9]+) .*/', $h[0] , $status);
    return ($status[1] == 200);

Javascript - loop through array of URLS
When I first started playing with this I used it mainly for error checking of values submitted in forms. For my noobs, you should also do error checking on server side. Many people like me may have javascript turned off.

This code scrolls through webpages after 10 seconds, does it entirely using CSS and Javascript, and has a start, stop, and next button. This is ideal for people who have hardware limits and may need to see multiple screens at once.

Here are some key pieces of code that make my code possible:

    <style type="text/css">
      #down_below {
        z-index: 1;
        position: relative;

      #on_top {
        z-index: 5;
        position: absolute;
        background: #afeeee;
        bottom: 5px;
        left: 5px;
        width: 100;
        height: 15;
        font-family: Georgia, serif;
        -moz-border-radius: 15px;
        border-radius: 15px;

    <div id="down_below">
      <iframe id="content" name="content"
        vspace="0" hspace="0"
        marginwidth="0" marginheight="0"
        width="100%" height="100%"
      <div id="on_top">
        <a href="javascript:void(0)" onclick="startCycle()">Start</a> -
        <a href="javascript:void(0)" onclick="stopCycle()">Stop</a> -
        <a href="javascript:void(0)" onclick="nextPage()">Next</a>

MKV split by chapters thanks to fryk.
Here is a little batch script for the windows command processor. Copy the code in your text editor and save it as 'SplitMKV.CMD' in your MKVToolNix program folder. The script can handle up to 400 chapters in a single MKV file (XP or better). It will search & find all the chapters, and split the MKV file on every chapter time mark. Usage: 'SplitMKV MyVideo.MKV'.

@echo off &setlocal EnableDelayedExpansion

set source=%~1
set destination=output\%~nx1

if not exist output\ mkdir output

for /f "usebackq tokens=4" %%i in (\`mkvinfo --ui-language en "%source%" ^| findstr /i /c:"ChapterTimeStart: "\`) do (
  if defined timecodes set timecodes=!timecodes!,
  set timecodes=!timecodes!%%i

mkvmerge -o "%destination%" --split timecodes:%timecodes% "%source%"

Donate Donate An illustration of a heart shape                            1999 - 2021