About concept47

Ruby/Rails/Jquery/MySql/PostgresSQL hacker. Wannapreneur. Love to build beautiful things.

Something cool I learned about htop

So I have my own VPS where I get to play pretend-sysadmin after work and on weekends.

I typically use htop to view processes, cpu usage, memory … that sort of thing, but it wasn’t until I started dithering around in the settings section (just hit F2 while running htop) that I came across this screen (Look at the blue indicator)

What does it do?

Well, it splits your cpu-usage into 5 indicators instead of 3 … the critical one being the Yellow indicator which  shows how much time the cpu is spending waiting on Disk-io. An example of this is when a process sends a request to mysql, and the database has to use swap (hard drive instead of ram) to process the request.

The cool thing is that it updates the Avg CPU meter count as well so you can actually watch this number to see if you have disk io problems.
In this case, it turned out that I did. I had to use two other tools called pidstat and iotop to figure out what my problem was.

Turns out I hadn’t allocated enough memory to Thinking Sphinx and Mysql’s innodb_buffer_pool_size 

Catch Up!

But it is vital to remember that information — in the sense of raw data — is not knowledge, that knowledge is not wisdom, and that wisdom is not foresight. But information is the first essential step to all of these.

— Arthur C. Clarke As quoted in “Humanity will survive information deluge” in OneWorld South Asia (5 December 2003)

We now live in a knowledge economy, where information is rapidly becoming almost as vital (if not more) as actual assets. If you are not working at a place that puts this power in the hands of every single one of your employees/coworkers, then you are falling behind …

Catch up.

Brilliance

I happened across this sublime anecdote and I just had to share

Some years ago I spent a week giving an in-house program design course at a manufacturing company in the mid-west of the United States. On the Friday afternoon it was all over. The DP Manager, who had arranged the course and was paying for it out of his budget, asked me into his office.

“What do you think?” he asked. He was asking me to tell him my impressions of his operation and his staff. “Pretty good,” I said. “You’ve got some good people there.” Program design courses are hard work; I was very tired; and staff evaluation consultancy is charged extra. Anyway, I knew he really wanted to tell me his own thoughts.

“What did you think of Fred?” he asked. “We all think Fred’s brilliant.” “He’s very clever,” I said. “He’s not very enthusiastic about methods, but he knows a lot about programming.” “Yes,” said the DP Manager. He swiveled round in his chair to face a huge flowchart stuck to the wall: about five large sheets of line printer paper, maybe two hundred symbols, hundreds of connecting lines. “Fred did that. It’s the build-up of gross pay for our weekly payroll. No one else except Fred understands it.” His voice dropped to a reverent hush. “Fred tells me that he’s not sure he understands it himself.”

“Terrific,” I mumbled respectfully. I got the picture clearly. Fred as Frankenstein, Fred the brilliant creator of the uncontrollable monster flowchart. That matched my own impression of Fred very well. “But what about Jane?” I said. “I thought Jane was very good. She picked up the program design ideas very fast.”

“Yes,” said the DP Manager. “Jane came to us with a great reputation. We thought she was going to be as brilliant as Fred. But she hasn’t really proved herself yet. We’ve given her a few problems that we thought were going to be really tough, but when she finished it turned out they weren’t really difficult at all. Most of them turned out pretty simple. She hasn’t really proved herself yet — if you see what I mean?”

On craftsmanship and turning customers into fans

“Show me a man who cannot bother to do little things and I’ll show you a man who cannot be trusted to do big things.”
— Lawrence Bell

This morning, while I was getting ready for work, I picked my French Soccer jersey from a pile of clothes I had laundered last week and I noticed this, right behind where the Crest for the French Football Federation (facing outwards) sits on the chest of the jersey …

Turns out it  means “our differences unite us“.
Tres inspirer.

The quote sits right above a player’s heart while they have the jersey on (presumably striving for their country at the same time), and it hits so close to home on the issues the French have had historically, dealing with diversity, that I imagine a player would have a hard time forgetting it once they’ve seen it. Its also put in a place where jersey makers typically expend the least effort (Adidas is notorious for this, some of their replica jerseys are so uncomfortable because the insides are horribly tailored). Its the perfect blend of sentimentality and craftsmanship.

