Sunday, June 24, 2018

Traffic Jam Dynamics Before The Split

Imagine you are driving on a highway and there is a traffic jam in front. The one where only several lanes are blocked and some are free to go because the road splits. Everybody goes very slowly stopping from time to time. What most people typically do in this situation - they tuck together very narrowly so that no other car can go around the rear end of the traffic jam and inject themselves closer to the splitting point. This leads to a following situation - people who missed the rear end of a traffic jam go all the way forward and inject themselves in the last moment before the split. This makes the traffic jam even worse because these injections cause the following traffic to break and stop.

Imagine now an alternative. We make a large gap in front of the car to allow people to inject themselves closer to the rear end of a traffic jam. I think this relaxes the traffic jam and allows more fluid flow of cars. Because, with a large gap, there is less braking needed.
What do you think?

©VOL.AT/Steurer

Friday, May 25, 2018

Caravan to Holland 2018

История нашего путешествия в машине-доме. 4 дня в Голландии. 1200 км. 200 фоток.


Машину мы сняли у частного лица на сайте Paul Camper. Машина находится в 160 km от нашего дома. Мы хотели взять с собой все четыре велика. Но перевезти в своей машине можно было только два. Два других нужно было перевезти в поезде.

День 1. Среда. Я сходил на роботу на пол дня, забрал сына из школы и начал собирать вещи для путешествия.

Собрали вещи до конца и я с @С поехал забирать машину-дом. Мы с Петрой (хозяйкой машины-дома) около двух часов обсуждали что в машине есть и как всё делается. Потом она ушла, @С заснул, а я перенес вещи из нашей машины в машину-дом, повесил велосипеды сзади на подставку, набрал воды (в машину помещается 120 литров) с помощью садовой лейки и выехал в город Кассель за @М и @Л. Они как раз в 01:40 приехали на поезде, Мы повесили еще 2 велика и поехали на парковку спать. Заснули в 03:00.


День 2. Проснулся я в 08:00, покупался на заправке. Все позавтракали и поехали дальше.


Мы решили ехать не на юг, как планировальсь раньше, а на север, в Esonstad. Это милый городок на воде про который мы узнали из AirBnB и Google Maps. Мы быстро доехали и остановились на парковке возлe пляжа. На пляже нашли детскую площадку. Порывшись в песке мы посмотрели городок. В пиццерии не оказалось веганской пиццы и мы уехали дальше.


Покушать решили в городе Леуварден. Остановились на набережной канала и погуляв немного поели пиццу и мороженное.


Далее поехали в город Zurich, где и заночевали на стоянке возле моря.

День 3. Проснулись мы под блеяние овец и ягнят. Вышли на вал к ним пофоткаться и посмотреть на воду.


Переехалии IJsselmeer и доехали по дамбе Afsluitdijk (построен в 1932). Если бы мы ехали ночью то можно было бы посмотреть Gates of Light.

Доехали в магазин в городе Anna Paulowna. Он так назван в честь русской жены короля William II. Позавтракали прямо на парковке магазина и поехали в Petten - на пляж. По пути остановились пофоткать поля тюльпанов.


На пляже позапускали летающего змея и порылись в песке. Вечером покатались на пляже и залезли на песчаную пирамиду.


В дюнах нашли интересный длинный залив с беседкой по середине. Во время наводнения St. Elizabeth's (1421) насыпь снесло водой и город Petten затопило. С тех пор пляж пытались укрепить чем попало (камнями и асфальтом). В 2015 голландцы намыли 35 миллионов кубических метров песка и создали новые исскуственные дюны.



День 4.

Переночевав мы зашли в ближайший кемпинг набрать воды и помыться.


Далеше поехали в Bergen aan Zee. На пляже посидели и пошли назад в машину. На велосипедах поехали кататься в дюнах. Видели великолепную дюну из белого песка. Ходить по дюнам можно только по выделенным тропинкам. Но эта дюна пересыпалась прамо на нашу велодорожку. Можно было слегка по ней полазить.



Доехали до города Bergen. Зашли ещё раз в магазин за подарками и поехали назад по другой дороге. Пейзажи и закат были внеземными. В дюнах паслись дикие коровы.


Уставшие пошли спать.

День 5.

Утром @М встала в 5:00 и пошла гулять по пляжу и встречать рассвет. Мы проснулись в 7:00 и пошли её искать. Спустя 2 км нашли и вернулись вместе. Позавтракали и поехали в город Egmond aan Zee. Погода испортилась. Постояв на ветру мы вернулись в машину и заехав посмотреть  аббатство поехали назад в Korbach сдавать машину.


По дороге сделали два привала. Целый день лил дождь. В Korbach заправились второй раз и помыли машину из шланга. @М и @Л сели на велики и поехали на вокзал. Мы попылесосили пол в машине и здали ее Петре. Сели на свой Приус (он показался удивителько юрким и тесным) и доехали до дома в 23:30.


Общие впечатления. Ездить на машине-доме слегка тесно, вода быстро кончается, поворачивать нужно на первой передаче - иначе всё падает. Но за 4 дня мы увидели столько сколько за 4 отпуска не увидишь. Слегка дороже чем AirBnB. Зато свобода выбора места ночёвки. Однозначно рекомендую. Машину можно снять здесь - PaulCamper. Ссылка с промо-кодом.

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.

Composer

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

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.

Bootstrap

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.

Hybridauth

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.

Jquery-file-upload

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.

php-google-map-api

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:

include_once("vendor/bradwedell/php-google-map-api/releases/3.0/src/GoogleMap.php");
include_once("vendor/bradwedell/php-google-map-api/releases/3.0/src/JSMin.php");

$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>';

gmaps.js

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:

map.addMarker({
  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!

GMaps.geolocate({
  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() {
    alert("Done!");
  }
});

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;
    unset($properties->exif);
    $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];
            self.markers.push(marker);
        }
    }
});

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.

GeoLocation.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.

Modernizr

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