Authenticate Only Certain HTTP Verbs (POST, PUT, DELETE) in Laravel 4

In working on the API for an upcoming project, I needed a way to allow all reads (GET) to be allowed without authentication but any requests (POST, PUT, or DELETE) changing the data to require authentication.

Continue reading →

New Business Cards

After server iterations, here are the new business cards to match the updated site.

Continue reading →

PHP Class to Move Database Files (like MYD, MYI, and frm)

A client needed a quick way to transfer their MySQL database files (specifically MYD, MYI, and frm) from their Windows server over to the webserver running CentOS. Below is a quick class that we used to run every 4 hours via cron to do the job.

Please leave a comment below if you have any questions or improvements.

Download Class View on Github

Continue reading →

Site Update: RSS feed and social links

One of my summer last tasks to do with the site redesign was to implement an RSS feed for the posts/articles. The feed can now be found at the bottom of each page along with links to my github and Facebook page.

subscribe to rss
Continue reading →

Project: CSS Button Collection

I just released my latest project the CSS Button Collection. It is a collection of CSS only buttons of various designs - from large push downs to trendy flat. My goal is to keep updating the collection as soon as I can, but please feel free to hop over to the github page and submit some of your own.

View Demo Project on github
Continue reading →

Rotate Images using jQuery

To add extra functionality to an image upload form, you're likely going to want to include the ability to rotate an image. Most of the time it will simply be from portrait to landscape or vise-versa. Below is a quick demonstration of the frontend - the part the user will choose an image and rotate it.

Continue reading →

Display the Difference Between Two Dates in PHP

Here's a quick function to display the difference between two dates using PHP. The function will return the correct plurized wording and hide any with zero. For example if the date is less than 1 year, it would hide "0 year" from displaying.

/**
 * Display the difference between two dates
 * (30 years, 9 months, 25 days, 21 hours, 33 minutes, 3 seconds)
 *
 * @param  string $start starting date
 * @param  string $end=false ending date
 * @return string formatted date difference
 */
function dateDiff($start,$end=false)
{
   $return = array();
   
   try {
      $start = new DateTime($start);
      $end = new DateTime($end);
      $form = $start->diff($end);
   } catch (Exception $e){
      return $e->getMessage();
   }
   
   $display = array('y'=>'year',
               'm'=>'month',
               'd'=>'day',
               'h'=>'hour',
               'i'=>'minute',
               's'=>'second');
   foreach($display as $key => $value){
      if($form->$key > 0){
         $return[] = $form->$key.' '.($form->$key > 1 ? $value.'s' : $value);
      }
   }
   
   return implode($return, ', ');
}

// examples
echo dateDiff('1982-10-14'); // 30 years, 9 months, 25 days, 21 hours, 33 minutes, 3 seconds
echo dateDiff('2001-09-05 08:15:05','2002-02-15 04:10:02'); // 5 months, 9 days, 19 hours, 54 minutes, 57 seconds

Continue reading →

jQuery AJAX Loading – Display Images or Text Until Script is Finished

This is a simple way to display an image or text while an AJAX request is loading.

View Demo

What we’re basically doing is forcing a div to have a starting image and then replacing it with the data return from the AJAX request.

Continue reading →

Sync Files Between Servers using rsync

This is a follow up post to Copy/Transfer Files Between Two Servers Using Linux SCP. Transferring via scp copies all the files which is what you want sometimes, but I find rsync to be a much better solution in most instances.

I'll provide a handful of ways I tend to use rsync but check out the full Linux man page for the a complete description of rsync and all the available options.


Synchronize from Local Server to Remote

rsync -avuz /var/www/example.com/ root@108.175.12.239:/var/www/example.com/

// only one file
rsync -avuz /var/www/example.com/index.html root@108.175.12.239:/var/www/example.com/
Continue reading →

Working with Data in Pivot Tables using Laravel 4 Eloquent ORM (SELECT, UPDATE and DELETE)

Working with the pivote table data was not clear to me initially - especially deleting from the pivote table. I thought Laravel would handle this since it already handles the inserting and updating of the data. But it turns out this needs to be handled at the database level.

When setting up your pivot table, you need to set the referential actions to cascade on delete and update. This will force any update to the parent table to cascade down the data in the pivote table.

Below is a simplified example using a blog with posts and tags.

Continue reading →