LINQ TO SQL : WHERE X IN ()

June 22, 2009 – 7:44 pm
I recently needed to do a WHERE X IN () style query using LINQ to SQL. Here's the solution I used:

Extension methods (C#)

June 8, 2009 – 6:56 pm
Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type. For client code written in C# and Visual Basic, there is no apparent difference between calling an extension method and the methods that are actually defined in a type.

Delegates: Named methods, Anonymous methods, Lamda expressions (C#)

June 8, 2009 – 6:18 pm
Delegates The declaration of a delegate type is similar to a method signature. A delegate is a reference type that can be used to encapsulate a named or an anonymous method. Delegates are similar to function pointers in C++.

yield return (C#)

June 8, 2009 – 6:09 pm
The yield keyword signals to the compiler that the method in which it appears is an iterator block. The compiler generates a class to implement the behavior that is expressed in the iterator block. In the iterator block, the yield keyword is used together with the return keyword to provide a value to the enumerator object. This is the value that is returned, for example, in each loop of a foreach statement. The yield keyword is also used with break to signal the end of iteration.

How to generate an SQL script from a MySQL database

December 9, 2008 – 1:42 am
You can generate an SQL script from a mySQL database by using the mysqldump tool. The mysqldump tool will dump your mySQL database to a file (for example).

How to use DISTINCT on a single column of a multi-column select statement

December 6, 2008 – 8:43 pm
I recently came across this problem today of how to perform a SELECT DISTINCT but on a single column of a multi-column select statement. Imagine a database with a COUNTRIES table. The table contains a list of countries and there is also a "Nationality" column (eg. Australia is the country, Australian is the nationality). However, not all records have a Nationality value and also some nationalities are repeated in more than one record. So, if I want to select the CountryID and Nationality columns but to ensure the returned Nationality column is DISTINCT (ie. no repeats), how can I do this?

Understanding blocks in Ruby on Rails

December 6, 2008 – 6:32 pm
Understanding how to use blocks in Ruby is crucial to leveraging the full power of this language. A block, known as a closure in programming theory, is basically just a method without a name, or an anonymous method. All methods in Ruby have the special ability to accept a block as a parameter. The method is converted into an object, an instance of the Proc class.

MySQL : how to run an SQL script from the command line

December 5, 2008 – 5:24 pm
If you have an SQL script file you wish to run from the MySQL command line, you can use the source command at the MySQL command prompt as follows.

Deploy a rails application on Bluehost

December 4, 2008 – 12:03 am
Deploying a rails application on Bluehost for the first time is not a fun task, especially if you are fairly new to rails development. I hope the following details may save someone some of the hair-loss inducing troubles I experienced. Having said that I'm happy with Bluehost thus far. I have a Word Press blog, rails application, and PHP application all running via Bluehost. mkdir ~/rails cd ~/rails rails app_name cd app_name From within cPanel, select Sub-Domains and create a new sub-domain with the same name as the rails application folder you just created. cd ~/public_html/ rm -r app_name ln -s /home/YOUR_USERNAME/rails/first/public app_name ln -s ~/rails/app_name/public app_name go the website -> it works! Now db... How to create a rails migration for an existing database I had done things a little backwards with my first rails application so I wanted to create a rails migration file from my existing database (rather than the other way around). I did this as follows: $ rake -T ...

ASP.NET - what is the App_Data folder for?

November 30, 2008 – 8:00 pm
In addition to supporting server databases, Visual Studio 2005 / 2008 also supports local databases in an App_Data folder. Finding a clear answer as to what the folder is for was not easy but my basic understanding is this: