Tuesday, September 24, 2013

Birds also use passwords !!!


Recently, many websites were hacked or compromised because of the weak authentication logic used in them. Google/Twitter are now using 2FA to take care of such cases. New iPhone 5S has a fingerprint scanner for authentication purposes. We humans can do this and develop more security and their implementations around such problems.

Now, what about birds - How do they set and use any password? Following article shows you how birds use their password or coded scheme in their chirping to ask for or set a password scheme:

http://blogs.discovermagazine.com/notrocketscience/2012/11/08/fairy-wrens-teach-secret-passwords-to-their-unborn-chicks-to-tell-them-apart-from-cuckoo-impostors/#.UkFKhoYmtfS


Tuesday, September 17, 2013

3D View from 2D Images



Having a 3D View for a given 2D image has always been a long awaiting obsession for many of us. We have always wondered how do we add that extra information to any particular image to get its 3D View. Few days back, I saw a very nice attempt of the same posted as a youtube video here.



If this concept goes through reality; it is simply awesome. Yes, you could argue that this is not valid for all type of objects but valid for only symmetric objects but wherever its applicable and it works; it would be an amazing thing to try. I believe that this paper was also part of SIGGRAPH 2012.

In fact, there are a lot of other attempts to handle this problem but they deal in different sub-problems such as 123D catch by autodesk. Adobe Photoshop also has a workflow to try this situation - see here.

I am actually amazed to see this. I think the day is very near when we will be able to easily feel the objects that we click from our point and shot digicams.





Sunday, September 1, 2013

Obtaining Directory Change Notifications on Windows

This post is useful for developers only....

Sometime back, I was trying to look for a way to get Directory Change Notifications on Windows i.e. the same ones that dropbox or google drive any other file sync app would have used. The code would need to use FindFirstChangeNotification as well as WaitForMultipleObjects APIs:

MSDN Link - http://msdn.microsoft.com/en-us/library/aa365261%28VS.85%29.aspx
-------------------
Sample code
-------------------

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>

void RefreshDirectory(LPTSTR);
void RefreshTree(LPTSTR);
void WatchDirectory(LPTSTR);

void _tmain(int argc, TCHAR *argv[])
{
if(argc != 2)
{
_tprintf(TEXT("Usage: %s dir\n"), argv[0]);
return;
}

WatchDirectory(argv[1]);
}

void WatchDirectory(LPTSTR lpDir)
{
DWORD dwWaitStatus;
HANDLE dwChangeHandles[2];
TCHAR lpDrive[4];
TCHAR lpFile[_MAX_FNAME];
TCHAR lpExt[_MAX_EXT];

_tsplitpath_s(lpDir, lpDrive, 4, NULL, 0, lpFile, _MAX_FNAME, lpExt, _MAX_EXT);

lpDrive[2] = (TCHAR)'\\';
lpDrive[3] = (TCHAR)'\0';

// Watch the directory for file creation and deletion.

dwChangeHandles[0] = FindFirstChangeNotification(
lpDir, // directory to watch
FALSE, // do not watch subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes

if (dwChangeHandles[0] == INVALID_HANDLE_VALUE)
{
printf("\n ERROR: FindFirstChangeNotification function failed.\n");
ExitProcess(GetLastError());
}

// Watch the subtree for directory creation and deletion.

dwChangeHandles[1] = FindFirstChangeNotification(
lpDrive, // directory to watch
TRUE, // watch the subtree
FILE_NOTIFY_CHANGE_DIR_NAME); // watch dir name changes

if (dwChangeHandles[1] == INVALID_HANDLE_VALUE)
{
printf("\n ERROR: FindFirstChangeNotification function failed.\n");
ExitProcess(GetLastError());
}


// Make a final validation check on our handles.

if ((dwChangeHandles[0] == NULL) (dwChangeHandles[1] == NULL))
{
printf("\n ERROR: Unexpected NULL from FindFirstChangeNotification.\n");
ExitProcess(GetLastError());
}

// Change notification is set. Now wait on both notification
// handles and refresh accordingly.

while (TRUE)
{
// Wait for notification.

printf("\nWaiting for notification...\n");

dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles,
FALSE, INFINITE);

switch (dwWaitStatus)
{
case WAIT_OBJECT_0:

// A file was created, renamed, or deleted in the directory.
// Refresh this directory and restart the notification.

RefreshDirectory(lpDir);
if ( FindNextChangeNotification(dwChangeHandles[0]) == FALSE )
{
printf("\n ERROR: FindNextChangeNotification function failed.\n");
ExitProcess(GetLastError());
}
break;

case WAIT_OBJECT_0 + 1:

// A directory was created, renamed, or deleted.
// Refresh the tree and restart the notification.

RefreshTree(lpDrive);
if (FindNextChangeNotification(dwChangeHandles[1]) == FALSE )
{
printf("\n ERROR: FindNextChangeNotification function failed.\n");
ExitProcess(GetLastError());
}
break;

case WAIT_TIMEOUT:

// A timeout occurred, this would happen if some value other
// than INFINITE is used in the Wait call and no changes occur.
// In a single-threaded environment you might not want an
// INFINITE wait.

printf("\nNo changes in the timeout period.\n");
break;

default:
printf("\n ERROR: Unhandled dwWaitStatus.\n");
ExitProcess(GetLastError());
break;
}
}
}

void RefreshDirectory(LPTSTR lpDir)
{
// This is where you might place code to refresh your
// directory listing, but not the subtree because it
// would not be necessary.

_tprintf(TEXT("Directory (%s) changed.\n"), lpDir);
}

void RefreshTree(LPTSTR lpDrive)
{
// This is where you might place code to refresh your
// directory listing, including the subtree.

_tprintf(TEXT("Directory tree (%s) changed.\n"), lpDrive);
}

Thanks to my colleague +Abhijeet Singh for helping me with the above info.