Last week when I was bored I decided to play around with my Eee PC and was trying to think of a cool use for the built in webcam. If you haven’t seen an Eee PC then the webcam has been placed above the screen so it points at the user when the lid has been opened

This gave me an idea that could prove useful if you think there are snoopers who might be accessing your laptop. The idea was to use the webcam to take a photo when the laptop lid is opened. This way whenever you leave your laptop unattended and someone comes along, when they open the laptop to use it an incriminating photo will be taken

To take the photo I used a program called Streamer. Streamer is a small command line application that can take photos and videos using a webcam. Once installed you can take snapshots with the command:

streamer –o filename.jpeg

Note that the filename extension must be .jpeg rather than .jpg for streamer to work.

Now that you are able to take photos the next thing to do is set up the laptop to do so whenever the lid is opened. To do this Advanced Configuration and Power Interface (ACPI) can be used.

ACPI has a file called lid.sh which is located in Ubuntu under /ect/acpi. Opening this file as root in a text editor will show what a laptop does when the lid is opened and closed

Close to the top of the file should be the following line:

Code:

grep –q closed /proc/acpi/button/lid/*/state

This line is followed by an ‘if statement’. This statement is used to discover if the lid has been opened or closed. The first part of the statement (between the then and else lines) is what happens with the lid is closed and the second part (between the else and fi lines) is what happens when it is opened

Therefore, to get the laptop to take a photo when the lid is closed is add the streamer command to take a photo after the else line like so

Code:

else
  streamer –o ~/lidopen.jpeg
 
  for x in /tmp/.X11…

Save the file and it should take immediate effect. However, opening and closing the lid on my laptop didn’t work. Going back to lid.sh I noticed the line:

Code:

if [ `CheckPolicy` = 0 ]; then exit; fi

This line is checking to see if the command CheckPolicy runs on your system and kills the script if it cannot. From looking up the command CheckPolicy it appears it is a SELinux policy compiler. As I don’t use SELinux this command won’t be recognised by my system so the lines below this wont be run (which includes the line we added)

To solve this problem I changed this line to be:

Code:

if [ `CheckPolicy` = 0 ]
then
  grep –q closed /proc/acpi/button/lid/*/state
  [[ $? = 0 ]] || streamer –o ~/lidopen.jpeg
 
exit
fi

This code is does the same check, to see if the CheckPolicy command is recognised and exit if not. However it also now checks to see if the lid has been opened and if so it will take a photo before exiting


Posted by Kieren Searle on the 04/21/09

Compare two dates in C++

When comparing two dates that are of the data type string they will need to be first converted to dates. Once this is done a simple comparison test is possible.

Code:

void compareDates(string date1, string date2) {
  //create a time_t object
  time_t rawtime;
  time(&rawtime);
 
  //create a tm structure and load in date1
  struct tm * timeinfo1;
  timeinfo1 = localtime(&rawtime);
  timeinfo1->tm_year = atoi(date1.substr(6).c_str()) - 1900;
  timeinfo1->tm_mon = atoi(date1.substr(3, 2).c_str()) - 1;
  timeinfo1->tm_mday = atoi(date1.substr(0, 2).c_str());
 
  //create a tm structure and load in date2
  struct tm * timeinfo2;
  timeinfo2 = localtime(&rawtime);
  timeinfo2->tm_year = atoi(date2.substr(6).c_str()) - 1900;
  timeinfo2->tm_mon = atoi(date2.substr(3, 2).c_str()) - 1;
  timeinfo2->tm_mday = atoi(date2.substr(0, 2).c_str());
  
  //compare the dates
  if(timeinfo1 > timeinfo2) cout << "date1 is the latest date";
  else cout << "date2 is the latest date";
}

This function takes two strings, date1 and date2. Both dates are in the format of dd-mm-yyyy. Note that the hyphens can be any character as the sub-strings ignores them.

The function works by creating two tm objects and loading in some demo time data from our time_t object at the beginning of the function. This creates two identical time/date objects. We then overwrite the dates in these objects with our two dates. Once complete we have our two identical date/time objects but now with our two dates overwriting the date parts.

The final lines simply compare the two dates and outputs whichever one is the latest.


After upgrading my EEE PC 901 to Easy Peasy 1.0 I was prompted with the install dialog each time I logged in. Not only was this annoying it was taking up valuable space on my hard drive.

To remove this ‘feature’ all that is required is to uninstall Ubiquity. You can do this either with the package manager or by using the command

sudo apt-get remove ubiquity

This will stop the annoying prompt to install each time but will also free up over 10MB of space :)


Posted by Kieren Searle on the 01/06/09

MP3 support in K3b

Due to MP3 being a patented format and Ubuntu’s policy of not allowing patented software in their default installations K3b isn’t able to burn music CDs from MP3s out of the box.

Luckily adding MP3 support is very simple and only requires one extra package to be installed:

sudo apt-get install libk3b2-extracodecs


When I first started working with forms in Microsoft Visual Studio I had some problems getting to grips with their managed class. One of the more fustrating points was that text boxes returned text as type System::String and all my functions were expecting std::strings.

Converting from std:string to System::String was quite simple:

Code:

std::string myString = "Hello World"
 
System::String out = gcnew System::String(myString.c_str());

However, converting System::String to std::string was a little more tricky:

Code:

System::String myString = "Hello World";
 
std::string out = (const char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(myString )).ToPointer();

<< 1 2 3 4 5 6 7 8 9 10 >>

My name is Kieren and this is my blog. I use it mostly to document any solutions to problems I come across in computing.

Search

XML Feeds