‘Broken phone screen’ or ‘99% success = fail’

Hi folks

I’d like to share my fail story I’ve got yesterday.

Preamble (you may skip it)

I am using Nexus 5 smartphone for 2 years already and I like it very much.


I’ve already replaced its screen three times.

First time, I replaced it in 1.5 years ago after my first 1.5 years old son dropped it on tiles in bathroom and the screen cracked.

Second time, I replaced it 4 months ago after my second 6 months old son sucked it so my touch screen stopped to work in some areas.

Then 3 days ago I replaced it again because my second son sucked it again and broke touch screen again.

His saliva is poisonous, he also sucked my wife’s iPhone 4S and after that its Home button stopped to work.

So now we are strictly prohibit him to take any sensitive gadgets 🙂

Main story

Yesterday, my phone’s screen suddenly stopped to work. Half of it blacked out and other half got color bars on it

Unfortunately the photo of that screen is lost due to a stupid iPhone’s Horizon app which I used as a Camera and it pretended the photo was shot, but it was not.

Similar but not exact look was like


Initially touchscreen worked (at least on the visible half) but quickly it stopped to work as well.

I needed to make it working at least somehow, because I didn’t have a spare phone to put my SIM in.

I wanted to install some software to see my phone screen remotely, so I could see what happens on my screen, who called me, read SMS etc. It’s like a TeamViewer’s access PC from phone  but I needed a reversed scenario.

Fortunately, I can install programs on my phone via Google Play from computer without touching phone. I found and installed AirDroid

But I still needed to unlock my phone to configure app’s requirements.

My screen was not working so that’s a tricky part.

And I’ve managed to do that. I have USB OTG cable

And I connected my USB hub for wireless mouse and keyboard to the cable and could use mouse to access my phone’s screen.

So I unlocked it and tried to launch the app. But remember I could see only right half of the phone so it’s tricky to get something from the invisible left half of it.

Unfortunately, my phone had a setting to disable auto-rotate so I could not see more by rotating my phone to 90°

I remember that this auto-rotate was on quick settings panel (on the very top) but this button was hidden.

I googled default quick settings screenshot for Android 6.0 and found



So I found that my button should be left to the flashlight button and I moved my mouse to the left and blindly clicked. And… Hurrah… I turned auto-rotate on. WIN!

Then I’ve managed to run the installed AirDroid app and enter credentials. Here wireless keyboard helped a lot. On-screen keyboard would be challenging. WIN!

After that I could see in this app on my PC a list of missed calls and SMS

But I wanted to see a full screen and control it. The app told me that in order to use that functionality I have to go to the settings and enable USB Debugging Mode. It was pretty challenging, because I could not see settings names often (the mostly on the left half screen). But after some (very long!!!) time I’ve managed to enable the USB Debugging Mode. Remember, I was using USB mouse all the time. WIN!

Now I needed to connect my phone to PC via USB so I did and it showed me a screen where I needed to confirm that I allow to debug from that computer. But wait a minute, I can’t do that!!! I connected phone to PC so my mouse is disconnected. If I connect mouse, I disconnect it from PC. So I am nearly there, I just need to confirm the USB debugging mode and I can’t. FAIL!!!


I gave up on the idea to use the phone remotely and started to wait for the repairer who changed my screen 3 days ago.

He took my phone but couldn’t find any reasons for the issue. He said he waits for some reply from the screen shipper and this may take some time, and also there are public holidays coming, so potentially I can wait for more than a week.

I needed a temporary phone. My internet banking is linked to my mobile number. So in order to login and perform any operations, I need to receive and type my bank SMS.

He didn’t have a spare phone to give me temporarily. And I don’t have any mobile phone shops in a walking distance from home. So I gave up. I took a taxi and ask the driver to bring me to the closest mobile phone shop. So he did. And I bought used Nokia 1100

I paid ~ $12 for it. But now I can at least receive calls and SMS.

I came home and came back to work and soon I received a call from the repairer who said that he’ve managed to order, receive the spare screen and fixed it for me. I came and took it! Problem is gone!

