Posts

Interesting fact about the LINQ to SQL Designer

If you never want to go and set the columns of a table to “Never” update check, then just add a timestamp column to the table, and it will do this for you. Pretty cool!

Optimizing searches through lists

I just finished completing a significantly complex piece of work, and thought I would pen a few words on how I improved the performance of this code. This will help me remember how I did this as well as help the novice programmer: This is how my initial code looked like: for (int i = 0; i < small_list .Count; i++) {       item = small_list [i];       result = (from p in big_list where p.ToLower().StartsWith(item.ToLower()) && String.Compare(p, item, true) != 0 select p).ToList(); } If the size of the small list is “S” and the size of the big list is “B”, every time the code will go through “B” items to get the result. I optimized this code so that I use a dictionary to lookup the results of the search as shown below:         for (int i = 0; i < small_list.Count; i++)         {             ...

Miscellaneous Ideas!

How to start a Task in C# which takes parameters: Task .Factory.StartNew(() => Method(arg1, arg2, ...)); How to handle ambiguity in code: You may have a situation where you need to add a parameter to a method in the code which is called from 1000 places. And you do it, and you look at a calling method and realize that you have no idea about what value to pass for the new parameter. What you do in this case, is to add the new parameter as a parameter to the calling method as well. Keep on adding the parameter in the caller method until you reach a point where it makes sense to provide a value, or the user is entering the value. You will always reach a point where you will be able to provide a proper value, as long as what you are doing made sense to begin with. How to handle a crying toddler who does not want to you to brush his teeth: Give him your toothbrush and let him brush your teeth while you brush his. He will be having fun while you get the work done!

How to manually update the BIOS on an HP a1600n desktop with A8M2N-LA motherboard

After wrestling with this over 3 days, I found out a way to update the BIOS on this machine and thought I would post it online. Many people are having difficulty applying the HP update from the HP site especially on Vista and Windows 7. Without this update, the processor does not support virtualization. 1. Download processmon from the windows site after searching on Google. 2. While running the BIOS update, just before it fails, look into the processmon to see which folder the installer.exe is running from. 3. Copy the contents of the temp folder to the desktop before closing the failed BIOS update message. 4. Open the desktop folder and set the winflash.exe properties to vista compatibility and run as administrator. 5. Run winflash.exe, select the 507.rom file from the file menu 6. Select update all in the left side options. 7. Say update on the toolbar. 8. When the modal dialog opens up, select update. 9. Let it update, and it will automatically restart windows 10. When it...

Defensive Programming Techniques for any language

Never put code in else. What goes within else can change if someone changes conditions tomorrow. Always check exact a.k.a else if (condition) explicitly. Never assume something of the underlying framework. If the object supports a close + dispose, calling close() maybe a good idea, there was a case where the framework would not actually call close when dispose was called. So this is a good idea. Don't assume that books provide the best practices for anything. Try it out and find the best practices yourself. Your life can be a hell of NULL condition checks when you define properties of lists or complex objects. Maybe the best idea is to instantiate these properties in the constructor so they will never be NULL to begin with? Try not to put any kind of conditions within conditions which make it difficult to read the code, set the IF condition in such a way if possible that you don't even process further if it is false, then the next line of code will be at the same level ...

How to crop an image in c#

This works: using  ( Image  FullsizeImage =  Image .FromFile(sourceFilePath))         {              using  ( Bitmap  NewImage =  new   Bitmap (FullsizeImage.Width, ThumbHeight))             {                  using  ( Graphics  newgraphics =  Graphics .FromImage(NewImage))                 {                     newgraphics.DrawImage(FullsizeImage, 0, 0,                        ...

How to enable and generate unit test code coverage metrics in your VS2010 solution

Right click on the solution >> Add file >> Add a test settings file After it is added, VS will open a prompt for the test settings. Go to the Data and Diagnostics section, select code coverage and then click configure (left top in the same section as the checkboxes). Select all projects you want to have code coverage metrics for, other than the unit test project. Close this window, and then click apply. Remember: You can get back to this, by going to the Test menu on the top, "Edit Test Settings" and selecting the new test settings created. Now run all tests in the solution, and after they have completed execution, click on the "Show Code Coverage Results" icon on the extreme right top of the test results pane. You can now expand the heirarchy and see the code coverage results. If you get this error: "Strong name verification failed for the instrumented assembly Please ensure that the right key file for re-signing after instrumentation i...