Feb 4, 2011

Repurposing the Blog

I've decided to repurpose this blog to have more consistent types of posts. Right now I seem to have a weird mix of personal stuff, rants, stuff I found on the internets, and web design/development.

So I got a couple of writers who want to come on board, and we've decided to go a bit more niche with it. Expect to find more useful and consistent information/posts.

NOTE: We may be deleting some of the older posts on here, changing the layout, adding some pages etc.

Feb 2, 2011

What's With Blog Titles These Days?

Lately I've seen a lot of blogs with titles like:
  • The Legendary Scribbles of ___________
  • The Mediocre Ramblings of ___________
  • The Incoherent Diary of ___________
And so on...

What's with that? It's like they're setting the reader up to be okay with mediocre posts, because well, it's in the title. That's ridiculous. It's not okay.

Now I'm not saying my posts are amazing, but let's be honest. They are. :D

Stop naming your blogs like your opinions don't matter, because if you think they don't, they won't. I always thought blogging was a great way to share unique thoughts and ideas, but the trend of title's like that and the advent of reblogging leads to exactly what the names say they are: meaningless scribbles and incoherent rambling. People should not be satisfied with mediocrity. It just doesn't make sense.

You don't have to be a genius to make a blog. And you don't need to be a genius to have excellent posts - you just have to stop being afraid that people won't like you.

Weekly Awesome #2

Thank you StumbleUpon for this weeks awesome. Who needs a weather app for your phone when you have this awesome, and always accurate, weather stone?

Feb 1, 2011

HTML5 Quicktip - Cut Out a Few Bytes

Everyone's been talking about all the exciting new features of HTML5, but the little changes sometimes get lost in the fray. You can start using these features now, they are currently supported in all browsers:

No more long doctypes! Save at least 100 bytes per request.
<!DOCTYPE html>

No more long meta tag, content-type and all that. Save a few bytes per request.
<meta charset="utf-8" />

And no need for 'type' tags in script, link, and style tags.
<link rel="stylesheet" href="awesome.css" />
<style></style>
<script></script>

All this can add up to saving a little bit of server resources. And as any web developer knows, a little goes a long way.

Idea for this post taken from a thread I was involved in at indie-resource.com

PHP 5.3 Quicktip - __autoload

With PHP 5, true autoloading is possible. No more calling 'include' for every script you have. All you need to do is define an autoload function like so:
function __autoload($class_name)
{
  include $class_name.'.php';
}
Note - This is the simplest example. You can go as far as to create classes for autoloading that will differ depending on the needed directory structure.

Now when you call classes, if they weren't included, PHP will look for them and call that function to load them.

Jan 31, 2011

When Things Are Slow

Things have been slow in the business department lately. There are some times when you need to wait for one department to finish something before you know your next move - this is one of those times for me. It won't last long, though. Anyone who's ever been involved with a startup knows that you get very little downtime, and the little you have you should relish.

I use my downtime to work on my own projects, or to freelance a little bit, or what have you. Maybe catch up on some video games, watch some netflix and just generally relax for a little while. How do you use your down time?

Jan 29, 2011

Optional Function Arguments

Today's a two-for-one post day. :)

I just read this article, which I must have missed in the mess of RSS feeds I subscribe to. It's an interesting tutorial, definitely worth a read. But what interests me so much is the first part - Passing optional or any number of function arguments.

Now PHP has a huge range of functions, and there are no doubt some you may not know about. A lot of my functions have optional arguments, sometimes written like so:
function foo( $argument = FALSE )
{
  if ($argument)
  {
    //Do something
  }
  else {
    //Do something else
  }
}

Anyway, I had never thought of accepting any number of parameters to a function using func_get_args(). And there are plenty of uses for a function like that. The php.net manual has some examples that illustrate some uses. But I can think of plenty more. For my PBBG for example, I might accept lots of different params in a function that points a user action to it's respective class.

It might look something like this:
function foo()
{
  $action = func_get_args();
  
  //The first argument would always
  //be the action's name
  switch($action[0])
  {
    case 'attack':
      //The second argument would
      //be the players attack stat in this case
      battle::attack($action[1]);
      break;
    case 'retreat':
      //Maybe speed in this case
      battle::retreat($action[1]);
      break;
    case 'cast':
      //And so on and so forth...
      battle::cast($action[1], $action[2]);
      break;
   }
}

This is obviously a simplistic example, but with some extra code this could add a layer of security to my application.

Here's another example that can be used to sanitize queries:
function mysql_safe($q) {
    $x = array_shift(func_get_args());
    return vsprintf(preg_replace('/%([1-9]):(d|s)/','%$1$$2',$q),
    array_map('mysql_escape_string',$x));
}

Comment if you have an interesting use for this function, or if you have a function you'd like me to do a post on. Happy coding!