Something I've noticed a lot with PHP developers is how they handle session checking for users. Most people use a simple $_SESSION['...'] check and if that fails they use a header('location:...') redirect. I've also noticed that a lot of those same developers miss one key security flaw: not everything respects headers. Here is a small example using cURL to demonstrate what I mean.

Continue Reading

I was recently overhauling my permissions for a big rails app and needed to see which filters were on which controllers as an overview. I came up with this little snippet which will go through each of your controllers and print out which filters are on them, as well as their options.

Continue Reading

Ever want to break a small PHP app into an MVC-ish convention without the need of tacking on a massive templating engine? Are you opposed to remembering new syntax just for a template? Why not just use some ob_* code to roll your own simple templating engine?

This will allow you to create PHP includes which will render as templates so you can organize your app into an MVC-ish layout.

Continue Reading

This is admittedly ghetto, but I needed a super simple small-scale solution to creating unified diffs based off large blocks of text. The easiest way to do this was by creating temp file and using the native diff command to do the comparison.

I've used this method for a really small snippets app for our intranet, which can be found on GitHub.

Continue Reading

Ever need to provide a fuzzy date using PHP for your web app? Heres a simple snippet that will do just that.

Continue Reading

I recently had to format large numbers using JavaScript and was really missing Rails' numberwithdelimiter function. Heres a simple version for JavaScript.

Continue Reading