Paying It Forward

As an avid gamer, I often find myself perusing various subreddits and watching streams in my spare time. Among those is the Day[9] Daily, a regularly-scheduled livestream by Sean “Day[9]” Plott. Now if you’re not in tune with the Starcraft scene in the slightest, Day[9] means nothing to you. If you are, however, The Day[9] Daily is one of the most-watched live streams about being a better gamer, for the love of the game. Each show, Sean takes questions and answers them live. He’s able to do this with the infamous “Question Grabber”.

The Question Grabber, was written by Marky Ochoa, who at the time was just a loyal Day[9] fanboy, but now works as part of Day9TV. And this post is about Marky.

In August of 2012, Marky posted on the Starcraft subreddit, announcing The Question Grabber was available for public use, but also asking for help. He was having trouble paying his hosting bills, and was asking for help keeping the site going. As a fellow programmer, I pulled some of the profits out of my web hosting and sent it his way. Marky was a sir, replying back to me shortly after the donation. (Unfortunately, his server crashed and took the whole page with it — something that has happened to me before; it’s painful!)

Just minutes ago, I was shocked to find an email from Marky in my inbox. Attached to it was the donation I sent to him, and a thank-you message for the donation.

I can’t accept the money, though.

I gave him that money knowing full-well that I wouldn’t get it back. A fellow programmer and supporter of a common cause was in need, and I was happy to help. I’m also happy to know that he’s no longer in need of the extra cash. Instead of holding onto what he sent me, it makes more sense to give it to somebody else in need — something that falls under a common cause that we support.

Cue: Child’s Play Charity.

So Marky, thanks for not forgetting about the people who helped you out before. Instead of holding onto the cash though, there’s some sick kids out there that need this money more than I do. You rock, man!

marky[sir-level] => 9000


Photography Update: Dec. 20 2010

In a moment of stupidity, I had an energy drink at 11:30pm last night while at a friend’s party. Needless to say, at 3:03am the following morning (ie. today), I am unfortunately still awake. I guess I got what was coming to me.

On the plus side, that now means that I had the time to go through some of my photos that I’ve taken since the last photo update, pick out a few of the decent ones, and prep them to go up on time today. I have some photos from the last blues class at UMSwing, our year-end potluck, and my friend’s potluck that I attended last night (or was it today? I guess I left after midnight…).

I added the ability to vote on specific photos and a gallery as a whole now, so when you view an image that you like (I hope there’s at least one or two!), you can give it a good rating :P. Of course, comments on the album are always welcome.

Without further ado and without further caffeine-induced ramblings, here’s the photos!

[nggallery id=20]

Where I’ve Been

For the past four or five months, I haven’t had much of an online presence. In an effort to keep people updated (and perhaps explain the lack of posts), I have here a brief summary of my past few months, including notable purchases, projects, and job changes.

At the start of May, I started working a 16-week contract job working for the RCMP. Overall it was an interesting experience. I got to see the inner workings of Canada’s federal police force, and I got some hands-on experience working in a support environment. The work was not challenging in the slightest, but it paid well and I worked with some good people. In the interest of not breaking the law and violating my security clearance, I won’t go into any more detail.

Along with the very nice pay check I was getting was a goal I had of purchasing a new vehicle. My old car, as you may recall, was an old 1994 Plymouth Acclaim. After a few months of looking around, I settled on a 2006 Ford Focus ZX5 SES with manual transmission (oh, how I missed you). I pulled out my sound system from the Acclaim and put it into the new car with some mods that I’m very proud of (post coming next week!), including a new custom-built sub cabinet and custom-built trunk privacy screen. I also put some time into doing some lighting mods, and I even had to pull out the sewing machine for a few parts. All in all, I love the car; it’s far better than my old vehicle.

At the start of May, I took over the position of President with the University of Manitoba Swing Dance Club, which has been an exhausting experience, but definitely well worth it. I redesigned the website, and I have a great executive to help me out. Although my delegation skills need some work, I’m confident that my executive this year will keep me in line, and I in turn will unload work on them :). Our open house is today, so you should all come out! We have tons of things planned for this year, including potlucks, live band events, movies, and more.

I have also started doing some private contracting for my web development and computer skills, earning the occasional few extra dollars. A year ago, I started Windfire Hosting to offer cheap web hosting to friends (only $5/month!), and I’m pleased to say that I’m finally making a bit of “pizza ‘n beer” money off of it. I’ve started offering web development along side my hosting, so I can always guarantee that my applications run on the server it will be deployed to. Most notably, I’m building a photography portfolio for my friend Miguel; his site should be up within a week or so, so check out Chrestos Photography when it goes live.

