Categories
Technology

A Dev Environment with Trac+Subversion

Setting up development environments is something you do once in a while- hopefully. And over time, you tweak different areas and add in bits and pieces here and there and it evolves. Nicely. And then you get to do it all over again 🙂 But then you got to go back a couple of months/years and look at it all over again. Thank goodness for tutorials!

Incidentally, another good reason to make the effort to document (read blog) that learning, or even just link that learning into your own blog. You never know when you gonna need it again…

Setting up Trac and Subversion on Ubuntu

This is probably about the most comprehensive and easy to follow guide i’ve come across so far. It has all the basic necessities to serve as both a refresher and get you up and running quickly. There is one small “typo” but you should spot it quickly if you’ve done this before. It refers to the root web folder for the trac setup.

Categories
Technology

Ubuntu USB

They have a saying with Ubuntu: “It Just works” and freak- it’s true, especially with the latest release 8.1 (Intrepid Ibex).

My goal was to install Ubuntu Server edition on a machine that is really, _just_ a server. No shmancy graphics card, no CD-ROM.. wait. No CD-ROM!? How do you install server software onto a *disconnected machine with no CD-ROM? USB.

Now previously, the ability has always been there, and you had to download this and do that and change this- since you were doing something out of the ordinary (at least that is, back then it was). So they simplified the whole process with Intrepid and made it ordinary.

Sooo.. on a desktop machine (an existing installation of Intrepid) select to create a USB disk; locate/select the server ISO (or CD if you’ve burned the ISO onto CD already); select the USB device you want to use and the rest is a progress bar.

Now you can boot with the USB device and install the server OS onto the machine of choice. It really does just work.

Categories
Rants Technology

Pending Changes

One of the great habits now ingrained into my being are doing diffs on code before committing a check in. It’s a great habit, and worth the extra quick 2 minutes. It’s also a great time to review your changes and get your head into the right space for your next move. Of course, having great tools like Subversion and Tortoise (or even git and bzr) make the job a pleasure. But then you have this…

Pending Changes

(Names have been blanked for privacy reasons)

My pending changes tells me i got a whole bunch of changes to commit but comparing each one tells me they’re the same. 😮 Not exactly conducive to keeping up a good habit, i would say. I actually only had 4 files that really changed, in case you’re wondering. No amount of refreshing, getting latest version or checking out could give me just the files i want to review before committing. Sigh.

And most people still ask me why i insist on using open source tools to do the job (properly) :p

UPDATE:

I stumbled upon Derek’s posting on TFS and it does seem that things which should be simple (and were solved moons ago) are indeed quite difficult with TFS. The “plus” side though is ian has taken the time out to do something about it: cue LizardTF. Keeping an eye on that while i simply have to use TFS…

Categories
Technology

Bzr

Bzr have just launched their latest version. And while i’ve used it for development control on my *nix, i’ve also migrated it’s use onto Windows. The earlier versions were all very command-liney and so un-windows-like, but in it’s defence, the good ‘ol command line really is pretty fast and efficient for some tasks. Anyhoooo….

The latest bzr version for Windows, really has a best-of-both-worlds feel to it. Just go get it already 🙂

Categories
Technology

Optimizing And Readability

Optimizing code is generally an expensive process (read: time-consuming) and there are established ways of getting to the bottom of “what to optimize”. Thankfully, profilers are available to help with a lot of the guesswork, so it’s generally a good idea to make sure you work with one *most of the time*. Moving along, it was high time for me to look at some Ruby profiling.

The documentation for ruby-prof is pretty neat and the library itself is quick to get up and running with. And so we start. For my initial problem, I wrote a goal-seek algorithm for accurately estimating gross earnings, given a target nett earning using a tax table- as opposed to just using a base tax-rate. Anyhow, my first stab algorithm (a simple linear search) included the lines:

def seek_annual_gross(m_nett, base_perc)
  sample_gross = m_nett * base_perc
  paye = Paye.new(sample_gross)
  p_nett = sample_gross - paye.monthly_tax
  margin = MARGIN*m_nett
  if((p_nett-margin < m_nett) && (p_nett+margin > m_nett))
    return paye.annual_gross.round_to2.to_f
  elsif(p_nett-margin > m_nett)
    return seek_annual_gross(m_nett, (base_perc - (margin)))
  elsif(p_nett+margin < m_nett)
    return seek_annual_gross(m_nett, (base_perc + (margin)))
  end
