formatting imagepaultclark.com

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 have shared as the level of my capabailities. 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, HTML, CSS, C and curl. However, I have coded at least one program in the following languages: Cobol, Fortran, Pascal, Ada, Assember, Lisp, Smalltalk, Java, and C++. I do not use IDEs or programs such as Dreamweaver. I use vi or notepad and ftp or even better Winscp.


PHP - Custom justin.tv webpages
justin.tv 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 justin.tv 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);
    curl_close($curl);

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

  $url2 = "http://www.justin.tv/directory/entertainment";
  $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;
        text-align:center;
        font-family: Georgia, serif;
        font-size:x-small;
        -moz-border-radius: 15px;
        border-radius: 15px;
      }
    </style>

    <div id="down_below">
      <iframe id="content" name="content"
        frameborder="0"
        vspace="0" hspace="0"
        marginwidth="0" marginheight="0"
        width="100%" height="100%"
        src="http://www.paultclark.com/">
      </iframe>
      <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>
      </div>
    </div>


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'.

Code:

@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%"

endlocal