Blog posts tagged "special"

On the second day of Kirby Week, Four Island gave to me: a tutorial on pretty error messages.

Disclaimer: The post assumes you have Rails 3. It may work with Rails 2, but I dun know about that. Just to be safe, go ahead and install Rails 3. :P We good? Great.

Hi, 'yall! It's me! Do you know what's sort of annoying? Rails is really wonderful with all the things you can do with models. Specifically, validations are just great, and most of the time, they're really pretty too (because Rails is about Readability!), so you can write beautiful code like this:

validates_presence_of [:anon_name, :anon_email], :if => :anonymous?

You see? In one line, I made it so that the model checked for the presence of "anonname" and "anonemail" when "anonymous?" returned true. That's just great. However, there's a problem with this that you may be able to foresee. Let's see what kind of error messages are returned when "anonname" and "anonemail" are left out:

Anon Name is blank Anon Email is blank

That's not really that user friendly, is it. Oh well, we can just change our code a bit, right? Make it a bit less pretty?

validates_presence_of :anon_name, :message => "Your name is blank", :if => :anonymous?
validates_presence_of :anon_email, :message => "Your email is blank", :if => :anonymous?

It's a bit longer and clunkier, but it should work, right? Nope.

Anon Name Your name is blank Anon Email Your email is blank

D'oh! After searching around the Internet, the only solution I could find was this disgusting jumble:

validate do |comment|
  if comment.anonymous?
    comment.errors.add_to_base("Your name is blank") if comment.anon_name.blank?
    comment.errors.add_to_base("Your email is blank") if comment.anon_email.blank?

Now the error messages are correct, but the code itself is horrendously disgusting. I can't settle for that! Well, it turns out that there's another way. A way that works with the first method of validation shown above, the one that validated both fields in one line. Yes. Go back to that. Next, look inside your config/initializers folder for a file called "inflections.rb". Add the following to the bottom:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.human "anon_name", "Your username"
  inflect.human "anon_email", "Your email"

Now, restart your server and check your error messages. Guess what?

Your username is blank Your email is blank

This works because the inflector is used to humanize the names of fields before they are prepended to the error message. By customizing how the inflector humanizes the field names, you can effectively customize your error messages! Horray! The inflector can be a good ally once you learn how to use it properly because Rails humanizes things in a lot of places. Let the inflector be with you. Okay. I should end this post now. :P

Hatkirby on December 14th, 2010 at 12:30:07pm
πŸ‘ 0 πŸ‘Ž

On the first day of Kirby Week, Four Island gave to me: A tutorial on how to get Rails 3.

Oh my god, it's Kirby Week. That. Was. Fast. I just remembered yesterday (which was the first day of Kirby Week, but I didn't have to post on Sunday anyway) that I usually post once a weekday for Kirby Week (except Friday, which I have traditionally failed at life on :P ). Right. Anyway, since I have been doing a lot of work with Ruby on Rails recently with Four Island 3, I think I should focus this year's Kirby Week on Rails! :D

Now, I have been using Rails 3 to develop Four Island 3 (OH MY GOD THE THREES! RUN AWAY!!!!!) and it's quite nice. It doesn't seem beta-ish at all, and do you know why? Because it isn't beta-ish at all! :P Today, I'm going to show you how to install Rails 3 (as well as some other stuff) onto your computer because Rails 3 is pretty awesome yo dawg business. O_O

Now, as you may know, Rails 3 requires Ruby 1.9. Ruby 1.9 is pretty awesome, but it breaks a lot of old Ruby programs, so we're going to install it alongside your system Ruby installation by using something called "rvm", or the Ruby Version Manager. Note that this will only work on UNIX-based OSes, that means Linux and OS X (no Windows! :P ). First, ensure that you have "git" installed. Second, open a terminal and run this command:

bash < <( curl )

It seems pretty mysterious, but all it does is download rvm. You're not quite done yet--you have to inject rvm into your bash session. To do this, follow the instructions that the above command showed you, or just add this line to your ~/.bash_profile file:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

Next, open a new bash session or just source the profile (source ~/.bash_profile) to load rvm into your session. Finally, just ensure that everything worked by running the following command:

type rvm | head -1

