Static vs Dynamic

September 28, 2009

Since I’m now officially a wizard (Immortal/coder) on SWMud, I figured I’d share some LPC knowledge. I’m constantly improving and optimizing my own code based on looking at code belonging to so called ‘experts’. Along the way, I’ve learned a few things.

For this entry, we’re simply going to compare two types of coding. And in this particular case, I only have one really good example. I’m sure you could think up hundreds more once you put your mind to it.

Below is an example of code I see all the time:

   1: switch(random(2)){ 

   2: case 0: write(“Random thing 1.”); 

   3: break; 

   4: case 1: write(“Random thing 2.”); 

   5: break; 

   6: case 2: write(“Random thing 3.”); 

   7: break; 

   8: default: write(“Random broke.”); 

   9: }

First things first, remember that random() ranges from 0 (zero) to the integer you specify. People often forget this and don’t include a case for 0 in their switch statements.

The above code is not very dynamic. It’s written easily, with beginner skills (not to say that some experts wouldn’t use it, it has its uses). The trick to this code is that every time you want to add a new random thing, you have to edit your switch statement to increase random(), AND add another case. This code is static. It’s not meant to be easily updated, it’s meant to do its job.

What about this code?

   1: string *things;

   2: things = ({ "Random Thing 1.", "Random Thing 2.", "Random Thing 3." }) ;

   3: write(things[random(sizeof(things))]);

This code is much more dynamic. We’re providing the exact same end result, but now the code is smart enough to know how many items it has to iterate through randomly, without having you add more cases to a switch statement.

We define things as an array of strings. An array is just a collection of stuff, remember. Then we set ‘things’ to be a collection of three strings, the same strings we would’ve used previously. Finally, we write a random member of the things array to the user. sizeof() is used to get the absolute size of an array, so that number will always be the exact number of members in your array, no matter how many things you add to it. You should already know that you can refer to members of an array by their index in that array, so things[0] would return the first member of things. This works to our advantage here, where we pull that number using random() and sizeof() combined. So randomly, things[0], things[1], or things[2] will be written to the user.

Pretty nifty, eh?

image I decided to rearrange my laptop’s desktop. I saw these sweet desktop backgrounds on Lifehacker and I figured “Why not?”

As you can see, my icons aren’t organized in any particular fashion that you might recognize… they’re arranged according to how often I use ‘em.

Often-used programs go on the sticky.

“Work” and other things I access fairly often go onto the file folder or the cubicle wall. (What exactly is that anyway?)

Everything else goes around the outer edges of the screen. A digital no-man’s-land of icons. Those who didn’t make the cut, per se.

Now if only it was this easy to organize my house.

Evernote = EverLove

July 18, 2008

imageI’m hooked! I recently checked out Evernote and I think I’m in love. This awesome app is basically a mega-clipboard. You can copy screenshots, formatted text, images, even insert audio and video. It’s got a very cool windows client, and the best part is that it has an iPhone/iPod Touch client, so those people can quickly and easily collect digital scraps of whatever!

I used to use Jing for my screenshotting, and I probably still will use it for a bit longer because I like to be able to save my screenshots immediately, etc. Though I’m sure if I hunt around in Evernote I’ll find all those features that I like about Jing. I already like how Evernote takes over the Print Screen key and makes it a shortcut to Evernote’s screenshotter. One press of “Print Screen” opens an Evernote screenshot box that you can place on your screen somewhere, resize, and more. If you hit “Print Screen” again, you can now add overlays to the screenshot (such as arrows, or handwritten text), finally hit “Enter” and your screenshot is now in Evernote. Cool, huh?!

Man, I can’t wait to paste in some formatted text and collaborate with people on how it should look.

At my place of work we use a highly sophisticated spam filter to sift out all the crap emails we receive daily. It’s extremely effective, but since we can’t be sure we haven’t missed any legitimate emails… we have our receptionist look through the spam emails daily. After a week of doing this I can surely tell you that it’s definitely one of the dirtiest, unrewarding, grating jobs you can ever do. Here are some statistics:

  • On a daily basis we receive anywhere from two to three thousand spam emails.
  • Of these 2-3,000 spam emails, one or two (per day) are legitimate.
  • Every minute (on average) we receive 10 to 20 spam emails.
  • Most of the spam (~80%) is legitimate bounce-back emails from mailservers stating that spam we sent couldn’t be delivered. This is because spammers harvest email addresses and forge spam emails using them.

All in all this adds up to a lot of crap. This entire week I have yet to reduce the unread spam emails to zero. Every day I might read through a few thousand, only for that few thousand to be replenished the next day. Currently the spam inbox is sitting at 5604 and counting (I’m watching more trickle in right now). Luckily at night we employ a much more strict ruleset so that the spam is reduced to a few hundred, but just think if we didn’t have that option… we’d have seven or eight thousand spam emails to sift through per day.

