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:

[mysql]
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 joe@example.com that would be joe.
  6. Specify account’s domain in the Domain field.  For joe@example.com that would be examle.com.
  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 talk.google.com.
  13. Press Save.  You are done.