BTW. I enabled the USB debugging mode and can see my phone screen on PC after connecting to USB once (I may disconnect phone then)


Always have a spare phone to be able to take calls and SMS in case if your main phone dies suddenly.

Stay tuned

Posted in Uncategorized | 1 Comment

Best programming font – Source Code Pro

Hi folks

Recently, I reinstalled my Windows and started to reconfigure my environment to use font I am using for last 5 years – Consolas

I decided to search what is the most popular font nowadays and found http://www.slant.co/topics/67/~programming-fonts where Consolas is quite popular – 249 upvotes. But I found another winner Source Code Pro with 362 upvotes.

So I decided to give it a chance.

I installed it via Chocolatey – https://chocolatey.org/packages/SourceCodePro

And started using it. And initially I did not like it – https://twitter.com/mnaoumov/status/673887576097468416?lang=en

Then I used to it in Visual Studio but I still looked ugly in Sublime Text and ConEmu

Then I found how to configure it to look nice in Sublime Text – https://github.com/Maximus5/ConEmu/issues/74#issuecomment-166576653

But it dependent on DirectWrite support which many apps don’t have.

I raised an issue for the font itself – https://github.com/adobe-fonts/source-code-pro/issues/116 and they advised to use TTF font instead of OTF.

I checked and found that Chocolatey installed only OTF version. So I removed it and installed TTF manually from https://github.com/adobe-fonts/source-code-pro/releases/latest

And now it is nice and charming everywhere

Stay tuned

Posted in Uncategorized | Leave a comment

Funny ‘Lorem ipsum’ memories

Hey folks

I remember the first time I found ‘Lorem ipsum’ in our codebase. I was working for the Netherlands company so I thought it is something like ‘Hello World’ in Dutch 🙂

I only realized its real meaning when I found the same words at my next job’s codebase.

Funny mistake, isn’t it?

Stay tuned

Posted in Uncategorized | Leave a comment

Funny Out-of-memory error

Hey folks

I’ve just encountered a funny error

I tried to run my virtual machine from VirtualBox and got


I tried to reopen VirtualBox a few times but issue persisted.

I didn’t run anything memory intensive.

Then I open Task Manager and see


Oh wow. Looking into Sublime


Ah! That’s it. I accidentally pressed F4 in Total Commander so the file was opening in editor and eating my memory.

A gotcha moment 🙂

Stay tuned

Posted in Uncategorized | Leave a comment

‘One long debug story’ or ‘checkbox.onclick’

Hey folks

I spent another working day debugging something simple

I work on a legacy project which has many approaches that are discouraged nowadays.

The problem I tried to solve was around checkboxes. The very simplified version of the code looks like

