Friday, May 23, 2008

Using anonymous methods for Predicate in .NET

If you have a List, or an array, and you want to use Predictes for searching your array for example, but don't want to write a full function for this, you can use anonymous methods like this


string[] myArray=new string[2];

string = Array.Find( myArray,

delegate( string s )

{

if ( some condition ) return true;

else

{

return false;

}

}

);





you should always remember to return both true and false values, or your code won't get complied , the hidden reason behind this is, the exception "Not all code paths returns value"

Tuesday, May 13, 2008

Moving from MS SQL to MySQL : Selecting Top N Rows in MySQL Statement

If you have been working with MS SQL server for a while, and you decided to jump of to somthing else like Oracel or MySQL, your mind will remain thinking as MS SQL for a while, till you get used to your new DBMS sql syntax.
This happened to me when i was writing a query for a MySQL db, and i wanted it to only return one single raw, in MS SQL the answer is easy just use " Select Top N", but in MySQL its different,
there is no "Top" keyword in MySQL, however there is "Limit" keyword, but this won't be used in the "Select" clause, but its a clause byitself.
so if you want to select top 10 records from a table called products,
in MS SQL terms your query will be
Select Top 10 *
From Products

But in MySQL terms the query will be
Select *
From Products
Limit 10

its a little info, but it worthed documenting for my future use

Monday, May 12, 2008

ByPass US Export Compliance found when downloading from www.mysql.com

These days im working in a project that involves using MySQL database, i don't have any issues agains MySQL as a DBMS, but my problem is every time i try to install somthing from www.mysql.com , i face a nasty ugly access denied page, saying that i don't meet US Export Compliance , huh wtf is that, i didn't bother myself to look for it.
But it was getting me really annoyed, and i don't know if MySQL is free and open source, why should they stop ppl from downloading the product in favor of some US rules...
anyway since its a free world, and there is a way to get anything online, i was googling online and found an index for every thing downloadable by www.mysql.com
click here for that index, happy MySQL'ing.

Saturday, May 10, 2008

Even my MSN is Twittering,MSN Messenger Twitter Add-In

I statrted using Twitter lately , Twitter, is getting famous day after day, and many ppl enjoy using it, even marketing guys are using it as part of thier marketing tool box.

since im a newbie to Twitter i'm not yet interested in following others, but im interested in updating my status there regualry and easily without the need to go to Twitter.com , log in, type the new status message, and click the update button, actually this was making me frustrated , and i was thinking if there is an easier way, actually there are some ways, you can your mobile, or a very limited IM's support to update your Twitter status, however, i wasn't going to use my mobile, currently i have a Nokia N76 mobile, so to type somthing, i have to type on the mobile tinny keyboard..well i always hated doing that its time consuming.. and i wasn't going to buy a new mobile just for twittering :)

For the IM support, its very limited just GTalk,Jabber,LiveJournal.. but there is nothing for MSN Messenger, Yahoo Messenger, AIM .

What i was wishing to have is, the ability to make my Twitter status get updated every time i change my personal status message in my MSN messeneger... and this is what i did when i didn't find it anywhere.

Because Twitter is a Web 2.0 service ( as an undocumented property of any Web 2.0 service, is that they should have an API that can make other services built on top of data provided by the actual Web 2.0 service) , it provides an API that can be used to access the Twitter data, this include Updating your status.

Since MSN Messgener Live 8.0, It started to support Add-In's which are .NET 2.0 assemblies that can be added to enhacne your messenger fucntions.

Messenger Add-In's is disabled by default, and you will need to work on enabling it, the following article is a great one that takes your through Msn Messenger Add-In programming, "Your first Windows Live Messenger add-in" , once you finish this you will be half the way there.

Next thing you will need to do, is doing your .NET Twitter API wrapper, its not that complex thing to do ,but if you want to save your time, you can use Yedda .NET Twitter API.

The part of making messenger add-in updating your twitter status is trivial , just use a timer to check your personal status message and call the twitter update API to copy whatever status message you have.

However, what is not really trivial is making your Add-In work, because it will not by default, this is because Code Access Security (CAS) , which will prevent your add-in form making web requests and in our case we always going to do web requests, when you run your add-in, you will get an exception about "Failed to get web perimission " for your add-in dll.

This got me frustrated for a while till i got over it by doing the following:
1- Sign your Add-In dll.
2- Add your dll to your GAC.

and its done, and now Even my msn messenger is twittering