end

The profiler showed up what i kinda suspected- always a good sign. Essentially, my incremental margin for the next step was too small (fixed) and thus, getting closer to the solution was taking too long- and endangered the stack 🙂 What i needed was a better guess at how much to increment.

% cumulative self self total
time seconds seconds calls ms/call ms/call name
22.58 0.28 0.28 177 1.58 3.22 Integer#times
16.13 0.48 0.20 171 1.17 259.18 NettGoalSeek#seek_annual_gross
6.45 0.56 0.08 179 0.45 0.50 Float#round_to2

Some minor adjustments to the routine, including an adjusted guess:

increment = MARGIN*(p_nett - m_nett)/margin

and modifying the appropriate calls

if((p_nett-margin < m_nett) && (p_nett+margin > m_nett))
  return paye.annual_gross.round_to2.to_f
elsif(p_nett-margin > m_nett)
  return seek_annual_gross(m_nett, (base_perc + increment))
elsif(p_nett+margin < m_nett)
  return seek_annual_gross(m_nett, (base_perc - increment))
end

And the profiler now reports:

% cumulative self self total
time seconds seconds calls ms/call ms/call name
2.78 0.16 0.01 11 0.91 6.36 NettGoalSeek#seek_annual_gross
2.78 0.35 0.01 17 0.59 1.18 Integer#times
0.00 0.36 0.00 19 0.00 0.00 Float#round_to2

A significant difference! Incidentally, the time to run, according to the test harness, went down from 1.122316 seconds to 0.189661 seconds. The high-level indicator showing enough of a difference as well.

The by-product of this optimization included the ability to get even more accurate estimations since the stack never overflowed, despite the required margin of error.

The moral: optimization doesn’t need to sacrifice code readability. At the right time, in the right spot, for the right reasons, you can achieve a sweetspot (of sorts) between two opposing(?) constraints. But that’s not to assume i’ve found the nicest sweetspot in this little piece 🙂

So in between refactorings or when there’s a lull in production, indulge the geek inside you.

Categories
Technology

Snippets

How often you store code snippets, only to lose them again? Often enough (or maybe you aren’t writing that much code). There are plenty useful routines out there, already written, some you could probably rewrite in your sleep without looking them up and probably aren’t worth saving. Others are gems that need to be published for posterity- not for yourself, but more importantly for somebody else struggling with the problem/language for the first time.

So after much delay, besides posting snippets here in this blog, i’ve taken to posting some around. There’s also an interesting angle wrt copyright and code ownership which can be completely circumvented (thus ensuring the longevity of tried and trusted routines) if you publish your snippet in the public domain.

Strictly speaking, depending on the kind of labour contract you’re engaged in, whoever pays you, pays you for your time plus the product of your time, and by implication, with intent and legal claim to that code routine. A highly contentious topic if there ever was but a difficult one to implement or monitor.

Nonetheless, with certain freedoms in place, you can strike a happy balance between ensuring your client gets full copyright and ownership of code particular to their domain, while you remain free to reuse that general routine in another (unrelated or not) project with a clear conscience: public domain. Of course, again technically speaking, you need to decide who pays for the time on that routine, and it should be you unless there is a transparent agreement from your client. Yours to work out or not.

Other than that, just a general shout-out big THANK YOU to everyone who does post code snippets- it’s helped me huge in my career; hoping to pay it back to others somehow. And a general encouragement to everyone else… get pasting.

Categories
Business Rants Technology

PAYE

UPDATE: 3 July 2008
Updated code to reflect more recent tax tables (2009)

When I was asked to estimate PAYE on a gross monthly salary, i hauled out the calculator and started chipping away, according to the SARS Tax Tables. Not being a tax consultant or looking at various structured packages, the first stab is mostly always a straightforward estimate without investigating further deductions. While doing this, the math-programmer inside me went… “Mmmm. Calculator. Boring. Ruby. Smile”

Turns out, it’s a simple little script; a useful little snippet and, bonus, i migrated some more learning onto Ruby. An aside; there’s definitely something about the difference in speed and endurance of learning between my brain versus my hands. You know the feeling. You can forget a password mentally, but let your fingers do the talking… And utilising muscle memory as an aid is just one of the many senses you can draw on…

