Wednesday, June 30, 2010

using regex groups for ruby's gsub

I won't spend long on this. If you've done your due diligence and carefully read up on the way regex matching works in ruby, you wouldn't be on this page. If you were like me and figured that you could probably just nail it the first time without looking anything up, you might have written something like this:

cleaned_string = "7.30 AM".gsub(/(\d)\.(\d)/,"#{$1}:#{$2}")


This is about as completely wrong as you can get while still looking somewhat right (as I found out today). You see, the global variables like "$n" do indeed store the matched groups from regex operations....AFTER they've executed. At the time when these parameters to the gsub method are evaluated, these variables are still nil. Thus the string you end up with is something like ":0 AM".

Correct syntax for including matched groups from regex expressions?

cleaned_string = "7.30 AM".gsub(/(\d)\.(\d)/,'\1:\2')


this way it's evaluated later, after the method has been called. Note the single tick marks, as doubles will cause the slash-number combinations to be interpreted.

Tuesday, June 22, 2010

quarter_time 0.3.1 released

A small but useful addition to the quarter_time gem I released a couple weeks ago. Normally the scope added to models that include the QuarterTime::QuarterDriven module would be used with other Quarter objects:

class SomeModel < ActiveRecord::Base
  include QuarterTime::QuarterDriven
end

q = Quarter.new(2010,2)
model = SomeModel.for_quarter(q).first
However, in cases where I didn't already have a quarter object built or coming from another model, it seemed like overkill to build the object just to pass a couple parameters. So, here's an additional (equivalent) syntax you can use to select models by quarter:
class SomeModel < ActiveRecord::Base
  include QuarterTime::QuarterDriven
end

model = SomeModel.for_quarter(2010,2)

Saturday, June 19, 2010

Off topic but on fire

Today I wanted to spend some time working on my Lingq.com client gem that I've been working on this weekend. It's a fun litte project, and if you're into learning another language I recommend you go check out lingq.com, it's pretty cool.

But that didn't happen. No, instead today I spent a few hours trying to figure out how I'd been fraudulently charged for $325.50 over the last 6 months. I wish this stuff didn't happen very often, but the guys who got me are pros, and if you're someone who has a credit card (and you are), you should immediately go check your statements for anything that looks like one of these:

MVQ*PRIVACYM
MVQ*CLUBSAVE
MVQ*SHOPESSPLUS
MVQ*SHOPPINGESSENTIALS+
MVQ*BIZMAX
MVQ*BUSINESSMAX
MVQ*DLMAX
MVQ*DEALMAX
MVQ*TWENTY4PROPLUS
MVQ*24PROTECTPLUS
MVQ*TRAVELMEMBER
MVQ*TODAYSESCAPES
MVQ*PRIVACYMID
MVQ*PMIDENTITY
MVQ*HOMERWRDS
MVQ*ATHOMEREWARD
MVQ*VALMAX
MVQ*ValueMax
MVQ*PASSPRT2FUN
MVQ*PASSPORTTOFUN

I'm sure you see the pattern. There are tons more, but who has time to copy and paste all that mess 300 times?

These guys run a ton of billbord sites like this:

http://www.mvq-dlmax.com/

Clue one that this is a problem is how every site of theirs is basically something that says "want to know why this mysterious charge showed up on your credit card statement?". Check out this excerpt from http://www.mvq-todaysescapes.com/

You're probably here because you were searching the billing descriptor MVQ TODAYSESCAPES after finding it on your credit or debit card statement.
The billing descriptor MVQ*TODAYSESCAPES that you saw on your credit or debit card statement is used to indicate a fee for enrolling in Today's EscapesSM, an online membership discount program that offers consumers much-desired discounts on travel plans, dining out, home entertainment and more.



Oh my freaking God. If I had signed up for a membership with you, why would I be searching by the BILLING descriptor for your service? Why in the name of reason would the front page of your website be dedicated to explaining why I shouldn't ask my credit card's fraud department to bring the attorney general down on your slimy ass?

Yep, I called my credit card company, and what did they say? "Yeah, we see this a lot". Wow. Now, I'm glad they were able to help me, they issued me a new card cancelled my old one and credited the charges, but I have to wonder about how this situation reflects on the world of software developers world wide. Obviously someone has shown they can make a quick buck by obtaining credit card numbers and charging them monthly because most people won't investigate charges smaller than $50. And even then, once someone cancels their "account" with these criminals, they usually won't go so far as to file fraud, because it's time consuming. So they have a system that does this automatically, and a phone answering service that lets you cancel your account (it's pretty much the only option on the phone menu, minus some bullshit "explanation of your benefits" speech). And the money rolls in every month.

This probably isn't very coherent, because I'll admit, I'm furious right now, but these people will be allowed to operate only as long as we don't report them because it's too much administrative overhead. Now, I did my part today. I filed a fraudulent charge claim for every transaction they hit me with since they got my credit card number back in september. Today, right now, go to your credit card account search for MVQ. If you're being scammed too, please report it to your credit card company's fraud department so that we can get these lowlifes shut down.

Thursday, June 10, 2010

quarter_time: progeny of RailsConf

Well, it's been a great week so far at RailsConf!

There have been at least 47 times that I've looked at someone and thought "hey, I know that guy!" recognizing them from their avatars on github.com or their names on twitter.

Dr Nic Williams, Obie Fernandez, Greg Pollack, I could go on and on.

Most importantly, I've been overwhelmingly inspired to dive back into self-improvement in my coding ability. Dr. Nic's talk especially galvanized me towards engaging more with the gems and libraries I'm taking advantage of, and contributing back my own. In the spirit of my newly found ambition, I've released a mini-gem today that I use in a couple different applications my startup runs.

quarter_time, here linked to my github profile, is a gem for dealing with the problem of quarter-based business cycles. For instance, we have a medicaid-billing application that processes claims for every quarter of the year (Quarter 1 2010, Quarter 2 2010, etc). The claim models, and many other pieces of supporting data, are stored according to what year and quarter they belong to. Of course, the normal ruby data doesn't have any assistance for moving between quarters, and there are certain things that are common between models that are governed by a quarter (for instance, a scope to find objects by the year/quarter they are part of, a way to find the date range the model covers (start_date and end_date), and so on. This early-stage gem (well-tested, but not fully featured yet) is here to help solve that problem.

Sometimes the best part of going to these conferences is the energy you get from being around so many people who are interested in the same stuff. Thanks RailsConf, and I'll see you next year.

~Ethan