Category Archives: Coding

discourse

Installing Discourse with Amazon EC2 t2.micro Instance and SparkPost

This is more notes and reference than an in-depth tutorial, but after spending a few hours trying different things, here’s how to get it all set up. Remember, just as Discourse recommends, a t2.micro instance only has 1GB of memory, so if you intend to grow things to an Internet-wide audience, you should use a t2.small instance instead.
Continue reading

Dropout Rate compared to Accuracy

Testing Dropout Rates for Machine Learning with FastAI

As I continue my adventures in machine learning through the FastAI courses, I wanted to explore the concept of dropout rate. If you would like to see the Jupyter Notebook used for these tests, including full annotations about what/why, check out my machine learning github project. Specifically the Testing Dropout Rates (small images).ipynb.

Really quickly, dropout rate is a method in Convolutional Neural Networks (CNNs) of removing neurons (e.g. in the first layer of an image this would be individual pixels) to prevent overfitting (i.e. doing notably better on the training set than on the validation set) and thus increase the general applicability of the model. In other words, block a percentage of the material to force it to not become to overdependent on repeating patterns that lead it astray.

These tests were setup to isolate dropout rate as much as possible. Also, while this test was using ResNet50, results may differ using a different model. Okay, enough jibber-jabber, let’s jump right to the conclusions, shall we?
Continue reading

Machine Learning Install on Windows with Fast.ai

When getting started exploring machine learning, you will likely come across the free lessons at Fast.ai. These lessons require a few gigabytes worth of programs and algorithms as well as access to a powerful GPU from Nvidia (e.g. GTX 1060). The first lesson even walks you through setting up a cloud server for just that purpose, but what if your PC already has a powerful Nividia graphics card? What if you use Windows?

No problem. This quick guide walks you through the process of setting up a local environment for machine learning, starting with the Fast.ai tutorial series. It’s designed for Windows PCs with an Nvidia graphics card. Alright, let’s get started with a few quick downloads.

Continue reading

Selectize.js ComboBox: Cloning and Destroying

Selectize.js is a javascript library that allows you to offer more complex HTML select boxes, such as combining a select and an input box, commonly known as an autocomplete combobox. Most importantly, they have a built-in stylesheet for Bootstrap 3. However, I discovered a problem when you are trying to add another form field dynamically, specifically using jQuery’s .clone() function.

However, selectize() does not clone well… it breaks horribly. The key you must .destroy() the selectize() prior to cloning. Of course, another problem occurs then: The select element, upon selectize.destroy(), will reset the value to the last option. Solution? Store the value, destroy(), then set the value.


// When add button is clicked
$('#add').on('click',function(){
   $('.combobox').each(function(){ // do this for every select with the 'combobox' class
      if ($(this)[0].selectize) { // requires [0] to select the proper object
         var value = $(this).val(); // store the current value of the select/input
         $(this)[0].selectize.destroy(); // destroys selectize()
         $(this).val(value);  // set back the value of the select/input
      }
   });
   $('#monsters .form-group:first')
      .clone() // copy
      .insertAfter('#monsters .form-group:last'); // where
      selectizeme(); // reinitialize selectize on all .combobox
});

Here’s a working demo of the functionality.

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