Back to the snippet. Not too much interesting going on in terms of code. I chose a multidimensional array for storing the tax table. First used a hash, found it was overkill, reverted. Also did a classic switch in the beginning, to determine which “bracket” your pay falls into, but then figured a straightforward loop works just as well. This was an interesting break in habits from C# however.

In C#, looping through an array would be: for(int ii=0;ii<array.length-1;ii++)
I did the same in Ruby, transliterated the code, first time round: for ii in 0..array.length-1
But then, the knowledge of the “times” method changed my thinking completely: 6.times { |ii| … }
There are, afterall, one of 6 tax brackets you are likely to fall in (for all positive salaries)

And that’s where it hit me: the uncomfortable (more about that later) shift away from a corporate-sponsored, statically typed, IDE-integrated, certificate-oriented, compilable(?) programming language into a community-driven, dynamic scripting language is underpinned by these sudden ferocious rushes of freedom. Too much freedom? Certainly, too much to what i’m accustomed to sometimes.

Why’s that uncomfortable? Well, MSDN, VS, MS communities and the framework tell you how to code- to a large extent. They dictate the patterns, the constructs, the idioms; in short, they impose a very definite way of doing things. And it’s a big abstraction layer, forever changing (but not really) and giving you tons of resources to make your coding easier. This is good. Books, online help, built-in help, IDEs, intellisense… and more of all the good stuff. Don’t get me wrong, these things made me very productive and i’m grateful for that. But then you break away from that.

You gotta search for help (no nicely packaged MSDN DVD delivered to your door). You gotta scratch under the hood. You have to engage with community blogs and real people in a virtual world. You are forced to read opinions. You are stripped to the only the most simple of tools- a plain text editor. On a coding level, you are forced to remember namespaces, method names, variable names, libraries… no more intellisense to rely on. And this is where it was difficult. No more crutches to help me be more productive. I had to start thinking- for real now- and remembering stuff. And then i got scared: what if the “community” changed something and i didn’t know about it- or worse, didn’t agree with it? And I didn’t get an email with an updated change delivered to me automatically via updates or DVD? Hang on! Is that really the way it’s supposed to be? Have i become that lazy? Oops.

And all i was doing was having some fun, writing a little script to calculate PAYE so that next time someone asks me, i save myself a little more time.

Btw, the Source Code is here, if you’re interested.

Categories
Technology

Mac

Finally. It has arrived. After some time of deliberating, this once MS-only geek, turned and ran for the cover of open source operating systems; but not happy to just stay there, went one step further and has now immersed himself into the world of Mac 🙂

Afterall, i was tired of hearing the debates all the time; and to a large extent, i couldn’t really care which OS is best, since “best” is a loaded term and sparks off quasi-religious wars amongst the zealots; so i decided to live my opinions out, if i had any. And i definitely have some now.

My early comments can be summed in one thought which continuously bumps against the inside of my skull as i discover some new joy lurking under the hood of UI: “how on earth did i ever compute without a mac?”

Categories
Rants Technology

Clamour of Petty Kings

We have some serious issues facing our world today. Heck, in South Africa, the land of opportunity, we have more serious issues than we sometimes care to face up to. Tackling real issues is hard work. So, what’s the alternative?

Stop the press! Houston, we have a problem! In fact, call Heather Brenner out of retirement! Google does not display a link to it’s privacy statement on the home page. God forbid!

Something so serious demanded the attention of the world media (and my blog :sigh:), along with a host of, ahem, clamour, of petty kings. Good thing they were watching because if Google manage to continue getting away this kind of arrogant in-your-face lawlessness, who knows what cheecky and utterly ludicrious cheap shot they might plan to get away with next? :p

Categories
Business Technology

Ding

That’s roughly equivalent to the sound of the resonating chord which struck me this morning.

But today’s revolutionaries are sheep in wolves’ clothing. They’re lost in the economically meaningless, in the utterly trivial, in the strategically banal: mostly, they’re cutting deals with one another to…try and sell more ads. That is, when they’re not too busy partying.

Oh, if it weren’t so true. The rest of the article, is soul-searching and uncomfortably challenging because it has that “truth bites” edge to it. It’s also filled with quotable quotes, not for the purpose of quoting, but for serving as reminders when you get enough chance to breathe and realize exactly what it is you are doing.

That is to say, it serves, at the bare minimum, as a reality control against going too far in one direction; but only if it failed to catalyze something deeper within you.