Estimating sunset time with your hand

I came across this handy tip over at Lifehacker website.  I think that’s pretty useful for outdoor photography, when camera people want to some of the best sky colors.

All you need to do is extend the hand full and count the number of finger width distances between the sun and the horizon.  Each finger is approximately 15 minutes, which means each hand is about an hour.  This is of course just an approximation, but it’s always better to have an approximation than nothing at all.  Enjoy.

Vim tips of the day

I’m using Vim text editor for more than decade now.  And I still can’t say I really know Vim.  I’m used to it and my fingers remember the commands.  And for those commands that I don’t remember, I’ve found some way of working around and got used to it too.  Today I came across not one, but two tips that I’m adding to my arsenal of Vim tricks.

Re-selecting visual block

Usually I only need to select the block once.  I then process it and never get back to it.  But sometimes, I need to select the same section of the text a few moments later.  Until today I was simply switching to visual selection and marking the block again.  Not too much of a problem, but it would be nice to have a shortcut for re-selecting the previous selection.  Of course, there is such a shortcut in Vim.  I just didn’t know it.  Simply type ‘gv‘ (without quotes) while in normal mode and your last visual selection will be selected again.

Increasing line limit on cross-file copying

There is no limit to number of lines copied between files, if all files are being edited in the same instance of Vim.  However if you copy a large selection from one file, then quit Vim, then open another file, and paste, you’ll probably see that only the first 50 lines or so were copied and the rest was lost.  Again this is not such a frequent scenario for me, and when it was happening I was simply opening both files in the same instance of Vim and copy all that I needed.  It turns out, I don’t really have to do that.

Vim uses ~/.viminfo file (default location) to remember things like command history, file marks, and registers between Vim instances.  There is a way to configure what and how much of what is going into this file.  If you are annoyed by any limits, you can easily raise them or totally remove them.  Have a look at “:help ‘viminfo’” manual page to see what is possible.   Adding “set viminfo=’100,<1000,s100” to ~/.vimrc file solved my problem.


P.S.: my messy Vim configuration files are available from GitHub, in case you wanted to take a pick at what else I have there.

MySQL prompt

I’ve been using MySQL for quite a few years by now, but only today I learned that it is possible to define MySQL prompt.  As per this blog post, all it takes is a couple of lines in .my.cnf file with something like:

prompt="\u@\h (\d)> "

That alone will help to prevent a gadzillion of destructive mistakes when you think that you are working with one database, when, in fact, you are working with a totally other.  On top of that, the blog post suggests using rlwrap tool, with which one could add some colors to the prompts as well.

chmod text modes

I came across this blog post which praises text modes for /bin/chmod.

There are two ways you can change file permissions in Unix – one is using chmod‘s symbolic (text) modes (like chmod ug+x file), the other is using the octal modes (like chmod 0660 file). It turns out that symbolic modes are more powerful because you can mask out the permission bits you want to change! Octal permission modes are absolute and can’t be used to change individual bits. Octal modes are also sometimes called absolute because of that.

I have to agree, they are superior.  However I feel like the article needs more examples.  So here we go.

Use “u” for user, “g” for group, “o” for others, and “a” for all, or you can use a combination of letters, similar to how you do for access rights:

$ chmod ug+rw *.php

This will make all .php files in current directory readable and writable by both user and group.

Use several permission changes within one command.  Just separate them by comma.

$ chmod a-rwx,ug+rw,o+r *.php

The above will reset permissions on all .php files to readable by all and writable only by user and group.

And my favorite and most used example, which would be tricky with octal permissions is the “X”.  In recursive change mode, “X” will affect executable bit only on directories.  Difference by illustration:

$ chmod -R a+x /some/path

The above will add executable bit to all files and folders under /some/path.

$ chmod -R a+X /some/path

But the above will add executable bit only to folders under /some/path.  The files will remain as they are.

Adding Google Apps GTalk account to Pidgin

Google Apps help page is a little bit outdated and I had to spend a few minutes working out the solution, hence this post.  Here is how you add your Google Apps GTalk account to Pidgin.

  1. In Pidgin, click on the Accounts menu.
  2. Select Manage Accounts.
  3. Click ‘Add…‘ button.
  4. Select XMPP protocol.
  5. Specify account’s local part in the Username field.  For that would be joe.
  6. Specify account’s domain in the Domain field.  For that would be
  7. You can ignore the Resource field and leave it empty.
  8. Specify account’s password in the Password field.
  9. Switch to Advanced tab.
  10. Change Connection security to ‘Use old-style SSL’.
  11. Change Connect port to 443.
  12. Change Connect server to
  13. Press Save.  You are done.

Adding flags to Gnome keyboard layout switch

