Restart mysql replication after hard shutdown

We have an “A-B” replication set up. The power went down (boss flipped the wrong breaker). When the servers came back up, replication was broken.

The SQL thread was running fine, but the I/O thread would not start.

I found this stackoverflow answer: mysql-slave-i-o-thread-not-running. Luxknight007 seemed to have the answer for my case, as I knew this wasn’t a permissions issue. His answer, voted up several times, indicated the following method of fixing the issue:

But which bin log and which position? When I went to the bin log folder on the A (master) server (you can find this in the my.cnf file as the log-bin configuration), I found one log file that was smaller than all of the others and had a last modified date at about the point where the power had been cut, so that was clearly the correct point.

I used to read mysqlbinlog program to read the end of the log, and just picked the last end_log_position. I did remove the RESET SLAVE command as it would only wipe out all of the relay logs and there was no need to do this in my case.

Super Simple PHP File Uploader

I can’t recall how many times someone’s needed to get me a file to large to email, but didn’t know how to use FTP – or even DropBox or Google Drive. My recourse has always been throw an upload script up on whatever PHP server I can get to and direct them there.

Here’s the script. Just uploads right to the folder the script is in. Has some super simple javascript to flash an “Uploading!” message.

That’s it.

ffmpeg: Image Slideshow with Audio and Title Overlay

I often need to put audio interviews on YouTube, which requires they be movie files. Making slideshows in Adobe Premiere can take a long time to create and export. This ffmpeg process is quick to set up, and even quicker to export. You end up with a .mp4 format video slideshow with a transparent PNG title overlay  in a 16:9 aspect ratio (960×540 pixels) set to the audio of your choice. There’s no fancy transitions or anything, but the time it saves is tremendous.

I am using OS X El Capitan with ffmpeg version 3.0.

First we’ll start with a folder that contains your audio (as a single file – to concate multiple audio files, see trac.ffmpeg.org) and your images (jpgs and pngs of any size, we’ll convert them shortly).

If you want a title overlay, use the drawing program of your choice (or an online png creator) to make a transparent png that will overlay your whole slideshow. Make it 960×540 pixels, and place your text in an area where it won’t interfere with your images too much. We’ll name it MyTitle.png and put it in the folder with the rest of our images.

Next thing we’ll do is make a python script which will take all of our images and fit them into a 960×450 pixel frame with black padding. We’ll retain our images aspect ratio so they aren’t distorted. I am used the script here at www.bogotobogo.com as a starting point, and improved it to add black padding and maintain aspect ratio with answers from this stackoverflow.com post. The script will also convert all of our image names to “img-XXX.jpg” and convert them to jpgs.

**Notice that there is a configuration variable called “title_image”. You’ll want to make sure that matches the name of your title overlay or else it too will be transformed and become part of the slideshow.**

Place this script in the folder with your images.

Next, we make our bash script that contains our ffmpeg command.

What’s going on here?

First is just ffmpeg setup:
-y : Overwrite any existing file

Next, we deal with our image slideshow:
-loop 1 : loop the images
-framerate 1/3 : the “framerate” of the images. This gives us about 3s per image but you can adjust it. Smaller the number the longer the images will show.
-i img-%03d.jpg : tells ffmpeg which files to use (get anything named img-XXX.jpg)

Then our overlay:
-i MyTitle.png : set the title overlay filename
-filter_complex “0:0” : set the overlay filter. Since we used a title that filled our whole screen, we can just position it at (0,0) coordinates. If you want to be able to scale or more specifically position your overlay, the ffmpeg docs for overlay and this stackoverflow post are good places to start.

Then, our audio:
-i “Track01.mp3” : indicates which audio file to use (change this to your audio name)
-c:a copy : tells ffmpeg not to change the audio format. Just use it as is.

Finally, our output:
-shortest : tells ffmpeg to stop our slideshow when the audio is finished.
-aspect 16:9 : sets our aspect ratio for the final product.
-r 5 : gives the framerate for the output. I chose 5fps because it is quicker to export.
“FinalSlideshow.mp4” : the name of our output. Simply change the extension to change the output type.

That’s it. You should now have a folder with:

      • slideshow images
      • title overlay
      • audio track
      • resize.py script
      • make_show.sh script

 

Just run your python script python resize.py and take a look at your images. You should see a similar conversion to this:

weasel

weasel.jpg

img-038

img-001.jpg

Next, run your make_show.sh script sh make_show.sh

You should see a flurry of ffmpeg activity, and after a while (a slideshow lasting an hour took about 8 mins to do) your FinalSlideshow.mp4 movie should be inside your folder along with everything else.


Here’s what I came up with for a slideshow with some transitions (fade to black). It’s based on this StackExchange post for the transitions, and this one for the concatenating.

Basically what we are doing is making a short slideshow of a few slides as one short video, then concatenating it together a bunch of times. Then we go and add the audio track to that. A little clunky, but we do get some nice transitions!


Sources for this project:
https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
http://www.bogotobogo.com/FFMpeg/ffmpeg_basic_slide_show_from_images_jpeg.php
http://www.bogotobogo.com/FFMpeg/ffmpeg_adv_slide_show_from_images_jpeg.php
https://ffmpeg.org/ffmpeg.html

Homemade Drum Machine

128 Light Switches – a Casio MT-205 keyboard – a load of electronic components = a Homemade Drum Machine


Install Composer & PHPUnit

Install Composer and PHPUnit globally:

Improved PHP exec() Function

When using PHP’s exec function, it isn’t possible to get stdout which makes troubleshooting difficult. Thanks to Mark on StackOverflow, this improved version of exec(), using proc_open(), lets you capture not just the output but also the errors in a separate variables.

This came in useful for me when setting up a simple InterMapper probe which counts files created within a certain time period. It was failing, giving different results from when I would run the command in the Terminal. It was a permissions error, and the function above helped me to verify this.

 

Send Email from Mac Terminal (Yosemite 10.10.5)

You can send an email directly from the Mac Terminal:

 

AngularJS: Detect Completion of Nested NgRepeats

I am working with a large table in AngularJS which builds itself from a json object using nested ng-repeats. I needed to know when this was all completed so I could format the table at the end of the process.

I decided on creating a service to track the running of the ng-repeats, and a directive which sits on the same element as the ng-repeat continually resets an $interval until the ng-repeats are completed. Why is this better than some of the many posts online which show how to run a callback on the completion of an individual ng-repeat? Because it allows you to watch a group of nested ng-repeats and only fires once all are complete, not each time each ng-repeat finishes.

Start it up right after adding your data to the ng-repeat element (in my case, after a service retrieves the data from an $http request):

And finally, just listen for completion and then do what you need to do:

 

Barebones GruntFile.js

This is my basic GruntFile.js. Just watch, concat and uglify all the js files in the app folder.