Statamic

If you have followed this blog over the years you know I am always changing something. So this may not surprise you that I have switched blog platforms, again. I had been using Tumblr which is perfect for my normal posting routine. Sharing quick links, photos, quotes, and occasional articles. As much as I liked Tumblr some things just irked me.

  • They control your data
  • No easy way of setting up redirects in bulk
  • No importing

Mainly the control of my data is what I didn’t like. I want all my content stored where I can do what I want with it. Of course, they do offer an API but what if one day they stop providing it?

I did have a short stint of using kudos which is a flat file Laravel app created by Ian Landsman and it worked great for me. Except for one major drawback. You still have to open your editor and write the post and then push. Just too much work for me and my number of posts went down considerably. I guess I am just lazy :)

A few weeks ago I came across a new cms named statamic and quickly applied for the beta. I ended up getting just before it was officially released but had enough time to play with it and enjoy how they set up the system. Everything is stored as flat files just like the jekyl flavor. But with one huge difference and that is the ability to post from an admin section. Which still just creates flat files.

So now I can post quickly from the admin and later on when I feel like it sync with git so I have a full off site backup of all my posts. Even though the cms is pretty basic the possibilities are pretty much limitless with what you can do with it. For instance, I have duplicated my whole Tumblr setup with it. Now I have all four post types and it really wasn’t much work. Just a few hours over two evenings.

Statamic is commercial but the pricing is very fair and I don’t mind paying for something top quality with support. All my little questions have been answered quickly and with a good answer. So yes I fully endorse what they are doing and excited to see them grow.

I will miss the Tumblr followers, but I always have an rss feed you can use to keep up to date ;)

Hosting

Another negative is hosting. With Tumblr it is free and well you can’t beat free. I tried aws but it was to expensive for me. I am outside of my year free micro and it seemed like a micro was running around $30 a month. I started researching other hosting options and was going to go with a shared system but meh. I would rather have full access to do whatever I want. After browsing what felt like weeks I settled on Linode and was lucky enough to get in when they offered a $100 credit. Woot. :)

So now this site is running on Linode with Ubuntu, Nginx, PHP5-fpm, and apc. All data is stored in a private git repo at BitBucket.

CodeIgniter Security Basics

By default CodeIgniter is a very secure framework and it also does a lot behind the scenes to help you out. I was recently contracted to look over a CodeIgniter application that was constantly getting hacked. So in light of what I seen I want to share some common pitfalls you need to avoid.

  1. Use Active Record! You should “almost” never write your queries manually.
  2. If you must write a query without active record be sure everything is escaped properly. $this->db->escape()
  3. Validate user input! CI has $this->input->post(), $this->input->get_post() and you should use those.
  4. Validate file uploads and use the upload library.
  5. Use the framework tools. It comes with tons of libraries and helpers that are designed to help you with common tasks. There is no reason to write
    your own if already accomplishes what you need.

Yes I know every php developer should know about these but some people still just haven’t gotten the memo. So spread the word, write secure apps, and make the world a better place.

Atlanta PHP Meetup

I had the pleasure of attending the Atlanta PHP’s meetup on Thursday at StrongBox West where Ben Edmunds gave a talk about the Laravel framework.

Doug Grubba and I decided to carpool down since Atlanta1 is about 4 hours from Charlotte. I will be totally honest I really didn’t have high hopes on how the meetup would go. I have been to some local meetups and I was just not that impressed. Low turnout, weird locations, etc. But Chris Spruck and the ATL guys are top notch. They had a lot of great sponsors, food provided, free prizes, and above all a nice turn out. (I estimated about 50 people).

After the meeting a few of us went over to local pizza shop and talked about all sorts of web topics and where our next stop in hotlanta should be.2

I had a wonderful time and wished I lived closer so I could attend more of their meetups. They get two thumbs up from me and hopefully I will get to visit again.


  1. Photo by tableatny 
  2. Ended up going back to the hotel and watching some gator hunting. But hey my wife is happy about that. :) 

Summer Hours

In all my work history I have always had a 5 day work week. Either Monday through Friday in the IT field or Tuesday through Saturday in retail. I am working at UserScape now and we started summer hours two weeks ago. Which basically means we get half the day off Friday.

Honestly going in to the first week I was a little worried I wouldn’t get as much accomplished as I wanted. Now that we have passed our second week I think I get more done on Friday than some of the other days. My mind shifts from thinking about what I can get done by the end of the day, to what can I get done in the next 20 mins. Friday mornings feel like a sprint and I am focused on getting as much done as possible. This means I take away as many distractions as I can. (rss, email, im, etc)

Not only do I feel very refreshed coming into Monday and ready to jump in but that extra time with the family is awesome. I don’t know about your weekends but mine are so crammed full of activities it goes by really really quickly.

If you are an employer I would recommend you give something like this a try. You may find your employee moral improves and more things get done in less time.

Cheating Or Good Design?

A comment on Reddit (by raygundan) points out an interesting technique Apple uses on their iOS platform:

when you switch apps, the device saves a screenshot of what the last screen looks like for that app so that when you switch back again, that saved screenshot is the first thing you see. This is done to buy time for the app to fully load. Instead of showing you a blank screen or a loading screen, the device shows you a screenshot of the app. This technique works because the time it takes to load the rest of the app isn’t very long anyway, so a second of showing a screenshot that the user cannot interact with doesn’t cause confusion. What it does do is make it looks as if the app has loaded instantly, which results in a very good experience for the user.

I think this is a brilliant idea. It seems we live in a world full of loading gifs and I appreciate fine details like this. The fine details that you don’t see is the difference between mediocre and extraordinary.

Laravel Blade

