2

Unreasonable People

We all do it from time-to-time, and some more often than others: allow our emotions to control how we react instead of using logic to properly deal with a situation. As a person who frequently turns to the Internet for information, I often stumble into forums and blog comments where one person says a little more than they should have, and then someone else takes it way out of context or too personal and ends up starting a volatile back-and-forth. Insults, name-calling, and cursing only stoke the flames and turn a campfire into a nuclear disaster.

With this in mind, I try my best to think twice about what I say and how I say it. First, I don’t want to cause a flame war, and second, should one start, it’s at that time I allow my logical mind to overpower my emotions and tell myself “This person cannot be reasoned with, so there’s no point in engaging them; just walk away”. This works pretty well, and I never end up looking like the fool.

But today, I got sucked into one, and I’m going to share it with you.
(more…)

0

The evolution of the geek

It will forever be a huge source of amusement for geeks that they are now officially deemed cool. It’s true. There have been surveys and everything. ‘Experts’ have been saying so since the early 2000s, but I don’t think anyone truly believed it until technology began to get ultra cool. Who was behind it? Geeks of course.

The social networks like Facebook, the online games like World of Warcraft and partypoker, the amazing improvement in film and game graphics, the iPhone. They have all come about thanks to the imagination of geeks, and the non-geeks of the world finally acknowledge that, ultimately, we rule the world.
(more…)

0

Rails: clean old ActiveRecord sessions

If you use ActiveRecord for session storage, you’ll find that the sessions table fills up quickly. reset_session deletes the current session (say, when implemented in a logout action), but stale sessions can still build up when a user simply closes their browser. To combat this, here’s a simple solution using a class and a cron job (Rails 3.1 and Ruby 1.9.2 under RVM):

Create a file called session_cleaner.rb and place it in the lib folder:

1
2
3
4
5
6
class SessionUtils
  def self.cleanup
    session_store = ActiveRecord::SessionStore::Session
    session_store.delete_all( ['updated_at < ?', 1.hour.ago] )
  end
end

Then, in a cron job, you can simply execute the following however often you determine is adequate to prevent buildup in the table (higher traffic applications may want more frequent cleanup, but every hour should be a good start):

1
/var/www/my_rails_app/rails runner -e production "SessionUtils.cleanup"

(more...)

0

Generate vertically-ordered HTML table in Ruby

In a major Ruby on Rails project, I recently had to generate a table of data which had to be organized with data flowing from top-to-bottom in each column before moving on to the next column, instead of left-to-right. This seems simple, but I had trouble getting my head around it for some reason (maybe it was a long day and my brainz were just tired).

Anyway, for those of you who are as easily confused as I am, here’s how to do it. Note: the instance variables in this example are used simply for clarity in identifying what controls the number of columns and rows.

1
2
3
4
5
6
7
8
9
10
11
12
<table>
  <tbody>
    < % 0.upto(@rows_per_column-1).each do |row| %>
      <tr>
        < % 0.upto(@columns-1).each do |column| %>
        < % index = row + (column * @rows_per_column) %>
        <td>< %= index %></td>
        < % end %>
      </tr>
    < % end %>
  </tbody>
</table>

(more…)

0

Keeping track of JavaScript timers

While working with a complex AJAX script today, I discovered a long-standing problem with an interval timer duplicating itself. I spent most of the morning trying to figure out ways to prevent more than one instance of the timer from firing, but since the timer could be stopped and restarted based on user interaction, there had to be another way. Well, I’m here to show you a nifty solution so you don’t have to learn the heard way like me.

Typically, when you create timers in JavaScript, you created them like so:

1
2
3
4
5
6
7
8
var delay = 5000;
setTimer(function() {
  // Do something once after delay
}, delay);

setInterval(function() {
  // Repeat something after every delay
}, delay);

(more…)

2

Define “plugged in”

Did you see the movie Social Network (a.k.a. the Facebook movie)? It was about the founding of the most popular social networking site, and in it was a term used many times: “plugged in”. Well, I’m under no illusion that I am or can be among the elite when it comes to software programming, but the fact is I am a programmer, and I tend to become “plugged in” quite often. But what does that mean?
(more…)

0

Goodbye, Steve

I still can’t believe it. He’s gone — a legendary business man who created a market for people who were more interested in a product that worked, rather than how it worked. He stepped down from Apple as the CEO only a few weeks ago, and I knew it was because of his un-winnable battle with pancreatic cancer, but I didn’t think it would take him so soon. I’m still in shock.

Apple’s website remembers Steve with the following:

Apple has lost a visionary and creative genius, and the world has lost an amazing human being. Those of us who have been fortunate enough to know and work with Steve have lost a dear friend and an inspiring mentor. Steve leaves behind a company that only he could have built, and his spirit will forever be the foundation of Apple.

It was one of my secret wishes to meet Steve Jobs. I guess it was unrealistic, but still, it’s almost like losing a friend.

Page 1 of 6012345...102030...Last »