Tuesday, November 07, 2017

How to learn touch typing quickly (my story)

There is no doubt that touch typing (Wikipedia) - a way of typing on the computer keyboard without looking - is much faster than the visual hunting for the right keys. Imagine how much more you could achieve if you typed faster. I will share my story how I learned this in two weeks.

TL, DR: Just do it.

Back in 1996, when I studied computer science at the Kiev-Mohyla Academy, some American (don't remember the name, it was something like Mike) has organized a computer room at the university with Internet access. This was a big deal back then. Most people with computers had only BBS access using the slow modem devices. I was immediately hooked and spent time in the room almost every day.

Sunday, August 06, 2017

TED Talk. Info-faith.

As a child I used to think that all or almost all information and knowledge about the world is known. My primary source of information was my father who had told me different scientific facts in a way a child could understand. And if he would not know I was sure there's somebody clever out there who does.

Later I started to realize that it's far from truth. As I grew and learned more - I noticed that all the knowledge of humanity is just a small fraction of what's there to learn.

The more we learn about the world the more we wonder. Think of an ancient man who saw the forces of nature, the great mountains, the vast oceans, soil producing food... He thought it's must be created by a God. Fast-forward to a Newton and his apple. The guy was clever enough to come up with an explanation of the planetary movements when he was hit hard by an apple. I wish I had brilliant ideas every time I'm banged on my head ;-). At that time people started to realize that there are forces and laws that make life possible. Not only the existence of the gravity is important but the precise magnitude of it as well. If the gravity were weaker, Earth would be larger and less dense, water freezing point would be higher, surface tension smaller, tons of other effect would be much different leading to a lesser chance of live. The same for stronger gravity - everything would be heavier, trees would be just 15cm high, no much biomass, no chance for any animals to get enough food to evolve.

Nowadays, scientists have came up of dozens of different universal parameters each of which is probably having quite wide range for life to emerge, but all together, being dependent on each other, they form a fragile web of relationships to each other. Touch one parameter and the whole perfectly tuned system would crash like a card-house. You can learn more about this here: Why is our universe fine-tuned for life? | Brian Greene.

That said, it's kind of sad that most scientists are atheists. Just think about all these dependent universal constants: they are all perfectly synced. Who did that? Mere luck? Scientists leaned not to believe in luck - they believe in statistics. So they've come up with this idea that there are indefinite number of other universes with all sorts of different values for the universal constants and we just happen to be living in the best of them. There isn't just one perfectly tuned universe but lots of them. And the life in other unsuitable universes just doesn't exist to be asking such questions.

But this approach is against the Occam's razor: don't make complications when there's a simpler explanation. One just needs to admit that the universe is created they way it is. The difference is subtle: "created" instead of "happens to be". Yet this gap is too wide for them to cross.

Religion starts when faithful people organize themselves and start collecting money. As soon as there's money involved it's business. Religion is a business of making money from faithful people or people who think they are faithful. That's why there are Jehovah's Witnesses willing to talk to you everywhere - the business model requires new sources of money. Faith is only loosely related to religion.

The point of my talk is to bring you closer to understanding and appreciation of the world we live in and comprehension of the fact that it exists. When walking around, looking at the flowers, trees, creeks, mountains, valleys and while at the zoo - think of the what you see and understand that what you're looking at is a miracle.

Thank you.

Single most annoying Xperia Arc flaw

It's the back cover which is curved and not flat. Not the hardware (a mere 600MB RAM is desperately not enough) nor software (laggy and crashing launcher). The problem is that the phone is not usable on a flat surface, it's rocking left and right when touchscreen is touched making it impossible to operate accurately. And it's curved on most Xperia phones (I owned 4), not just some. There's one exception AFAIK, Xperia Z. It's square as a thin brick. I can put on the table and touch it without my gestures being smudged. What a relief!

Friday, July 21, 2017

Markdown blogging example

Sunday, September 13, 2015

Thoughts on the perfect city

What is the most important feature of the property (I mean a flat,  house,  appartment or bungalow)? More important than the amout of rooms or how well it's decorated? It's a location!

Would you like a penthouse in a desert? A small house by the sea is a dream of millions. But our cities are far from being a dream come true. Some people live next to the park or a lake,  but most are not. I was thinking - how should have our cities been built to make everybody happy with their property.

In the past, people took what the nature gave them - a cave, leather drape for a door, a branch as a weapon. With time people started making their own tools and build their homes. But we still build cities randomly - where there's some place not too steep and not too wet and not too dry. I think with time people start making their cities according to the plan larger than just "filling the area with buildings packed as close as possible to each other like in Tetris".

