rulururu

post Dead Man’s Switch

September 10th, 2008

Filed under: Internet, Nonsense — Kai @ 10:10 am

The website I yesterday night found is the proof again that almost everything, achievable by man, can be found in the internet. The project idea shows me in a very obvious way that the respond to individual human needs in some parts has moved into the world wide web.

It’s called Dead Man’s Switch but what is it for?

If anybody already got confused even by its name, don’t worry: In general a Dead Man’s switch is, as its name suggests, a switch that is automatically operated in case the human operator becomes incapacitated. For example firefighters use it when being in a burning building.

Alternatively, as some of you might have seen in the movies, the switch detonates a bomb. This is applied in suicide bombing, to trigger the explosive if the bomber is shot or overpowered.

The concept of www.deadmansswitch.net is similar:

Everyone carries valuable information in their heads. It might be about their work, financial information, etc. If anything were to happen to them, this information would be lost, unfortunately.

This is where Dead Man’s Switch comes in.

I’d like to give to a quote from the founders website about how the website works:

This is how this works. You write a few e-mails, and choose the recipients. These emails are encrypted with military-grade algorithms, so you can be sure that no-one except the intended recipient will ever read them. Your switch will email you every so often, asking you to show that you are fine by clicking a link. If something were to… happen… to you, your switch would then send the emails you wrote to the recipients you specified. Sort of an “electronic will”, one could say.

You can regard the project as a system designed for people who really have paranoia or somehow are just crazy. I’ve seen lots of crazy, even useful projects in the internet therefor I just say it’s kinda funny thing. Even thought I will not use it to anytime!

Apart from that I’ve noticed that the website itself is well done and designed appealingly in terms of color :D

post A Terabyte of RAM - Why not?

September 8th, 2008

Filed under: Computers — Kai @ 10:02 am

Just a few thoughts I’d like to share with you.

None of us who isn’t running supercomputers or one heck of a cluster is there yet, anyway. But as RAM continues to drop in price, I can see the day coming.
Come the day we get a terabyte of RAM in our systems, we’ll find a need for it. After all, recall that great prophet Bill Gates who swore 640K of memory would be all we’d need. Real-time high-definition video editing anyone?

That day, by the way, isn’t as far away as you might think. Violin Scalable Memory will be happy to sell you a terabyte-capable memory device to attach to your server. Indeed it would cost you a few - well more than a few - hundred thousand dollars. Still, you can see it coming.

But while I can dream up applications that could use a terabyte of RAM, that leaves aside the wee technical problem of how you access that much memory. Daniel Phillips, a Linux developer, has an idea: the ramback virtual device.

In short, Phillips is using several cache coherency concepts to make using huge amounts of RAM as a virtual drive a practical approach to speeding up I/O-intensive interactions. For example, with enough RAM, you could run, say, an Oracle database running on Oracle or Red Hat Linux, at real-time speeds.

Of course, Phillips’ idea isn’t the same as coming up with an API for applications to address multiple gigabytes of RAM, but still, it is a very useful idea. Indeed, with its potential for vastly increasing database interactions, I can see it being a commercial success and driving the demand for huge memory.

This in turn will bring RAM prices down to normal user prices.

So, what will you do with your first laptop with a terabyte of RAM? You don’t need to worry about it yet. Well, not quite yet, anyway.

post Don’t use void for functions without arguments

August 4th, 2008

Filed under: C++ — Kai @ 2:50 pm

In ANSI C, void Foo() takes an arbitrary number of arbitrarily typed arguments (although the form void Foo(...) is preferred) and void Foo(void) doesn’t take any arguments. In C++, however, the situation is different and both declarations are completely equivalent. As there is no need to write void in this situation, let’s not write it — it can only be confusing and create an impression that it really means something when it’s not at all the case.

post CompareNoCase does not work as expected

July 30th, 2008

Filed under: C++, MFC — Kai @ 11:18 am

Recently I found a program of mine doing all kind of unexpected things because of CString::CompareNoCase() not returning what I expected it to return.

My application usered names containing the characters: é, è, à. Somewhere in my app I used the given name to search the corresponding object in a list. Since the given names had to be (case insensitive) unique I stored those names in uppercase format.

Afterwards I compared (in a case insensitive way) the given name with the uppercase name of each object in the list.
And that went unexpectedly wrong! Look at the following code snippet:

