Categories
Technology

Sweepers

The most exciting discovery of the day award goes to Sweepers.
And the most straightforward “in the wild” dissection of it, goes to CodeLevy.

Basically, and in my cases unrelated to caching (not unlike David Parker), i needed to observe my controller actions. Well, i needed to couple behaviour onto an existing process and observing is (one of) the nicest ways to do it really.

When a user requests a report, let the controller do the checks and balances, pass it on to a presenter, and then let the world know a (correct) report has been requested. Interested parties (for now) include:
* monitoring for statistical purposes and
* rendering soft copies for prosperity (which in turn notifies the world that soft copies are available)

Sweepers are the new black for this morning.

Categories
Technology

A New Language: Where To Start?

When you learn a new speaking language (English, French, Spanish, Hebrew, Afrikaans….) you generally find your course or program is broken down into scenarios. For example, mostly all books, audio or videos will have the topics: Greetings, At The Airport, Public Transport, At The Hospital, Hotel, Restaurant and so on. Essentially, everything you need to “get going”. Of course, a lot is assumed, but the assumptions cover 80% of the market picking up a new language. Is it different with programming?

I think not. What we don’t always have is a “program” of topics to cover that can be referenced- or at least, not one readily packaged. There are many reasons for that being the case, but this post is not about that. So what are the topics….?

For me, that is, i find going back to good ol’ One-Oh-One basics of data structures a really useful way to learn the ins and outs of a language. This is not a new idea by any stretch of the imagination. But take a list like this, and tackle the structures one by one in your new language. Pretty soon, you get to figure the language out in the detail you need to get on with the job.

Of course, the bonus is that you’re going to need a variation of one of those implementations somewhere in some form or another (even if your framework provides native implementations). But building data structures from the ground up teach you all the essential scenarios: How to define a class, inheritance capabilities (if applicable), methods, signatures, variables… And provided you are (should be) familiar with the details of the requirement, you can free your mind to focus on the language, and not a new problem at the same time.

Categories
Technology

Classical, Functional or Prototypal?

I have updated the maths playground on this site as part of an ongoing adoption and learning of new languages and in particular, programming approaches. The language itself is not really the issue when you’re tackling a task. In fact, learning a ‘programming language’ itself (the syntax that is) is a non-issue. What you do come up against is, is a mindset.

Taking the “classical” languages like C, C++, C# and Java as examples, the way you code in each is roughly the same. Different semantics, but a lot of variable commonality. (Of course, you can get frameworks, like the Symbian SDK, which obsfucate things enough for you to appear as another language). Then you take something like Ruby, and the way you think _has_ to change, or you’re just going to hit your head against the proverbial. And then still, something quite different like Javascript (in it’s more modern form).

Having been schooled in more classical approaches (C, C++), the jump to functional programming was an interesting curve. And now, another shift to prototypal programming has been as interesting. Still some concepts make me ponder though. Nonetheless, i’ve documented the differences, in the form of code, between the pseudo-classical and prototypal approaches in using Javascript.

Any pointers welcome, thanks 🙂

Categories
Technology

Rails, PDF + prawn jumpstart

Looking for a “to-PDF” solution for your rails application? Well, if your journey is (has been) anything like mine [which is pretty standard judging from what i’ve read] then you’ve probably decided prawn is the way forward. And you’re also probably convinced that prawnto is a good idea (it is also highly recommended).

So by now you’ve created a blank rails app, installed the gem, added the plugin, got a controller of sorts setup- all for the purposes of test-driving prawn (with prawnto). You’ve reread the documentation but it’s not going _that_ smoothly. There are one or two little things (not mentioned as explicitly as you’d might want) that you should be aware of. After trawling through some prawn discussions on google groups, i picked a bright penny-moment. Aha! Of course 🙂

Sometimes, while learning a new library/tool/tech/whatever, your brain seems to focus too hard on the problems you’re experiencing and forgets about the basics of the bigger context. When you step away, you (hopefully) realise that the issue you’re having is not the library/tool/tech/whatever, but with the fact that some fundamental got glossed over/ignored/forgotten about. This was one of those.

