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');
    document.getElementById('downloadlink').download='notes.txt';
    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 geobreadbox.com which I can't decide if it is funny or horrifying serious.

http://www.geobreadbox.com/blog-1/2016/10/27/53-geospatial-friday-halloween-special

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.