<input id="abc" type="checkbox" onclick="someWeirdLogic()">
function someWeirdLogic() {
    var str = makeSynchronousAjaxPostback(); // don't ask me why it is synchronous... legacy...
    // and here str is
    // "document.getElementById('abc').checked = true";
    // or 
    // "document.getElementById('abc').checked = false";
    // depending on some server-side logic
public string WeirdResponse(bool currentAbcValue)
    bool newValue = !currentAbcValue;
    return string.Format("document.getElementBydId('abc').checked = {0}", newValue.ToString().ToLower());

I know it is weird…
But previously it was working…

Now I had to implement a new requirement. Under some conditions you click on the checkbox it should not become ticked

So I implemented

public string WeirdResponse(bool currentAbcValue)
    bool newValue = DoSomeAdditionalCheck(currentAbcValue);
    return string.Format("document.getElementBydId('abc').checked = {0}", newValue.ToString().ToLower());

But I found that my checkbox is being ticked on and off ignoring this logic.

Then I tried to modify the HTML to skip built-in checkbox click behavior

<input id="abc" type="checkbox" onclick="someWeirdLogic(); return false;">

And now my checkbox is not being ticked at all also ignoring the server-side logic.

I thought maybe there are some other code where my checkbox checked state is being modified and I tried to use the approach I described in my recent post.

So I kinda set a breakpoint on checkbox checked property setter to see what code makes it unchecked.

But that setter was firing only once with true value and when I stopped on the breakpoint, the checkbox was ticked. But later on when I released the debugger, checkbox became unticked again. WTF?!

I did not know what’s going on and tried many-many hours trying here and there. You can imagine that the real code was way more complicated so I spent some time debugging the server-side code first…

And after many hours I realized what’s going on.

We can see this behavior in a much simpler form without going server-side and eval.

<input id="abc" type="checkbox" onclick="document.getElementById('abc').checked = true; return false;">

You can try it http://output.jsbin.com/jidibotaku/

Actually your checkbox is not ticked even if onclick handler explicitly said to make it checked.

And the trick here is to use delayed execution.

<input id="abc" type="checkbox" onclick="setTimeout(function() { document.getElementById('abc').checked = true; }, 0); return false;">

And this works! See it http://output.jsbin.com/sepodevino/1/

You can’t untick the checkbox anymore, but that’s what we explicitly set in onclick handler.

Damn! That was not easy to find at all.

Stay tuned

Posted in Uncategorized | Leave a comment

How to debug JavaScript to find code which modifies your DOM

Hey folks

Sometimes, especially on legacy projects, it’s too difficult to find what code modified your DOM control.

I had such situation recently. I spent almost 5 hours trying to find where some malformed value was coming from.

To simulate the problem, please follow https://output.jsbin.com/wufimi . It has an input and a button. Some bad value is being set to the input value when you take mouse out of the button.

Let’s pretend that that code is not obvious and we have too many JavaScript code to look it through.

1. Our first approach would be to search through JavaScript files to find word bad, but unfortunately it is slightly obfuscated, so we won’t find anything.

2. In modern browsers like Google Chrome you can set breakpoint when DOM element changes. See https://developer.chrome.com/devtools/docs/javascript-debugging#breakpoints-mutation-events . Unfortunately this won’t help us because those events are not triggered when value property is changed. Those events would be triggered if value attribute is changed.

3. We’ll need to try some kind of property debugging. Chrome has some non-standard Object.observe. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe . Unfortunately this doesn’t work either. Try it https://output.jsbin.com/cahodo/

4. My next idea is to overwrite value property and set some breakpoint. And that worked. Try it https://output.jsbin.com/kojuvud/
Your F12 Developer Tools should be open.

For completeness I’ll copy the debugging magic code here.

    var input = $("input")[0];
    var defaultDescriptor = Object.getOwnPropertyDescriptor(input.constructor.prototype, "value");
    Object.defineProperty(input, "value", {
        set: function set(newValue) {
            if (newValue.indexOf("bad") !== -1)
            defaultDescriptor.set.call(input, newValue);

Here input.constructor.prototype could be replaced with input.__proto__, or even HTMLInput.prototype. This doesn’t really matter.

Such if statement is helpful when you are trying to debug changes that happen on focus/blur, as control looses focus when breakpoint hit and it may become extremely annoying.

The call for defaultDescriptor is needed because we want to modify actual value

I did not invent this technique, I found this first http://stackoverflow.com/questions/11618278/how-to-break-on-property-change-in-chrome but it says nothing about defaultDescriptor which is crucial.

I hope this may help you with difficult debugging one day.

Stay tuned

Posted in Uncategorized | 2 Comments

Perfectionist’s hell or SQL formatting

Hi folks

As a programmer-perfectionist I have a habit which is killing me.

Every time I need to add some script to SQL file, I am formatting it manually.

I would like to get a tool which would format SQL for me but everything I’ve tried has some flaws.

I tried online formatters, stand-alone tools and SQL Server Management Studio plugins. I am wasting so much time to configure them but still results are not perfect.

I was already thinking to write my own formatter which formats ideally, but decided to write this blogpost to get ideas from community.

I’ve many people just take the script as it is from SQL Server Management Studio with all that autogenerated crap.

Does anyone had similar problem? What do you do with your SQL scripts?

Stay tuned

Posted in Uncategorized | 1 Comment