Blade is the simple template/theme system built into Laravel and up until this point it has been very basic. It supported most of the simple things such as variables {{ $var }}, @if @else, @section, and finally a thing called @yield.

Because of the simplicity of it on a new project I thought we would need something more advanced and went with Twig. Twig had more features and was more powerful but it also didn’t really fit into my workflow. The biggest problem was working with Eloquent results and twig doesn’t like calling results like this:

foreach (Book::with('author')->get() as $book)
{
    echo $book->author->name;
}

I asked Taylor about it and he did a few changes to get that working but then I had troubles with other calls. So it just felt like it was more of a fight than what it was worth. After discussing this, last week Taylor and Shawn McCool really made Blade awesome. First Shawn recommended a “render_each” method. Which is an excellent feature in my opinion. It works my including a looped view:

<ul>
    {{ render_each('categories.list', $categories, 'cat') }}
</ul>

// categories/list.blade.php
<li>{{ $cat->name }}</li>

As you can see that is a big time saver. But it doesn’t stop there. Now Blade can have layouts inheritance and several other really useful goodies:

@layout('layouts.common')

@section('content')

    <p>My content</p>

@endsection

Then inside layouts.common:

<html>
<head>
    <title>Test</title>
</head>
<body>
    @yield('content')
</body>
</html>

This is just some of the basics of the new features and it does a lot more. Although I don’t consider it a full replacement for Twig it has 90% or more of the features I wanted to use. The biggest missing feature (depending on your needs) is that Blade still just parses as php. So it can call things that are not assigned and doesn’t prevent you from using php code in your views. Personally I like that feature but if you are really wanting to limit what people can do in the views then this may not be ideal. So use what is best for the task at hand.

For a video overview of what is coming please watch this:

Laravel Bundle Assets

The past few weeks I have been building a few Laravel bundles and one of the features of bundles is the ability to have assets that are moved to your public folder during install. This is great when your bundle has css, js, images, etc..

The downside to this though is that while building the actual bundle it is a pain to keep having to run the following command each time you change a file:

php artisan bundle:publish

I have came up with a few different options to make this easier for developers. The first method which I believe would be supported across every os is to symlink the assets to public/bundles/folder/. However the down side to this is you have to add new symlinks when you add new files. So not ideal for the way I typically develop.

The second option is specific to mac but it works wonderfully. What I have done is purchase live reload and use it to run the bundle publish command. The reason I originally purchased the app was because I am using less for my css and I liked the fact that it would compile the css and also refresh your browser so you can see changes instantly.

The bigger benefit is live reload allows you to run terminal commands after you save and before it refreshes your browser. So all you have to do is add in your artisan command and not have to worry about it again. Here is a screenshot showing this:

livereload

Hopefully this will help you if you are building bundles with public assets. If you have any other tips please post them in the comments.

Laravel Log Viewer

A simple Laravel bundle to display your log files via the browser.

Installation

php artisan bundle:install logviewer

Publish assets

php artisan bundle:publish logviewer

Then edit your application/bundles.php file and add:

return array(
    'logviewer' => array(
        'location' => 'logviewer',
        'handles' => 'logviewer'
    )
);

Download

You can clone the repo by running the code below:

$ git clone git://github.com/ericbarnes/Laravel-Log-Viewer

Or visit the GitHub Repo.

New Laravel Bundle App

Since starting at UserScape I have been tasked with building a new bundle application for the Laravel framework. So far all the work has been done “behind the scenes” but I wanted to share a few screenshots of what I have completed so far.

bundle-home

This is a temporary home page which showcases the latest and the most popular. Currently the most popular will be determined by number of installs but I have some ideas for better stats and filtering that will come later.

bundle-user

This is the grid list. I tried keeping it simple so you can quickly scan the titles and also show each users gravatar for branding.

I am really happy with what I have completed so far and it should be a simple and effective way for users of the framework to find pre-built code to put in their applications.

If you are interested in seeing how to create a bundle check out Taylor’s Videos

CodeIgniter Output Caching

This week I had the privilege of doing load testing on an aws setup. The goal of the test was to support 25k concurrent users and was designed to ramp up over a period of a few minutes. The first round of testing failed pretty quick and I only had a select number of large queries cached. So the db spiked and was the bottle neck. During that test we was only able to reach 10k concurrents.

For the second round of testing I decided to just setup output caching before I even loaded the db in a MY_Controller. I set the number of minutes to something relatively high and was ready to commence the load test. Unfortunately this test maxed out the db again and I was honestly scratching my head on just why that would be the case.

Since this didn’t make any sense to me I decided I better figure just what is going on. I got my local system setup the exact same way, enabled mysql query log, and then proceded to test and see what was going on. Queries was being ran even after the cache file was written. At this point it was way late so I decided I better sleep on it and try and think about what I was missing.

The next morning I got to work ran the same tests and got the same results. Starting researching and then realized it was just my ajax calls that was generating the queries. This had me puzzled because the ajax controller extended the MY_Controller so it should be cached as well. Turns out I was wrong and missed the most important note in the user guide:

Warning: Because of the way CodeIgniter stores content for output, caching will only work if you are generating display for your controller with a view.

The more I thought about it the more sense that makes since the Loader ties into the output library but I wasn’t thinking clearly at 3am. Looked at my ajax controller and sure enough I was just returning a json string.

return json_encode($vars);

The quick fix was to change the return to the following:

return $this->output->set_output(json_encode($vars));

My hope is this will help others if they ever run into the same situation. Unfortunately the load testing was only scheduled for two rounds but I feel confident by fixing that it would have passed with flying colors.

So the moral of the story. READ THE MANUAL :-)