If you know someone who has to look through spam daily to retrieve legitimate emails, pat them on the back. Tell them you understand and sympathize with them. In fact, tell me that before I tear my hair out.

The Colour of Spring

March 20, 2008

I recorded a little how-to video for changing colours in the windows command prompt (AKA a Dos Box). Hit the jump and let me know what you think.

Link to Video

Firefoxlogo2 I just updated my Firefox3 to Beta 4 last night and I must say I’m impressed. Though, I was impressed with Beta 3 so perhaps I’m just impressed with FF3 overall. A revamped toolbar, speedier response time, and many other noticeable improvements make Firefox 3 a superb next-gen browser. You may want to wait though seeing as it’s still in beta, and it’s still bleeding edge. Hit the jump to grab your own copy.

Download Firefox 3 Beta 4

A Spin-Off Already?

February 12, 2008

SoylentCola For a few months I was maintaining a blog I affectionately called “SoylentCola.” Due to some software issues, and bad timing, I was unable to continue updating the blog and it began to stagnate. I felt pretty bad when I had to let my poor little blog sit and grow old. I would keep coming back, if only to clean off the dust and pretend I was going to fix the damn thing. I’ve got good news, though…

SoylentCola is coming back!

Stay tuned to SoylentCola.com and you’ll have a sneak peek at my latest project.

Current Events

February 12, 2008

If you’ve been keeping up with the news lately then you’re probably aware that Microsoft offered a $44.6 billion bid on Yahoo!. Recently, Yahoo! turned down the offer. They feel that Microsoft has “undervalued” them. Microsoft responded, and they feel that the offer is fair. Yes, I just went through a week of news in 30 seconds. Why did I just pass over this like I’ll be passing over the entire Valentine’s Day? Because this isn’t big news anymore. What I’m trying to say is that we’re so used to crazy business deals, unethical business practices, and gussied-up media hype, that even a bid on Yahoo! by Microsoft doesn’t phase us. There were many a blog that reported on the deal, and of course it made it into newspapers and TV news, but it didn’t become an “end of the world” style foretelling of the future. It’s just business. Thank goodness for that. And even though the current news is that Yahoo! rejected the offer, that doesn’t mean Microsoft is going to drop the issue. Just like the kitty in the picture, they’re biding their time…

Rock Band is a hit.

February 4, 2008

This past Thursday, Jan 31st, Oyen Wiggs Green & Mutala LLP had a staff Beer & Cheer. It’s basically just a staff party once a month to keep morale alive and give everyone a nice break. This one was special. It was supposed to be a “Games Night”, according to the flyers floating the firm. I decided to bring my new Xbox360, and “Rock Band.” What follows is a short excerpt from that evening…

WHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!

Yes, that sound was heard a lot. Rock Band was a hit at the party. Multiple people stepped up to try out the drums, guitar, even the singing! I managed to record a bit of video, and I’m very glad I did. This game brings people together like nothing I’ve seen, except perhaps a good ol’ fashioned book burning.

Unfortunately I hadn’t unlocked many songs yet, and we were missing a particular adapter so the sound was terrible… but all in all I think everyone had a great time. This is a game I plan to bring to every event where it would be appreciated. It’s perfect for anyone, gamers and non-gamers, musicians and non-musicians alike, Rock Band caters to all. (The drums are so much fun.)

I came across a great little free software package today called Revo Uninstaller. This awesome program produces a screen very much like the built-in windows Add/Remove Programs control panel utility but it contains so much more.

2008-01-29_1203 At first glance I wasn’t sure what to expect, except that the website stated all sorts of neat things and I wanted to see them in action! First up, the uninstaller. To your right is a screenshot of the uninstall portion of the program. It lists all your installed programs (as far as I can tell) and easily lets you uninstall a program or just remove an entry. The “remove entry” feature is very useful, I don’t know how many times I’ve had to manually delete a program and had its entry left behind in Add/Remove Programs. Revo solves that problem!

2008-01-29_1206 Also included (still free!) is the junk file cleaner. Seen here, the list of junk files is empty. I would’ve run the scan to give you an idea of what it shows, but the scan takes a while. Revo will offer to delete any of those junk files, and will even inform you if it can’t remove any files due to them being in use by a program or by windows. Very nice.

I’m certain I’ll be using this tool a lot, as it’s already proven useful in the half-hour I’ve had it. If you’d like your own copy, visit the download link below.

Thanks to Kent and his blog for leading me to this software.

Download Revo Uninstaller Freeware – Free and Full Download