Access USB and mobile Internet on LG GT540

For my mobile application’s testing purposes, I’ve purchased an old, creepy LG GT540 with Android 3.2.1 CyanogenMod 7. I’ve got a lot of troubles with USB and mobile Internet on this phone (first time happened to me, all other mobile devices with Android on board had USB and Internet ready out-of-the-box). So I wanted to share some things and solutions for others.

Read More “Access USB and mobile Internet on LG GT540”

Real APK Leecher

Real APK Leecher is a great tool that allows you to download offline versions (installers) of all your Android’s (Google Play) applications, even paid ones. As good as any other free. For what purpose? Why this is obvious. You can finally install any APK you want on any Android-based device without need to provide your Google login and password. You won’t be able to update them automatically though, but who cares? You can always use this piece of software again to get the newest version as offline installer.

Read More “Real APK Leecher”

Google Loader and ClientLocation object for IP-based geolocation

Google Loader is a convinient way of loading other libraries and APIs.

And, if you know, where to look for you can even find nice examples of now undocumented ClientLocation object, which can give you location of your visitor — less accurate than GPS (navigator.geolocation object), but based on IP address and therefore not requiring user agreement on using this feature.

Setup PHP to use Xdebug in Netbeans

This guide shows, how to setup Netbeans (edition for PHP developers) and local PHP interpreter with Xdebug — a world famous on-line debugging tool for PHP.

Since I’m using XAMPP package as my server in development environment, you may find some references to it in this text. But most of it should be clearly readable to anyone using Netbeans and Xdebug.

Intro

Double or even tripple check, if you have correct Xdebug configuration (see below)! I was fighting with some stupid bug for nearly two days only to find out, that it was caused by incorrect configuration. During that time I’ve read more than a dozen guides and each time I run into “Configuration” section or “check your configuration” statement I was always automatically assuming: “yes, yes — it is correct“. As it turned out (after two days), I was wrong and configuration was not correct. Don’t repeat my mistakes and don’t waste your time so stupidly!

Also, keep in mind, that if you’re using Windows 7 or newer version and you’re running your webpage locally, you should definitely use 127.0.0.1 address everywhere, instead of localhost. This will give you a much faster performance, speed and server response times. Follow to Stack Overflow, to this answer to find out a detailed explanation, why this is happening.

Which Xdebug for me?

First of all, get correct version of Xdebug for your PHP environment. As you go to Xdebug’s download page you will notice, that list of available editions is long enough to get a headache.

You must closely match version of Xdebug to:

  • your PHP version (5.3 or similar),
  • your system / platform version (either 32-bit or 64-bit),
  • version of compiler used to compile your PHP version (not Xdebug itself), for example VC6, VC9 or VC11,
  • and finally, whether your PHP was compiled in thread-safe mode (TS) or in non-thread-safe mode (Xdebug version without TS addition).

And this can be a hard task.

To make it easy, Xdebug author has provided us with tailored Installation Instructions.

Setup Xdebug

Installing Xdebug in your PHP is easier than most guides shows.

Locate and open php.ini in your editor. Remember, that PHP is Linux/Unix software at first, only ported to Windows, so pay attention to use text editor that supports Linux line endings (LF). Make sure, that you don’t write changed php.ini with Windows line endings (LF&CR). If you see everything in this file bloated in one line (for example after opening in Notepad), then this is clear evidence that you’re using wrong editor.

Locate extensions part of php.ini and after last extension= add a new line with extension=xdebug.dll. Supply correct filename, you’ve copied to ext folder.

Then hit Ctrl+F to locate [Xdebug] group and do some Xdebug configuration changes there. List of options is quite long, some of them may already be selected other are commented-out (ignored). After robsnotebook.com, a fairly good, but bloaty and poorly written article I cite, that you should consider at least these settings:

zend_extension = C:xamppphpextxdebug.dll
xdebug.remote_enable=true
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp

Make sure, that zend_extension points to correct location of your Xdebug DLL.

Consult above mentioned article for more details on each option, you enable here. I only wanted to have Xdebug working and to be honest I didn’t much care what am I setting here.

If you’re using Zend Optimizer, you have to disable it, by commenting out any zend_optimizer settings in php.ini. Consult above article for more details on this. I don’t have Zend and all, I don’t like it (too heavy) and I don’t care.