One of the little things that has been bugging me for a few years now is the Gnome keyboard layout switch.  I am using two layouts – English and Russian – and instead of having two nice flags, like in KDE, I had to live with ‘USA’ and ‘RUS’ letters in my task bar.  Not that big of a problem, but annoying.  Icons are much easier and faster to understand than text.  And all the other things in my task bar are graphical, so the text stands out too much.

Today I finally decided to do something about.  Thanks to this forum post I had a solution in hand which almost worked.  The steps were:

  1. Download en.png and ru.png icons into ~/.icons/flags/ folder.
  2. Run gconf-editor.
  3. Change the value of /desktop/gnome/peripherals/keyboard/indicator/showFlags to true.

The only thing that went wrong for me were the actual images.  Gnome scaled them to 24×24 pixels and they looked rater ugly.  So I created my own icons using Gimp.  I created a new image 24×24 pixels with transparent background and then dropped in the center of it the flag icon that I got from the FamFamFam icon set.  Saved the results back into the ~/.icons/flags/ folder and vuala!

It’s not 00, it’s a +

I am getting tired complaining and explaining the difference between 00 and a + in the telephone and fax numbers.  It’s quite simple actually and I wonder why the mistake is so frequent.  So, here it goes in written form, so that I won’t have to explain it anymore – just provide a URL.

If you are writing phone number as 0035799513109, you are doing it wrong. It works for some, but not for everyone.  00 in this case is international dialing code.  Many countries are using 00 for international dialing code, but not all of them, by far.  For example, in Russia, the international dialing code is 810.  So the phone number should be 81035799513109, not 0035799513109. See?

So, how are you supposed to know all these codes for each country and how are you supposed to provide your phone number so that anyone in any country can dial it and get where they are supposed to?  The answer is simple: use ‘+’ for the international dialing code, followed up by the country code, and then the rest of the number.  Each telephone company in every country will replace the plus in the beginning of the phone number with the appropriate international dialing code.  Write the phone number as +35799513109. This will always work.  And where it won’t, the person will at least know what to do with the number.

Google Translate tip for Google Chrome

Here is something that I thought of today, played with, and found quite useful – integration of Google Translate with Google Chrome via the search engine configuration.  Of course, I know that there are addons for Google Chrome to integrate Google Translate.  Of course, I know that Google Chrome comes with certain integration out of the box.  But what I need is something else.  Once in a while, when I write an email or a blog post or something like that I’d forget a word in English that I know in Russian, or the other way around.  I usually open a new tab, go to Google Translate, and type the word in faster than I think of a better way to solve the problem.  It’s a completely automated process for me.  My fingers know how to do it.  Plus it’s all so fast because I do it from the keyboard with shortcuts, so even if I’d have some addon installed with a button in the toolbar, I’d need to reach for the mouse, which would slow me down.

So, here is what I did.  I went to Options->Basics->Default Search->Manage.  Of course, I didn’t want to change my default search engine from Google to anything.  Instead I wanted to add a new search engine.  See the above screenshot.  I named the search engine “Google Translate (English->Russian)” to avoid ambiguity when I add more search engines for translations between other languages.  I assigned the keyword “en,ru”, which is what I’ll have to type in the address bar for this search engine to kick in.  And I configured the search URL.  Nothing fancy.

Now, whenever I type “en,ru” in the browser address bar, Google Chrome switches from generic completion to a search engine, where I just have to type the word that I want translated and hit Enter.  Again, see the screenshot above for how the address bar looks.

In exactly the same way I can add more search engines to translate between different languages.  It’s even possible to use “auto” as the source language for Google Translate to figure out in which language the original word or phrase is.  And, of course, you don’t have to limit yourself to Google Translate search engines only.  I have search engines defined for PHP functions lookup, Wikipedia and IMDb searches, and more.  The trick is to find the search URL by performing the actual search on the site that you want to add, and then replace the search query with “%s”.  That’s all. Enjoy!

Shell keyboard shortcuts

I came across a very useful post with the listing of many shell keyboard shortcuts.  The article covers a mix of bash, csh, zsh, and Cisco shell keyboard shortcuts.  The article is in Russian, but I think it will be helpful for more people, so I took the liberty to translate it.  Continue reading for the translation.

Continue reading “Shell keyboard shortcuts”

Monitoring tree of Linux processes

Once in a while there is a need to see the tree of processes on a Linux system.  When such a need arises, I usually run “ps auxw –forest“, which results in something like this (partial output, top only):

/bin/ps auxw --forest

Today, via this blog post, I’ve learned that there is another way – “pstree“.  This command accepts a number of parameters, but in its simplest form, results in something like this (partial output, top only):


On my Fedora box, /usr/bin/pstree is a part of the psmisc RPM, which is the one that brings /usr/bin/killall to the system.