Saturday, August 17, 2013

Scary features in Google+ images

I'm a technology enthusiast, I really look forward to any new innovation and improvement using technology. But sometimes even I get caught totally off-guard. Like today.

When flying back to HK through Incheon in South Korea. We were flying over a lovely small island which was partially covered by small, fluffy clouds. I took my phone and started to take photos in a fast sequence to make an animation which also happens to give it some depth perception. Ok, now I have a spare moment, so I imported the pictures to Picasa, color-corrected them to remove the grayness caused by the distance and exported them to Gimp in order to make the animation. And, while Gimp was struggling reading the EXIF metadata (I haven't upgraded the poor program in a while..) I got a notification on my Android about the freshly uploaded photos. I opened it and there, in my Google+ albums was sitting a complete animation from all those pictures.

wut

Ok, this won't be so difficult to implement in an algorithm, but still, the idea that they include details like this means something. They must be pretty efficient at Google. And there are some other similar features as well like creating a panorama or a HDR photo.



This little feature blew my mind, because I totally didn't expect that. If I had discovered the unlabeled object recognition feature by accident before reading about it, I would probably first try to wake up from a dream. I have no idea how in the world could they do that.

I wonder what's next and I'm looking forward to it.

Thursday, June 6, 2013

中国大陆

Mainland Chinese in Hong Kong

Nowadays, Hong Kong consists of locals, westerners and mainland Chinese. While Westerners usually don't have much trouble, the integration of people from mainland can be a peculiar issue. It makes me think, does that mean that HK culture is closer to Western than Chinese? No, the locals would say, it's a world of its own.

When I arrived, I noticed that baby milk powder was a big topic. I saw that mainland Chinese were coming to HK to buy cans of milk powder for their babies because some time ago, some of the milk produced in China contained toxins and a number of babies died. Most people are aware that Chinese products usually don't shine in quality and the Chinese know this as well, so they decided not to entrust their children's life to their own country's production and started to buy the milk powder in other places.

The problem is that China is so big. Whatever their citizens decide to do will impact the rest of the world like a thousand ton hammer. Baby milk was sold out in Hong Kong, Macau and shortage was reported even in Germany and the UK. Hong Kong government was forced to come up with a law prohibiting anyone from taking more than 2 cans of milk powder over the border. A similar problem occurs in maternity wards in HK where mothers from the mainland are desperately trying to get a place. And, of course, the space in HK maternity wards is limited.

When I came here, I felt that the milk powder shortage was the biggest problem of Hong Kong and I found it rather amusing. Now I know that, actually, the biggest problem are the astronomic property prices which, among others, give young people only very pessimistic outlooks on their future, prevent them from having children (because they can't afford it) and just drive the costs of everything higher and higher. And even this is partially caused by rich people from China who buy properties in HK and sometimes don't even live there because they just flank it as a status symbol - it's very cool to own an expensive flat in HK...

It seems that not too many mainlanders live here officially, but there are tens of millions of tourists every year. I got some statistics from HK government, year 2011. It shows the population over 15 by attained education level, divided by sex and education. Women are red, men blue and the brighter part in the middle denotes mainlanders. Of course, mainlanders living here unofficially are not included.

While it's understandable that Chinese mothers want to make sure to get the best for their children, HK locals are not very happy about the changes the crowds of mainlanders are bringing to their city. And that's not all. The dynamics of university students from HK versus mainland is also interesting. Locals are very serious about getting proper education and trying to reach for the stars in their careers, but if you let them compete against the top 100 students from a 1.4 billion people country, they are going to lose. That's a mathematical fact. It's unbelievable how hard can those top-performing mainland students work. You'll find them in the library even in the summer, they are more determined to get business contacts at any opportunity and can speak better English. The locals just can't keep up (read more in the source article).

The other side of the social spectrum is represented by tourists from mainland and their totally uncivilized behaviour. The things I heard about them include relieving their physiological needs on the streets (no matter how hard are the cities trying to put a public toilet everywhere), spitting everywhere, being loud (mandarin is a loud language...), drawing on Egyptian monuments and so on. Of course not all of them do this, but the problem is there and it's perceived by many.
And now, after seeing a popular movie about Thailand, chinese tourists are flooding Chiang Mai as well. And the Thai are taken aback by their behaviour, no less than people in HK.

Perhaps China will soo raise their own huge cities to the same level as HK in terms of quality of life, products and education so that their citizens wouldn't need to colonize HK. But the HK economy is already highly oriented towards the Chinese shoppers and most of its industry has moved away to Shenzhen (which is now also growing like crazy). Looks like a vicious circle to me...

    Monday, May 20, 2013

    Income Inequality

    Hong Kong really is a very unusual combination of the West and the East and also of the rich and the poor. Some areas feel very Asian and Chinese, selling fruit, meat as well as clothes in local markets, there are cheap local restaurants and everything is packed inside as well as on the streets, in so little space. Walk a bit further and you'll find yourself in a completely different world - a world of gold, jewelry, luxury watches, cosmetics, sports cars and suits. Some areas are nothing else but enormous shops with luxury goods in modern skyscrapers. And in those places, you'll be surrounded mostly by westerners.

    This is an image you can see every day and it should give you an idea also what the income distribution will look like. I wanted to have some numbers, so I did some research and found figures coming from the government, from the year 2010.


    I can still remember the shock when I told some westerners what a HK university graduate's salary looks like and my amount of surprise was no less. Students who are able to obtain an university degree still haven't really won themselves a comfortable life, because the average salary is a puny 12.000 HKD per month. Monthly rent of an apartment in a cheap place (New Territories) will be around 7.000 HKD, which is more than the monthly income of 16 % of households! It is only because of government provided flats that the society has not yet collapsed. According to my information, more than half of local population lives in these flats. Of course, people are trying to get out of that vicious circle, many try very hard to study fields with prospects of a good salary (law, IT, ...), but without any passion, which turns them into mindless fact-repeating drones lacking any real understanding.

    The contrast is emphasised by all those low-class, presumably low-wage workers all around the place. Toilet attendants, elevator button cleaners, people who stand in hallways and warn you that the floor is wet and slippery, trash sorters and so on. No one would do these pointless-seeming jobs in Europe. In Hong Kong, I assume, these people cannot just fall into the comfortable social security safety net. And I believe it's a good thing. Compared to plain-out begging & starvation in undeveloped countries or the opposite, getting social security while doing nothing in "overdeveloped" countries, it at least gives the people some structure in their lives. To move it from good to awesome, the government could try to provide opportunities to get a better job, perhaps by some kind of education.


    Now consider that the monthly rent of an apartment in Central (the, ugh, central area of the city) can be over 30.000 HKD. Most families can't even begin to think about living in that place so it's occupied by westerners, rich mainlanders and rich locals. The sky-high cost of property together with the income disparity are the biggest problems of the city. The Gini index, a measure of income inequality, is between 0.4 and 0.5, close to (if not!) the highest in the developed world.

    If things continue this way, I think that a part of the Honkies will be forced to move out to mainland China. It would be a natural continuation of the integration of HK and China, as rich Chinese are moving in, the poor would have to find places which are more suitable to their income level. But no local would ever want to leave HK for mainland. But it seems that the preferences of rich Chinese occupants and shoppers are changing and the government has created laws that forbid market speculations with apartments, so the future direction might be completely different. It will certainly be very interesting to see that.

    Thursday, March 14, 2013

    Autorelease pool hell

    I spent a lot of time hunting down a problem with a crash in autorelease pools in our Python - Chromium Mac application and I finally found the primary cause. I couldn't find any information at all about this kind of crash on the internet, so I decided to share the experience with you. Brace yourselves, it's going to be long.

    Our app was crashing on exit somewhere in AutoreleasePoolPage::pop. Attempting to access memory at 0x00000010 which is very bad. Everybody on the internet says that for Objective C crashes, use Instruments and Zombies, right? Well, zombies were sleeping in the graves peacefuly for me. Nothing found. So let's try the next tool.

    I couldn't get Valgrind to work for this app on OS X, because I had a recent machine which supports HW instructions for AES and Valgrind in 32b mode doesn't, which is basically game-over. So I got an older machine, without these instructions, and found ... nothing. Really, no information related to this problem at all. It seems that I'll need to do some more thinking.

    In the meantime, I discovered some other problems, largely unrelated to this one. Because of them, I was considering to remove wxPython as the window-creating mechanism from our app and roll my own. This did solve the problem with accessing the USB on OS X, but this crash, in exact same form, persisted even after getting rid of wx. It's starting to get sad, really.

    I was forced to roll up my sleeves and dig once more into disassembly. I found that the memory which AutoreleasePoolPage::pop() is accessing is somewhat wrong. But I couldn't find any more information from that mountain of instructions and this is where I got lucky - I found that there is actually source code for this class! Just get the right version of objc from http://opensource.apple.com! This made things a lot easier and clearer. And what's more, after a while I was able to compile this project and use the debug version instead of the system one. How awesome is that!

    What I found out is that autorelease pools are nothing more than a block of memory containing pointers. This memory is managed manually by the AutoreleasePoolPage C++ object. And that is rather unfortunate, because there are almost no safeguards at all. If they were using the standard malloc or new, I could employ all kinds of diagnostics, safeguards and checking and they may be able to slap me at the right moment. But with this manual management, we are on our own. This was probably one of the reasons why Valgrind, Guard Malloc and other tricks just didn't work.

    Takeway 1: If you manage memory by yourself, you will probably need heavy checking, the kind that malloc has.

    So I knew that I'm somehow overwriting my own memory inside an AutoreleasePoolPage. So let's introduce some logging and custom diagnostics. I used dtrace and Instruments to get arguments and call stack at key points in the program (well, basically at every call to AutoreleasePoolPage methods). dtrace is awesome, if you don't know it, you need to. This told me that, indeed, one autorelease pool memory block is getting overwritten by a different one. And I also knew which one! I didn't need much to realize that I'm using the pools incorrectly. It seems they should always be used like a block and nested correctly:

      p1 = [NSAutoreleasePool alloc init];
      p2 = [NSAutoreleasePool alloc init];
      [p2 release];
      [p1 release];
    or use this shorthand syntax:

    @autoreleasepool {
      @autoreleasepool {
        ...
      }
    }
    

    which means creation and destruction in a single function. What I did was to create the block somewhere in one method and release it somewhere in a run loop. This apparently breaks nesting and causes all this headache.

    Takeway 2: Always nest autorelease pools correctly.

    Thanks to the call stacks from Instruments, I knew which pool is destroying which other pool and now I only need to figure out how to fix it. Phewww.

    Friday, March 1, 2013

    英文

    As for English knowledge, this varies a lot. Some people don't speak at all, some speak at an average level and some speak very well, better than me. I heard that some universities teach entirely in English.

    Have I already mentioned that education is really big in HK? As well as status symbols and money. One foreigner living here posted this and I do feel very similarly about it:



    Ahh... Hong Kong... it takes your insecurities and enhances them tenfold to the point where you're always self-conscious or you don't care about them. Little kids will point out your every flaw while everyone else is silently judging you for your technological and fashion choices. The populace is hungry for money and will jump on any opportunity to make a buck. In the meantime, little Sally Wu is only getting four hours of sleep every night because her mother wants her to be the perfect student.

    It might be the environment I work in, but many local students of Computer Science are trying to pursue PhD and other things people usually do in non-engineering disciplines to try and advance their career. Things that programmers and SW people usually don't do, because they don't need it. Because at least in Europe + US most employers consider real-world experience rather than academic degrees.

    Sunday, February 17, 2013

    Peopleware summary

    • In SW development, deadline will not make people more productive, but it will likely make them less productive.
    • Parkinson's law (work expands to fill alotted time) is just a joke.
    • Productivity cannot be increased by simply taking some (heavily advertised) magic pill, only by improving working conditions. And yet managers are so susceptible to buying magic pills, maybe because they feel desperate?
    • Noise and interruptions at the workplace are really annoying - in programming, most meaningful work gets done in the flow and it takes at least 15 minutes to get back there after an interruption.
    • When the members of a team work in physical proximity, they tend to discuss things at the same time and go to quiet, flow-mode at the same time as well.
    • Are deadlines really so important to justify losing good employees to burnout?
    • Price-vs-quality: end users usually don't care about quality that much (because it costs money), but low-quality products reduce the programmers morale. It's best in the long-term to let the developers set their own standard. In some companies, developers can even veto shipping.
    • The book is also rather funny or sarcastic: "Before drawing plans for its new Santa Teresa facility, IBM violated all industry standards by studying the work habits of those who would occupy the space.
    • Quiz: what annual turnover does your company have? How much does it cost to replace a person? Scoring: If you had any answer at all, you pass. Otherwise you fail. Most people fail.
    • It has come to my attention that some of you, when travelling on expenses, have been travelling economy class. This is not an economy-class organization. This is a first-class organization.
    • Managers with low confidence or ego problems may feel the urge to impose their position of status on their lowly subordinates, such as moving the company/office closer to their homes or  suppressing people who are different, because they feel threatened by them (around page 97).
    • Hawthorne effect - people are more productive when they do something new or in a different way or different environment (page 120).
    • People enjoy working in teams for a common goal. The challenge of work is important, but not in and of itself; it is important because it gives us something to focus on together.
    • At one company, they made a team of testers who took their pride in finding as many bugs and problems as possible, often in very mischievous ways. Grown men and women were reduced to tears by watching their programs misbehave under the demented handling of these fiends. The testing team started to dress in black and really enjoyed their work. 
    • To build a team: The team members need to get into the habit of succeeding together and liking it. A good manager/leader will set up situations to gain this kind of momentum. 
    • Internal competition has the direct effect of making coaching difficult or impossible. This means that internal competition (employee of the year, ...) makes no sense. 
    • Introducing change: There will be people strictly against change, strictly for-change and the doubters. And these are actually the only meaningful potential allies of the change.
    • To promote the change, forget about rational claims. People take sides based on emotions. So it's much better to emphasise how the old system was working well, how it served so many requests of the customers and then slowly transition into motivating the people to embrace the change (page 211).
    • How do you think about salaries? Do you consider them to be expense that, once paid, is gone, like the heat energy in winter? Or do you think of it as an investment? Because replacing people and bringing them up to speed takes a lot of time and money, so it's worth it to try and keep them. (page 217)
    • The office and environment you work in influences productivity to a high degree. Some really
    •  nice inspiration: http://officesnapshots.com/2012/12/27/most-popular-offices-2012/

    Monday, February 11, 2013

    People in Hong Kong consider education to be very important. There are many expensive schools, parents and kids alike obsess over passing entrance exams, you hear phrases such as "he's not highly educated" from girls. But then, being the tall guy I am, I did have a chance to see what other people do on the MTR. Few of them actually read books, despite carrying iPads or Galaxy Note Twos. Everybody is just playing Candy Crush. And if people are not reading on public transport, which is the best time to do so, I doubt they read at any other time. Kindle is my faithful companion on every single journey around the city I take and I've actually finished Heretics of Dune in the month I've been here. In fact, few people here even ever heard of the Kindle. After discussing this with some people, I learned that students are simply overloaded with the school tasks to have any strength left for reading.

    There is also an interesting distinction in the quality of services. My tiny apartment is nicely private, but doesn't have any cooking facilities, leaving me dependent on restaurants. I certainly don't need to be afraid of starving, in Tai Wai, in 500 m around my place, there surely are at least 10 Chinese restaurant-o-fastfoods, and I yet have to see them closed (maybe on lunar new year?) so it's just a matter of  overcoming the language barrier. But for some reason, I don't like these places very much, mostly because they don't appear to be very tidy and orderly. And, based on a few observations, the attitude and service quality of the staff is rather far from awesome. Higher-class restaurants in shopping malls, on the other hand, have service that comes a lot closer to awesome. And they also pay close attention to appearance and style. Of course, you could also tell these two classes of restaurants apart just by looking at the bill for the food.



    The services in shopping malls even go to such lengths to hire a full-time toilet attendant. He stands there in the hand-washing area wearing a uniform making sure that the place remains clean. There is even a plaque on the wall with his name and photo. 

    Friday, January 18, 2013

    Thinking that you can just learn 3 cantonese words and just walk in to a local restaurant-o-fastfood is very naïve. Of course, most places, especially on the Westerner-infested Hong Kong Island, have english-speaking waiters, but not where I live. Here you can find authentic chinese restaurants with authentic people who can't speak English.

    Anyway, so a guy walks into a restaurant and tries to order using the 3 words, "chicken", "meat" and "rice". It does not work. Instead, he is showered with more questions regarding the type of sauce, the colour of rice and more. The foreigner does not even manage to say "I don't understand".

    Fortunately, there was a guest who could speak some English. And when I tried it again in another place, they had a friend on the phone. No starving for that day at least!

    Tuesday, January 8, 2013

    So it begins

    Right now, as I'm writing, I'm sitting on a plane to Hong Kong where I'm going to work in iPatrolTech.  It's the result of about 4 months of planning and some paperwork and I got the idea that I should change something as early as March 2012. Before that, I was working in a small company in Olomouc. The work was interesting and I was (hopefully still am!) friends with most people there, had fun and everything was comfortable. But I knew I had to step out of my comfort zone while I was still young, so I quit and started looking for new opportunities.

    The people in the company understood and before I left, they asked me to tell my friends about the free programmer position. This, unexpectedly, was a great lesson for me.  Their product (MoNET) is not (yet) very famous, but it's quite interesting and can do things that few others can duplicate.  It allows you to create an information system, complete with web, desktop and Android GUI within mere days. And as I said, I liked the company, so I didn't hesitate about trying to find someone for them. I put an ad on the job board at two IT universities in Brno and told about it to everyone I met. And I really didn't expect that I would not find anyone. Even people who didn't appear too bright turned the offer down.  You can see it on the internet every day that there is a shortage of programmers, but as with many things, experiencing > hearing. Now I know much better how valuable my skills are. And, if you're a programmer near Olomouc and would like a full or even flexible part-time job, fire up your email client and let me know at me@rplasil.name!

    Let's get back to the plane now. Before I get dinner, which should be marinated lamb with basmati rice, I'm going to describe how I even got the job in HK. My first idea was to get an internship or a job in Sillicon Valley, but soon I found that the H1B visas are already all used up until September 2013, so I had to accept that I'll have to visit the IT Mecca some other time and that I need to start looking somewhere else. Europe, to me, seemed not very interesting. I asked some people from the GE Foundation Scholar-Leader programme for some ideas and they referred me, among others, to an organization called KOPRA. There I found an ad from a startup in HK and that's when the idea first came to my mind. I applied, got a reply, but it didn't work out. But the idea of working in HK was already there. I already visited Singapore for a few days and HK is another Asian tiger. As I was learning kung-fu, Hong Kong seemed to be a very interesting place to live in for a few months. The first company didn't accept me, so what should I do now? Well, of course, start spamming all the others! But to be honest, I first needed some encouragement from my friends, especially from Aleš. But then I started searching, writing to all sorts of places with the idea that I wouldn't stop until I knew it was impossible.  And then I found iPatrolTech, a stealth startup in the Science Park...

    I think I would not have the courage to leave my home and go for half a year to literally the other side of the world if I hadn't made a few intermediate steps.  First, I went on Erasmus in Vienna. That meant living away from home for almost half a year. Last year I went to Singapore, Malaysia and Thailand, which gave me at least some familiarity with Asia.

    I'm looking out of the window and hope to see the Himalayas. But it seems we are too far south from there. The altitude is about 11 km and it's not particularly warm outside the plane, only -58 degrees Celsius. We are approaching Hong Kong at the speed of 918 km/h. HK here I come!