Thursday, December 18, 2014

Simple No Captcha reCaptcha implementation with PHP

Using new "No Captcha ReCaptcha" is quite simple. Below is a working example done in a single PHP page.

You can get ReCaptcha keys here:

ReCaptcha secret key: Use this for communication between your site and Google. Be sure to keep it a secret.

ReCaptcha site key: Use this in the HTML code your site serves to users.

All you need to get this working is to edit values of $secret_key and data-sitekey. Just enter your values and it should work even in localhost. I believe that code is self-explanatory:

<!DOCTYPE html>
        <meta charset="UTF-8">
        <title>No Captcha ReCaptcha</title>
        // Get submited data.
        $g_recaptcha_response = filter_input(INPUT_POST, 'g-recaptcha-response');
        $msg = filter_input(INPUT_POST, 'msg');
        // Check if set.
        if (isset($g_recaptcha_response)) {
            // Your secret key.
            $secret_key = 'your-secret-key';
            $google = ''
                    . $secret_key . '&response=' . $g_recaptcha_response;
            // Get JSON response.
            $google_json = file_get_contents($google);
            $google_data = json_decode($google_json, true);
            if ($google_data['success']) {
                echo 'Hello human, this is your message: ' . $msg;
            } else {
                echo 'Robot detected! Error codes: ';
            echo '<hr />';
        <form method="post">
            Your message: <input type="text" name="msg" />
            <script src=''></script>
            <div class="g-recaptcha" 
            <input type="submit" value="Submit" />

I also made authentication library using "No Captcha" so check it out here:

Tuesday, November 4, 2014

How to fix USB drive after using it with Cisco D3 4682DVB

When you connect USB drive to the Cisco D3 4682DVB receiver, it will prompt you to format it in order to record video from TV. If you decide to use that drive with the PC you will notice that even after reformatting it, it will show less space than it actually has. For example, my 16 GB Kingston DataTraveler 100 G2 showed only 754 MB of total space. To fix that follow these steps (for Windows):

Open command prompt (CMD) and run following commands.

  1. diskpart
  2. list disk
  3. select disk #, where # is the number of your corrupted drive.
  4. clean
  5. create partition primary
  6. format fs=FAT32 QUICK

and that's it.


Thursday, October 23, 2014

Xamarin studio debugger bug - doubles have same value but are not equal

Recently I had a bug in my C# library that was hard to find due to the bug in Xamarin debugger. Problem was in the "Watch" window that showed String (rounded) representation of a double value, instead of showing all decimal digits. As you can see in the picture below, sideProductSum and diagonalProduct are both 16 but somehow they are not equal:

Here is the same method debugged in Microsoft Visual Studio (doubles shown correctly):

Tuesday, October 21, 2014

JavaFX TextField always returns empty String.

Today I worked on JavaFX fxml application and found unusual bug. This application has multiple tabs with many TextFields in each tab. While testing, one of the TextFields always returned empty String when using getText() method. It was very very confusing for me at the moment, but eventually I found out what was the problem. I accidentally gave the same ID to two TextFields in the different tabs. Debugging this was a challenge because I assumed that Scene Builder 2 would informed me if something like this happened.
So if someone encounters similar problem, check your IDs first.

Sunday, October 5, 2014

Cyanogenmod battery problem

A few days ago I wrote about how I fixed Huawei Y300. I must admit that I like Cyanogenmod very much. It's much faster and stable than stock Android that came with the phone.
But after first day of use I've noticed that battery life was terrible. In settings I switched the battery indicator to percentage (Battery status style > text) so that I can get better insight of battery consumption. Every couple of minutes battery went down for 1%. I checked the settings again and switched display brightness to Auto. Battery consumption seamed unchanged.

Then I googled it. After some search I found out that you need to re-calibrate battery after installation of new Android rom. I found this app called "Battery Calibration" that claims to do just that:
Calibration needs to be done after flashing a new ROM, but you can calibrate any time you think your battery is miscalibrated. This program does it by removing the batterystats.bin system file. The OS generates a new clean batterystats file soon, thus any fake information from the previous ROM is removed.
It's suggested, but not necessary, to let the phone fully discharge after calibration, then charged to 100% without break.
App is very simple. Just charge your battery to 100% and then press "Battery Calibration". After that you should fully discharge your phone.

After I calibrated battery it got better. Phone was with WiFi on for about 30 h without charging and it's now at 62%. So far so good.

Update: after the calibration battery lasted for 72 h 36 min. WiFi was always on, I made approximately 10 shorter calls and browsed the Internet for 3 h.

Monday, September 29, 2014

How to fix Huawei Y300

For it's price Huawei Y300 delivers decent hardware. It has dual-core processor, 512 MB of RAM and surprisingly good camera.
My girlfriend used this phone for a month and everything worked relatively fine (UI was a bit sluggish but usable). Then suddenly applications started to close after few minutes of use, without any error code or warning. Keyboard was also closing randomly (and frequently) and the only way to show it again was to restart current application. So we decided to switch phones and I would try to fix Y300.

The first thing I've done was to restore factory settings. After reboot everything looked like when the phone was bought. Great, all must be good now. I turned on default web browser and opened 3 tabs. Browser crashed. I tried that a few times, and same thing happened. Also keyboard was crashing randomly, but mostly when a text field was using autocomplete functionality. I thought that something must be wrong with Huawei's keyboard, so I switched to default Android keyboard. Same thing happened again. I then installed few keyboards from Google Play but it didn't solve the problem. I also tried different browsers with no success. Firefox never showed keyboard when trying to input text in address / search field.

There are two solution to this problem, simple and a bit complicated one.

Simple solution:

I downloaded Clean Master Phone Boost (by Cheetah Mobile) from Google Play.
First thing I've done was to clear "Junk files". And there was over 140 MB of them. Almost 90 MB of junk files were from Huawei's system applications!
Then I went to "App Manager" > "Pre-installed Apps" and disabled every application I thought was made by Huawei.
Then I installed Advanced Task Manager - Killer (by INFOLIFE LLC).
I killed all applications with it and begin to test the phone. I disabled default (stock) browser so I couldn't test it. Firefox showed a keyboard and that was a good sign. I opened 11 tabs with different pages and it worked flawlessly. I also viewed a Youtube video while Firefox was on (with 11 tabs) and nothing crashed. Same test was repeated with Google Chrome and all went fine. Keyboard showed up every time and stayed on screen. Speed improvement was tremendous, it was like I was using different phone. I've tested phone for a few days and didn't notice any problems whatsoever.

But I wasn't satisfied with this solution. Some Huawei's processes was still lurking in the background (ones I couldn't disable) and it annoyed me. So I decided to root phone and install custom rom for the first time (that's a bit complicated solution).

A bit complicated solution:

You should check if rooting / unlocking of your Android device is legal in your country. You should also check if rooting will break the warranty of the device. You perform rooting at your own risk and it is your own responsibility. It can damage your device.

Link to the used files will be provided at the end of this article.

First thing I had to do is to find how to unlock bootloader. In order to do this, you need to install very specific drivers:

My first attempt was on Windows 8 x64 Enterprise. Driver installation went fine - installation window will automatically close when done. There is a nice tool called DC-Unlocker Client (I've used version 1.00.1131).

This is very important: disable the option "Settings" > "All" > "Fastboot" on your phone. Every time phone is restored to the factory settings you must disable this option.

Next thing you need to do is to turn off your phone. When phone is off, press and hold vol+, vol- and power buttons at the same time. Purple screen will show up.

Connect phone to the PC and start DC-Unlocker. Windows will install Huawei device, so wait until installation is over and then set "Select Manufacturer" to "Huawei phones". "Model" should be left as "Auto detect".
Click the search button (magnifying glass). If everything went fine, you should get following message:

DC - Unlocker 2 Client 1.00.1131
Detecting phone :
selection :
manufacturer - Huawei phones
model - Auto detect (recommended)
Found Applications port COM7
Found Diagnostics port COM6
Waiting modem/phone to be ready ...
Model               : Huawei MSM8X25 series
IMEI                :
Wi-Fi MAC           : D0:7A:B5:8F:B8:69
BlueTooth MAC       : D0:7A:B5:8F:B0:98
Bootloader status   : Locked
Bootloader code     : 1212037156182471
SIM Lock status     : unlocked

Copy "Bootloader code", because you will need it.

Well, for me everything didn't went fine. I kept receiving an error that phone couldn't be detected. Few times I even got an error that application couldn't connect to the server. I almost gave up. Then I tried the same thing on Windows 7 x86 Pro with different USB cable. Everything worked without a hitch and I've got my bootloader code.

So now we have bootloader code and we can unlock bootloader. For this we need to use excellent tool called "adb-toolkit". This is a console application, so be prepared to enter some commands via keyboard.
Navigate to the "\adb-toolkit\bin" folder. Inside that folder you will find "files" folder. Hold "Shift" key and right click on that folder. Choose "Open command window here". CMD window will show up.
Disconnect your phone and turn it off (remove battery and put it back in). Press and hold vol- and Power button for about 10 seconds. Phone screen should only show "Huawei Ascend". Now connect it to the PC.

In CMD enter the following command:
fastboot devices

You should get following output (or something similar):
d4703013        fastboot

This means that application has connected to your phone.
I have run into a problem here. I was getting an error "AdbWinApi.dll is missing". So I found files "AdbWinApi.dll" and "AdbWinUsbApi.dll" and copied them to the "\adb-toolkit\bin\files\" folder. Problem was fixed. You probably won't need to do this because I already packed those files into correct directory.

Next command should be:
fastboot oem unlock ????????????????
(where ???????????????? is your bootloader code).

After that you should get an message "OKAY".

To check if bootloader is unlocked, enter this command:
fastboot oem get-bootinfo

Now we need to install custom recovery program. That is recovery-clockwork- file.
Copy this file in "\adb-toolkit\bin\files\" folder and then run the following command:
fastboot flash recovery recovery-clockwork-

You should get "OKAY" message.

Now run command:
fastboot reb

Phone will reboot. This was the hard part, next is much easier. Turn on the phone and copy these files to the root directory of your memory card (sdcard0).
First file will enable superuser access.
Second file is our custom rom, in this case CyanogenMod 11.
Third file is installation of Google services (such as Play store).

Turn of your phone. Press and hold Vol+ and Power button at the same time. Hold for about 10 seconds and release. You should see Recovery menu. You will notice that touch screen is disabled. Navigation is done by using Vol+ and Vol- buttons. Power button is used as confirmation button (click). Select install from zip and install first file ( When installation is finished, navigate to the main screen using back button and reboot.

Now we need to install CyanogenMod 11. Turn off the phone, then press and hold Vol+ and Power button at the same time. In Recovery menu use both "wipe" options to wipe the phone system caches. When done, go to install from zip option and install file. When installation is finished, navigate to the main screen using back button and reboot.

You should now have fully working CyanogenMod 11 Android. You will notice that there is no Google Play in applications. Turn off the phone, then press and hold Vol+ and Power button at the same time. Select install from zip and install file. When done, navigate to the main screen using back button and reboot. That's it.

Now it is a totally different phone. Much, much faster than it was when bought. Huawei offers good hardware for a price, but their software is terrible. If you don't want to get your hands dirty, then you should avoid Huawei phones. It doesn't matter how high specs phone has, poorly done software can render it unusable.

Hope that this will be helpful for someone and sorry for my bad English.

Download used tools here.
Check file integrity with md5.