Archive for the ‘uncategorized’ Category

How to go off the record in Gmail when "Go off the record" is grayed

Friday, October 14th, 2011
It is well known that due to a "bug in Gmail" [sic], it is possible to detect whether a user (that is apparently offline) is really offline (or has blocked you) or he/she is just hiding in invisible mode. To do so all you have to is to go in the Actions menu (in your chat box) and select "Go off the record", and then send a simple message to the user. Absence of error message implies that the user is online, and hiding.

This is probably yesterday's news for most of you, but a small detail is being often overlooked is that this option is clickable only if the other party is online. This complicates things a bit, as those people that love to practice the "invisible mode", almost never show up online giving you almost zero chance to reveal them.

image-1.png



This article explains how to overcome this obstacle, by presenting one way to go off the record with a user, even when he is (or appears to be) offline, causing the "Go off the record" option to be disabled ("grayed"). The procedure that is described below is not trivial, but also not prohibitive, even for the average user. You may also need to install some additional software. So, let's get started!

We need a Web Browser that is capable of Inspecting Elements (that is, when you right-click somewhere in the page, you get a "Inspect element" item in the context menu). I suggest either using Chrome, or Firefox with the Firebug plugin installed. For this example, I'm going with Chrome, because the desired functionality is built-in, and I don't have to install any additional plugins.

Whenever you're ready with the browser of your choice, enter your Gmail account and open a chat window with the person that you want to go off the record. Remember that if the person is offline (which is possibly our case), you must not just click on the person's name, but rather you must click on the "Chat" button in the pop-up box.

image-2.png



In the chat window, click in the Actions menu. The menu shows up and the "Go off the record" is disabled (grayed):

image-3.png



Now be careful not to close the menu and right-click on exactly that menu item. You will see the context menu:

image-4.png



Now click on the "Inspect element" item of the context menu. The "Developer Tools" console will open at the bottom of your browser (or in a pop-up window), and a TD html element will be highlighted:

image-5.png



Then you must locate the nearest parent DIV element of the TD element. It must be 3-4 lines above:

image-6.png



You should be able to see the attribute class="jM jK". What you must do now is to change the class "jM" to "jL". Double click between the double quotes to start the attribute value editor. Then simply change "jM" to "jL". And press Enter to save the modification.

image-7.png



And almost magically the "Go off the record" menu item is now enabled for you to click it!

image-8.png



I hope this helped! :-)

See also: How to Detect invisible user in Gmail and gtalk Chat

Replace "\n" with new line characters, using Notepad++

Tuesday, July 5th, 2011
In case you have a file which contains "escaped" new lines (\n), like this:

notepad-1.PNG



and you want to replace the escaped new line sequences with actual new line characters, you can easily accomplish this task using Notepad++.

First load your file (or just copy paste the text) in Notepad++.

notepad-2.PNG



Then select Search → Replace from the menu, or hit Ctrl-H. The Replace dialog will show up. Therein make sure that you fill out the following values; Find what: \\n (yes, two back-slashes), Replace with: \n (yes, just one back-slash), and the most important, make sure you select the Extended (\n, \r, \t, \0, \x, ...) radio button. Your Replace dialog must look like this:

replace-1.PNG



Click the Replace All button, and all escaped new line sequences will be replaced with new line characters:

notepad-3.PNG



I hope this helped!

PHP Extensions do not load on fresh WAMP installation

Wednesday, June 8th, 2011
So, you just installed WampServer on your Windows PC but the smile went away from your face as soon as you tried to use mysql. PhpMyAdmin reports that it "cannot load mysqli extension" (or "cannot load mysql extension"), or your mysql application is not working any more, and you can not load and use any PHP Extension.

One possible cause for this, is that an previous installation of PHP existed in your computer, and Apache gets confused and loads the wrong php configuration file. Be aware that although you may have uninstalled PHP (from "Add/Remove programs"), the PHP's configuration file (php.ini) may still reside in your disk.

