Tuesday, December 29, 2009

C# Clipboard in Console Application

In C# accessing the Clipboard suppose to be easy, but you'll find out it doesn't work in the normal way.
Here is a small note from MSDN that I missed at first:

The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.
So, in a Console application, use this function:

public static object GetClipboardData()
    object ret = null;
    ThreadStart method = delegate()
        System.Windows.Forms.IDataObject dataObject = Clipboard.GetDataObject();
        if (dataObject != null && dataObject.GetDataPresent(DataFormats.Text))
            ret = dataObject.GetData(DataFormats.Text);
    if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
        Thread thread = new Thread(method);
    return ret;

Saturday, December 26, 2009

Step-by-Step Math

Have you ever given up working on a math problem because you couldn’t figure out the next step? Wolfram|Alpha can guide you step by step through the process of solving many mathematical problems, from solving a simple quadratic equation to taking the integral of a complex function.

From here:


Sunday, December 20, 2009

Windows 7 & HomeGroup: Sharing with Windows XP, Windows Vista, and other operating systems


Windows 7 - Remove User From Login Screen

The users on the log-in screen are all the users that belong to the "Users" group.

To remove a user invoke the following command:

  net localgroup users /delete <username>

Instead, on Windows 7 Ultimate and Professional, you can use the User Manager to do that:

Monday, December 7, 2009

How to grab Google autocomplete list

We all know this wonderful feature:

Automation of grabbing that list can be helpful for instance if you want to know what people are looking for.

While typing in the search box, somewhere there is a Javascript code that makes the following HTTP GET request:

For example, the following query gives the same results as in the picture:

window.google.ac.h(["how to be better at ",[
["how to be better at halo 3","43,100,000 results","0"],
["how to be better at basketball","87,500,000 results","1"],
["how to be better at math","52,900,000 results","2"],
["how to be better at soccer","88,300,000 results","3"],
["how to be better at football","207,000,000 results","4"],
["how to be better at beer pong","2,760,000 results","5"],
["how to be better at call of duty 4","72,600,000 results","6"],
["how to be better at madden","25,900,000 results","7"],
["how to be better at volleyball","9,370,000 results","8"],
["how to be better at chess","15,300,000 results","9"]]])