If it replies with rvm is a function, then congratulations! You've successfully installed rvm, and not much else yet! :P Just to keep things safe, run rvm notes to see if there's anything special you have to do for your particular operating system (for instance, I believe you need to have Xcode installed for OS X).

Great! Now, let's install Ruby 1.9.2. It's fairly simple--just run the following commands:

rvm install 1.9.2
rvm --default use 1.9.2
rvm default

The first line is the one that will take a while, but it's a fairly simple process overall--it just installs Ruby 1.9.2, sets it as the default ruby and then chooses it to be the interpreter for the current session.

Finally, let's install Rails 3. Run the following command:

gem install rails

Note that you should never use sudo when installing gems when you are using rvm. Anyway, yes, it really was that easy. Now that you have Rails 3 installed, you should explore the great wondernesses of its wonderness! :P You should read that page. Yes. Anyway, I'm going to be writing about some cool tips and tricks of this you can do with Rails this week and it's going to be great. :D And, now that you have Rails 3 like I do, you can be sure they'll work! :P

Oh, and if you ever want to switch back to your system's default Ruby, run this command:

rvm use system
Hatkirby on December 13th, 2010 at 12:30:13pm
πŸ‘ 0 πŸ‘Ž

On the fourth day of Kirby Week, Four Island gave to me: A deeper insight on the true meaningful nudules of randomness.

Randomness is a trait. It's also a blog, but we're talking about the characteristic here. So, what is randomness. WLEll of carser oiyoar know RANODMES S I shyperactivity!!!!!!! pbuttu!!!! Well.... no, not necessarily. You don't have to be a radioactively hyper sheep to be random. Randomness comes from within. Yeah right. :P

Randomness isn't really anything. You want to be random, go run outside and pull a tube-sock over your head. Write a story about someone's brain falling out. Oh dear, I do believe I feel a list coming out!

  • Write a poem on a banana peel and then place it in front of your bedroom door.
  • Exclaim your love for Russian mashed potatoes.
  • Learn how to do the Macarana.... backwards.... twice as fast.
  • Eat a computer.
  • Radioactively reproduce Shakespeare's complete body of work. (This one requires fourteen lifetimes of practicing, so we don't expect you to complete it)
  • Write a post about random stuff as a cop-out because you have a deadline in 12 minutes.
  • Throw one of your favorite belongings into an empty trash bag, dance with it and make sure it knows how to spell "marfsky".
  • Try new things. I've heard catfood is tasty.
  • WRITE WRITE WRITE. Writing a random story is seriously fun and easy. Just think about the stupidest possible thing that could happen AND MAKE IT HAPPEN TO GEORGE WASHINGTON!!!! It never fails.
  • Moderate comments.
  • Listen to the collected works of Ludwig von Beethoven. Backwards. With each song logarithmically faster than the previous one.
  • Download 200 pictures of lolcats, print them out and decorate your favorite mausoleum with them.
  • Sing. Lady GaGa songs. Of course, it has to be backwards.
  • Read a book on advanced physics and apply it to garbage collection in modern programming languages.
  • Make a website about something you enjoy. Such as dust-mite finding. You like finding dust-mites, amrite?
  • EAT A MOOSE. Fine, it can be dead.
  • Using red litmus paper, test various household objects for acidity and alkalinity and then throw them out the window and watch Spongebob Squarepants.

As you can see, there are many ways to be random. INVENT YOUR OWN, DUDE. See? That was random. Be random, spread happiness and try to ignore the fact that this post is so obviously a cop-out. Comment! :P

Hatkirby on December 17th, 2009 at 11:58:32pm
πŸ‘ 0 πŸ‘Ž

On the third day of Kirby Week, Four Island gave to me: A review of a random web-service.

HI. Welcome to Wednesday. Kirby Week is halfway over, how sad is that? Anyway, today's post is not as late and not as completely insane as yesterday's. Today, I'm reviewing Google Wave!

Okay. I'm not usually the first to know about something and this is no exception. I only found out about Google Wave about two months before it was released and that was only because Bluemonkey was ranting about it for some reason that I can't be bothered to check my chat-logs for. :P I wasn't really that interested.... that is, until I saw the features.

Google Wave boasts equal parts conversation and document. I didn't really understand that at first. Perhaps I still don't. All I did know was that it looked cool and people were apparently going nuts over it.