Needless to say, I’m a little bit more of a Nike and French Soccer team fan than I was yesterday, and all because of a silly little thing like an inspiring message on the inside of a soccer jersey.

It got me thinking about a Steve Jobs anecdote I had read a while ago.

In an interview a few years later, after the Macintosh came out, Jobs again reiterated that lesson from his father: “When you’re a carpenter making a beautiful chest of drawers, you’re not going to use a piece of plywood on the back, even though it faces the wall and nobody will ever see it. You’ll know it’s there, so you’re going to use a beautiful piece of wood in the back. For you to sleep well at night, the aesthetic, the quality, has to be carried all the way through.”

How does this apply to software?

The little things matter. The craftsmanship of your product, the care you show on tiny things like 404 pages, error messages, and page layouts looking perfect in all browsers … or even unseen things like formatting your code beautifully, or leaving instructive comments become part of the dna of your creation; that intangible signal of ‘high quality’ and sentiment that draws people in without them knowing why.

Its just the sort of thing that might turn a customer into a fan.

PS: A fantastic place to see brilliant little design touches, pertaining to software is Little Big Details.

Unit Testing and Mock Objects

Recently, I’ve been working hard to plug one of the biggest holes in my game … testing. I stumbled across this article, which helped make a lot of things clear for me, with respect to mocking and its relation to Unit testing.

This is partially due to the fact that most geeks don’t actually know what a unit test is. They think that testing the methods of a specific class constitutes a unit test, but that’s only part of the story. A unit test test is when you test the methods of a specific class in isolation, and the difference is critical. You know how some people call us “computer scientists”. Yeah, well this is the science part.

If you’re not doing this, you are not unit testing. That’s not meant to deride what you’re doing. I mean that as a literal statement of fact. Anyone, for example, who is using the built in Rails “unit” testing framework with fixtures (or FactoryGirl fixtures) is guilty of this. No test that relies on a separate class, or API, or interfaces with a database in any way is a unit test. It is an integration test (some people call them functional test), and when something goes wrong it is just a matter of time before it misleads you.

Enjoy the article – The Thing about Mock Objects

Sit down and write two letters …

There’s a story from this one scene in the interminably brilliant movie ‘Traffic‘ which I have never been able to forget (I went and found it on imDb).

You know, when they forced Khruschev out, he sat down and wrote two letters to his successor. He said – “When you get yourself into a situation you can’t get out of, open the first letter, and you’ll be safe. When you get yourself into another situation you can’t get out of, open the second letter”. Well, soon enough, this guy found himself into a tight place, so he opened the first letter. Which said – “Blame everything on me”. So he blames the old man, it worked like a charm. He got himself into a second situation he couldn’t get out of, he opened the second letter. It said – “Sit down, and write two letters”.

I’m not a very funny guy, but everyone I tell that story to, laughs … a lot

Recently, I’ve been thinking about it a lot in relation to software development. A few times in my career, I’ve come across a codebase that I thought was horrible/ridiculous/over-engineered/whatever, and my first reaction as a young developer was to ridicule or berate the the previous developer, loudly.

The funny thing is that it actually worked, initially anyway. The client was usually apologetic and cut me a lot of slack on deadlines and estimates. Then as I started to work on the code, I would begin to see why the developers made some of the decisions that they did. Maybe their pointy haired boss keeps pushing to get things done faster than is realistically possible, forcing the developer to write smelly code just to get done (“I’ll come back and fix it later!”), or there is some bureaucratic technical constraint that forces you to do things that appear very stupid at first glance. Sometimes, even, the developer was more advanced than I was and I couldn’t understand what they had written initially, so I just labeled it ‘overly complex’ because I couldn’t figure it out in one sitting.

The moral of the story is, professional courtesy matters. Always give the person that went before you the same kind of benefit of the doubt that you’d want someone coming after you to have for your work. Badmouthing the code you’re working on, can come back to bite you in the ass when you become its undisputed owner.  Be slow to do it, and if you must speak ill of the dead (so to speak), then be respectful, unless they absolutely deserve it (this is rare).