Restart Apache and carefully check, if there are any errors reported during startup. Either as message box or in Apache’s logs. Correct anything that looks wrong or suspicious.

Run any PHP script with phpinfo() command to display environment information and use Ctrl+F to determine, if your installation of Xdebug is OK. If you find xdebug group, followed by xdebug support -- enabled information, then you’re fine. Congratulations!

Setup Netbeans

Run Netbeans, if it is not running yet and open your project inside.

Open Tools > Options and go to General > Web Browser to set your prefered web browser, that will be used in debug process. The best option seems to be selecting internal browser, to not get crazy of pressing Alt+Tab all the time to switch between browser and Netbeans. But see some side notes on this below.

Configure debugger in Netbeans, by opening Tools > Options and going to PHP > Debugging. You should leave most options in default states. The only thing you may consider is unchecking Stop at First Line checkbox.

And… you’re done! :]

Note, that Netbeans powered by Xdebug can easily debug simple websites and pure-PHP applications as well as complex apps written basing on any framework.

Debugging with Xdebug and Netbeans

Set some breakpoints and click proper toolbar icon or hit Ctrl+F5 to start debugging your currently selected Netbeans PHP project.

Debugging of your project should start. And your webpage or application should be opened in external or internal browser, according to your selection in Netbeans configuration. If there are any problems at this stage, you can always click your project (in projects tree) with a right mouse, select Properties from context menu and go to Run Configuration section. Check, if everything is OK there, at first place.

When your application or webpage start in debug mode, Netbeans will switch to selected browser (either internal or external). If execution flow is halted by an error or breakpoint, you’ll be switched back to your code only in case of using internal browser. In you’re debugging in external one, you have to manually switch back to Netbeans.

Once your debug starts, you get access to all debug information, Xdebug can get out of your webpage or application and provide to Netbeans. You can see all variables available in current context. If debug stops on any of your breakpoints or run into an exception, you can see entire call stack of your current context.

After stopping on a breakpoint you have access to all standard execution flow control functions like Step Into (F7), Step Over (F8), running to cursor etc.

To end current debug session, press Shift+F5.

Some browser side-effects

For debugging process (as well as for simple running your project) you can use either internal (based on WebKit) or external browser. You set it in configuration, in Tools > Options > General > Web Browser. There are some side-effects depending on what you actually choose.

When choosing external browser, you can test your application in any environment you would like. But you have to switch manually between Netbeans and that browser, each time something change in execution flow (an error, a breakpoint etc.) or each time, you want to check a variable, stack trace etc. You can also end up bloated with browser’s tabs (or even windows), because Netbeans opens up new one for each debug session initiated and second one with “DEBUG SESSION ENDED” message, once your done in current debugging session (this is most initiating).

I don’t know, why it (or Xdebug or browser itself) can’t take over existing tab, especially because it uses the same Xdebug token (netbeans-xdebug) all the time. Opening new tabs or windows for each new debug session was understandable in Eclipse, because that IDE uses different token for each debug session. In Netbeans this has to be some bug, especially that when using internal browser, it can always work on one and only tab. As I said, I don’t know, why this is happening. But this is stupid, annoying and was key factor for me to choose internal browser instead.

If you do the same and choose internal browser, you have to suffer the fact, that altough it is based on a WebKit (not ugly, pesky, standard-less IE), but it still far from general browsers development stream. Which means, that your website or application will lack some newest solutions and in general may look a bit different than in external browser. I think, this is acceptable, as we’re using internal browser only to catch-up bugs and fix them. And once they’re fixed, we finally test application in external browser, so everything is fine at the end.

Using internal browser is also convenient, because Netbeans will automatically switch you to code tab, once it reaches a breakpoint or an error.

Netbeans opens up internal browser window (tab) automatically, after you press Ctrl+F5 to start the debug process, but it can’t close it after debug session ends. Probably another stupid bug in IDE. So, in current version (7.3) you always end with _DEBUG SESSION ENDED_ message once you’re done with debugging and there is no auto-going back to code. But, in case of internal browser, it can be easily worked around. Simply learn yourself to press Shift+F5 (terminate debug session) followed immediately by Shift+W (close internal browser tab).

Summary

