EC2 High CPU Wait and the EBS Provisioned IOPS Difference

On our small Graphite monitoring server (c4.large), we kept having very high CPU wait times. It would hover around 80% almost continuously. I could scrub back in the graph timeline to see where it started and there were no major changes made on that day. (like adding a fleet of new servers or extra data points) So I was pretty confident it was not an application issue.

Continue reading →

Heka JSON Decoder using a SandboxDecoder and Lua

First let me say if you're looking for help on Heka, check out their IRC channel. It's full of great guys that are extremely helpful! [IRC: #heka on]

This Heka JSON encoder converts any simple key/value JSON payload into Heka fields.

Continue reading →

Drop MySQL Primary Key with Foreign Key using Laravel 4 (error 1025 & 105)

This issue is really not specifically related to Laravel. But the code below shows how to handle the issue within Laravel 4.

The issue comes from trying to delete a primary key that's also a foreign key. MySQL would spit out the following "useful" error:

SQLSTATE[HY000]: General error: 1025 Error on rename of './database/#sql-10e9_9c' to './database/table' (errno: 150) (SQL: alter table `table` drop primary key)

To solve this you just need to delete the foreign key first and then the primary key.

Schema::table('products_fulltext', function(Blueprint $table) {
Continue reading →

Laravel 4 Unable to Read Package Configuration File

I was trying to add a configuration file to an existing Laravel 4 package (revisionable) to help improve the functionality. But no matter what I tried I could not get the package to read from the src/config/config.php file.

Continue reading →

How to create a temporary storage directory that automatically deletes contents after X days (Mac)

Here's a quick way to have a directory that allows you to store files and other subdirectories for temporary usage. For example, I use this to save all my downloads and other files that I only need for the next day or two.

We first need to create a new cron job. If you're not familier with cron, it's basically instructions to the cron daemon of the general form: "run this command at this time on this date". (or for some light reading) We're going to use cron to run a command to move all the contents of a directory to the trash.

// from the terminal enter to create new crontab or open existing
crontab -e

// next press Esc+i to enter into "INSERT" mode which will allow you enter text
00  */2  *  *  *  find /path/to/temp/ -mtime +1 -exec mv {} ~/.Trash ; >/dev/null 2>&1

// then save the crontab by pressing Esc, :, w, q (write & quit)

Now let's explain what's going on with the cron job.

00 minutes (ie: 2:00,18:00)
*/2 every 2 hours
* * * every hour, day of the month, day of the week
find /path/to/temp/ finds all contents of directory
-mtime +1 where the file's make time is X days more than current date
-exec mv {} take all contents found from find comment and executes the mv (moves) command
~/.Trash ; users trash can (could be any directory though)
>/dev/null 2>&1 suppresses any output from displaying (ie fulling up your users mailbox)

Also, if you're looking for a quick way to add extra storage to your Macbook, checkout the Nifty Drives. This is what I use for my temporary storage.

Continue reading →

PHP session_start() failed no space left on device (Plesk plesk-php-cleanuper)

I kept receiving intermissive PHP warnings saying some thing like E_WARNING: session_start(): open(/var/lib/php/session/sess_ji9k4chqke3pde98a5n5m1vca5, O_RDWR) failed: No space left on device (28). Usually this would indicate that the disk where the sessions were being stored is full. The best place to start is to check if the disk where those session files are being stored is in fact NOT full.

// to check disk space usage
df -h

// should display something like this
Filesystem            Size  Used Avail Use% Mounted on
/dev/md1              4.0G  883M  3.2G  22% /
/dev/mapper/vg00-usr  4.0G  1.8G  2.0G  49% /usr
/dev/mapper/vg00-var  890G  231G  614G  28% /var
none                  5.9G  116K  5.9G   1% /tmp

In my case the disk where the sessions were being stored had plenty of space - 600GB free!

Continue reading →

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 →