Code that scares (scars?) the Nick.

So here I am, fixing code that one of our old, evil programmers wrote long ago, and I stumble across a script. This script needed a list of the days of the week, as well as some other day periods like “Monday-Friday”, in an array to put into a <select> box later, but the way this array is generated just… boggles the mind:

for($k=0; $k < 7; $k++ ){
    $days[] = date("l", strtotime("2006-05-".$k));
}
Posted in Coding, PHP, WTF?! | Leave a comment

JavaScript frameworks and Juice

I’ve been toying around with some code that – while not needed – would benefit greatly from a nice JavaScript enhancement framework.

After going through Prototype and not being very happy with the functions, steep learning curve or feeling of bloatyness, I’ve settled on JuiceLib. It’s a nice, small and clean framework, that adds just what it needs to and nothing more.

One of the features I really like is to be able to submit a form via AJAX and have the results return without needing to do a page refresh. Very useful when you’re updating simple form fields and need instant feedback.

Posted in Coding, JavaScript | Leave a comment

Fun Fact!

Thunderbird/Firefox’s dictionary knows the word ‘guesstimate’

Posted in Language, Mozilla | Leave a comment

My comments

I’ve always been known to comment my code fairly verbosely. I’ll put in little niggles I had while writing the code, and sometimes – like in the following snippets – what I think of either code I’m writing, or code I’ve come across that others have written.

Going over the code I’ve been working on for the past few weeks (SMS module for our software suite) I’ve found a number of comments that I’ve jotted down that I chuckle at as I read over the code, debugging…

  • // suppress - same as above, but recip list will be suppressed... (this is a bitch to implement and i rue the day i suggested it)
  • // i loathe to be the next person that needs to change something in here, however.
  • // ugly, but it works... i guess...
  • // this whole function sucks the big one, but i'm lazy and just want this thing out of the way!!! (note to self; fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it fix it)
  • var $soap; // mastar soap object lawls.
  • // i don't know what this does
Posted in Coding, PHP | Leave a comment

Plural function

I know it seems basic, but I wrote this a while ago and use it in many many applications I’ve written. I’m surprised alot of languages don’t have something this simple in a small, native function…

Takes three arguments: number, singular and plural.

Basically, if number is plural (!= 1), return plural, else return singular, as per the following PHP code:

function plural($num, $singular, $plural) {
	if ($num != 1) return $plural;
	return $singular;
}

Useful when writing copy that needs to read correctly, eg: You have 0 credits; You have 1 credit; You have 2 credits.

You could write:

print "You have " . plural($num, "$num credit", "$num credits");

*shrug* I like it.

Posted in Coding, Language, PHP | Leave a comment

LOLCODE

Oh dear…

Posted in Coding | Leave a comment

PHP + Unicode = Shit

Working on trying to get Chinese and Japanese characters to transmit correctly over email, a major problem is that in using PHP to process the text, PHP can’t handle the characters for shit and I got absolutely nowhere. Grr.

I took this article from this URL, in case the link ever died and I needed to look at it again.

Continue reading

Posted in Coding, Language, PHP | Leave a comment

Quote

From the author of Space Moose (name unknown)

Of course, it’s easy to say offensive stuff without using forbidden words like “Fuck”, “Shit”, etc.. In North America, these words induce idiotic knee-jerk reactions, and can offend even when taken out of context. Here’s a little experiment you can try. Go up to a total stranger in North America, and say in a big booming voice, “CUNT!” They’ll get pissed right off. And why?! You didn’t really say anything. You didn’t say, “your mother has a great big cunt,” you just said, “cunt.” You could be talking about anything. Anyway, I just think that people should smarten up and stop banning things like words.

Posted in Language | Leave a comment

Note to self:

Keep an eye on the size of apache’s error logs. I don’t like seeing this

-rw-r–r– 1 root root 114184167424 2007-05-25 15:06 error.log

Posted in Linux | Leave a comment

My collection

This is just where I’ll be storing my collection of interesting pieces of information that I come up with.
Code snippets, Linux tricks… stuff like that.

That is all.

Posted in General | Leave a comment