Title Be Here

Meetup Events in Octopress

Have an Ocotpress-powered site and want to show upcoming meetup.com events? Check out meetup-octopress. It’s a work in progress, but good enough to display dates and event names in the sidebar for the Charlotte Ruby User Group.

History

The more things change, the more they stay the same.


$ history 1000 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
64 git
59 ./bin/rake
56 ls
53 vim
44 cd
30 gst
20 gp
17 cat
16 rake
13 glog

Masking Credit Card Numbers With MySQL

So you need to export a list of credit card numbers and send it off someone, but don’t want all the digits shown. Sometimes it’s for post-processing, QA, or to solve a client dispute with an order. Whatever the case may be, here’s how to mask numbers in MySQL:

Masks everything but the first and last 4 digits:

SELECT
  CONCAT(
    SUBSTRING(c.card_number, 1, 4),
    REPEAT('X', CHAR_LENGTH(c.card_number) - 8),
    SUBSTRING(c.card_number, -4)
  ) AS masked_card
FROM
  table_name;

Or if you want just the last 4 digits and everything else masked:

SELECT
  CONCAT(
    REPEAT('X', CHAR_LENGTH(c.card_number) - 4),
    SUBSTRING(c.card_number, -4)
  ) AS masked_card
FROM
  table_name;

Replace table_name as appropriate. To find out more on these functions I’ve used, check the mysql docs on String Functions

The President With a Lightsaber

500x_Obama1.jpg

How awesome is that?

Using Keyboard Shortcuts to Mute Skype Calls on OSX

I’ve been a Skype user for over 5 years now. The service and call quality have always been great for single and conference style calls. One thing I’ve noticed about myself though is that I breathe into the headset at odd times, making everyone else feel like there’s serial killer or an angry giant on the other end. Skype solves these uncomfortable sounds for everyone else with the mute button. The downside is that there’s no shortcut for this. To mute you have to use the mouse, which is slower for me and louder when I click. My keyboard on the other hand is quick and really quiet.

Enter keyboard shortcuts. From System Preference pane, there’s a keyboard shortcuts panel you can add application shortcuts for any menu item. The only thing you need is the name of the menu item. In my case the menu item is Mute and UnMute, Skype just changes the menu item’s name depending on the state of the audio for the call.

System Shortcuts

Once you add the shortcut in, it’ll show up in the menubar.

Skype call bar

So now you can continue breathing loud, stuffing your mouth, continue listening to CNN, or whatever it is that might annoy people on the other end of the line.

Small Ruby Date Trick

Well I don’t know if it’s a trick, but this sure was useful when I was coding up some sql reports.

Date.new(2009, 1, -1).to_s => "2009-01-31"

Agile Carolinas Andy Hunt Presentation

When I first moved out to Charlotte, I didn’t have much experience working in a corporate environment, and I went along with many of bad practices the company had. Around the same time I picked up The Pragmatic Programmer by Andy Hunt and tried to use the tips in the book. Sometimes I used the tips at the wrong time or misinterpreted principles, but for the most part it helped bring out many of the social and communicative aspects of being a programmer that I wasn’t very good at. Being able to detect a bad situation before things turn ugly can be a lifesaver. It also helped with preventing me for constantly working 50+ hrs a week and not benefitting from it.

That was about 4 years ago. Fast forward to yesterday, where I attended an Agile Carolina meetup. I’ve been a member for about a year, but haven’t attended to any meetings lately. Then I got an email saying Andy Hunt was coming down to Charlotte and was going to give a talk on how to “Refactor Your Wetware”. Odd title, but if it was going to be anything like his books, I couldn’t miss the talk.

For the most part, the talk was less about programming, and more about we operate as people. It reminded me a little bit of when I took psychology courses, but used with metaphors like CPUs, shared buses, and memory to describe how our brain works. Here’s a couple of points I found interesting about the talk:

Aesthetics affect cognitive performance.

There’s a reason why you should get up and walk around when stuck on a problem. Dwelling on it in the same space won’t solve them. Brining in other senses by stepping away from the keyboard and taking a walk, smelling the ink while using a whiteboard, or taking a break to play a video game can help stimulate other areas to help solve a problem.

Write everything down.

