Tuesday, August 7, 2012
Small screen big window trick
Ever happened to you that you opened some application on your netbook with screen resolution small x even smaller and the application contains big unresizable window? And do you know the frustration when the thing you need to click (save/ok/whatever) is in the bottom part of the window which is invisible to you? Then you know what I am talking about. Especially because you cannot move window above top of the screen. Well, at least, not with only mouse. Today, I am proud to introduce you a linux (gnome) solution for this problem. It is called ALT+F7 and it is "move window" shortcut. Except, for some strange reason, there is no limitation on where you move the window with this shortcut, i.e. you can move it over top edge of the screen!
Bike trilogy - part I
The trip was quite eventful. I started by getting into a wrong train. Seriously! I was standing on the platform and two trains come, one to Geneva and one to Brig. But they arrived at different tracks that was announced. So I tried to be clever and entered the one in the good direction. Except for the fact that they reversed both trains (although I was keeping an eye on potential change of the locomotive) and I ended up going to Geneva instead of Sierre.
My goal was to go from Sierre (540m) to Lac De Moiry(2250m). In order to avoid frequent main road towards Zinal, I decided to take less frequent one through Vercorin and Val d'Anniviers. This implied ascending another couple of hundreds of meters more (from Giettes d'en Bas (1460m) I descended to Mayoux (1200m)). From Mayoux it was tiresome climb, the ascent was quite steep and I was already tired from previous climb. Therefore I was stopping a lot to catch my breath. The last half a kilometer was especially steep and I was glad when I climbed through the final tunnel directly to the dam.
There I worked a few minutes with my mouth in order to increase my chemical energy. I did not stay too long however. The sun was hidden behind clouds, the temperature wasn't exactly 30 degrees and the wind made it even worse. To heat up, I continued on the road for another 4 kilometers to the small lake below the glacier where the road ended. Took several photos and quickly decided to go back because the weather did not look so great.
On my way back, I took a "shortcut" down on a mountain-bike road. Very great and steep descent (I was glad I did not choose this road for ascent). The only problem with the road was that my hand muscles were quite tired from braking all the time.
After stopping at Grimentz for some food and consequently discovered that there was some culture festival, I descended again to Mayaux where I took a more direct road to Sierre. Maybe a kilometer later, near small hydroelectric plant, I decided that instead of taking main road which climbed a few tens of meters I can take an asphalt road parallel to the stream. Never mind that it was marked as dead-end. There was a bike sign there and also my GPS was pretty convincingly routing me there. It was therefore a surprise when after maybe five kilometers the road suddenly ended with another hydroelectric plant and that was it. GPS was happy directing me over some hiking trail which was obviously used only rarely. With panic, I figured out that the best solution would be to use different hiking trail which climbed maybe 200 meters but at least seemed to be decent. With sweating, I started pushing my bike ...
And because it was so nice day, my bike decided to make me even happier. Suddenly, there was a crash. When I looked back, the bag holder above rear wheel wasn't above rear wheel, rather it was lying on the ground. Great, what a fortune! Fortunately it was only unscrewed and I managed to fix it with plastic wire used for organizing computer cables.
Back to pushing the bike. And swearing that I should better check tracks proposed by my GPS. Finally up to small willage Fang and back on asphalt road. The rest of the trip was just dreamy downhill!
As usual, you can find photos here.
Wednesday, July 11, 2012
PHP and consistency? No way
Today I was debugging my PHP code and trying to figure out why my references (quite nasty feature of PHP but sometimes required) do not work only to learn that my bug was in array_key_exists function call.
So, try to guess what are the arguments for array_key_exists. If you think it is
you are quite wrong, just read the documentation:
You may say, ok, this is just a convention. Well, not exactly, looking at the manual, one can summarize the functions as following:
vs
But the best part is this (can you spot the black sheep?):
In summary, PHP requires a manual, unless you are good at guessing/coin flipping.
Bonus from the manual:
So, try to guess what are the arguments for array_key_exists. If you think it is
array_key_exists($array, $key)
you are quite wrong, just read the documentation:
array_key_exists ( mixed $key , array $search )
You may say, ok, this is just a convention. Well, not exactly, looking at the manual, one can summarize the functions as following:
array array_change_key_case ( array $input [, int $case = CASE_LOWER ] )
array array_chunk ( array $input , int $size [, bool $preserve_keys = false ] )
vs
array array_combine ( array $keys , array $values )
array array_fill_keys ( array $keys , mixed $value )
mixed array_search ( mixed $needle , array $haystack [, bool $strict = false ] )
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
But the best part is this (can you spot the black sheep?):
array array_filter ( array $input [, callable $callback = "" ] ) array array_map ( callable $callback , array $arr1 [, array $... ] ) mixed array_reduce (array $input, callable $function [, mixed $initial = NULL ] )
In summary, PHP requires a manual, unless you are good at guessing/coin flipping.
Bonus from the manual:
string implode ( string $glue , array $pieces )
string implode ( array $pieces )
Sunday, July 8, 2012
Grand St Bernard pass on a bike
On Saturday Maciej and I went to a quite challenging bike trip from Orsieres (cca 900m) to St Bernard pass (2470m). It was very good trip. We started at Orsieres and used forest roads along the river all the way up to Bourg St Pierre (except for a special "bonus" section right before Pont de la Tsi where we needed to carry our bikes 200m uphill on a hiking trail with traverses and wooden steps).
From there, we continued to dam of Lac des Toules, where we climbed up and started second bonus part -- trail along Lac des Toules is just a big hiking trail and we were glad that most of the part was downhill. After the dam, we crossed the river and tried to go to Bourg St Bernard. Except ... it wasn't easy. There were two possibilities: a) cross another stream on an iron bar probably 30cm wide which would be fine on foot but a crazy idea on bikes b) cross the stream on a very inconvenient place c) take stairs to the roof of the tunnel. We took last option in the hope that it was designed as a hiking trail -- a big mistake. The roof wasn't particularly good for biking (or hiking for that matter). So we went down on the other side of the tunnel but our problem remained -- there was a road but there was also a big stream through it. After enumerating possible choices, we went for the easiest -- cross the stream with naked foot. And it was really cool (or I should say really cold -- water was probably from melting snow). This was however final obstacle and we reached Bourg St Bernard (1900m) where the majority of cars go to the St Bernard tunnel and thus there is less traffic on the old road. There we had a lunch and started the last part of our trip -- final (and quite hard) 600m of ascent on an asphalt road.
But it was worth the sweat. The views from St Bernard pass were amazing. After we went a few hundreds of meters in Italy, returned back, shopped for souvenirs and visited church with a display of old relics, it was time to go down. This time, we chose the main road all the way down.
Hungry for more photos? Here they are.
Vim, your gpx swiss knife
Did you ever have a gps file which was consistently moved from the map by few meters?
It happens mainly if you are travelling fast and the gps tries to catch up after tunnels or other losses of a signal. But now there is universal solution to it. And it is in VIM!
Just get the offset (in lat/lng), open file in vim, select problematic region (it helps if the file is not in one line as some programs prefer) and run following mega-command:
:'<,'>s/lon="\([0-9.]*\)"/
\='lon="'.printf('%.10f',str2float(submatch(1))+0.002).'"'/
To explain few things:
:'<,'> matches on selected lines
s/xxx/yyy/ replaces regrexp with yyy
\(xxx\) is a submatch
[0-9.]* matches floating point value
\= tells vim to use expressions instead of strings while replacement
'xxx' is a string expression
. concatenates string expressions
str2float(submatch(1)) gets a floating point value of the matched latitude/longitude
It happens mainly if you are travelling fast and the gps tries to catch up after tunnels or other losses of a signal. But now there is universal solution to it. And it is in VIM!
Just get the offset (in lat/lng), open file in vim, select problematic region (it helps if the file is not in one line as some programs prefer) and run following mega-command:
:'<,'>s/lon="\([0-9.]*\)"/
\='lon="'.printf('%.10f',str2float(submatch(1))+0.002).'"'/
To explain few things:
:'<,'> matches on selected lines
s/xxx/yyy/ replaces regrexp with yyy
\(xxx\) is a submatch
[0-9.]* matches floating point value
\= tells vim to use expressions instead of strings while replacement
'xxx' is a string expression
. concatenates string expressions
str2float(submatch(1)) gets a floating point value of the matched latitude/longitude
Tuesday, July 3, 2012
Ppershing:Sustenpass 0:1
Welcome to the match between Ppershing and Sustenpass. The bicycle is starting at home field near Realp and PPershing is pushing fast towards Andermatt. There, he kicks in the direction of Göschenen and bike is going fast downhill. The bike is near Göschenen and the player is kicking ... nooo, in the wrong direction. The bike is slowly climbing towards Göschneralp, through high grass. Bike and the player are in the off-road position. Finally, the touchdown in Göschnealp and half-time break. After the game is restarted, bike is again kicked towards Göschenen and from there to Wassen. And here Sustenpass starts actively playing. Sustenpass is defending by off-road and gradient tactic. Ppershing is clearly out of breath and he is not able to make any long kicks. In fact, several times he is just pushing the bike by hands. And the game is near the end -- the reserved time is almost over. It is unlikely that Ppershing will score in this game. In order to avoid even bigger defeat, Ppershing ends at 1600 metres out of 2200 and returns to home. The result of game is 0:1 but PPershing says he will try it again and will be better prepared.
Photos from the match
Photos from the match
He's half-dead, Jim
Computers never fail to impress me. At least mine computers. They always have some new way of failing. For example, yesterday my old laptop (really a piece of crap now, but I use it as my desktop) started running only on the battery. Hmm, wait, why is my laptop running on the battery, especially when it is plugged into the power? This happened a few times ago because of the overheating. However, right after the start there is a little change of overheating. So what is the problem? Finally my power source broken down? Or maybe n-times patched connector? Well, I just shot down the computer and ... surprise ... the battery is charging. What the heck? I turn on the computer and ... AC power led just dies. Veeery strange. Anyway, it seems that my power source is half-broken and not able to produce enough voltage/current. Therefore, the laptop decides to go with the battery which is after 5 years almost dead too. A very unlucky combo...
So, my third option -- go without battery. It seems that this is the most promising solution -- when laptop dehibernates, it seems to be running without any problems. Except for the fact that it dies with high probability (which can be reduced by plugging out usb devices) during the dehibernation process.
So, my third option -- go without battery. It seems that this is the most promising solution -- when laptop dehibernates, it seems to be running without any problems. Except for the fact that it dies with high probability (which can be reduced by plugging out usb devices) during the dehibernation process.
Subscribe to:
Posts (Atom)
gluestring. Note: implode() can, for historical reasons, accept its parameters in either order. For consistency with explode(), however, it may be less confusing to use the documented order of arguments.