You see, the client/your boss will usually give you the time and resources to fix up the code, so you only get to blame the old guy for so long. Eventually, the question becomes “Why does the code still suck after all this time that you’ve been working on it?”. If you can’t answer that satisfactorily, you might find yourself out of a job, and who knows what the next guy is going to say about you?

How to freeze old rails gems

You probably came here wondering why

rake rails:freeze:edge RELEASE=2.3.2

doesn’t work, right? (It times out trying to pull the rails gem from http://dev.rubyonrails.org/archives/rails_2.3.2.zip)

Now you could try to hack the rake task in your rails gem

OR

– you could just go to rails github page https://github.com/rails/rails
– click on the ‘switch tags’ button  and select the version of rails you’re looking for
– after the page reloads, click on download and select the ‘zip’ version
– download it to your ‘vendor’ directory in the rails app you’re trying to freeze rails to
– unzip the file and rename the directory to rails
– you’re done!

To make sure you’re running a vendored copy of rails you can just  put

<%= debug Rails.vendor_rails? %>

somewhere in one of your views, or run

Rails.vendor_rails?

from the console.
enjoy.

How to get Ruby Native gems to install on your windows machine

The bane of any ruby/rails developer on a windows box (apart from piddling performance) is seeing the dreaded …
‘gem install error – ‘cl’ is not recognized as an internal or external command’

No more!
Devkit, a tool used by the folks who create the Windows Ruby Installer of each version of ruby helps you with (most) gems that need to be built natively.
Muchos Gracias to them for graciously providing it to us.

How to install gems without ri and rdoc documentation on Windows

Installing gems is usually very quick on my computer … its the accompanying ri and rdoc installations that slows everything down to a crawl.
There’s an easy way to stop ri and rdoc installs on Windows.

All you have to do is go to
C:\Documents and Settings\All Users\Application Data\ on Windows XP
or
C:\ProgramData\ on Windows 7

create a file called gemrc

then put in the following
gem: --no-ri --no-rdoc

Hat tip to this Stack Overflow comment, give the man some more upvotes!

Uploading a file using the simple_form rails gem

Simple Form is a rails gem that takes a lot of stress out of dealing with forms in Rails. Knowing what field nomenclature handles file uploading should be simple but its not. It took a lot of screwing around and reading the documentation to figure it out.

Simple Form uses the Provided Rails Form helpers so, if you want to specify a file upload field in Rails, just do this

<%= simple_form_for @user, :html => {:multipart => true}  do |f| %>
    <%= f.file_format :photo, :label => 'Your avatar please' %>
 <% end %>

Adobe Acrobat Reader UI sends mixed messages?

Check this out.

Navigation for Adobe Reader 9

This is the UI for Adobe Reader that you use to Navigate through the pages in a PDF. Clicking the buttons move through the pages one at a time in each direction.

Guess what keyboard keys you have to use to navigate through the pages of the same PDF … the Left and Right Keys!

Very bad dissonance there, because the arrows keep making you think you should be hitting the up and down buttons to move through the pages.
Those icons should be left and right arrows to match the keyboard navigation and send a good visual cue to the user about what keys to hit. #dontmakemethink

The 2 dumb mistakes Twitter made with its ipad app

The twitter app for the ipad is pretty darned spectacular, not just from a visual perspective, but specifically because of the brilliant UI choices they’ve made

However, there are two things that it/twitter does that are almost unbelievable.

Twitter app on the ipad

1. You cannot delete your tweets

No that’s not a typo.
You simply cannot delete a tweet you’ve made on the ipad app. If you make a mistake in one of your tweets, you’re SOL.

I understand getting a product to market fast, but leaving off a crucial feature, like deleting error ridden tweets, strikes me as a bit brain dead.
Its certainly a HUGE source of frustration for me … enough to keep searching for an alternative app.

2. You cannot access twitter.com from the ipad

I’m sure you’re saying “You whine too much dude. Just go to twitter.com and delete your tweet!”
Right?

Here’s the kicker …
You cannot access twitter.com from Safari browser on the iPad.

If you try to go to http://twitter.com you get this screen

twitter for the ipad splash screen

Very dumb, guys.
Please. Fix it.

PS: I lied … you can actually go to urls like http://twitter.com/concept47 … but thats about it, you can’t login or anything.