Everything. Yes, everything. He maintains a personal wiki, covering everything from daily habits, to one-time affairs. I’ll have to look more into this because it seems interesting. I’ve always used wikis for work, but never in my personal life. I also noted the act of writing is more important than going back and reviewing what you wrote. Sometimes you have to write something and remind yourself multiple times, but other times writing it down once is enough to never have to look again.

Andy suggested that our memories are terrible. He even went as far as saying those memories you believe to be vivid will change over time or possibly never occurred in the way you imagined them. He suggested that even if it doesn’t make sense, keep writing. Use a moleskin, small stacks of paper, whatever. Just keep writing. I suppose the idea here is that the more you notice something and write it down, the more you think about it. Instead of your brain sitting idle, it’s working more and more. Then your brain gets used to thinking this way and you are able to come up with better ideas and solutions. This was probably the most important part of the talk for me.

Failing takes the pressure away.

If it’s ok to fail, then you won’t. A little funky, but makes sense when you talk about unit testing. Basically the first thing you do when you write the test is that it actually fails. So I suppose if we’re already failing at the beginning, that takes some of the stress out.

Handling Interruptions

Interruptions happen all the time and can take a long time to get you back in productive mode. One interesting tip Andy mentioned was getting as much information out of your head before you’re completely interrupted. So if the telephone rings, you’d type out as much as you could before answering the phone. It’s alright if it’s not a full sentence, but the idea is to leave breadcrumbs and be able to pick up where you left off faster.

I’m a left-brained guy (with the right side sneaking out to play guitar), so it was nice to hear from someone who could offer tips on how to improve your wetware. I’m probably the youngest in the group, but Andy presented in a way that was understandable to pretty much every generation of programmer that was there. His book comes out really soon and I’d recommend it to anyone who’s a fan of the pragmatic series. It was also nice to put a face and voice to all the words you have read that helped shape the way you are as a programmer.

MySQL Bindings With Ruby 1.9

I’ve started messing around with Rails 2.3.1 (aka RC2) and seeing how it works with Ruby 1.9. Aside from having to install all my gems for the new version of Ruby, the mysql bindings needed to be installed too. Here’s how I got it working:

Note: I’m using macports installations of ruby 1.9 and mysql

Grab mysql-ruby wget http://rubyforge.org/frs/download.php/51087/mysql-ruby-2.8.1.tar.gz

Setup to use your mysql configuration files ruby1.9 extconf.rb --with-mysql-include=/opt/local/include/mysql5/mysql/ --with-mysql-lib=/opt/local/lib/mysql5/mysql/ --with-mysql-config=/opt/local/bin/mysql_config5

sudo make

Run tests to make sure everything passes ruby1.9 ./test.rb -- localhost

And to finish it out sudo make install

History

I’ve been trying out Git lately. Can you tell?


$ history 1000 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
55 git
44 cd
42 ls
39 rake
35 ruby
34 sudo
26 ri
21 port
16 rm
13 irb

First EnvyCasts Video Is Available

This week the railsenvy guys released their very first screencast. They’ve got weekly podcast, delivering news on the ruby/rails community. It’s pretty good. If you like banter and sound clips, you’ll enjoy it.

Their first screencast is titled Advanced Active Record, covering the following:

  • Loading large data sets
  • Using indexes
  • Caching
  • Named Scope
  • STI & Polymorphic Associations
  • Dirty Objects

They take a different approach from the typical screencasts I’ve seen with rails. Normally screencasts involve someone typing away in Textmate, switching over to the terminal, and then showing a demo in Firefox. Instead, they’ve taken the greenscreen approach. Code is displayed in the background, with Jason and Gregg popping in and out of the forefront to explain things. There’s plenty of charts and diagrams too. I really like this approach. To me, it’s more exciting to see things come across the screen with a person pointing at them. If you’re afraid these are like typical powerpoint presentations, don’t be. These guys do a good job of explaining how each of the concepts work, showing snippets, and examining log files so you don’t have to drown in some of the gigantic SQL that’s generated by ActiveRecord. There’s also examples of what’s new in Rails 2.1, including dirty objects and how partial updates work.

So if you want to learn some of the more advanced active record topics, check it out.