Most poeople like fresh air of the forest. So a city must be a forest. Many like lakes. There should be lakes in the forest. Cities should have good bycicle infrastructure. Bycicle roads in a forest. Cars and roads are still needed. Transporting heavy stuff or lazy people is important. Quickly. So we need highways in a forest.

For a biker a 100 m. detour is more annoying that to a car driver. So we build straight and convenient bycicle roads, without traffic lights! Cars can drive around a bit without much trouble.

Now the houses. Current high building are an efficient use of land but that is not a priority anymore. They are a problem for disabled people, for firefighters, for moms with children, for elderly - effectively for all of us at some stage in life.

So we build a 2-3 storey houses. In which arrangement? Currently every house is isolated from it's neighbors. Often with a fence. Everybody has their own garden,  their own lawnmower, own drill, vacuum clener, Internet connection, phone line, network router, printer, etc. This is very ineffective. It's a share nothing architecture. I suggest to build houses arranged in a circle around a central shared area.

This shared area may have a small playground, a common house used by everybody in a circular block, a common garden. In a house there can be a set of instruments and tools, a large table with chairs for everybody in a block, storage shelves for common and private stuff. People should be encouraged to share things they don't use everyday with their closest neighbors. Why not? Of couse, you can have your private juice maker if you like. I can't convince you. You either support the idea of sharing or you don't.

Parking is underground under the buildings. With space for visitor cars and bikes. Cars can be shared as well, by the way.

So we have circular districts of houses with a common shared house in the center located in a forest with bycicle routes to other circular districts, but in which arrangement?

Current cities are either circular (like Moscow) or square (like New York). Circular are more natural as they evolved around a palace, castle or church. We always have a center or a downtown in every city, where there are more of everything (government institutions, restaurants, entertainment, shops) and the property prices are higher. This leads to traffic into and out of the center,  parking problems, pollution, waste management - all the city problems we heard of so much.

My suggestion is to disperse all that can be usually found in the center equally thoughout the forest-city. There will be a bakery for each X of the circular districts, a kindergarden, school, cinema, hospital and everything else. Yes, this way we need more of these facilities and they will be smaller. Different facilities will have a different dispercity level, of course. But they should not tend to be situated close to each other. Or maybe we can have islands of public service buildings for every X of the living blocks.

Do you imagine a homogenous city consisting of neighborhoods in a forest? Such city can be easily expanded in any direction by just adding living districts with some islands of public service areas. These areas should be reachable in 5-10 minutes by bike.

Would you live in such a city? Let me know in the comments.

About Mapping Services and Other PHP Libraries for using in Mashup application

How I built an http://have-you-been-here.appointment.at/ using third party libraries from http://github.com/

http://have-you-been-here.appointment.at/ is a site where users may submit images of different locations on Earth (provided with geo-coordinates) so that other users may find nice places to visit. When building the site I had used many different PHP and JavaScript libraries. Here I'm sharing the information I leaned about these libs.


First of all, I use myself and recommend composer. You list the libraries you need to use in your project and then say composer update and all listed libraries get installed into the vendor/ folder. The same command is installing updates to the libs, if available. That's great - no need to check for updates manually. Below is part of my composer.json file. The rest of the post will shortly highlight each of these libraries.

