Skip to content

First jQuery Plugin

November 22, 2011
By andy in JavaScript

I wrote my first jQuery plugin. It’s nothing fancy, but I’ve got the boilerplate down for future plugins.

Thanks to jMar for the jump start.

(function($){
 $.fn.truncate = function() {                    ////truncate is the name of the plugin
    var defaults = {                             ////set up default parameters
         ////default values here
    };
    var options = $.extend(defaults, options);   ////options will be the parameter scope
    return this.each(function() {                ////loop through each matched element

    });
 };
})(jQuery);

My plugin takes containers and horizontally spaces all images they contain. I built it for the images across the top of my web site. It could definitely be expanded upon. Currently, it only takes a width option (default: 120) and only works horizontally.

Regardless, you can check it out here.

Tags: , ,

By andy in Audio-video, Linux

I have often wanted to extract a good clip from an audio file and publish it on YouTube. I finally got around to doing it and it was easier than I had imagined (once I figured it out). All I’m doing here is creating a video with a still picture and audio.

  1. I’m using Fedora Linux. I had Audacity(audio editor) installed, but it did not have MP3 (which was the type of my audio file) support. Thankfully, there was an easy fix:
    1. $ sudo yum remove audacity
    2. $ sudo yum install audacity-freeworld
    3. Thanks to http://insidesocal.com/click/2010/08/audacity-in-fedora-cant-import.html
  2. My .mp3 file was almost two hours long. I wanted about three minutes of it. I opened the .mp3 file and found the location of the clip and then did the following:
    1. Clicked on the wave pattern about where I wanted the clip to start
    2. Shift-clicked on the wave pattern about where I wanted it to end
    3. Hit the space bar to play/pause the clip.
    4. When paused, edit the start and end points by Shift+left-arrow/right-arrow to expand the selection and Control+Shift+left-arrow/right-arrow to contract. Click on the timeline above the wave pattern to start at that point (when tweaking the end of the selection).
    5. When you’re happy with your selection, go to Edit->Trim
    6. Move the selection to the start of the timeline by going to Tracks->Align Tracks->Align to Zero
    7. Go to File->Export … , select .mp3 as the format. and hit Save.
    8. More thorough instructions from the Audacity team
  3. Now open OpenShot.
    1. Right-click in the top right panel and choose “Import Files” to add the .mp3 clip and an image.
    2. Drag the audio into Track 2.
    3. Drag the image into Track 1.
    4. Right-click on the audio in Track 2 and choose “Properties”, so to the “Length” tab and copy the value for “Out”.
    5. Follow the same steps for the image in Track 1, but paste in the value you copied from the audio
    6. Got to File->Export Video …
    7. Give it a name and select where to export it
    8. For Profile, select Web
    9. For Target, select YouTube
    10. Click “Export Video”
    11. Instructions with screenshots

Congratulations, you’re ready to upload your video to YouTube!

Tags: , , , , ,

By andy in Uncategorized

Probably a no-brainer for many, but I can never remember, and this seems to be best practice:

Personally, I would set the ownership of /var/www/html to apache. You can do this by:
chown apache /var/www/html

Next, I would create a group of let’s say “Web admins”:
groupadd webadmins

Add the user webadmin to the newly created group:
usermod -G webadmins webadmin

Add group permissions to the newly created group:
chmod g+rw /var/www/html

Source:

http://serverfault.com/questions/310325/how-do-i-give-a-user-access-to-var-www-html

I also had to
chgrp webadmins /var/www/html

and log out.

Tags: , ,

PHP Anonymous Functions

October 11, 2011
By andy in PHP

Sweet, but a little awkward. The good news is that PHP supports anonymous/lambda functions (that you can pass around, etc.), the bad news is you pass the function in as a string.OK, I admit the bad news isn’t that bad, but passing as a string could be a let-down if you’ve done much JavaScript.

http://php.net/manual/en/function.create-function.php

<?php
$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');
echo "New anonymous function: $newfunc\n";
echo $newfunc(2, M_E) . "\n";
// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599
?>
All syntax aside, I’m impressed PHP has had this since June 2000.
http://php.net/releases/index.php

Tags: ,