The unlink function returns TRUE on non-existing files!

Is seems, that unlink() returns FALSE only, if file, that is about to be deleted, exists and there was a problem removing it. If file wasn’t there, when unlink tried to remove it, it still does return TRUE. Keep that in mind!

This seems to be reasonable. Logic, that I see here is:

You wanted me to delete that file and… swoosh… it is gone. It doesn’t matter, that I had nothing to do with its deletion, right?

For some this could be surprising — unlink() function returns logic value about whether file, that should be deleted is deleted. It’s return value says nothing about whether actual deletion process occurred.

For me this is not only surprising, but also wrong! Dear PHP, I wanted you to “delete” this file (which you didn’t). Not, to “make sure it is gone” (which, we may agree, that you did).

Dealing with ‘No external storage available’ error in Android 4.3

I’ve been cleaning internal storage (the only one, that I have) on my Google Nexus phone and it seems that I remove a bit too much… My storage stopped responding and when I went to gallery or photo camera I saw a beautiful message, saying:

If you’re facing the same or similar problem, you may find solution in this post. However, I must warn you that most likely you’re going to loose everything on that storage!

Read More “Dealing with ‘No external storage available’ error in Android 4.3”

Key difference between GPL and BSD licenses

For the project, I’m working on, I came over Plupload library, which is dual-licensed on GPL+OEM model. Since paying commercial license (OEM) in this project is not an option, I told my boss, that we can’t use this library, because we’d have to publish all our project’s sources as open source (base GPL licensing requirement).

He told me, that this is not true, because both PHP and Yii, that we use, are licensed in the same model.

I was so sure, that I’m correct, that I immediately made some research and wrote this article as a summary of all my findings. I was more than happy to prove my boss, that he is wrong! :>

If you think similarly to my boss, then you should definitely read this post.

Read More “Key difference between GPL and BSD licenses”

Upload files via AJAX and fill up other model properties in the same time

There’s a comment to Yii 1.1: XUpload Workflow Wiki article, made by MeDroogie, who asks, how to handle situation, where file is correctly uploaded (via AJAX, in separate layer, handled by upload action), but form submission itself fails, as form processing action stops on some model’s validation errors.

I had the same problem with other AJAX uploader, that I think, I solved gracefully.

Keep in mind, that since solution, that I’m discussing in this article, is part of proprietary project, I cannot share any code. This is purely design or theoretical discussion.

Read More “Upload files via AJAX and fill up other model properties in the same time”

Remove file from repository and from all revisions [updated]

Say, that you have commited to a Git repository, a file, that contains sensitive or confidential information. You want to literally purge it from the repository history.

Simple git rm --cached <file> won’t do the trick. It will remove a file from the repository (keeping it in your working directory), but it will still keep the file in history. What now?

Read More “Remove file from repository and from all revisions [updated]”

Write a directory tree to a text file in Windows command line

I found a question “How to write a list of directory trees to a text file?” on Stack Overflow, as I was looking for exactly the same solution. It has two brilliant answers, and since I’m using this blog as my personal remember-that-diary, I decided to share it here, so I shouldn’t look for this solution again.

Read More “Write a directory tree to a text file in Windows command line”

Where should I keep JS and CSS code — inline or in an external file

Hamlet’s great question (“To be or not to be“), turns in web development and mobile world into Javascript (or CSS stylesheet) asking the developer: “To be inline or not to be”. In other words: what is better — to put code inline of HTML page or to put it in an external file? I was more than sure, that the answer is pretty straightforward — external file is always better. And I keep myself with this answer. However, I found a few arguments, that my sound interesting at first, but must be answered.

Read More “Where should I keep JS and CSS code — inline or in an external file”

Invert non-consecutive data column in Excel

Let’s say, that you have a one or more columns, in which you would like to invert data. What is most important — data does not follow step-by-step (in which case you’d use simple data sorting function in Excel), It can have something like –1, 5, 76, 23, –65, 124 in each following row of column and you want it to have like 124, –65, 23, 76, 5, –1. How to do this, if you deal with hundreds or thousands of rows, so manual change is not an option?

Read More “Invert non-consecutive data column in Excel”

A library for gauges, charts or data visualisation

There are certain drawing and graphic libraries in Javascript that can be considered for:

  • drawing charts,
  • doing some data visualization for the website,
  • using them as gauges / clocks for the mobile client

(gauges can be used in limited manner on the website as well).

This article deals with most interesting ones that you may consider for above purposes.