I must admit, that I was quite surprised on how good Netbeans and Xdebug works together in debug process of a PHP application. After all, PHP is a scripting language, where general application execution flow is request-reply based. But these two binded together lets you debug it nearly the same as you would debug any standard application. I.e. allowing to stop on breakpoints, giving you full flow control (including fabulous Run to Cursor) and even working perfecly on complex, framework-based applications.

Xdebug is a famous debugging tool for PHP. Maybe even the most famous. The other one is ZendDebugger. I haven’t got chance to check it out, because Zend and Microsoft agreed some time ago that the only stable way of running PHP on Windows is NTS mode (non-thread safe mode). Zend followed that and since PHP 5.2 started to publish only NTS versions of ZendDebugger. Unfortunately my server package (XAMPP) was not invited into that Microsoft-Zend meeting, was not part of that agreement and does understand, that running PHP on Windows in thread safe mode is the same as in non-thread safe. And continues to publish PHP in TS mode only. In other words, I haven’t got chance to check out ZendDebugger, because it is not available for me. But since Xdebug does the job perfectly and since I don’t like Zend at all, I’m fine and happy with that.

Netbeans vs. Eclipse

Netbeans is much slower and has a lot of bugs, but even so I decided to continue using it for my PHP development environments. There are few strong arguments, which beats Eclipse like a hell. Here you’ll find why. I’m trying to answer here, why quite experienced developer (that would be me! :>) decided to use less stable, slower and more buggy IDE than Eclipse.

Keep in mind, that I’ve been using Eclipse only for a few hours, while Netbeans over three hears. This may influence my judgement.

Read More “Netbeans vs. Eclipse”

“Class SQLiteDatabase not found” error after upgrading SQLite

Class SQLiteDatabase is an object from sqlite library, which support was dropped in PHP 5.4, but on various systems and configuration could be disabled in an earlier releases, as this library was long time marked as going to be deprecated.

Library php_sqlite.dll (Windows) or php_sqlite.so (Linux) is no longer supported in newer versions of PHP and was replaced with php_sqlite3.dll or php_sqlite3.so respectively.

Read More ““Class SQLiteDatabase not found” error after upgrading SQLite”

Are password-protected ZIP files really secure?

In general, password-protected .zip files can be considered secure.

Some may be surprised to find out that (without knowing the correct password) any program (or user) can:

  • browse list of files inside password-protected ZIP archive,
  • check file types (try to send encrypted, password-protected ZIP containing EXE file via Gmail).

And… there are some other “interesting” things you should be aware of…

Read More “Are password-protected ZIP files really secure?”

Professional Git commit comments

Git commit comments / log messages are (may / should be) more complex than those from Subversion. They can be automatically converted into e-mails sent to other commiters or other kind of group of interest. Some Git commands and tools may generate additional commit messages. That’s why comments written by you manually, should follow some rules and guideline. Most of them are expressed in this article.

Read More “Professional Git commit comments”

Using git-svn under Windows for migrating SVN repo into Git

I wanted to import SVN repository into Git repository, where SVN repo had uncommon structure (without trunk / branches / tags folder). And I wanted to skip all the remote branches stuff, just export entire SVN repository as current master branch in Git repo.

Note, that I used console commands (like git svn) only to do hard job of migration. Other stuff, that I was able to achieve in TortoiseGit (like pushing to remote) I did manually.

Read More “Using git-svn under Windows for migrating SVN repo into Git”

Example of using cURL for converting a webpage to a pure text

The preg-replace function takes a URL and returns a plain-text version of the page. It uses cURL to retrieve the page and a combination of regular expressions to strip all unwanted whitespace.

This function will even strip the text from <style> and <script> tags, which are ignored by PHP functions such as strip_tags (which strips only tags, leaving the text in the middle intact).

Read More “Example of using cURL for converting a webpage to a pure text”

Model saving vs. model validation when uploading files

Newbies to Yii and ActiveRecord design pattern, are often confused, what is difference between $model->save() and $model->validate(). though difference should be obvious, there are many code examples in the forum and Yii wiki, that proves, that many people still doesn’t understand it. Especially, when it comes to performing additional operations around saving model, like file upload.

Read More “Model saving vs. model validation when uploading files”

Using Twitter Bootstrap’s popups like real menu items