I finally received an invite from Bluemonkey and got to discovering. Google Wave seems to be a way to communicate and collaborate efficiently and quickly (in real-time, in fact). The thing is, however, I don't really know what I'd use Google Wave for. If I want to chat with someone, I'll use GTalk or Skype or Yaplet (which we are bringing back! :P). There isn't really anything compelling me to continue logging in and checking for new waves.

Not to say that my feelings toward Google Wave are completely negative. Wave seems to have some pretty neat applications. It's just that I haven't really found a need for any of them.

To end off this post, I'm going to present you with a surprise! I finally received my Google Wave invites today! So, if any of you still don't have Google Wave and would like to join in, please comment and I'll send you one! :D

Hatkirby on December 16th, 2009 at 10:34:51pm
πŸ‘ 0 πŸ‘Ž

On the second day of Kirby Week, Four Island gave to me: A short story about nothing in particular.

It was the first day of Christmas.

"Wait," a voice yelled, "Christmas only lasts one day! By saying the 'first' day of Christmas, you're implying that there is more than one day!"

For the sake of continuity, can we simply assume that there are more than one days of Christmas?

"That sounded really grammatically incorrect, you know."

Shut up. Just.... shut up. Anyway, it was the first day of Christmas. The snow had blanketed the beach house and everything around it so everything looked peaceful and-

"....snow? At a beach house? As in, on the beach? Not likely. And when you say that it blanketed everything around it, you're implying that it also blanketed the ocean. You know, the one adjacent to the beach the beach house is doubtlessly on?"

You don't have to take everything so seriously, you know. It's just a simple story. And a beach house doesn't necessarily have to be next to a beach.

"Yeah, well, stereotypically, you will find beach houses on the beach."

My beach house is in Iceland, okay? Moving on....

"You do know that Iceland is the one with the green, right?"

Don't make me come out of here.

"You're just a narrative device used to tell the reader of the story what is going on without using dialogue. You can't hurt me!"

I'm best friends with the writer of this story. She'll erase you if you don't qwazam.

"Seriously? You're making up words now?"


"Hi there! Guess who I am."


"Yes, I like to write confusing stories. Good luck with that whole multiple personality disorder thing."

She walked away laughing, leaving the narrator very confused. Soon, however, the story was over and everything vanished.

Yes, okay, that story was very odd. But, well, that's what you get when you promise PROMISE to write a blog post and then fall asleep and laze about until you are only three hours away from your deadline. Tomorrow's post should.... make more sense. :P

Hatkirby on December 15th, 2009 at 8:59:55pm
πŸ‘ 0 πŸ‘Ž

On the first day of Kirby Week, Four Island gave to me: An extremely weird rant on what Starla did last weekend.

Hi peoples, and welcome to the first day of Kirby Week. I'm sure you're all super-spectacularly excited for the upcoming holiday, yes? Well, today, I'm rewinding a bit to the weekend when Advent 2 ended and Kirby Week started. Some weirdly cool things happened that I fell like talking about.

First, on Saturday, I was bored. I didn't know why I was bored because I had plenty of things to do: work on Pillowcase, work on FourSearch, implement many of the pending renovations currently required around Four Island, work on the HKRPG site, work on one of my games, or anything else listed in The Bet. But, instead, I continued to be the queen of procrastination, and did nothing.

So, it was with boredom that I opened Google Reader. Oh yes, that's right, it's Saturday, none of my usual humor blogs had updated. I did notice, however, that TimTam's feed had over a hundred unread items in it. I decided to work that number down to a reasonable (0) amount.

That totally didn't work. The first post I read was a list of Lifehacker's best posts during 2009. Among that list was an article on how to install the Homebrew Channel on the Wii without needing the Twilight Princess hack. I had previously found out about the Homebrew Channel (it was The Daily WTF, actually) but was always annoyed because I didn't have, nor had any intention of getting, Twilight Prinecss.

Excitedly, I fetched my SD card from my broken camera and followed the instructions. Amazingly (because cool things that I want to do never work), it worked perfectly. The Homebrew Channel sat peacefully in the Wii system menu and I was ecstatically excited.

If you know me, you may not know that, among my normal programming, I also like to indulge in some homebrew programming. I've written for the GBA and the DS (both required special cartridges to put the homebrew games on and both have been lost by my evil siblings) but now I could possibly write something for the Wii! And as I was pondering this, the perfect training exercise that would get me into programming for the Wii popped into my head: I would port Maze Of Life to the Wii!

