Tuesday, April 28, 2009

the World's Most Influential Person is moot

In a stunning result, the winner of the third annual TIME 100 poll and new owner of the title World's Most Influential Person is moot. Read more here and here

Monday, April 27, 2009

Wednesday, April 15, 2009

c++ stl – find_if and not1 used to fined vector item which is exception to the rule

//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

#include <algorithm>
#include <vector>
#include <iostream>
#include <iterator>
#include <functional>

class Person
{
public:
    Person();
    Person(int a, std::string n);
    Person(const Person& src);

    bool Person::operator==(const Person& src);
    friend std::ostream& operator<<(std::ostream& out, const Person& person);

    int age;
    std::string name;
};

Person::Person()
: age(0)
, name("")
{};

Person::Person(int a, std::string n)
:age(a)
,name(n)
{};

Person::Person(const Person& src)
{
    age = src.age;
    name = src.name;
};

bool Person::operator==(const Person& src)
{
    if (name != src.name) return false;
    if (age != src.age) return false;
    return true;
}

std::ostream& operator<<(std::ostream& out, const Person& person)
{
    out << " Person name: '"
        << person.name
        << "' age: '"
        << person.age
        << "'";

    return out;
}

struct PersonOlderThen18: public std::unary_function<Person, bool>
{
    bool operator()(const Person& person) const
    {
        return (person.age >= 18);
    }
};

int main(int count, char** args)
{
    std::vector<Person> personVec;
    Person p1(18, "Person1");
    Person p2(20, "Person2");
    Person p3(12, "Person3");
    Person p4(21, "Person4");

    personVec.push_back(p1);
    personVec.push_back(p2);
    personVec.push_back(p3);
    personVec.push_back(p4);

    std::cout << std::endl;
    std::copy(personVec.begin(), personVec.end(), std::ostream_iterator<Person>(std::cout, "\n"));

    std::vector::const_iterator it;
    it = std::find_if(personVec.begin(), personVec.end(), std::not1(PersonOlderThen18()));
    if (it != personVec.end())
    {
        std::cout << std::endl;
        std::cout << " Found person (age < 18): " << *it << std::endl;
    }

    return 0;
}


Thursday, April 2, 2009

Google uncloaks once-secret server

Google uncloaks once-secret server

VirtualBox 2.1.4 and Ubuntu 9.04

When you try to install Guest Additions in Ubuntu 9.04 after executing the installer:
sudo sh ./VBoxLinuxAdditions-x86.run 
You will get the following error message: Warning: unknown version of the X Window System installed. Not installing X Window System drivers. What should you do? One work around for this problem Mount the VirtualBox Guest Additions CD. enter the following command in terminal:
$cd /media/cdrom/ 
Extract the installer: (Choose which file to extract ('x86' or 'amd64') and which directory will be target directory '/vbox').
 
sudo ./VBoxLinuxAdditions-x86.run --target /vbox
cd /vbox 
Open install.sh file with gedit editor:
sudo gedit install.sh 
In Line 415 change '1.5.99.* | 1.6 )' to '1.5.99.* | 1.6.0 )' Save and exit the file Now run installer:
sudo ./install.sh
Reboot your system.

Wednesday, April 1, 2009

c++ stl - use find_if for finding all items of set that contains satin substring

//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

#include <iostream>
#include <set>
#include <functional>
#include <iterator>

struct checkIfContainsSubstr: 
public std::binary_function<std::string, std::string, bool>
{
    bool operator()(const std::string& str1, 
                    const std::string& str2) const 
    {
        return ((str1.find(str2) == std::string::npos)?(false):(true));
    }
};

int main(int argc, char** argv)
{
    std::set<std::string> testSet;

    testSet.insert("111test111");
    testSet.insert("test333");
    testSet.insert("111111");
    testSet.insert("222222");
    testSet.insert("2test222");
    testSet.insert("3test222");

    std::copy(testSet.begin(), testSet.end(),
            std::ostream_iterator<std::string>(std::cout, " "));
    std::cout << std::endl;            

    std::set<std::string>::iterator it = testSet.begin();
    while(it != testSet.end())
    {
        it = std::find_if(it, testSet.end(),
                            std::bind2nd(checkIfContainsSubstr(), "test"));
        if (it != testSet.end())
        {
            std::cout << "Found substr: " << (*it) << std::endl;
            it++;
        }
    }

    return 0;
}