Saturday, 10 December 2016

Create files with Javascript

In web apps (the new trend is to call them progressive apps) it is often useful to create files on the fly. On this I talk about creating files on the user’s computer by executing some piece of code on the user’s browser and then let the user view them and even store them locally. The other alternative is to create files on the cloud so that the user may then download them, but sometimes this is not necessary. So let’s see how this can happen by placing a few lines of Javascript code on the web app.
The following example regards creating text files from text that is inputted by the user. For this we need a web page with basic formation and a textarea with id=”input” where users may type whatever they wish. Then some function that creates a file from input. And finally a function that makes the file downloadable.
The makeTextFile function creates the file on text input. At first it creates a null variable named textFile which will become the text file. Then a Blob named “data”. A blob is an object of immutable data (text or binary) that may be used like a file and Javascript uses blobs in order to manipulate files; in some cases this technique is used in order to prevent direct access of a script to the file system. You may create blobs containing binary or text data but in this example we focus on text files so our blob is of type 'text/plain'. Next step is to create a URL pointing to the blob using function URL.createObjectURL.

var textFile = null;
function makeTextFile (text) {
    var data = new Blob([text], {type: 'text/plain'});
    textFile = URL.createObjectURL(data);
    return textFile;

Function txt() that follows stores user input in variable textbox which will then be the input of makeTextFile function. Then the link with id=”downloadlink” of the web page is declared to point to the output of makeTextFile function. So by clicking on the link, user input is downloaded as a text file.

function txt() {
    var textbox = document.getElementById('input');
    var link = document.getElementById('downloadlink');
    link.href = makeTextFile(textbox.value);

Find the full source code of the above example in this link. In order to make this example I used various sources and examples from the web so there is no ownership on it; in other words “use it as you wish”.

Saturday, 29 October 2016

Zombies and other freaks in GIS workplaces

In the past, in certain jobs and certain offices I had the sense that I was surrounded by zombies and freaks.
It seems I 'm not the only one to have had such experiences. Read this post by which I can't decide if it is funny or horrifying serious.

Wednesday, 24 August 2016

Maps are better displayed on big (TV) screens

TV sets these days have become more powerful than ever. They are equipped with powerful operating systems like Android and WebOS and their screens seem more magnificent than they could ever be. So why not to use them for map display?
Maps contain information related to spatial data and it is always better to view them with a big clear view of the spatial information they carry. For instance, sometimes it is not so informative to view a generalized weather map in the small screen of a smartphone; a big screen or printing the map in a big paper give you a clear insight of the situation it represents. Also a school could use a set of digital maps for educational purpose rather than using a few printed maps not viewable from distance.
Of course professionals know these things and the use big computer screens for drawing maps but most other people use small screens even at home. Personally, I always thought that TV screens could have much more potentials beyond their traditional use. On this spirit I have released two applications that link viewing my web mapping application WMS Map Viewer On Line to Android TV and Amazon TV. The result is really great try it.

Play Store link

Amazon Appstore link

Saturday, 25 June 2016

Sea Hero Quest

Sea Hero Quest is a mobile game which contributes to research on dementia. It was designed by British game company Glitchers in 2016 in association with Alzheimer's Research UK, University College Londonand the University of East Anglia and with funding from Deutsche Telekom. The idea for the game came from neuroscientist Michael Hornberger of the University of East Anglia who collaborated with Hugo Spiers of University College London and a group of six other neuroscientist.

The way in which players navigate the game will help researchers to understand the mental process of 3D navigation, which is one of the first skills lost in dementia. It is hoped that a large number of people will play the game, thus contributing much more data than could easily be obtained in a laboratory experiment.

Source: wikipedia

Find it in Google Play. There is also a greek version.

Sunday, 5 June 2016

How to describe or represent an infinite object efficiently

There are many cases where you need to represent an infinite mathematical object on a way that you will be able to work on it. In other words, create a representation or a description of an infinite mathematical entity on a way that you can perform computations over it. In these cases just using a variable to denote the entity is not enough. You need a description of its structure and to be able to reproduce any part of the object using this description.
Usually these situations occur in theoretical studies but this does not rule out practical applications. An infinite object can be a number (real, irrational, transcendental etc.) or a sequence like an infinite binary sequence.
It is safe to consider a description that may be inputted in a Turing Machine (TM). It is a general purpose computational model and if you can build a TM that accepts as input your infinite object description then it is an efficient representation of your object, otherwise the description and the object itself are probably uncomputable.
Let’s see a few cases of infinite mathematical objects and how they may be represented in Turing Machines starting from trivial cases and moving on to more difficult ones.

Irrational numbers. Set Q of irrational numbers contains numbers of infinite decimal expansion like the number equal to 3/10. Despite this, it is very easy to describe any irrational number using the definition of infinite numbers. For each irrational number i stands that i = a / b, where a, b are natural numbers. On this way each i is easily described. Using this description we may perform computations between any two irrational numbers.

Algebraic numbers. The set A of algebraic numbers consists of computable numbers so each a of A is Turing computable and has a computable description. Using the definition of algebraic numbers we may construct a description. Each a is the root of some polynomial p so it may have infinite decimal expansion p however is of the form
hn xn+hn-1 xn-1+…+h1 x1+h0 x0
As a is computable p is also be computable, so it is of finite length. In order to represent p in a TM we introduce symbol “|” that substitutes the x^n factor so that p is represented on the tape of a TM as follows
hn | hn-1 | … | h1 | h0
Each p has a bounded number of roots. Let a be the i-th root of p then it may be represented in a TM as
hn | hn-1 | … | h1 | h0^i
by introducing symbol “^” in the alphabet of the TM.

Infinite strings. Each string may be encoded to a binary string so let’s talk about binary strings. Following Computer Science theory, infinite binary strings are either computable or uncomputable. About the uncomputable ones there is not much we can do, it’s clear that you cannot describe something that you can’t compute. The computability of the rest of binary strings implies that for each string s there is algorithm H that produces s. Each character of s may be produced by H so its operation describes it.
Of course H may be simulated in a Universal TM that accepts as input the description of H which is of finite length otherwise it wouldn’t be computable. As a result the description of H stands for a description of s.
Algorithm H is of finite length while s is infinite this directly implies that the structure of s follows some pattern that H iteratively produces while running on TM.

Transcendental numbers. These numbers have infinite decimal or binary expansions but for each one there are algorithms that may produce any part of its expansion. Following the same reasoning as with infinite strings, the description of any algorithm that generates the sequence of digits of the decimal or binary expansion of a transcendental number may stand for its description.

Thursday, 28 January 2016

Geometry and randomness reduction

Think of a 2-dimensional space, say a piece of paper. Let’s call it d. Each point p in d is random on the sense that on there is nothing special about p in comparison with any other point in d.
Now let us define arbitrarily in d a coordinate system and place in some point that we also choose arbitrarily coordinates (0, 0). Based on our coordinate system and its metrics the points in d now have coordinates and they are not so random anymore. The interesting thing is that some points in d are still more random than others, before explaining this let's talk very very briefly about randomness.
The sense of randomness on modern science is studied in many fields and has to do with probabilities, complexity and our descriptive ability and there are many different ways to define it. I think the easiest way to discuss it is through examples. Let a and b be two strings
a) 100000000
b) 197599249
String a is less random than b for a number of reasons. At first if we use a random number generator (or simply throw some dices) it is really difficult to generate string a with number 0 to appear 9 times consecutively, a string with structure similar to b is more possible to come up.
Then string a is more special while b is more common. You can characterize a as special as it has lower information entropy and lower Kolmogorov complexity (or else algorithmic complexity). This kind of complexity is related to the best means we may use to describe this string. Given a computational machine T the algorithmic complexity of a string s is equal to the smaller algorithm that we may develop in T so that T will produce s. Algorithmic complexity is uncomputable so we may not get an absolute number as a measure of complexity for s. Nevertheless it has an interesting property based on the invariance theorem which allows us to compare the complexities among different strings. No matter what computational model we choose the difference in algorithmic complexity between two given strings will still hold. This means that we may use just one computational machine T in order to examine the randomness of a and b. Let us describe abstractly two programs that produce these strings.
a) printf(10^9)
b) printf(14057^2)
These are probably the shortest descriptions of the strings. String a has sorter description so it is less complex and more special than b.
Now let's go back to our 2D plane d in which we have defined a coordinate system. Some points on d are less random than others on the sense that we may form more special descriptions on them and some points are more special as they have more special properties than others. The point in (2, 2) is less random than the point in (1.9876, 3.4567).
Moreover if we define a straight line between point p1 and p2 there are along the line some points that are more special than the rest. The midpoint of the line and the points that split the line in segments l1 and l2 for which stands that l1/ l2 = n, where n is some integer, they have this special property that makes them more special and less random than the rest of the points on the line. Also all the points on the line are described by the equation of the line y = mx + c which makes them more special than the points in the rest of d.
As mentioned earlier the coordinate system is arbitrary places in d, yet this does not affect generality. No matter where we place point (0, 0) there will still be special points as described so far. The existence of less random points in d given any coordinate system is a property of d and an effect of defining geometrical structures in space.
If in d we draw regular shapes then the points on their periphery will have even more special description and properties. Their positions may be described using the equation of each shape. Also the space enclosed in a regular shape is described by its equations and is affected by its properties.
The same reasoning stands for classical geometry as well. Without using coordinate systems but instead using rulers and compasses we may describe special properties in any space and in geometrical shapes in it.
Geometry is one of the ways that humans have invented in order to describe the world around them and it has an important utility, it makes space less random by providing methods on describing special properties of it.