Why use client side MVC frameworks

I recently posted regarding my new preference of RoR vs Django. Moving forward with updating my knowledge of web development, I took a look at AngularJS and I have to admit I like what I see. Their tutorial is very well built and clearly demonstrates how to render views on the client side based on data generated on the server side.

This means your back-end does not need to render any HTML code anymore and you can focus on developing REST APIs providing the data. While client overload may still have been an argument against client side MVC framework a few years ago when this new kind of framework appeared, modern computers can really handle the rendering, and modern mobile phones are way faster than older desktop systems.

I chose AngularJS because the application I am currently working on was originally developed with it but you can find a very clear comparison of client-side MVC frameworks on TodoMVC where you can find a to-do application implemented using the various frameworks available today.

RoR vs Django

I love Django. It was the first framework I used when I took a new look four years ago at web development after playing around with PHP during my high school years (it was PHP3, almost 4 at the time…). And I developed two projects with Django.

But now I am considering getting a new job with a startup and they already have a website developed by a freelancer using Rails. So I spent the last week going through this book and I have to admit I am impressed.

So impressed that I will probably be using Rails from now on when I do not need to develop single page applications where I believe Meteor has a stronger case.

This is just my opinion but in case you still have a doubt on which framework to go with to get things done quickly, go with Rails.

Meteor: closer to the future of web frameworks

Back in April last year I was writing about my recent discovery of the full stack javascript frameworks, and at the time I was thinking this was maybe going to be the way of the future in web development.

Well almost a year later, I have kept reading articles on these libraries and I have to admit I never really tested anything, and stuck to Django for my web projects.

Until this week where I heard about Meteor from a friend. And now I have to admit that even if I am a little reluctant to fully dive into this new tool due to the lack of a proper debugging for Javascript, I was more than impressed by the features it offers: fully responsive, live update, easy deployment, package system, thriving community, etc…

It will not kill Django and Rails overnight, they keep an edge for the backends, but if you have not already done so, try the demo project: a persistent collaborative todo list.

Some guys even wrote a Trello clone on github.

Parabolic SAR implementation in Python

I have recently tried to use the Parabolic Stop and Reverse indicator to track the VIX index (volatility on the S&P 500). A while back, I had used TA-lib and many of its indicators, but it was a while back. And I found it fairly painful to setup for Python this time. Given that I only needed this indicator, and that it is often better to have your own code for this kind of analysis, I simply translated an implementation from AmiBroker to Python. And here is a quick overview of what it looks like: pypsar20141209 The full code can be downloaded from my GitHub account.

def psar(barsdata, iaf = 0.02, maxaf = 0.2):
    length = len(barsdata)
    dates = list(barsdata['Date'])
    high = list(barsdata['High'])
    low = list(barsdata['Low'])
    close = list(barsdata['Close'])
    psar = close[0:len(close)]
    psarbull = [None] * length
    psarbear = [None] * length
    bull = True
    af = iaf
    ep = low[0]
    hp = high[0]
    lp = low[0]
    for i in range(2,length):
        if bull:
            psar[i] = psar[i - 1] + af * (hp - psar[i - 1])
        else:
            psar[i] = psar[i - 1] + af * (lp - psar[i - 1])
        reverse = False
        if bull:
            if low[i] < psar[i]:
                bull = False
                reverse = True
                psar[i] = hp
                lp = low[i]
                af = iaf
        else:
            if high[i] > psar[i]:
                bull = True
                reverse = True
                psar[i] = lp
                hp = high[i]
                af = iaf
        if not reverse:
            if bull:
                if high[i] > hp:
                    hp = high[i]
                    af = min(af + iaf, maxaf)
                if low[i - 1] < psar[i]:
                    psar[i] = low[i - 1]
                if low[i - 2] < psar[i]:
                    psar[i] = low[i - 2]
            else:
                if low[i] < lp:
                    lp = low[i]
                    af = min(af + iaf, maxaf)
                if high[i - 1] > psar[i]:
                    psar[i] = high[i - 1]
                if high[i - 2] > psar[i]:
                    psar[i] = high[i - 2]
        if bull:
            psarbull[i] = psar[i]
        else:
            psarbear[i] = psar[i]
    return {"dates":dates, "high":high, "low":low, "close":close, "psar":psar, "psarbear":psarbear, "psarbull":psarbull}

Playing around with Javascript & 3D: Three.js

Following on my previous post on Node.js, I continued to catch up with what I missed in JavaScript, and I discovered 3D with three.js.
Back in my college days I played with OpenGL in C but as 3D was not a primary focus at the time I never went very far as the scaffolding required to get started was too time consuming.

But with three.js you can prototype amazing animations in just a few lines.

I wrote two samples using this library, best used with Google Chrome:

  1. CrazyBox: this simply shows a box rotating randomly at the center of the space, throwing spheres around. The spheres are moving according to a parabolic movement caused by a constant gravity, with no friction. You can move around the box using the mouse thanks to orbit.js
  2. Rosenbrock: in this one you visualize particles animated following a Particle Swarm Optimization (PSO) searching for the minimum of the Rosenbrock function

Let me know if you need explanations on the parabolic movement or the PSO code.

Enjoy!

Node.js and friends: the future of web frameworks?

Once in a while, you realize you are reading more and more about new tools without understanding why they are becoming so popular.

I have been looking again at web technologies lately after several years of pure C#/desktop oriented development, and I found myself guilty of not quite getting the success behind node.js.

At first I was mislead by the “.js” name and thought it was yet another fancy jQuery like. But then I came to realize that it had really no connection, except the language.

Node.js is in fact a bundle of the V8 JavaScript engine and JavaScript libraries providing an environment to execute JavaScript on the server side.

Check these two links to understand how the full Node.js stack can be used, and in which cases: