Category Archives: Coding

WebM Converter Batch File

Encode WebM Video Files on Windows for HTML5 with FFmpeg

If you want to put video on the web, you’ll probably just going to upload it to YouTube and use their embed code. However, if you want to embed video on your own site without YouTube you want to make use of HTML5’s video element. To do that, you’ll want to make two encodings of your videos: WebM (Google backed) and H.264 (current standard). H.264 is easy because it’s been a standard for a long time (I personally use HandBrake), but WebM is quite a bit more difficult. There hasn’t be a defacto winner when it comes to encoding, though Miro Converter has come close.

However, the core of Miro and many others is the open encoder FFmpeg so we’re just going to setup an easy way to use that in this tutorial. Here are our goals:

  1. Install FFmpeg on Windows
  2. Create a Batch file (.bat) that we can drag-and-drop video files on to create WebM video
  3. Write the HTML5 code to allow for maximum speed and compatibility

Continue reading

Tutorial: Exporting Messages from WhatsApp and Graphing with R

This tutorial is posted with permission by Prometheus09 on Reddit. It was originally posted as an album on Imgur.

Number of messages sent per week throughout the relationship

Number of messages sent per week throughout the relationship

So here is a quick tutorial on how to construct the graph shown above, showing the distribution of messages over a given time period. First of all we must obtain the dataset we are going to use, which for this tutorial is the chat history obtained from WhatsApp. This can be obtained following these instructions or for iMessages or FaceTime data you can use this (paid) software.
Continue reading

Connecting Remotely to MySQL Database on an Amazon EC2 Server

While this was tested using a TurnKey LAMP Server build (Debian Linux), it applies to any Debian/Ubuntu server with MySQL.

Top-Level View of Tutorial

  • Enable MySQL access through server’s firewall (Amazon AWS-EC2 Security Groups)
  • Create non-root MySQL user with % (any) Host permissions
  • Alter the bind-address in the MySQL configuration file (my.cnf) file
  • Restart MySQL

Continue reading

jQuery Mobile Filterable Collapsible Listview with Smart Expansion

Wow, that’s a mouthful. Basically, I wanted to make use of the data-filter option to search a listview, but instead of a listview, I wanted it to be a collection of collapsible elements. Do accomplish this I needed some custom CSS to make it look right. Here is the example code with the ID iamalist. The page’s content section ID is iama, which is used in the CSS.
Continue reading

Using AutoHotKey and Ditto with PHP

I’m a purist I suppose. I write PHP, Javascript, CSS, and HTML in Notepad++. I don’t use an IDE (such as NetBeans), but I do have some shortcuts to make things go faster for me. The first one, Ditto, is a clipboard program that remembers the last 10 things put into the clipboard. This means you don’t have to worry about losing that copy/paste because it was overwritten. It’s simple, open, and a no-brainer addition. For those on OSX, Jumpcut is a great option.

The second one is AutoHotKey, which is crazy powerful, but for this example, I’m using its simple text replacement features. For instance, when I type qwhi, it is replaced with this:

while ($row = mysqli_fetch_assoc($result)){

You can imagine how handy this can be. Below are some of the shortcodes I use in my AutoHotKey file. Enjoy.
Continue reading

Mysqli and BLOB binary database fields

This post exists to save you hours of research on the web. The following things may be true about you:

  • You recently transitioned from mysql PHP functions to mysqli functions (staying current)
  • You prefer procedural PHP over object-oriented PHP (functions and arrays are cooler than classes)
  • You are storing some data in a MySQL BLOB, MEDIUMBLOB, or LONGBLOB field, which is Binary

Continue reading

mysqli_result() function to match mysql_result()

As of PHP 5.5, the MySQL functions are deprecated and will be removed by PHP6. The recommendation is to switch to MySQLi functions, which conveniently offer both a procedural (my preference) and object-oriented structure. Luckily, it’s a rather easy transition to MySQLi as functions names and functions are nearly identical (just change mysql_ to mysqli_). The only exception to this is the mysql_result() function, which has no analog.

Quick review: mysql_result() is used to write less code when your database query is returning only a single row (LIMIT 1) and/or a single column.

$output = mysql_result($result,0);

Pretty simple and straightforward. To replicate this in MySQLi, the following function can be used:

function mysqli_result($res,$row=0,$col=0){ 
    $numrows = mysqli_num_rows($res); 
    if ($numrows && $row <= ($numrows-1) && $row >=0){
        $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
        if (isset($resrow[$col])){
            return $resrow[$col];
    return false;

It has one improvement over mysql_result(), which is you can choose to only include the resource and no row and/or column. It will just assume mysqli_result($resource,0,0).

EDITED Dec 19, 2014
Function updated to allow for the column to be referenced by field name as well as numerical offset.