Migration that requires user confirmation to continue

Since there’s a pure Linux underlying PHP, you can use STDIN (actually: php://stdin) and read it with fopen when your PHP script is run in console to stop execution of your script and read a button user pressed.

Since Yii migrations are run in console, you can use this mechanism to ask user whether she or he want to continue with your database migration.

Quite handy in some scenarios (like: destroying entire database), don’t you think?

Read More “Migration that requires user confirmation to continue”

Converting database structure or .sql file into Yii migration

Yii Framework 1.x migration system is very powerful and gives you much more power and control over database update process. But it becomes a horrible nightmare, if you have to deal with .sql files and convert them into Yii migration files manually.

This article should help you in that strike or at least ease your work.

If you have any doubts, why the hell migrations are better than using plan .sql files then this blog post should provide you with at least some reasons.

Read More “Converting database structure or .sql file into Yii migration”

From Drupal-based blog to Yii-based application

If you are in need to migrate Drupal’s content data (articles, pages, events, etc.) to your own CMS or database structure then this article may be helpful for you.

Note however, that I have little to none knowledge of Drupal and that my MySQL experience is very limited. Therefore, information provided in this article may be useful, but on the other hand, I can write something wrong (even up to a complete bullshit) or mess things around.

Use this text with a caution and at your own risk. You have been warned. No money back guaranteed! :>

Read More “From Drupal-based blog to Yii-based application”

Importing large datasets to MySQL using command-line

Command-line MySQL client is way faster and more stable for importing large datasets into MySQL database. For all those Linux geeks, this is of course obvious. But, for use, lame Windowsers, using phpMyAdmin was nearly always a better choice, and this such articles like this still should be written! :>

In my case, it was 152 tables, nearly 120k records and 30 MB of uncompressed .sql file.

Read More “Importing large datasets to MySQL using command-line”

Changing default PowerPoint presentation

Changing default document for Word (i.e., the one, that is opened each time you start Word) is an easy task. You just have to open %APPDATA%\Microsoft\Templates folder and save any document as Word Template under Normal.dot file name in this location. Changing default PowerPoint isn’t that easy, because file names and file paths are different. I keep forgetting about this, so I wrote this article as my personal memo.

Read More “Changing default PowerPoint presentation”

Force macro-enabled documents to not display warning after opening

If you work with macro-enabled documents in Microsoft Office and you run on default settings, each such file will be always opened with macros disabled and you’ll have to click Enable macros each time to enable it. If documents are your own, you trust, that they contain no malicious code and they’re all stored in a secure location (i.e. not in some temporal or shared folder), you can change each Office program settings to have these files always opened with macros enabled.

Read More “Force macro-enabled documents to not display warning after opening”

Implementing own slideshow functionality to Colorbox

I have set slideshow:true in Colorbox‘s configuration and Start slideshow link didn’t appear.

I was pretty sure, that this is due to some stupid bug made by me, but because I was on steroids that day, instead of investigating on what is wrong, I decided to write my own implementation of slideshow func.

Code isn’t pretty, but it can be useful for beginners in determining, how events and other stuff around Colorbox works. This example can also be useful for implementing slideshow functionality to other, non-Colorbox, photo gallery libs, that do not have this functionality implemented in core.

Read More “Implementing own slideshow functionality to Colorbox”

Combine pure string and jQuery object. A word about outerHTML property

You can’t simply combine pure string and jQuery object using Javascript concatenation operator (+). You cannot easily mix strings and DOM elements. So, something so trivial like surrounding link with [ and ] brackets becomes not so trivial. At least to beginners. This article should help.

Read More “Combine pure string and jQuery object. A word about outerHTML property”

Feeding data to Flightradar24 using DVB-T stick. Part 2. Software

You want to feed data to Flightradar24 using DVB-T stick and you have already received your hardware. Great. Now, it is time to talk about software, installation and configuration. Note, that (contrary to FR24) I’m providing information about Windows Vista and later editions of Windows. If you’re an old dinosaur, still using Windows XP or you need info for Linux, Unix or Mac systems, consult “Add Coverage” pages at Flightradar24.

IMPORTANT! Read this article BEFORE you even plug your DVB-T stick to spare USB port. If you do this, you’ll waste some additional time on uninstalling Windows drivers, which are completely useless in this scenario (since we want to receive flight data, not the actual TV signal, right).

Read More “Feeding data to Flightradar24 using DVB-T stick. Part 2. Software”

Installing Composer to PHP on Windows

There are a few small issues and changes, when installing and using Composer dependency manager to PHP running on localhost (local development environment) on Windows.

This article should clarify these things and answer some questions about using Composer on Windows.

Enabling HTTPS

First of all, you need to have support for HTTPS protocol and wrapper enabled in your PHP. Edit php.ini and look for extension=php_openssl.dll line. If if has ; character in the beginning (library disabled), remove it (enable library). Then restart your Apache.

Now, to install Composer.

Just a single installation

If you need it for just a single project (it’s author forces you to use it, but you normally don’t care for all these composer.json files), then you may use typical way, described at Download page. I.e. execute:

curl -sS https://getcomposer.org/installer | php

from command-line. If this does not work (or if you don’t have curl), try alternate version of:

php -r "readfile('https://getcomposer.org/installer');" | php

It this, again, don’t work, try the next method of central installation.

Central installation

In most case you’d like to use Composer for many projects. Therefore you need to install central version, that will be accessible in every path. The simplest (and the only tested by me! :>) method is to use installer file. You’ll get it at Download page or in here.

Run downloaded Composer-Setup.exe file and follow on-screen instructions.

Default settings seems fine, so clicking Next > few time should do the trick.

Once Composer is installed on your system, you should either exit all terminal windows and/or all Windows Explorer windows and open them again, to force system to re-read PATH environment variable, just updated by Composer installer. Alternatively, if above seems to be not working, restart entire Windows.

Usage

Most pages for developers and most code repositories are handled by geeks using Linux. So, they write to run php composer.phar install. This won’t work under Windows and should be replaced by simple composer install. Since Composer is (should be) listed on your PATH, it should be available in any directory.

That, of course, matches only installing “central” installation, using Composer-Setup.exe file. If you installed only single, per-project version of Composer, you’re normally running php composer.phar install.

Remove all kind of quotation marks

I say: “Remove all quotation marks from a string“. You say: “stripslashes“.

Works fine. In most of situations.

If you have to deal with quotation marks manually entered to rich editor (i.e. by copying large block of text from Word for example) or with a string being a poor effect of even more poor encoding routine, you may be sure, that stripslashes won’t do all the dirty work for you.

This is the place where my handy method comes in.

Read More “Remove all kind of quotation marks”

Changing default icon for a file type in Windows 7

Windows XP was the last Windows system to have File Types tab in the Folder Options applet and to allow user easily changing default icon for particular file extension. This tab was replaced in Windows Vista and following systems by Default Programs applet from Control Panel. It lacks many features, including changing icons for file types. Therefore, in Windows systems following Windows XP you have to either use 3rd party software for achieving this simple task or dig in Windows Registry. This isn’t that hard task as it seems, so read on, if you want to give this method a try.

Read More “Changing default icon for a file type in Windows 7”

Dump current database state to Yii migration

There’s a wonderful extension to Yii 1.x, called database-command, written by the one and only schmunk, which allows you to quickly and easily generate any set of CDbMigrationCommands (actually, entire single migration code) based on current database schema.

This isn’t, of course, the only one out there. There are some others. But I like this one the most, mainly for flexibility (may parameters to suit generated migration file to your needs). However, if this is your first approach to using custom yiic commands, you may get a little bit confused. This article should help you.

Read More “Dump current database state to Yii migration”

Shortcuts for direct TeamViewer session on Windows desktop

To quickly access some partner or remote computer in TeamViewer 10, you can login to your account, check to be always logged it, and add particular machine to the list there. Each time you start TeamViewer, you’ll have list of your computer ready in a window to the right. All you have to do, is to double click any item in that list. Can it be even faster? Can we initiate TeamViever session to particular machine or customer by double clicking icon on Windows desktop? Sure thing, we can!

Read More “Shortcuts for direct TeamViewer session on Windows desktop”

Password prompt when accessing account without password via network

If you are trying to access computer, that has only one account, without password, you’ll be asked to provide password anyway. This is normal. By default, Windows blocks all non-local logins to accounts that don’t have passwords, for security reasons. There are few things you can do with this situation.

Read More “Password prompt when accessing account without password via network”

Use jQuery to load element from another page

You can use jQuery to load any element from another page as easy as you get it from the same document.

Here is how (source):

$.get("../index.html #header1", function(data)
{
    $("#indexHeader1").html(data);

    alert("Load was performed.");
});

It’s no magic. It’s a regular AJAX call, only jQuery parses result and tries to strip requested element only.

Keep Sublime Text 3’s replace panel open after replacing all elements

By default, if you open the replace panel (Ctrl+H) enter search and replace patterns and click Replace All button or hit Ctrl+Alt+Enter, replace panel will be hidden. This is very annoing to many users. However, there’s a partial solution to this problem.

This is tested only in Sublime Text 3, but should work in Sublime Text 2 as well:

  1. Select Preferences > Key Bindings — Default.
  2. Search for ctrl+alt+enter and copy entire block.
  3. Select Preferences > Key Bindings — User.
  4. Paste copied block anywhere and remove , "args": {"close_panel": true} part from it.
  5. Save Key Bindings — User and test it (you don’t need to restart Sublime Text).

Since, you have just modified key binding, then you should remember, that expected behavior will work only if you execute Ctrl+Alt+Enter inside it. If you click Replace All button, the “old” behavior will be applied — i.e. replace text panel will be closed.

Posted to Stack Overflow.

Feeding data to Flightradar24 using DVB-T stick. Part 1. Hardware

So… you want to have a Flightradar24 Premium account for free or you want to make the world better and you decided to start feeding data to this service, right? Well, great! But, information provided by FR4 about installation, configuration and feeding process itself have a lot of crappy and irrelevant parts. So, I decided to write my own mini-serie of articles on how to start, what to purchase and what to look for. So you can avoid all the pitfalls I felt into.

IMPORTANT! Read the next article, about software BEFORE you even plug your DVB-T stick to USB port. If you do this, you’ll waste some additional time on uninstalling Windows drivers, which are completely useless in this scenario (since we want to receive flight data, not the actual TV signal, right).

Read More “Feeding data to Flightradar24 using DVB-T stick. Part 1. Hardware”

Plural formula in PHP to evaluate ending for a number in Polish language

Providing correct plural form of countable words in English is easy, because there is a difference only between one (1 item) and other (0 items, 2 items, 5 items etc.).

In Polish (and some other languages) this is much harder, because Polish has two different plural forms and plural form of countable words is way, way more complicated and based sometimes not only on whole number but also on last digit of this number etc.

Read More “Plural formula in PHP to evaluate ending for a number in Polish language”

Text truncating function that secures both HTML tags and full words

Akshaya K Sahu’s answer to this question at Stack Overflow is a great example of text parsing function that can truncate any HTML-encoded string at given length, taking care of all the needed aspects, i.e.:

  • full words,
  • properly closed HTML tags and
  • respected UTF-8 encoding (double-byte characters!)

I have actually nothing to add to it, so I keep a copy of this code only for my own reference. And only because the original answer lacks some comments.

Read More “Text truncating function that secures both HTML tags and full words”