To solve the problem do the following. First make sure that the WAMP icon is green (which means that all services are running). Then click on the icon and select Localhost. Go to the Tools section and click on "phpinfo()". In the new page use your browser's search dialog (Ctrl-F) and look for "Loaded Configuration File". You should see something like this:

php2.jpg



If the path does not start with "C:/wamp/...", then this is a good sign, it means that probably the wrong php.ini file is loaded, and this is easy to fix. Just make sure to delete the php.ini file from the location mentioned in the php info page, then go to the WAMP icon and "restart all services".

Then refresh the php info page and repeat the search to see which php.ini file is loaded this time. Now you should be able to see the correct one, the one from the C:/WAMP folder:

php3.jpg



Now all PHP extensions should be able to properly load and mysql should be working again.Good luck!

Restore window's visibility (Windows 7)

Friday, May 6th, 2011
Sometimes it can happen that an application window may get "locked out" of the visible area of your desktop. Especially when you are extending your desktop in multiple displays and later on one of these displays is disconnected, a program may keep positioning its window in the good-old coordinates it had when it closed, even if these coordinates are not inside the accessible frame any more.

And this is where the move-window-by-keyboard feature comes to the rescue, a feature that I guess most people never ever use, as most of the time we use the mouse to move windows around the screen.

Locate the window that you need to bring back on the Windows taskbar, at the bottom of the screen. Then right-click on it while holding the Shift key down. You must be able to see this context menu:

this is the right menu



It is very important to hold Shift pressed while right-clicking because if you don't, you'll get a whole different menu, which is not the one you're looking for:

this is the wrong menu!



Click on "Move". After clicking on Move the hidden window should be already focused and movable using the keyboard. Use your keyboard's arrow keys and within a few seconds you will be able to drag the window with the visible area of your Desktop. When you can see the title bar of the window you can leave the arrow keys and continue with your mouse.

I hope this helped!

counting and listing hard links on Linux

Friday, April 15th, 2011
A hard link is actually nothing more than a regular directory entry, which in turn can be seen as a pointer to the actual file's data on the disk. The cool thing about hard-links is that a file can be stored once on the disk, and be linked to multiple times, from different locations/entries, without requiring to allocate extra disk space for each file instance.

But then a question arises: Given a specific file on disk, how can someone know whether it is linked to by other directory entries or not? This can be easily answered using the ls command:

giannis@zandloper:/etc$ ls -l passwd
-rw-r--r-- 1 root root 1402 2008-03-30 17:49 passwd


Do you ever wonder what is this small number between the file permissions and the owner in the output of ls's long listing format (its value is usually "1" for files, or "2" for directories)? This number is actually the link-count of the file, when referring to a file, or the number of contained directory entries, when referring to a directory (including the . and .. entries).

So, the answer to the question "are there any other directory entries linking to this file, and if so, how many?" can be simply answered by executing ls -l for this file and checking the link-count column. If it is just 1 that means that this is the one and only instance. If it's greater than 1 then there are other directory entries linked to that same file.

Now, imagine you find out that a file is linked to by some other directory entry. The next thing you would want to know is who is linking to that file. To figure this out you must know what all these directory entries share in common. And that is, an inode.

inode.pngAn inode is a data structure used internally by a (unix-like) file system to store information about a file (it can be also considered as the file's meta-data). Every inode has a unique (in the scope of the file system) identity number. We will use this property to locate all the hard links of a file within a file system. And this is how we can do it.

By passing the -i option to the ls command we also get the inode number for a directory entry:

giannis@zandloper:/etc$ ls -i passwd
199053 passwd


In this case, the inode number for the /etc/passwd file is 199053. Now that we have the inode number we can now do the actual search for directory entries that have that same inode number. But because it would be pointless to do such a thing since we know that there are no other hard links of this file in existence (recall the link-count "1" in the output of the previous ls -l command which states that there is only one instance of that file), I'm going to first create a hard link of the file in my home directory:

giannis@zandloper:~$ ln /etc/passwd
giannis@zandloper:~$ ls -l passwd
-rw-r--r-- 2 root root 1402 2008-03-30 17:49 passwd


Now we're going to search the entire file system for files with inode number equal to 199053. To do so we are going to use the find command and its -inum option:

giannis@zandloper:~$ sudo find / -inum 199053
/etc/passwd
/home/giannis/passwd


And that was it! I hope you learned something useful today :-).