My controller code was fine. The actions were pretty much {empty}. My view filename was either action.pdf.prawn, action.pdf, action.prawn.pdf, action.prawn or actionpdf.prawn- all sorts of variations ‘cos i couldn’t consistently get the desired effect: an inline pdf render. But the documentation said quite clearly ‘.pdf.prawn’. What does it take to get a simple demo going to start experimenting with? Well… it turns out all i had wrong was the request. I completely ignored the basics (routing) and focused on the problem (pdf library). Not exactly a library issue.

http://localhost:3000/controller/action won’t work => renders .html
http://localhost:3000/controller/action.pdf won’t work either => no route

What i wanted to request was: http://localhost:3000/controller/action/:id.pdf
and :id is the identifier for your model (even if you’re not actually riding with one in our test drive).
And this is due to the default configuration of a default rails app. Check out your routes.rb. Back to basics. Evidently, if you want a different ‘route’ to get to your pdf, then, you guessed it: create a route 🙂

Categories
Technology

PAMP

Continuing with the mobile web server theme, the underpinnings of the previously mentioned project are available as part of various open source projects. What’s more, the ability to now host PHP (and not just python) websites on your phone (huh?) is so there, but still begs the immediate question: why?

Now there be some answers to that, but then, just how feasible is this? I mean, just how practical is having a full-blown CMS web application hosted on your phone? Mmmm.. that aside, i still see quite a bit of usefulness already. For one thing, the world of mobile data interchange just got looped onto its head, in a public kind of way. Just engage reverse and let the creativity flow 😀

Categories
Technology

Mobile Web Server

The title should pretty much sum it up. It’s new, and if preliminary “user” reports are anything to go by, very scary. I mean, why would you want to open your phone up and turn it into a web server for all the world to access? Heck. Why not? 🙂

So Nokia have been working on this tech (still in beta, like most good things) and have published it at http://mymobilesite.net. And it rocks. Installed it and have my mobile web server running around with me on my Nokia N81. Check it out.

Of course, i don’t run it 24×7 (yet) so you may get an “offline” response. For now (because of the scary factor) i still keep a close eye on it. But i would encourage you to spend 15 minutes and set yourself up. And then just think of the possibilities….

Categories
Business Technology

Morty

Morty is a pet project i been working on here and there which spills out an amortization schedule for you, based on your loan attributes. I’ve been incubating it at Heroku since it is quite a fascinating concept and tool. Their online console is pretty geeky but easy to use and deploying rails apps is straightforward really. Anyhow…. Morty.

Say you considering a loan for (in any currency) $150000 at an annual interest rate of 12%, compounded monthly over 5 years (or 60 compounding periods). Immediately you get an idea of how much your repayments are going to be.

In this case, 3336.67 per month. The schedule part is the interesting bit; if you are indeed interested. First, you can see, at a glance, how your equity in the loan grows and how quickly (slowly) the loan capital is repaid over time.

As you can see, it’s only just after halfway that you start to owe less than you’ve repaid. You will notice slight curves due to the nature of amortization. Experiment with bigger loans and interest rates to see just how the curve is affected.

You can also see how much total interest you end up paying, versus how much of the interest you’ve paid off so far.

Here, the curves are slightly more pronounced. Of the ±50k interest you’re going to pay back in total, most of it is paid off quite early. Which makes sense. The more you owe in the beginning, the more interest you pay. So if you really want to make a difference on the interest on your loan, over time, make the biggest impact you can as early on as possible. You can see that towards the end of the loan, how flat the curve is. If you start making advanced payments at this stage, you’ll still save, but not nearly as much as you could have if you were even one or two months earlier with that payment…

The schedule…

Numbers number numbers. All it is is numbers. The numbers tell you that when you make your first payment of R3336.67, almost half of that payment is paying back the interest. R1500, in this case. So, in effect, you’ve only paid back R1836.67 of the capital (R150k) back after actually paying R3336.67. That starting to make sense now? Sucks, eh? So you make another payment, through enforced religiosity (ie. debit order). This time, you’re _only_ paying back R1481 interest. The balance pays off the capital. And so it goes until eventually you reach a stage where you’re paying off more capital than interest with each payment.

