Sunday, February 25, 2007

7 Habits For Effective Text Editing 2.0

I've been watching videos on Google lately. Here's one that I really enjoyed and it's inspiring me to do a talk at my work on vim. It seems like every vim hacker has their own bag of tricks that help their productivity and cross-pollination is a good thing.

Seriously, find time to watch a little bit of this video. Actually, more importantly--find time to learn more about your text editor and then hack! This video encouraged me to find ways to leverage my vim knowledge in other areas. I've finally started using mutt for email (for some reason I thought it was going to be hard to get working and had been putting it off for a long time).

Sunday, February 18, 2007

Stickittodamanitis

I stumbled across this program last night and figured I hack it out for those of us who don't met the installation requirements. It's been something that has annoyed me about every cell phone carrier I've ever had--not having an easy way to know my monthly usage. Actually, I can't complain too much, I remember when I had SunCom years ago and I couldn't even get that information from a website. The truth is Verizon's site isn't that much fun to use and I never check it more than once a month. Enter saldo.rb:

(I don't have enscript configured on this machine, please forgive me for how blogger displays this)

#!/usr/bin/env ruby
require 'rubygems'
require 'curb'
require 'hpricot'

username = Curl::PostField.content('IDToken1', ARGV[0])
password = Curl::PostField.content('IDToken2', ARGV[1])
realm = Curl::PostField.content('realm', 'vzw')
charset = Curl::PostField.content('gx_charset', 'UTF-8')

c = Curl::Easy.new
c.url = "https://login.verizonwireless.com:443/amserver/UI/Login"
c.enable_cookies = true
c.http_post(username, password, realm, charset)

c.url = "https://ebillpay.verizonwireless.com/vzw/overview/unbilled-usage-minutes.do"
c.perform
Hpricot(c.body_str).search("//table[@class='modStdTbl']").each do |table|
(table/"//tr").each do |row|
#I couldn't get the CGI library to unescape ;
(row/"//td").each {|c| print c.to_plain_text.gsub(/;? /, "") + "\t\t"}
puts
end
end

Saldo is a term used in Spain to refer the the remaining balance on your phone. Since most people over tend to use the 'pay as you go' plan it's important to always know how much you have left. All the providers I know of in Europe make that fairly painless to find out from your phone. Until I get that from Verizon I'm going to be running this as a cronjob and mailing it out to myself and my wife.

I'm not sure how watchmycell is implemented but my guess is it's something similar. I couldn't find any sort of web services provided by Verizon so I had to use curb and hpricot.

Saturday, January 27, 2007

Windows is driving me to the bleeding edge...

of my sanity. Did you know that Ruby's green threads on windows are worthless? Ok, they aren't completely trash, I mean, they do indeed work but the problem is that they don't run in parallel. Kind of a bummer, eh?

It's especially frustrating when I hacked up a dsl and a RESTful service for executing commands on remote clients in a few hours and I have spent an entire day of my life trying to get it to work properly in windows. I guess this is where Ruby's unix prejudice really starts to show (personally, that's fine with me).

So, after finally figuring out why my DRb server was unresponsive after spawning a new thread I figured I would try using JRuby since it uses Java Threads. Let me first say that I'm quite impressed with the work that the JRuby team is doing. However, due to a bug that exists in the 0.9.x branch I was still unable to get DRb to spawn the thread properly either (for totally different reasons). On a sidenote my friend ruby-debug doesn't currently work under JRuby either. I will dig deeper into that problem later, but after spending and 2 hours and getting 'no where' I have moved on.

So I'm switching to edge YARV. That's the bytecode interpreter that's shipping with Ruby 2.0. I read that there are more threading options available in YARV and I'm interested to see if it helps me out at all.

Thursday, January 18, 2007

Mark, we need arrive at a clearer definition of the word free...

Because it's really starting to bother me that you say the word 'free' as if you don't know there are two distinct meanings in the open source ecosystem. I will choose freedom before I choose free beer. Let's call your definition of free 'FREE' and we'll call mine 'free'.

While I think it's important to many people that things are FREE I believe the greater good is freedom. Freedom to tinker, break, improve and understand. I'm worried you think that if everyone just starts using FREE software the world will be a better place. I posit that if the world (for some definition of 'world') understood the freedoms that come with free software and used it to it's full potential the world would indeed be a better place. From what I've seen on the net recently the EU might be starting to understand this.

Let's put our motives aside and not label companies that have made great contributions to freedom as not 'FREE'. The truth is Mark the freedom is in the source.

http://www.markshuttleworth.com/archives/77

Friday, January 12, 2007

Overloading a method within a class.

I came to an interesting realization today what I came home from work and started to look through what had been posted to comp.lang.ruby. The language I program in has drastic effects on my design. Actually, I guess I've always thought to that be true. That's probably why I prefer to do certain things in one language over another. Anyway, enough of my being theoretical. Read this.

What I find fascinating is that in over two years of hacking ruby it has never even once occurred to me that I couldn't overload a method within a class. Why? Because Matz and the other Ruby commiters have found it to be a Bad Thing(TM) and Ruby encourages you to do good things. Yeah, yeah, if you read the whole thread another reason for not implementing it is because it would be hard to do. With that aside I've already started to loathe seeing multiple constructor signatures in a class and that's pretty much the same thing. Just make a static constructor and give it a name that actually means something. None of this 'new Foo(x); new Foo(x,y); new Foo(x,y,z)' trash.

Wednesday, January 10, 2007

Kernel#gets vs. IO#gets

I made an interesting discovery tonight while hacking on widi (it's actually quite embarrassing that I never came across this before). Whenever you are trying to read from stdin in ruby you typically just type 'gets' and don't think twice. I found out there are actually two different 'gets' methods, Kernel#gets and IO#gets.

Usually you don't notice the difference simply because if ARGV doesn't exist Kernel#gets simply reads from stdin. However, tonight I started building out some of the scm wrapper functionality of widi and naturally I was adding command line arguments. This caused widi to die a painful death. It's last words were:
kill #: widi.rb:27:in `gets': No such file or directory - kill (Errno::ENOENT)
from widi.rb:27

To fix the problem I googled a bit and realized I needed to explicitly tell ruby to check stdin using the global variable $stdin (IO#gets is private so don't even bother trying to call it!). Not exactly intuitive but I guess I can't complain too much.

Sunday, January 7, 2007

I will learn something new about vim every day of my life until I die.

I never cease to be amazed by the raw power of vim. Over the last year it has become my editor of choice for ruby code. I even find myself closing my IDE and using vim to edit java code from time to time when things get serious (I swear I could write a web app using only vim macros).

So, I suggest you take some time and read Jonathan's McPherson's blog entry on efficiently using vim.

Tags

my google reader feed