Building Grids with PHP, the easy way

In my years as a developer, I have found myself building grids in html, always with a different number of elements per row. The first few times I solved this problem, I used the modulus (%) divided by the number of elements needed for the row, with an if statement to see if the row container should be closed or not.  This especially sucks if you are doing something recursively, so why not do it in a way that is easy to read, doesn’t require css hacks, and can take advantage of the row-fluid and span classes in bootstrap. Use array_chunk.

Isn’t that much easier to read?

Beginning NodeJS for PHP Devs: Getting Started Locally

You’re no stranger to locally hosted php. Especially using MAMP or XMPP. Here is how you get started locally with NodeJS.

Getting started setting up your first node.js app up locally on OS X is so easy it makes my eyes tingle. I have always developed on a Mac, so if you are interested in windows, it’s probably best to find someone who specializes in that. If this doesn’t concern you, read on!

Continue reading “Beginning NodeJS for PHP Devs: Getting Started Locally”

Redirecting www domain to non www on Ghost

Sure. There are other ways you can do this. .htaccess on apache, or a config in nginx. But one of the cool things about node.js is that It can be its own webserver. And in many cases, thats exactly how your ghost blog could be running. That’s how mine runs.

Since Ghost is built using express.js the redirect rules can be right in your codebase.

To redirect www to non-www in ghost, you simply need to open up your frontend.js file which is located in

ghost/core/server/routes/frontend.js

And add this block of code before all of the other routes.

server.get('/*', function(req, res, next) {
  if (req.headers.host.match(/^www/) !== null ) {
    res.redirect(301, 'http://' + req.headers.host.replace(/^www\./, '') + req.url);
  } else {
    next();
  }
});

This will catch the request, and if the www is included in the url, does a 301 redirect to the non-www url.

Restart Ghost and you are done.