For now, however, I just wanted to play something fun. I ran back to my computer and looked through the list of homebrew applications to find something cool to play. As I was scrolling through the list of games, one caught my eye. POWDER. I sort of freaked out at that. POWDER is an extremely fun roguelike that I (during my DS homebrew days) had previously playing on my DS. I remember it to be an extremely fun game. I don't, however, remember being any good at it. :P

So I downloaded it (and a few other games including a super-cool looking port of SuperTux) and loaded it onto the Wii. I immediately became hooked. Yes, obsessively so. I played that game for two hours straight today, and many more not in succession. I even found the Linux version of POWDER and started compulsively playing it on my computer. I was even.... doing well, occasionally! :P If you've never played POWDER, you must do so. Seriously.

One other cool thing I did on the Wii was downloading the port of Visual Boy Advance (a GBA emulator). I had this emulator on my computer and (during my GBA homebrew days) used it to test my GBA games. However, it was difficult to play actual games on it because the keyboard isn't the intended controller for these games. So, I couldn't enjoy my Kirby Amazing Mirror ROM (I had lost the physical copy of this game years ago and really wanted to enjoy its amazing funness again). So, my grand idea was to use the Wii, VBA and the Classic Controller to play the game in its full greatness. And what do you know, it totally worked. Yippie for me. :)

So, I hope you've enjoyed this randomly long post. I'm off to play POWDER now.

Hatkirby on December 14th, 2009 at 12:52:45pm
πŸ‘ 0 πŸ‘Ž

Wow. Nobody even attempted to misguide me into thinking The Fourm was alive and well. And I'm pretty sure I voted "LADY GAGA IS AWESOME" three times. So there. :P

SADLY YES CRY O_O FSDSF - 3 vote(s)! Um.... whut? It's a series of electrical impulses, it cannot die. - 0 vote(s)! LADY GAGA IS AWESOME - 3 vote(s)! Indifferent - 0 vote(s)!

Sorry I updated late again, but yesterday I was having this weird problem where I wasn't able to log in. I tried logging in and it wouldn't even give me an error message. I eventually figured restarted Google Chrome and it worked, oddly, and that leaves me with no excuse as to why I didn't update the poll yesterday. Oh. :P

Anyway, has anyone realized what today is? Yes, it's Kirby Week! For those who can't be bothered to follow the link and find out, Kirby Week is the third week of advent, the week in which is candle is pink. I know, I know, I'm hilarious, right? :P

Anyways, it's become a bit of a tradition (how can I say that? I started it last year!) to do something special for the week on Four Island. Last year I wrote a series on how to write a blog system (and yes, that series was a total failure :P), but with my dismal posting rate this year, I don't think I can. This year, my Kirby Week goal is to publish one post everyday this week. Yes, you heard me, I'm going to post.

I can hear you all gasping.

I've prepared (okay, that's a lie, read: I'm going to prepare) 5 posts, one for each day of the week. They probably will not be related, but my goal is to ensure that there is at least one post in pending queue by 12:30 every day this week. Be prepared. Be prepared.... to throw things at me if I don't live up to this goal. Seriously, if I fail, throw full bottles of wine at your computer screen. Thank you.

And if you've noticed, yes, I'm continuing another Kirby Week tradition that even extends back to Kirby Week 2007, the Kirby Week poll. :P

Hatkirby on December 13th, 2009 at 9:53:18pm
πŸ‘ 0 πŸ‘Ž

You must be looking at this post and thinking, "Ok, what?" Yes, probably. I really don't know.

Anyway, this is just a rant. And it's about my iPod. It's a new (well, two months new) Chromatic (yellow and pretty) and works pretty well. However, randomly, during arbitrary songs, the music will suddenly STOP.

And then, you know you have to hurry if you want to keep listening to that song. When that happens, I have to rip the headphones off of my ears and unlock (take out of HOLD) the iPod. At that moment, the iPod will make a very loud noise. So loud, you can hear it quite clearly even without the headphones on. "Oh, goodness," you should think to yourself, "I just saved my eardrums."

Immediatly after I do that, the music starts playing and the pause button doesn't respond for a few seconds so I miss some of the song. :( This is really annoying, and I don't know why it happens. Does anyone know? Knowing Apple, is it a feature or a bug? :)

