Category Archives: Coding

PHP Alternatives for Nested IF Statements

We’ve all done it. It starts as a single IF statement:

if (empty($var)){ // does it exist?
   $error = 'No username entered';
   return $error;
}
// everything is OK

Then we decide, we need to check something else, so we just add in one more IF statement:

if (empty($var)){ // does it exist?
   $error = 'No username entered';
   return $error;
   if (strlen($var) > 20){ // Is it too long?
      return 'Invalid username';
   }
}
// everything is OK

Continue reading

Install Apache, MySQL, PHP5, and PHPMyAdmin on Debian “Jessie”

This is a quick guide to getting an Amazon EC2 server up and running with LAMP and PHPMyAdmin based on the LTS (Long Term Support) Debian version 8.5 “Jessie”. This guide was written using the Community AMI image debian-jessie-amd64-hvm-2016-04-03-ebs for Debian “Jessie” and assumes you are able to launch the server and connect via SSH.

Amazon assumes an EBS volume of 8GB (t2.nano) or 10GB (t2.micro), but if the server will be storing very little, the real minimum size of the EBS can be calculated safely as:
1.5GB + (RAM x 2)
That is roughly 3GB EBS for t2.nano, and 4GB EBS for t2.micro.

Continue reading

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)){
 
}mysqli_free_result($result);

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