Monday, May 4, 2015

GPS Calculation Methods

What Method Does Garmin Use to Calculate Distance ?

Edward Sargisson, at Trail Hunger, concludes that Garmin devices do not use the 3d slope distance when reporting distances, but rather the distance at sea level.

Calculation of the Distance Between 2 Points on the Surface of a Great Sphere - the Haversine Formula

This can be achieved using the Haversine Formula, here is a javascript implementation from Movable Type Ltd:

var Bx = Math.cos2) * Math.cos21);
var By = Math.cos2) * Math.sin21);
var φ3 = Math.atan2(Math.sin1) + Math.sin2), Math.sqrt( (Math.cos1)+Bx)*(Math.cos1)+Bx) + By*By ) );
var λ3 = λ1 + Math.atan2(By, Math.cos1) + Bx);

See Also

R. W. Sinnott, "Virtues of the Haversine".  Sky and Telescope, vol 68, no 2, 1984

Sunday, May 3, 2015

Practical Object Orientation in JavaScript

http://www.phpied.com/3-ways-to-define-a-javascript-class/

methods defined internally

function Apple (type) {
    this.type = type;
    this.color = "red";
    this.getInfo = function() {
        return this.color + ' ' + this.type + ' apple';
    };
}

methods added to the prototype

function Apple (type) {
    this.type = type;
    this.color = "red";
}
 
Apple.prototype.getInfo = function() {
    return this.color + ' ' + this.type + ' apple';
};

using object literal syntax to create a singleton class

var apple = {
    type: "macintosh",
    color: "red",
    getInfo: function () {
        return this.color + ' ' + this.type + ' apple';
    }
}

Saturday, April 25, 2015

Convert .MP4 to .AVI - Linux

$ sudo apt-get install mencoder

$ mencoder source_movie.mp4 -channels 6 -ovc xvid -xvidencopts fixed_quant=4 -vf harddup -oac pcm -o dest_movie.avi

Wednesday, April 8, 2015

simple python http server - BaseHTTPServer vs apache

http://stackoverflow.com/questions/5693741/whats-difference-between-a-simple-webserver-and-apache-server

Question

What's difference between a simple webserver and Apache server?

Answer @ ninjagecko
Or in other words, if i want to use python to implement a server which can be put into use of business, what also should i do?
There are already python-based web servers, such as CherryPy (which I think is intended to be a web server solution on the same stack level as Apache; it is more python-based though, and Apache has been around a lot longer).

If you wish to write a lightweight extremely simple webserver from scratch, there is probably nothing wrong with using BaseHTTPServer, other than perhaps a few outstanding design issues (I hear race conditions might permanently clog a socket until a thread dies).

Though I would not recommend it (alone) for business, some of the big boys use BaseHTTPServer with a bit of extra machinery: http://www.cherrypy.org/browser/trunk/cherrypy/_cphttpserver.py?rev=583

To elaborate, Apache is the industry standard. It has a plethora of configuration options, a security team, vulnerability mailing lists I think, etc. It supports modules (e.g. mod_python). Python-based web servers also support python-based modules (maybe they might allow you access to non-python things) via something called a WSGI stack; a WSGI application can run on any python-based web server (and Apache too, which also has a modwsgi); I think they are narrower in scope than Apache modules.

Apache module examples: http://httpd.apache.org/docs/2.0/mod/
WSGI examples (not a valid comparison): http://wsgi.org/wsgi/Middleware_and_Utilities

I might code my own webserver if I'm doing something extremely lightweight, or if I needed massive control over webserver internals that the module interfaces could not provide, or if I was doing a personal project. I would not code my own server for a business unless I had significant experience with how real-world web servers worked. This is especially important from a security vulnerability point-of-view.

For example, I once wrote a web-based music player. I used a BaseHTTPServer to serve music out of a sandbox I had written to ensure that people couldn't access arbitrary files. Threading was a nightmare. (I recall a bug where you needed to pass special arguments to Popen since threading caused an implicit fork which would cause hangs on dangling file descriptors.) There were other various issues. The code needed to be refactored a lot. It can be very worthwhile for a personal project, but is a significant undertaking and not worth it for a business that just needs a website.

I know two startups who have been content using Pylons (using Paste) or Turbogears (using CherryPy) in the past, if you're looking for a lightweight python web server stack. Their default template systems are lacking though. The choice between Apache and a leaner more python-based web server may also depend on the skillset of your co-developers.

Friday, March 13, 2015

uBuntu - Error Reporting - Turn Off

edit /etc/default/apport, e.g. 

$ sudo gedit /etc/default/apport
 
then set 'enabled' to 0, and save 

Tuesday, March 10, 2015

Dieter Ram's 10 Principles of Design

Dieter Rams is an industrial designer, renowned for the functional, minimal style he demonstrated at Braun, where he worked from 1965 to 1995.

He is cited as a major influence on designer Johnathan Ive, who is associated with the functional, minimalist design aesthetic reintroduced to Apple products with the advent of the ipod music player, and continued in their phone and operating system product lines.

- - -

Good design:

    Is innovative - The possibilities for progression are not, by any means, exhausted. Technological development is always offering new opportunities for original designs. But imaginative design always develops in tandem with improving technology, and can never be an end in itself.

    Makes a product useful - A product is bought to be used. It has to satisfy not only functional, but also psychological and aesthetic criteria. Good design emphasizes the usefulness of a product whilst disregarding anything that could detract from it.

    Is aesthetic - The aesthetic quality of a product is integral to its usefulness because products are used every day and have an effect on people and their well-being. Only well-executed objects can be beautiful.

    Makes a product understandable - It clarifies the product’s structure. Better still, it can make the product clearly express its function by making use of the user's intuition. At best, it is self-explanatory.

    Is unobtrusive - Products fulfilling a purpose are like tools. They are neither decorative objects nor works of art. Their design should therefore be both neutral and restrained, to leave room for the user's self-expression.

    Is honest - It does not make a product appear more innovative, powerful or valuable than it really is. It does not attempt to manipulate the consumer with promises that cannot be kept.

    Is long-lasting - It avoids being fashionable and therefore never appears antiquated. Unlike fashionable design, it lasts many years – even in today's throwaway society.

    Is thorough down to the last detail - Nothing must be arbitrary or left to chance. Care and accuracy in the design process show respect towards the consumer.

    Is environmentally friendly - Design makes an important contribution to the preservation of the environment. It conserves resources and minimizes physical and visual pollution throughout the lifecycle of the product.

    Is as little design as possible - Less, but better – because it concentrates on the essential aspects, and the products are not burdened with non-essentials. Back to purity, back to simplicity.

Sunday, February 8, 2015

GIT Sub-Modules

use other git modules within your repo by reference


git-scm.com/book documentation