Now take a look at your home loan. An average value in current property markets might be something like R800k at 14% over 20 years (or 240 compounding periods). You’re paying back almost R10k every month but your first 42 payments don’t even dent the capital by more than R1000 at a time. Effectively, after 3.5 years, you’ve paid over R420k back, but still have R767k out of the original R800k owing.

Eish. That’s why credit is so expensive and not everybody can afford to jump into the property game.

Which also brings me to another point… a parting shot, if you like. Think _very_ carefully about the impact of renegotiating your outstanding debt. Imagine: 3.5 years later, and almost half a million out of pocket, you get a generous offer an opportunity to renegotiate your existing debt. In essence, you start all over again. Remember the curve! Another 3.5 years later, another R400k out of pocket, and you’ve only managed to claw back R35k, give or take. Sound like a smart move?

**NOTE: Different institutions structure fees into their loans, so the actual repayments may vary if you ask them for quotes and compare to this calculator. Query the fees. Always.

Categories
Technology

Deploying Rails

A while ago, i got addicted to RoR. Life before RoR was… well. Mundane. Don’t get me wrong. There was still a lot of exciting stuff going on, but RoR opened up a brave new world and it’s “differentness” added to its appeal. And since then, i’ve written a fair amount of Rails apps and a few libraries in Ruby for my own use. And then i tried to deploy a Rails app.

… ?:o

It was hard. And especially hard since i couldn’t eat, sleep and breathe the environment; so every opportunity i got to tackle the problem, i had to relearn the same commands. But i got used to it. I read _a lot_. And i managed to actually understand the conversations at one point. A major plus 🙂

In case you’re wondering what a *normal (or typical?) deployment might look like, take a peek here.

*Normal or typical probably doesn’t even exist, it’s just a phrase which suits my goals at the moment.

In any event, there’s some configuring going on. Examples are here, and here, and here. And there are more.

And despite the seeming “mission” related to deploying apps (and why a lot of folk just abandoned the platform altogether), i still believed it would get better. It just had to.

Hello, Phusion Passenger. Phenomenal! And suddenly, the roses are redder, the skies are bluer, the birds sing clearer and the apps deploy smoother. Waaaay smoother. Keep your eye on this one!

Oh. and here’s more about using Phusion Passenger in development.

Categories
Technology

J2ME Math

While developing a financial calculator on the J2ME platform (MIDP2.0, CLDC1.1) i had the need for some “basic” math functions like pow() and log(). As it is, there’s nothing quite like that natively available on the platform which on one hand surprised me; on the other, got me quite excited. I’d have to implement my own 🙂 Geek.

Now there’s a lot of discussion online and i’m not going to repeat all that here about the various math libraries and the reasons why the implementations aren’t available. What i will link to however, is a friendly, but relatively in-depth review of implementing your own pow() function. Incidentally, this article also implements an “inline” function for determining ln(x) in the dissection on using the Taylor series algorithm.

Wikipedia also have a pretty decent discussion on the fundamentals of logarithms which lead to more insight on the implementations discussed above.

So if you plan on doing math on J2ME, plan ahead. You will need to Google for some math libraries, or be prepared to roll your own. I prefer the roll-your-own method unless you need _all_ the features of library X. Keep it trim. And i get to apply some years of text-book learning 🙂

Big plus is you can unit-test it and luckily the laws of math don’t change too often so once you’ve written it, porting to other platforms/frameworks/languages in future is straightforward. Where as the entire library you might have linked to is only available on that one platform/language.

Categories
Technology

CodeIgniter Playground

After some tinkering with CodeIgniter, i’ve setup a small playground (which will hopefully grow over time) to test drive the framework.
I like the framework for it’s lightness- and you get quite a lot of control without having to rely on helpers to do _everything_. You can learn the helpers as you need to, so getting something up and running is easy enough and requires no massive investment in a proprietary methodology, terminology, apiology or documentology.

As for rhe RoR-ish slant. It is well… erm… RoR-ish. But really, nothing beats RoR. CodeIgniter is not bad. Rails still kicks!