If I ever had free time on a weekend, a couple friends and I started getting back into gaming of all sorts: board games, consoles, and tabletop role-playing. We’ve gotten on a regular schedule, so my friend Tyler (one of them) started a podcast called “I, Gamer“, which has actual play recordings, discussions about multiple gaming topics, and some random philosophical talks. If you’re interested in gaming, I highly recommend checking it out, and I’m not just saying that because I’m a regular contributor and I’m responsible for the podcast recordings.

Last but not least, I have university to contend with, including two of the hardest computer science courses offered at the undergraduate level: automata and cryptology. All of my courses are really interesting (at least the content is), so hopefully my other time commitments will not interfere with my studies.

Next week, I’ll have a post talking about some of my car mods that I’ve done, along with a bunch of photos of the partially-gutted interior, the finished mods, and more.

Dynamic Named Routes for Semi-Static Pages in Rails

When I was designing the new UMSwing website, I had a few issues that, at the time, I didn’t have a clean method of implementing. One of those was the creation of semi-static pages. After watching this episode of Railscasts, I had a pretty good idea of how to implement them. The only issue with the solution offered was the lack of dynamically generated routes.

Semi-static pages are used everywhere on websites. They’re those pages like an “About” page, which has content on it that doesn’t really change that often. Typically, a controller would have to house these actions (/about, /faq, /contact, etc.), and  the routes specified manually. Railscasts came up with an ingenious idea to create a controller which was routed to /static/*, so that semi-static pages could be created on-the-fly and modified easily. It also allows for modifications to change without committing to a repository and going through the process of deploying all over again.

For those needing a quick Rails primer before going on, here’s the quick and dirty of what you need to know to understand this:

  • Rails is a MVC-based web application framework that runs on Ruby. In short, Ruby code is written to create webpages on-the-fly.
  • Every request in Rails is first put through the routes file in config/routes.rb. This file tells Rails which Controller and Action is run.

Okay, let’s get started. Let’s create our static pages scaffold (which includes model, views, and the controller). Obviously, there are sections of this that you would want to require authentication for (editing and deleting, for example), but that’s outside the scope of this tutorial.

script/generate scaffold pages title:string permalink:string content:text;
rake db:migrate

Now we need to modify our controller slightly. More specifically, our show action. Right now, it will respond to showing an element only when the ID is displayed. We want to modify it to handle a permalink as well (/about and /contact look better than /pages/135, don’t you think?). Here is your modified show action:

def show
  if params[:permalink]
    @page = Page.find_by_permalink(params[:permalink])
    @page = Page.find(params[:id])

Before we go any further, we need to create two custom methods in our model. These will format the permalink to remove any unwanted characters for the custom route name (replacing all unacceptable characters with an underscore) and for the URL (replacing all unacceptable characters with a forward slash to allow for nesting of pages). It’s also important to note here that previous validation should be done to ensure that the permalink does not have leading or tailing non-alphanumeric characters, but I removed that for simplicity’s sake.

class Page < ActiveRecord::Base
  def route_name
    p = self.permalink.gsub(/([^A-Za-z0-9])+/, '_').downcase # Change non-alphanumeric characters to an underscore
  def uri
    self.permalink.gsub(/([^A-Za-z0-9])+/, '/').downcase # Change non-alphanumeric characters to a forward slash

At this point, we can create and modify our pages as we would regularly expect from a new controller. All of our pages are accessible via /pages/1, /pages/2 etc. We now need to make our controller act as our catch-all (so that all requests that do not match any of the other controllers get routed to our Pages controller), and we also need to provide permalink support. Finally, we will dynamically generate customized, name routes for all of our semi-static pages. All of that gets accomplished with a few short lines of code. Add the following code to the top of your config/routes.rb file, starting at line 2 (inside the ActionController::Routing::Routes.draw section):

def map.static_page_actions
  pages = Page.find(:all)
  pages.each do |page|
    self.send("static_#{page.route_name}", "#{page.uri}", :controller => "Pages", :action => "show", :permalink => page.permalink)

Finally, we need to call this method close to the bottom of the code, right before our default catch-all routes.

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

What this method does is retrieve all of the static pages in the database, then creates a customized, named route for each page, telling Rails what each URI should look like, and where to direct the request to.

Hopefully this helps some people out with their dynamic page creation. I’m pretty sure there’s a pitfall or two here, but I think it could be taken care of by doing some simple route housecleaning in the Pages CRUD controller. The perk of this option is that it allows the routes to be named, and hopefully that is of some benefit for others.

March 5 2010 Photography Update

So I haven’t put up any photos in a while. I’ve been on a bit of a dry spell, but I went through my archives and pulled out some that I think were better. Comments, as always, are welcome and encouraged.

Next Monday, I have an interesting post for all of you with iPhones. One thing I really like about the iPhone is that I don’t have to delete text messages. I have a quick and free way for you to back up all of your text messages to read later on. There’s a lot of paid services out there to do it, but you don’t have to pay anyone for this quick-and-easy trick!

[nggallery id=14]

ViM Made Easy – Part 1

Well, after the massive spike in traffic to my site after writing the blog post on GNU Screen and Byobu Made Easy, I decided to do another quick tutorial on another Linux command-line tool, ViM. ViM, or “Vi Improved”, is a command-line editor that has been around since the dawn of Linux command lines, and is deceivingly powerful. Although we won’t get into the more powerful parts of the program today, stay tuned for some power tips later.

Now, anyone that has been around two or more Linux command-line junkies I’m sure has heard the Emacs vs. ViM argument at some point. Regardless of which one you like, they’re both great editors. Give them both a shot and choose your favourite.

ViM Overview

Vim can be very overwhelming to start off on, but is great once you get used to it. When you first open ViM, you will be presented with a blank document and you will be in Normal mode (see below). Soon, we will be able to start writing text, undoing a mistake, perform cuts, copies, and pastes, as well as some search-and-replace.

A quick note that almost everything is case-sensitive!

Program Modes

There are six main program modes in ViM, listed below. We will only cover three of them in this tutorial for the time being.

  • Normal Mode. This is where you type all of your commands, typically to move into one of the other modes.
  • Insert Mode. Here is where you’ll actually type text into your document.
  • Visual Mode. Visual mode is mainly used for yanking (copying) and deleting (cutting). Although it can do more than this, we’ll focus on these for now.
  • Select Mode. Similar to Visual mode, Select mode is typically used for deleting a selection of text and immediately typing over top of it.
  • Command-Line Mode. This is where you type your commands, such as saving, searching (and replacing), and the ability to edit ViM’s options.
  • Ex Mode. All-in-all, this is pretty much command-line mode, except after typing a command you end up staying in command-line mode instead of reverting back to Normal mode.

Let’s Write Something!

You’ve just opened up ViM, but every time you try to type text, nothing seems to happen? What gives?! Well, right now you’re in Normal mode, and ViM is waiting for an instruction. In order to start typing text, just type “i” (for “Insert”) or “a” (for “Append”). The Append mode will move your cursor one character forward before you can type, so keep note of that. After you’re finished typing what you want, just hit Escape to get back into Normal mode.

Let’s say, that you just wrote “ViM is awesome!” in your spiffy new document, but saying it once just isn’t enough! You want to say it over and over again, but typing it out so many times just seems like a waste, doesn’t it? Time to go into Visual mode! Move your cursor to the beginning of your text using the cursors, then type “v” (lower-case). This puts you into Character-Select Visual mode. Move your cursor to the end of the text, and press “y” (for “Yank”), which copies the text into it’s built-in clipboard. Move your cursor to where you want to paste, and type “p” (for “Paste”). Note that “P” will paste BEFORE your cursor, so keep that in mind.

Fixing Screw-ups

Whoops! You pasted it one-too-many times, or you pasted it in the wrong spot! Never fear, the Undo tool is here! Make sure you’re in Normal mode (just hit Escape if you’re not sure), and press “u” (for “Undo”).

What if, for example, you ended up typing “ViM is awsemoe!” (hey, your fingers got tied up; it happens). It doesn’t make sense to undo all of that, so let’s just do a search-and-replace. Go into normal mode and type “:%s/awsemoe!/awesome!”, then hit enter. Poof! Problem solved! I’ll discuss the search-replace a bit more in the cheat sheet. If you just want to search for text, type “/your-text-here” in Normal mode, then hit enter. “n” will move you forward through all the findings, and “N” will move you backwards.

Saving and Exiting

Saving and exiting is really easy. “:w myfile.txt” will write the file to myfile.txt. If you opened an existing file, you don’t need the file name, so “:w” is all you need. To do a save and quit at the same time, type “:wq”.

What if you want to quit but don’t save your changes? The best way to do this is “:q!”, which will quit without heeding any warnings about the file not being saved.

Command Quick-Review

- a - Append
- i - Insert
- /<your-text-here> - Search for <your-text-here>. Does NOT use regular
- dd - Delete the entire line that your cursor is on
- x - Delete the character your cursor is hovering on.
- :42 - Move to line 42
- G - Go to the last line in the document
- :s%/<search>/<replace> - Regular expression-compatible search-replace.
    - :s/<search>/<replace>/g - Same as above, except replaces everything on a
      single line. Remove the "g" to replace only the first occurrance.
    - :s42/<search>/<replace>/g - Same as above, except replace on line 42.
- V - Line-select Visual mode
- v - Character-select Visual mode
    - y - Copy (yank) the selected text
    - d - Delete the selected text
- :w - Write the file to disk
- :wq - Write and quit
- :q - Quit
- :q! - Quit without saving

Hopefully those that are starting out on Linux will find this useful. I plan on going in to greater depth in the near future, so stay tuned for that. If you like this article, I’d love for you to Digg or Reddit this page below. It’s such a great feeling when your traffic spikes to 1000 hits in a day. And, for those Emacs lovers, I’ll be doing an Emacs writeup as well.

I’m Back

Well, it’s been a while since I’ve posted; about three weeks, actually. To the one or two readers I have, my apologies that you don’t have something to waste your time on twice per week. I’m getting back into the writing mood, so I should be building up a buffer of things to write in the near future.

A lot has happened since I last talked about the IPAM presentation that I took part in. To start with the related topic, I was approached to do the presentation again, this time internally to other departments. Thus, the other co-op student and I set about cleaning up the presentation a bit, fixing some errors, and making it flow smoother. It went much better the second time, thankfully, both from a public speaking perspective and a demonstration perspective. As fun as it was to work on that, I’m glad it’s over and done with right now.

Speaking of work, the number of days that I have left at IPC are dwindling quickly as the new year approaches. I work until December 31st, at which point I’m back in class. It’s been a fun past couple of months, and the paychecks have been very nice, but I’m also looking forward to getting back on campus to get some more studying done. I’ve decided that I won’t get a job during the winter semester so I can concentrate on my studying; I’ll have more than enough money to get through four months, and then I’ll be working in the summer again.

After that presentation was done with at work, I found that I had a fair amount of spare time, as there weren’t too many tasks to work on. I spent that time learning Ruby on Rails, and putting that knowledge towards the new UMSwing site. Although on the outside it will look almost the same as before, this new site will have an extensive backend that will make UMSwing virtually paperless. Although you may not think we use that much paper, think again; I have a full 3″ 3-ring binder in our office that says otherwise. All of our memberships, attendance, and transactions will be tracked on the web application, thus eliminating the need for those pieces of paper to be printed in the first place. Anyways, I’ve been working very hard on the site, and it’s almost ready to be tested by some other people. So, if you’re interested in testing some software for an eco-friendly cause, let me know in the comments section and I’ll keep you informed.

That’s a quick update on what’s happened in the past few weeks at work. I have a few more updates to spew out in the coming days, one of them involving my server upgrade (*cough* RAID *cough*), and some involving some extra-curricular activities (including some new photos to go up soon).

A Busy Past Two Weeks

So my twice-per-week updates seem to have fallen a bit behind as of late. To those one or two dedicated readers, my apologies for not giving you something to burn a couple minutes from your day with.

I have three culprits to lay the blame for this lack of updates. One of those has been a savage case of writer’s block. Another of those has been a very busy schedule for me. Busier than normal, even. As such, the third and final culprit goes by the name of “Sleep Deprivation”, which always seems to tag along with culprit number two. In a possibly vain attempt to get myself back on my writing pedestal, I figured I’d fill you all in about the past two weeks.

As those of you who are involved in the Winnipeg swing scene may know, UMSwing had two events to demo at last weekend, the first being the Gilbert & Sullivan Gala Fund-raiser, and the second being the Winnipeg Jazz Orchestra’s performance. The fund-raiser involved a couple of demonstration songs, and the WJO performance involved dancing for 20 minutes during their intermission, as well as the opportunity for one or two couples to dance on stage during one of their songs. Although they took place over the weekend, I’ve been in talks with organizers of both events for quite some time, and the last week became crunch time for me as I made sure everything went as expected. I’m really glad that we were invited to both events, and we’d certainly be interested in doing it again.

To swing (no pun intended) from one quirky interest to another, this Wednesday a couple of us took advantage of the day off and planned for a session of Dungeons & Dragons. I need to take a minute here to explain this:

  • No, it did NOT die out ten years ago
  • Yes, it IS fun
  • No, you do NOT need to be an über-nerd to play
  • Yes, girls DO play it.

Anyway, in this group (which has yet to receive a name), I am the DM; I’m the one who tells the story, plays the non-player characters (NPCs), and guides the other players through their adventures. Although very fun to DM, it also requires a lot of work to create your own adventures; dungeons, the global map, encounters, and NPCs all need to be planned. Thus, that chewed through a fair amount of spare time that I had. On the plus side, I over-prepared, so I have everything I need for the next time around.

This weekend, I have plans to go out to a friend’s cottage for some much-needed rest. It’ll be nice to get away from it all, and hopefully take some great photos, which I hope to put up for Monday’s post. I also have some ideas for another Linux command line tip, so those of you reading my previous post regarding Byobu: stay tuned.

“I’ve never seen you here before. I like that in a woman.”
— Renaldo ‘The Heel’, Crimewave (1985)