Read More “A library for gauges, charts or data visualisation”

Reverse geolocation with OpenStreet Maps reverse geocoder. Pros and cons

Reverse geolocation is a process of obtaining certain geographical information (like street name, city, country etc.) based on geographical coordinates only.

OpenStreet Maps offers a cool looking (at least at first sight) reverse geocoder that can feed your application or website with a valuable geolocation data. However, as you go deeper in to the details, more cons over pros can appear.

Read More “Reverse geolocation with OpenStreet Maps reverse geocoder. Pros and cons”

Open phpMyAdmin with preselected database

The correct URL should be like that:

http://[HOST_AND_PATH]/index.php?db=[DB_NAME]#PMAURL-1:db_structure.php?db=[DB_NAME]

I found this path to work in any conditions. After logging-in with this path, user should see phpMyAdmin open with pre-selected database ([DB_NAME]) and should see that database’s tables list, not pMA‘s home screen.

And, as I just verified this, it works even on as old phpMyAdmin as version 2.11.3.

Static map from Google with no API key required [updated]

You must be a member of Google APIs Console and obtain a valid API to embed Google Maps into your website or web application. That’s a well known fact.

Not everyone knows that this is required only, if you want to embed a fully-featured Google Maps, i.e. with ability to scroll, zoom, use markers, calculate routes etc. For embedding a static image of Google Maps showing requested location you don’t need API and required Javascript code is nearly a one-liner.

Read More “Static map from Google with no API key required [updated]”

Configure email sending solution under XAMPP

This is the ultimate (at least for me! :]) solution to configuring mail sending in your XAMPP. Verified and confirmed that this is working. If you go through these steps and still have no results, I’m 95% sure, that problem is outside XAMPP or sendmail (i.e. something is wrong with your configuration). I hope, I don’t have to remind you, that every wise guy uses XAMPP only for development purposes and never, ever as stand-alone, production, webserver!

Do not get confused! This article is about fake sendmail, a solution designed for development environments, like XAMPP, to mimic mail delivery subsystem for developers, that is found on production servers. This text has nothing to do with original sendmail, world famous MTA, started 1979 (25 years before fake sendmail!) and still widely used on production servers and anywhere else in hosting area.

Read More “Configure email sending solution under XAMPP”

Round functions in PHP still returns float!

When you round any float number to integer, rounding function (for example floor) still returns float type variable! What?

Well… on second thought, this is reasonable (and explained). PHP does it, because “the value range of float is usually bigger than that of integer“.

So, for example, if you would try to round a number bigger, that integer type can handle (> 2 147 483 647), PHP wouldn’t be able to do anything with the result of such rounding, if it would return it as integer.

Change prompt and enable command auto-completion [updated]

I really like some simple extensions and changes to command line in Linux. An ability to enable command auto-complete, commands history navigation and changing prompts look in particular.

However, not every console is suited with these changes, so I wrote this simple article to keep all my how-tos around Linux command line in one place.

Read More “Change prompt and enable command auto-completion [updated]”

Enable LDAP support in PHP served under XAMPP and Windows

Connection to LDAP in PHP isn’t that easy task by itself. Things get even more complicated, if you’re working in XAMPP environment under Windows. It hope this article will help you in getting un-stuck, if you’re stuck on the similar things, as I did.

Notice: solution provided in this article may not work for you! It worked on my office computer and failed completely on my home computer, though both are quite similar (same version of Windows and XAMPP etc.).

Since, we’re talking about very stupid system (Windows) and about even more stupid situation (claiming, that file is not found, though it exists in folder listed in PATH variable), I have no bloody idea, why it doesn’t work (or why it does work on certain computers) and how to solve this problem.

Read More “Enable LDAP support in PHP served under XAMPP and Windows”

Two-way encryption in PHP

I found two quite interesting examples at Stack Overflow about two-way encrytion / hashing in PHP. While two-way encryption is never as secure as one-way version (some claim, that two-way encryption methods are not secure at all), it is still a good alternative to not using encryption at all. For certain simple tasks, you may find it quite useful.

Read More “Two-way encryption in PHP”

Never allow users to transfer files with non-Latin characters in name

I have received a PM message at Yii forum asking about possibility of transferring (via HTTP upload) files with non-English characters in filename. In this particular example, a Greek and Chinese (and English), but with option to support all the languages, that exists.

Conclusion: No f*ing way! But, if you wish to read something more about this, follow with this article.

Read More “Never allow users to transfer files with non-Latin characters in name”