{"name": "have-you-been-here",
    "require": {
        "components/jquery": "*",
        "components/jqueryui": "*",
        "components/bootstrap": "*",
        "hybridauth/hybridauth": "dev-master",
        "blueimp/jquery-file-upload": "dev-master",
        "hpneo/gmaps": "dev-master",
        "pear-pear.php.net/DB": "*",
        "needim/noty": "dev-master",
        "phayes/geoPHP": "dev-master",
        "anthonymartin/geo-location": "dev-master",
        "DanElliottPalmer/GeoJSON-Parser": "dev-master",
        "jrburke/requirejs": "dev-master",
        "flesler/jquery.scrollTo": "dev-master",
        "bradwedell/php-google-map-api": "dev-master",
        "ezyang/htmlpurifier": "dev-master",
        "fg/essence": "dev-master",
        "jakiestfu/Snap.js": "dev-master",
        "components/modernizr": "dev-master"


jQuery is a must in any project. It changes the way you will write JS. Your code would not look like plain JS anymore, but would become easier to read and shorter to write.
JQueryUI is a collection of widgets like a calendar, slider, ... and a nice CSS for these widgets and error messages.


Even better CSS framework than jQueryUI. Just like nobody is writing pure JS without any libraries, you shouldn't write your own CSS from the scratch.


Allows your users to login with Google, Twitter, Facebook and other accounts with OAuth. You can easily add any other OAuth provider which is not pre-configured in Hubridauth.


The best ever file upload lib with support for drag-n'-drop and unobtrusive degradation to standard HTML uploads. Accepting uploads in PHP is a little awkward (no data in $_FILES) but they provide a PHP class for handling uploads on the server.

Map libraries

I find the original Google Maps API too complicated for simple tasks like showing a map at the specified location and showing a single marker with a tooltip information.


Therefore I have gladly used a php-google-map-api. Usage is pretty simple, her3 it shows a map of a specific location and a marker:


$map = new GoogleMapAPI();
$map->_minify_js = TRUE;
$map->width = '100%';
$map->addMarkerByCoords($coords[1], $coords[0], $this->model->getName());
$this->index->header[__METHOD__] = $map->getHeaderJS();
$this->index->header[__METHOD__] .= $map->getMapJS();
$content .= $map->getOnLoad();
$content .= '<div class="popin">'.$map->getMap().'</div>';


This was fine for a static map, but once I needed an interaction with a user in the browser like repositioning the map after geolocation - I had to revert back to JS.
Luckily I've found a gmaps.js a wrapper to Google Maps API with MUCH simplified API than one provided by Google. Making a map is as simple as this:

var map = new GMaps({
  div: '#map',
  lat: -12.043333,
  lng: -77.028333

Adding a marker is so simple:

  lat: -12.043333,
  lng: -77.028333,
  title: 'Lima',
  click: function(e) {
    alert('You clicked in this marker');

Geolocation in one line with four event handlers!

  success: function(position) {
    map.setCenter(position.coords.latitude, position.coords.longitude);
  error: function(error) {
    alert('Geolocation failed: '+error.message);
  not_supported: function() {
    alert("Your browser does not support geolocation");
  always: function() {

Definitely a way to go if you're new to maps.

GeoPHP and GeoJSON

Once you have a map you most likely need to display more than one marker and download and update markers according to the view area of the map (when user is panning or zooming). Surprisingly, Google doesn't provide any help in this. So everybody is inventing their own JSON/XML format for transferring marker information between server and JS. And,  accordingly, a custom JS to parse and display markers.
There is one standard which kind of goes in the direction of standardizing the geo data transfer - GeoJSON. It allows you to transfer points, polygons, filled areas. I was interested of transferring markers (points in GeoJSON) with additional information (title, tooltip text, click link). Unfortunately point data type is not meant for markers - all additional data are transferred as custom properties and the propery names are not standardized. But there's at least a PHP lib for generating GeoJSON and JS lib for parsing it.
Generation is done without any library like this:

$json = new stdClass();
$json->type = 'FeatureCollection';
$json->features = array();
foreach ($this->data as $row) {
    $feature = new stdClass();
    $feature->type = 'Feature';
    $feature->id = $row['id'];
    $feature->geometry = new stdClass();
    $feature->geometry->type = 'Point';
    $feature->geometry->coordinates = array($row['lon'], $row['lat']);

    $properties = (object)$row;
    $feature->properties = $properties;
    $json->features[] = $feature;
echo json_encode($json);

AJAX requesting and parsing is done with GeoJSON JS lib:

GeoJSON.loadJSON(jsonURL, function(e) {
    var f = GeoJSON.parse(e);

    for (var a = 0; a < f.length; a++) {
        // add to the map
        var latlng = f[a].getCenter();
        if (!self.contains(latlng)) {
            var marker = new google.maps.Marker({
                position: latlng,
                map: map.map,
                title: f[a].properties.name
            marker.place = f[a];

As you can see, generation of the markers and reading marker properties is up to you to program.

Server side map support

I always thought (without having a clue) that one needs complicated queries for searching markers in the database. I've seen PostgreSQL even has a plugin for geo support in the DB.
In fact - it's very simple. Google Maps gives you north-east and south-west coordinates of the currently displayed map. This makes your SQL as simple as

WHERE lat BETWEEN 10 and 20
  AND lon BETWEEN 30 and 40

This, of course, requires that you have lat and lon in the database. If you need to geocode addresses into coordinates you cat use Geocoder-PHP.


There is a. lthough one situation where it gets more complicated. When geolocation has beed done in browser, you get lat/lon of the center of the map, but there is no predefined zoom level and hence - no map boundaries to use in the query above.
I decided to start searching for places in the 1 km area around the location. If there are no or less than three places found - I search in the 2, 4, 8, 16 etc. km area. To be able to search for markers inside the specified radius around the specified location requires converting location/radius into bounding-box coordinates. The math of the process is described nicely here. A GeoLocation.php library has a function for this.

function getBoundingBoxFrom(array $pos, $km) {
    $edison = GeoLocation::fromDegrees($pos['lat'], $pos['lon']);
    $coordinates = $edison->boundingCoordinates($km, 'kilometers');

    $lat1 = $coordinates[0]->getLatitudeInDegrees();
    $lon1 = $coordinates[0]->getLongitudeInDegrees();

    $lat2 = $coordinates[1]->getLatitudeInDegrees();
    $lon2 = $coordinates[1]->getLongitudeInDegrees();

    return array($lat1, $lat2, $lon1, $lon2);

SQL will look like this:

list($lat1, $lat2, $lon1, $lon2) = $this->getBoundingBoxFrom($pos, $km);
$pc = new PlaceCollection(NULL, array(
    'lat' => new SQLBetween($lat1, $lat2),
    'lon' => new SQLBetween($lon1, $lon2),

Additional map operations

Autofitting map area to the set of found and diaplayed markers.

After retrieving some markers from the above query and transferring them to JS with GeoJSON one needs to zoom the map so all the markers are visible. Probably one could do the calculations in PHP and transfer that somehow in GeoJSON but this operation is easily done with standard Google Maps API.
You collext all markers in an array and get Boundary class do the work.

Reacting on user panning and zooming.

This is easily done qith standard API.

The event 'idle' is triggered after the map is done panning/zooming. Note that this event should be registered AFTER initial displaying of markers as we do boundary fitting, which triggers pan/zoom itself.

Sanitizing user comments

This is very important. Noone wants his site to be vulnerable to XSS or contain viruses. I thought PHP function 'strip_tags' is good enough for this. You are allowed to define unharmful tags which will be kept (like <i>, <b>). But is appears the function is not safe enough. See explanation on the page of ###. It also reviews other solutions and thwir shortcomings. Using ### is as simple as

Embedding content from user submitted links

OEmbwd stansard allows you to embed contend from other sites when all you have is a URL of the content to embed. This ia how you can have YouTube links to be shown as a player and Share? presentations as presentations. ### is the best library for this. Usage:

It comes with a list of oEmbes aites and you can add moee. Other libraries arw listed here, but I disn't like them as much as ###.

Slideable drawer

I believe this cocept is invented by Android or maybe Facebook app. Anyway, I fins it vwry convenient as a way to hide the sidwbar on the narrow screen devices. After reciewing suggested libraries at ###, I have choaen Snap. It requires a very specific HTML layout and uaes absolute CSS positioning so I had some work to embed it into Bootstrap layout, especially as I dont want any drawer functionality on the desktop beowsers. So I have a browser setection after the pagw ia loaded and rhen I manually adjuat Bootstrap layput to fit the requiremwnts of the Snap.

On mobile browser it looks like this.


See how I detect mobile browser in the coee above? Modernizr is testing different browser feautirws and als adds correspinding classes to the tag, allowing you

Tuesday, February 10, 2015

Idea: Autobahn (Motorway) information app (site)

Imagine you drive on the autobahn and don't have a navigation system. Or you know the way and don't need the navigation system and it's too boring to enter the destination. But you still want to know what awaits you ahead on the way. So you open an app (or site autobahn.com) and it will:

  1. Detect your location with navigator.geolocation.getCurrentPosition(function(a) {console.log(a);})
  2. Query OpenStreetMaps with Overpass API to find which is the autobahn you're driving and where are the nearest exits, parkings, fuel stations and distances to the nearest large cities.
    Example query: http://overpass-turbo.eu/s/7Ao
  3. Parsing the data is described here: http://stackoverflow.com/questions/14946096/read-and-analyze-json-from-osm-overpass-api-get-polylines
  4. It shows the queries information on the site (in the app, it's very easy to make an Android app which works exactly like the site using WebView, see https://play.google.com/store/apps/details?id=spidgorny.noname_reader).
  5. Separately it should download the information from the TMC traffic jams. This doesn't seem to be available for free though. http://wiki.openstreetmap.org/wiki/TMC/TMC_Import_Germany.
  6. It may display local ads. Needs to be popular to make sense.
As most people have a navi hardware or software, this it mostly for nerds.

Friday, December 19, 2014

Time Tracking from Commit Messages

Everybody hates time tracking. Mostly because it takes some time (even if it's just several minutes) to enter the TT system, enter the duration, choose the project and maybe write a comment. Programmers have it a little easier. They are used to writing comments after their work into a VCS (Mercurial, Git, etc.).

Why not combine the two. What if you could write a time you spent on the feature directly into the commit message? Some VCS support this already.

Trac (http://trac.edgewall.org/wiki/TimeTracking)

It's a plugin which is not easy to configure but you can enter the time spent in brackets like this "(1h)".

Freckle Time Tracking (http://mir.aculo.us/2009/10/12/instant-time-tracking-from-git-commit-messages/)

"So Freckle Time Tracking now comes with Github integration, which means you can instantly log time from Git commit messages when you push updates to Github."

Entering times looks like this "f:2.5". More details: https://help.letsfreckle.com/import-export-api/log-time-from-commit-messages

Redmine (http://www.redmine.org/issues/1518)

Supports it since 5 years ago. Format "time 30 m" on a new line.

JIRA (https://confluence.atlassian.com/display/AOD/Processing+JIRA+issues+with+commit+messages)

That's the largest issue tracker, of course it supports it. Format: "#time 1w 2d 4h 30m".


I'm the developer of a small time-tracking system and I don't use any of the above. So I've made a small PHP script which would analyze the commit log and collect the times from it. Format: "[0.5h]" or "[22:15-23:00]". The results would look like this, but it's easy to customize.

Using all the power of millions of idle computers

Do you know how busy is your computer on average? You think 50%? Open a task manager and check yourself. Mine was busy at 2-3% only. That is having a browser, text editor and a couple other app open. Unless you are archiving or extracting an archive, your computer is almost doing nothing. It's the power wasted. Think of thoussands and millions of computers turned on but doing almost nothing. That's maybe not the case for computer professionals, but even they don't use more than 20% of what they have. Whatever you do: browsing, watchin video, listening to music, typing... Especially typing - it can do millions of operations between each two letters that you type. Why doesn't it?
In 2000, when I was graduating, one of the graduation topics was about "agents" - small applications running on multiple computers on the network performing some distributed task. It was a hot topic back then and it looked like in no time, all computers will run some kind of agent.
Now, in 2014, I can't recollect I've heard the word "agent" in years. What happened? And what can we do to revive the idea?

What are agents?

If you have head of SETI@Home or Folding@Home you should know what I mean with an "agent". It's: - a small application - running on multiple computers - receiving tasks to do from the Internet - processing something - sending results back to the Internet server.
This effectively allows to use the power of thousands (millions) computers to do a very complicated task which is split into smalled chunks in parallel. This is a huge potential. Imagine how much would it cost to purchase a thousand average computers, place them somewhere, connect them all, pay for the power they consume and maintenance. This is what companies like Google do. They have the money, many other organizations don't.

My suggestion

Programming a new system like SETI@Home is not a simple task. Redoing it again for another project is a waste of time and not DRY(http://wikipedia.org/wiki/DRY). But most complicated is to enlist users to download and install one more client on their computers. Why not having a general agent system which is capable of running any task? Users only need to install it once, but the participating organizations would only need to program the actual computational algorithms (about 20%) - not the 80% of the infrastructural code. This will allow smaller ogranizations to gain access to free computer power - benefiting the society. Users only need to install an agent once and rest assured they are helping the world by just not turning their computer off.
It should be written in Java. I don't like Java so much, but there's no other language which can be run on almost any computer that exists. It also features a relatively good security by isolating the running code from the operating system.
The client would be represented by a task bar icon. When you open the details it should show a project it is working on (SETI, Folding or anything else), current CPU idle percentage, CPU idle percentage if no task was running, total processing time spent since the installation and some kind of reward points collected for donating your computer. It should detect when computer needs some extra power for doing user-initiated task and pause the task processing so that users don't feel that their computer is any slower than before.
A server should be able to maintain a list of projects and hold the source and processed data for the project. The results may be obtained by the project's owner organization. A website of the project can show the total processing power in use (FLOPS).
BTW, do you know that the total processing power of Bitcoin mining machines have exceeded 16 petaFLOPS? The world's top ten (all ten of them) supercomputers can only do 5% of that. And Bitcoin mining is NOT what your average neigbour is doing. The amount of processing power being wasted is just mind blowing. The cure for cancer maybe found just 10, 100, 1000 times faster. Imagine a thousand other projects which are NOT done because of lack of computer power.
Would you allow your computer to do some research while you are browsing?