Base-2 and Base-N logarithm calculation in Java

Saturday, January 9th, 2010
I was surprised today to see that the Math package does not provide a method that the calculation of an arbitrary base logarithm, even though it provides a log10() method for base-10 logarithms.

One can easily calculate the logarithm of any base using the following simple equation:

log.png

Where logk is the function that returns the base-k logarithm of a number, and it can be any real number.

In terms of Java it can be written like this:
 public class Logarithm
{
public static double logb( double a, double b )
{
return Math.log(a) / Math.log(b);
}

public static double log2( double a )
{
return logb(a,2);
}

public static void main( String[] args )
{
System.out.println(log2(100));
}
}

Video appears BLUE after upgrading to Karmic Koala?

Wednesday, November 4th, 2009
I suppose that this only happens with NVIDIA cards. Yesterday I just upgraded to Karmic Koala and today I discovered that even though everything seemed normal, video playback appears in false color and in a shade of blue, like this:

john-locke-false-color.png



I tried to play with the NVIDIA X-Server Settings and I discovered that the Hue parameter under X Server XVideo Settings had a value close to -1000, instead of 0 which is the normal:

x-server-settings.png



If you click the Reset Hardware Settings button all values return to the default (0) and your video will appear in true color again:

john-lock-true-color.png



To open  the NVIDIA X-Server Settings go to: System → Administration → NVIDIA X-Server Settings.

Certainly this is rather a work-around than a solution, but it allows you to watch video until a bug fix is released.

Oracle: Select top rows from an ordered result set

Friday, June 26th, 2009
Oracle provides the ROWNUM pseudo-column to allow someone limit up the number of returned rows in a SELECT statement. However, you should be cautious when using ROWNUM in combination with an ORDER BY clause.

For example, consider the following table:

ColumnName
30
40
50
60
70
80
90


We can easily select the first three (unordered) rows, like this:

SELECT * FROM TableName WHERE ROWNUM <= 3;

ColumnName
30
40
50


Or we can even select the entire data set in descending order, like this:

SELECT * FROM TableName ORDER BY ColumnName DESC;

ColumnName
90
80
70
60
50
40
30


But, how about selecting the three highest values? A common pitfall is trying something like this one:

SELECT * FROM TableName WHERE ROWNUM <= 3 ORDER BY ColumnName DESC;

But this will falsely and not surprisingly return this result this:

ColumnName
50
40
30


What did go wrong? The answer is simple. At first, Oracle select the first three rows from the table in their natural order of occurance. They happen to be 30, 40 and 50. Then, Oracle sorts up the result set and returns it.

Intuitively, someone would think that the sorting and the row limit should occur in the reverse order, and that's correct. This is the proper way to do it:

SELECT * FROM (SELECT * FROM TableName ORDER BY ColumnName) WHERE ROWNUM <= 3;

ColumnName
90
80
70


In general, when you have an ordered result set, and you want to select only the first N rows of it, this is the syntax you should use:

SELECT * FROM (SELECT * FROM ... ORDER BY ...) WHERE ROWNUM <= N;

Ubuntu: Google Earth Error code: 29

Thursday, June 11th, 2009
Are you getting this error after Google Earth's splash screen?

google-earth-error.png


The you are possibly on a freshly installed 64-bit system and you haven't yet installed the lib32nss-mdns package. Run this command:

sudo apt-get install lib32nss-mdns

and then try to run Google Earth again, should be working now.

Eye Floaters

Tuesday, May 12th, 2009
I have eye floaters...

Floaters.png

Jeez, sometimes this can be really annoying...

Check out this outstanding eye floaters simulation.