CString strText("élève - à la façon - château");
CString strTextUpper(strText);
strTextUpper.MakeUpper(); // Upper case the original 
 
int match = strTextUpper.CompareNoCase(strText); //does not match

For CString::CompareNoCase I read:

Compares this CString object with another string using the generic-text function _tcsicmp. The generic-text function _tcsicmp, which is defined in TCHAR.H, maps to either _stricmp, _wcsicmp, _mbsicmp depending on the character set that is defined at compile time. Each of these functions performs a case-insensitive comparison of the strings, and is not affected by locale.

While digging deeper in MSDN I discovered the existence of CString::CollateNoCase for which I read:

Compares this CString object with another string using the generic-text function _tcscoll. The generic-text function _tcscoll, which is defined in TCHAR.H, maps to either stricoll, wcsicoll, or _mbsicoll depending on the character set that is defined at compile time. Each of these functions performs a case-insensitive comparison of the strings, according to the code page currently in use.

This knowledge led me to two workarounds:

  • Use CString::CollateNoCase instead of CompareNoCase.
  • Although the help says it works independent of the locale, before calling CString::CompareNoCase set (the LC_CTYPE part of the) the locale. e.g.:
    setlocale(LC_CTYPE, "french-belgian");

Finally my confidence in MFC’s CString comparison functions isn’t great after I discovered this. And that’s why I wrote my own ever-working workaround:

int MyCompareNoCase(LPCTSTR str1, LPCTSTR str2)
{
  CString strTmp1(str1);
  CString strTmp2(str2);
  strTmp1.MakeUpper();
  strTmp2.MakeUpper();
  return strTmp1.Compare(strTmp2);
}

post Getting back the root password

July 25th, 2008

Filed under: Linux — Kai @ 2:12 am

Let’s imagine you forgot your root password. Now you’ll just have to reinstall the entire machine. But it’s surprisingly easy to get on the machine and change the password. This doesn’t work in all cases (like if you made a GRUB password and forgot that too), but here’s how you do it in a normal case.

  • First reboot the system. When it reboots you’ll come to the GRUB screen. Move the arrow key so that you stay on this screen instead of proceeding all the way to a normal boot.
  • Next, select the kernel that will boot with the arrow keys, and type E to edit the kernel line.
  • Use the arrow key again to highlight the line that begins with kernel, and press E to edit the kernel parameters. Simply append the number 1 to the arguments.
  • Then press Enter, B, and the kernel will boot up to single-user mode. Once here you can run the passwd command, changing password for user root…
machine# passwd
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully

Now you can reboot, and the machine will boot up with your new password.

It’s also possible to do something similar with lilo, too. If I’m not wrong typing linux single at the lilo prompt should work.

post Single Instance managed by GUID

July 22nd, 2008

Filed under: C++ — Kai @ 3:29 pm

Some of the applications need to be restricted to run as a single instance. This can be achieved very easily in C++ applications.

When the application is started, it has to be checked if there is another instance running. If there is one already running, a message should be displayed and the application quit from the environment.

By default MFC provide no APIs or methods to satisfy this. But, by using mutex, the work is so simple.
For this we need a GUID (Globally Unique Identifier). You can create this by using the MFC application

A small tool called guidgen.exe generates a GUID.
First of all you have to start guidgen.exe. All you have to do is to click the New GUID button in the Create GUID dialog box.

After that you need to create a named mutex semaphore when you start your application. When the second one starts it tries to get access to the mutex but will fail…

Implement one method:

BOOL CThreadTestApp::SingleTest (LPSTR szName)
{
        HANDLE hMutex = CreateMutex (NULL, TRUE, szName);
        if (GetLastError() == ERROR_ALREADY_EXISTS)
        {
           CloseHandle(hMutex);
           return FALSE;
        }
return TRUE;
}

Call the method in InitInstance() like:

if (SingleTest (_T("SingleTest_48C56927-A0DB-4e31-8C32-FE15FBA45043")))
{
 
}
else
{
   AfxMessageBox(_T("Error: application is already running!"));
   return FALSE;
}

This check is performed inside the CWinApp derived classes in MFC. The CWinApp::InitInstance function is the ideal place for performing such initial check-ups.

ruldrurd
« Previous PageNext Page »
Powered by WordPress, Content and Design by Kai Bellmann
Entries (RSS) and Comments (RSS)