Testing the new Visual Studio 2010 features

Yesterday was an exciting one for all sorts of developers around the world. Visual Studio 2010 got available for both MSDN and DreamSpark subscribers. First time I installed VS2010 was in the RC form mainly because of WP7 Developer’s Tools and XNA4.0 but haven’t made many investment in searching for new features. But being available at Dreamspark I downloaded the Professional version and decided to try it out a bit. On a side note to WP7 developers, if you are using VS RC to develop application to the phone don’t install the RTM version of VS2010 since it’s not compatible with WP7 developer tools yet. You have to stick with the RC for now. ...

April 13, 2010 · 2 min · 340 words · David Amador

Write better code using FxCop

Microsoft FxCop, know what this is all about? Good for you, keep using it, It’s a valuable tool. For those who don’t know you can download it here and read the MSDN documentation here. FxCop is a is an application that analyzes managed code assemblies and reports information about the assemblies, such as possible design, localization, performance, and security improvements. I decided to make a profile of my current working project and it reported tons of stuff. ...

March 18, 2010 · 1 min · 107 words · David Amador

C# foreach VS for loop

When I started using C#, mainly because of XNA one of the things I got used to write is foreach loops instead of for, seemed easier and it’s a much cleaner code. Doing almost the same thing as a for loop I never really bother to see the differences, almost everyone in their XNA examples used it instead. Today I decided to see the differences between them: FOR int[] values = new int[1]; int total = 0; for(int i = 0; i < values.Length; i++) { total += values[i]; } FOREACH ...

December 12, 2009 · 2 min · 312 words · David Amador

Force a wmv to download instead of opening in browser

I recently needed to force a WMV to download using Apache. The default behaviour for most browsers is to try to open the movie inside the browser itself. This works fine if the person has the plugin otherwise we just gonna have a blank page. Also for huge WMV is easier to download the file for later viewing. So just place this on your .htaccess on the root of your website. ...

October 30, 2009 · 1 min · 95 words · David Amador

How to make a clickable div

Making a clickable text or image is easy, just add the <a> tag surrounding it. But this doesn’t work with divs and sometimes we need a whole div to be clickable and not just text. The following code is for JQuery but switching it to your favorite JS framework should be very easy. First start by adding this to your div <div class="clickable"> </div> Now a little css to simulate the pointer on that div ...

October 25, 2009 · 1 min · 108 words · David Amador

PHP Optimization Tips

As most languages PHP allows many ways to solve a problem. Some are faster then others. Here are a few ways to improve your PHP code. Loop At some point your program will require a loop. And loop is considered as efficiency killer if you have many nested loop (means loop in a loop) as one loop will required to run ‘n’ times and if you have 1 nested loop, this means your program will have to run n2 times. There are many ways we can define a loop in PHP. But how do you know which one is the best way to loop your data? Apparently, using a for loop is better than foreach and while loop if the maximum loop is pre-calculated outside the for loop! ...

October 22, 2009 · 3 min · 506 words · David Amador

Search and Replace in MySQL

I found something very handy today, search and replace on Mysql databases. You can do it on phpmyadmin or make a php script with this. After moving a wordpress site from server I discovered that all image links were broken because they are placed directly inside each post. They were still linking to the old server. Changing it manually would be a nightmare. Luckily MySql is your friend. To search and replace a text string, start up phpMyAdmin, and click on your database name that you want to run the search and replace through. At the top of the window, click on the “SQL” tab. ...

October 22, 2009 · 1 min · 123 words · David Amador

Test your website on multiple browsers

One of the most painful tasks of a web developer/designer is to ensure that his website is compatible with the majority of the popular browsers. Nowadays this includes Firefox 2.0 and 3.0, Internet Explorer 6, 7 and 8, Opera, and the newest Chrome. Well, you can have firefox, IE and Chrome all on the same system, but what about multiple versions? Most people still use IE6 (they should be shame by the way). ...

October 21, 2009 · 1 min · 106 words · David Amador

How to style a blockquote with CSS

Blockquotes are an easy way to make your website stand out, by indicating that you are quoting someone you give a more professional approach to you website. You can do this by using <blockquote> Im quoting someone else</blockquote> But it still needs a little touch, so on your css file add this. blockquote { background:transparent url(blockquote.gif) no-repeat scroll 0 0; font-family:Georgia,"Times New Roman",Times,serif; font-size:1em; margin:15px 0; min-height:32px; padding:0 50px; } Save this image : and watch the result. It will turn out something like this: ...

October 21, 2009 · 1 min · 89 words · David Amador

Cloning Objects in C#

After trying to manually clone some classes, but making a sort of copy constructor I was always ending up with lot’s of code and worse, if I add another variable to my class I would sometimes forgot to also clone it. Luckily and after a search I discovered that C# has a cool thing, Reflection. So you can do something like this: using System.Reflection; class MyClass { public int a; public float x; MyClass() { // default constructor } MyClass (MyClass my) { FieldInfo[] fields = typeof(MyClass).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach(FieldInfo f in fields) { f.SetValue(this,f.GetValue(oth)); } } } MyClass obj1 = new MyClass(); obj1.a = 1; obj1.x = 2.0f; MyClass obj2 = new MyClass(obj1); // Obj2 will have same values as obj1 and you // can now use them independently. I hope this is helpful. Let me know if you know a better way ...

October 12, 2009 · 1 min · 146 words · David Amador