Twitter Bootstrap framework is fabulous and thanks to many Yii extensions supporting it (Yii-Boostrap, Yii-Booster, Yiistrap, YiiWheels and more) using it in own application is like snapping with fingers.

One of the best features of Bootstrap is a very easy way of creating menus and adding popup menus to elements (like buttons). However, in default implementation popups are oriented toward working just like a fancy links — i.e. redirecting browser to destination URL. In this article, you’ll find how force them to work as real menu items — i.e. capturing their onclick event and doing something with content.

Read More “Using Twitter Bootstrap’s popups like real menu items”

Self-documenting code is a myth

How many times did I heard that stupid talk? “Comments aren’t needed! Code should be self-documenting”. If you think this way, then… believe me or not, you’re wrong. Good developer does not need comments to describe, what he or she is doing. But there’s always a purpose for doing something, which must be documented for future reference. If you think, you can achieve the same with self-documenting code, you’re going strictly into violating fourth of Five major software development rules. Which says: “Premature optimization is the beginning of all hell!“.

Read More “Self-documenting code is a myth”

CSS and JS minifier/beautifier that rocks!

I definitely love and adore Avivo’s CSS/JS Minifier/Beautifier. Mostly for options that similar tools lack. Like: braces on own line, preserve empty lines and ability to select intend character.

It has a small bug in CSS Beautifier. Every : is beautified to : (with space), which breaks pseudo-classes like :hover and and pseudo-objects like ::before. But, this can be easily fixed (manually; simple find-and-replace in text editor).

So, even with this, Avivo’s tool is just fabulous!

CGridView and CDetailView column or attribute value by expression

CDetailView does not use “deferred” evaluation like CGridView does on rendering rows. CDetailView gives you direct access to your model, while CGridView only to a per-row prepared data. So, to render CGridView‘s column or CDetailView‘s attribute row, you must use slightly different approaches. Here is how.

Read More “CGridView and CDetailView column or attribute value by expression”

Upgrading MySQL on-board XAMPP

XAMPP is a great package of Apache, MySQL, phpmyadmin and some others (actually the best I’ve ever used). The only disadvantage of it, is that guys behind this project haven’t got much spare time and update it fairly slow. Newest XAMPP version (1.8.1) is over a year old now and still has MySQL 5.1.41 on-board, while version 5.6.10 is available for download, as of writing this. Here are some tips on manually upgrading MySQL on-board your XAMPP package.

Simple copy & folder switch does the job and is enough to upgrade MySQL on-board XAMPP from 5.1.41 to 5.6.10. However there are slight side effects, you must consider.

Read More “Upgrading MySQL on-board XAMPP”

HTML-to-Markdown on-line tool, that actually works

If you search the web for “convert HTML to Markdown online“, Google will return you a quite big bunch of useless links. Mostly pointing to websites that only claims that can do HTML-to-Markdown conversion (while actually doing opposite one) or that are doing conversion in a really poor quality (failing on simple HTML).

After digging through many of them, I finally found “html2text” — a simple, yet powerful Python script that just do the job. It was the only online tool, that I found, that actually was able to convert my simple (three unordered lists with some links inside) HTML text into pure Markdown.

Using tcpdump for capturing data sent by TK102 GPS tracker

Xexun TK102 GPS Tracker and most of its clones can send localization data either via SMS messages (some models offers just a pure data, that you have to analyze yourself, some sends it out along with Google Maps link) or via GPRS protocol, directly to specified server. Which then can analyze and visualize that data. SMS sending works just great in most cases, while getting GPS data via GPRS can be a real pain in the ass. This post is written with hope to help you a little bit, if you’re facing the same problem.

Read More “Using tcpdump for capturing data sent by TK102 GPS tracker”

TK102 connector / plug / cable type (and schematic diagram)

The Xexun TK102 GPS Tracker and most of its clones is using something, what English Wikipedia calls UC-E6 proprietary (non-USB) plug. So, this is neither microUSB nor miniUSB as I was assuming in the first place.

Here you’ll find some links to information about this plug and some simple schematic diagram for tracker.

Here is mentioned schematic diagram:

TK102-connector-plug

If you’d like to purchase a cable for Xexun TK102 GPS Tracker, then eBay should be your friend. If, on contrary you’d like to craft your own cable, then this great article will help you or can be at least a good starting point.