Anyway, yes, you can say it.

"Ok, what?"

Hatkirby on December 21st, 2008 at 12:32:03pm
πŸ‘ 3 πŸ‘Ž

On the fifth day of Kirby Week, Four Island gave to me: An way of making URLs look prettier.

As I promised yesterday, today I'll be showing you how to use prettier URLs to reference your blog posts. We'll be removing the query string.

In this tutorial, I'm assuming you're using the Apache web server with mod_rewrite enabled. Otherwise, you'll probably need to read more elsewhere when we get up to the .htaccess file.

Speaking of the .htaccess file, let's do that now. In your kirbyweek08 folder, create a file called .htaccess and put this in it:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/ read.php?slug=$1 [L]

Well, that's yummy-yay-yay, but the read.php file does not yet accept a slug parameter. Let's add that functionality now with an upgrade to the read.php file. Find the line that says:

$getpost = "SELECT * FROM posts WHERE id = " . $_GET['id'];

Replace it with the following:

if (isset($_GET['id']))
 $getpost = "SELECT * FROM posts WHERE id = ";
 $getpost .= $_GET['id'];
} else if (isset($_GET['slug']))
 $getpost = "SELECT * FROM posts WHERE slug = \"";
 $getpost .= $_GET['slug'] . "\"";

This will allow read.php to parse slugged URLs. Now that Prettiful URL support has been added, you think you're done, right? Wrong. We have to fix the links to read.php in functions.php and rss.php.

Within functions.php, there are two occurances of this partial line of code:

<A HREF="read.php?id=<?php echo($sqlOutput['id']); ?>">

Replace both with:

<A HREF="<?php echo($sqlOutput['slug']); ?>/">

Of couse, remember to replace with the path to your blog.

In addition, the following partial line of code appears in rss.php:

/read.php?id=<?php echo($getposts3[$i]['id']); ?></link>

Replace it with:

/<?php echo($getposts3[$i]['slug']); ?>/</link>

And there! You're done! You've added prettiful URL support to your blog! YAY!

Tomorrow we'll be discussing other small improvements you can make to your homebrew blogging system.

Hatkirby on December 18th, 2008 at 12:30:25pm
πŸ‘ 3 πŸ‘Ž

On the fourth day of Kirby Week, Four Island gave to me: An article about implementing RSS.

It's another day of Kirby Week which means another tutorial! Today's post will be short because there's not that much to dynamically creating an RSS feed. What's that, you say? You don't know what RSS is? Le gaspez!

RSS stands for Really Simple Syndication. It provides a list of your latest blog posts (or anything, really, RSS can also be used nicely for things such as comments) in a format computers can read. This way, a computer can more easily tell if you publish a new blog post, for instance, and notify anyone who wishes to be notified.

RSS is an XML specification, so the entire thing is based upon a system of tags. Let's get to writing it!

Create an rss.php file in your kirbyweek08 folder. The root tag is the <rss> tag, with a mandatory attribute (version) that has to be set to 2.0. So, our document current looks like this:

<rss version="2.0">

Every RSS feed has to contain a <channel> tag with information about the feed in question. Let's populate it with some default data that you can change:

<rss version="2.0">
  <title>Kirby Week 2008</title>
  <description>A description! YAY!</description>

The fields introduced above should be pretty self-explanatory. The next thing to do is to dynamically introduce the latest 10 blog posts into the <channel> tag. I've done that here: Ensure you replace all instances of in the code with the path to your blog.

So, now you've got a feed. That's great, however, people probably won't know its there. Open up your custom header.php file. Somewhere between your <HEAD> tags, add this snippet of HTML:

<LINK REL="alternate"
      HREF="rss.php" />

Now that you have an RSS feed, there are other options to consider, such as using a service like Feed Burner to "burn" your feed. Feed Burner can track subscribers, links clicked on, suspicious uses and other things, for instance, making your feed look prettier with little widgets at the bottom of each post.

Currently, the URLs we use to access each of your blog posts are kind of ugly (they all contain read.php?id=). Tomorrow we'll focus on removing the query string from the blog post URLs.

Hatkirby on December 17th, 2008 at 12:38:32pm
πŸ‘ 3 πŸ‘Ž