Working with code snippets in Sublime Text 3

This is another article about my transition from Netbeans to Sublime Text 3. This time I’m going to handle code snippets topic. This is another area, which is much better solved in Sublime Text 3 than in Netbeans.

This article is generally based on “Working With Code Snippets In Sublime Text” blog text from hongkiat.com. And — of course — wonderful, yet unofficial Sublime Text documentation’s chapter about snippets. With some my personal additions and updates.

Read More “Working with code snippets in Sublime Text 3”

Useful keyboard shortcuts in Sublime Text 3

This is one of the last article in my private serie of blog entries targeting developers, who starts their journey with Sublime Text 3. Treat it as memo or list for easy remembering sometimes very useful, not always often, keyboard shortcuts, that are available in ST3. Where it is possible, I’m adding links to Sublime Text Unofficial Documentation, which is great source of information in any aspect related to Sublime Text 3.

Note, that entire document is based on default Sublime Text 3 key bindings, before any user changes, like for example those mentioned in [Netbeans-like keyboard shortcuts in Text 3.txt] text. Also note, that when speaking about Alt key, I’m referring to left key. As on some non-English keyboards, right Alt key may have different meaning (entering language-specific letters etc.).

Read More “Useful keyboard shortcuts in Sublime Text 3”

Beginning with Sublime Text 3

My journey started with reading (and watching videos) two good blog entries done by Stuart Herbert:

However, both texts are old and covers Sublime Text 2 only. And both are quite long. If you want a shorter version, updated for Sublime Text 3, then read on…

Note, that this article is filled with many comparisons to that Netbeans. Intentionally. I’ve been using Netbeans for past five or more years. And from the first day, I started using Sublime Text 3, I feel like I’m a newborn developer again. And I finally have super-fast, super-powerful IDE instead of old, slow, buggy, cranky Java-based Netbeans. Whoa! :]

Read More “Beginning with Sublime Text 3”

Changing sidebar’s font size in Sublime Text 3

Changing font size of editor (by adding "font_size": 14 for example to Preferences > Settings – User file) changes font size of editor area. But leaves font size of sidebar unaffected. I have found files and folders’ names, drawn on sidebar with 10 pt font size, quite not so comfortable on Full HD resolution screen.

So, I needed a fix.

There’s (of course!) a Stack Overflow answer, that explains, how to achieve this in Sublime Text 2. I managed to port this solution to Sublime Text 3.

Read More “Changing sidebar’s font size in Sublime Text 3”

Migrate PuTTY sessions between computers

PuTTY is one of the first programs, that I install on every computer. Since, it stores sessions in registry, it is a bit difficult to migrate sessions between computers. So far, I manage to do this with a little bit help of regedit.exe program and guides like this one. Today, unfortunately, I hit the wall, when my brand new installed Windows 7 told me, that it can’t merge entries from my putty.reg file, because it can’t access Windows Registry.

Read More “Migrate PuTTY sessions between computers”

Capture double click on Yii’s CGridView row

I was using a simple Javascript code (attached to CGridView.selectionChanged property) to capture click on any grid view’s row and redirect user to row-specific URL. I wanted to change it to double click only.

CGridView exposes selectionChanged even only, no click or dblclick, so that was a quite nice challenge. It seems that the only way is to capture this event yourself.

Read More “Capture double click on Yii’s CGridView row”

Delete model with relations

To delete in Yii a model with some relations we usually have at least three options.

Depending on many factors (RDBMS type, table type, situation, context etc.) most of them have advantages and disadvantages. Good developer already knows these options, so intention of this post is not to discuss them, but to show you an interesting, new (at least for me) fourth approach to solve this problem, that I found recently.

Read More “Delete model with relations”

urlReferrer and opening new browser tab

To open particular URL in a new tab, you have at least two possibilities:

  • click a link with middle button (usually under mouse wheel) or
  • open a blank tab and copy-paste URL to URL bar.

There is slight difference it this (at least in Chrome) when it comes to urlReferrer in Yii:

  • in first case browser sets referrer correctly (i.e. Yii::app()->request->uUrlReferrer contains a valid URL),
  • in second approach URL referrer IS NOT set (i.e. Yii::app()->request->urlReferrer is an empty string).

The second situation is obvious. Opening a new tab means that browser does not have a history for it and thus it is unable to set urlReferrer correctly. However, it is better to keep this information in mind. If you rely on this information, you may get yourself (or your code) into a problem.

CGridView: the summaryText maddnes!

I’m finishing entry phase of my first big project (first big project, where I’m key project manager and lead developer, to be precise). Right now I’m after four days of sleeping for 5 hours and coding for remaining 19 hours each day. My brain simply bowls. In this specific situation, I’ve crafted a helper method, which makes mad-laughing or mad-screaming, each time I see it.

Read More “CGridView: the summaryText maddnes!”

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]”