MVP Part II - Unit Testing
Posted @ Oct 20, 2008 07:04 PM | Permalink | 0 Comment(s)
Yet another great post from Rod about Model View Presenter. You can read the full article here.
Talking to a recuiter 5 minutes ago...
Posted @ Oct 12, 2008 07:37 PM | Permalink | 4 Comment(s)
YM Conversation:


Recruiter X: hi
Recruiter X: good morning
Recruiter X: this is rey of Recruiting Firm X
Recruiter X: an executive search company
Recruiter X: and i am currently in need of .Net developer
Chris Ongsuco: hey
Recruiter X: are you open for the position?
Chris Ongsuco: sorry i'm not currently available
Recruiter X: hmmmmm
Recruiter X: sayang ang opportunity
Recruiter X: well thank you na lang
Recruiter X: and have a great day
Recruiter X: this is for regular position pa naman sana


At this point I was blown away by his sarcasm. This dude is getting on my nerves! And so I answered back with sarcasm as well...


Chris Ongsuco: i am also a regular at my current company
Recruiter X: heheh
Recruiter X: and my client offer high salary
Recruiter X: aside from benefits and allowance


Ding ding ding...did he just say "high salary"? To my curiousity...


Chris Ongsuco: how high?
Recruiter X: anyways
Recruiter X: keep na lang muna kta in my active file
Chris Ongsuco: give me a range
Recruiter X: 30-60k
Recruiter X: it depends on your years of experience


blah blah blah....and so on...


Well, there is always a first time for everything...


Microsoft supports jQuery
Posted @ Oct 09, 2008 07:00 PM | Permalink | 0 Comment(s)
I know its late but I am going to say it anyway. I am very glad that Microsoft finally decided to support jQuery as part of Visual Studio. Whoever made it happen, thank you.

For the news on jQuery and Microsoft you can read ScottGu's Blog.

To learn more about jQuery please visit their site at jQuery.com

My next posts, if I still have time, will be about my jQuery and ASP.Net experiences...
Database BLOB Compression using C# and SharpZipLib
Posted @ Sep 05, 2008 10:40 AM | Permalink | 0 Comment(s)
Sometimes you just have to save files in the database. The reason? Because "Simon" said so. So without further ado, here is a simple example on how to compress files using C# and SharpZipLib:

1
2 using System;
3 using System.IO;
4 using ICSharpCode.SharpZipLib.Zip.Compression;
5 using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
6
7 namespace YourNamespace {
8 public class GenericCompressor {
9 public static byte[] Compress(byte[] buffer) {
10 MemoryStream ms = new MemoryStream();
11
12 Stream stream = new DeflaterOutputStream(
13 ms,
14 new Deflater(Deflater.BEST_COMPRESSION),
15 buffer.Length
16 );
17
18 try {
19 stream.Write(buffer, 0, buffer.Length);
20 }
21 finally {
22 stream.Close();
23 stream.Dispose();
24 }
25
26 return ms.ToArray();
27 }
28
29 public static byte[] Decompress(byte[] buffer) {
30 MemoryStream ms = new MemoryStream();
31 byte[] data = new byte[4096];
32
33 Stream stream = new InflaterInputStream(
34 new MemoryStream(buffer)
35 );
36
37 try {
38 while (true) {
39 int bytes = stream.Read(data, 0, data.Length);
40
41 if (bytes < 1) {
42 break;
43 }
44
45 ms.Write(data, 0, bytes);
46 }
47 }
48 finally {
49 stream.Close();
50 stream.Dispose();
51 }
52
53 return ms.ToArray();
54 }
55 }
56 }


To compress files in ASP.Net, the code would be something like this:

1
2 byte[] data = new byte[fileUpload.PostedFile.ContentLength];
3
4 fileUpload.PostedFile.InputStream.Read(data, 0, data.Length);
5
6 byte[] compressedData = GenericCompressor.Compress(data);
7
8 // Then save to your favorite database...


Conclusion:


I prefer having this utility over other solutions because I don't have to be tied up to a specific database vendor and of course, no database component or assembly to install. No hassle.

LiteSqlHelper - yet another .Net data access helper
Posted @ Sep 03, 2008 08:02 PM | Permalink | 0 Comment(s)
LiteSqlHelper is a lightweight data access helper that I developed sometime ago. It's a good replacement to SqlHelper or DAAB. It's simple to use, extensible and free (without limitations).

Source code and samples can be found here.



Cheers,

Chris
C# 3.5: Extending System.String
Posted @ Sep 01, 2008 01:36 AM | Permalink | 0 Comment(s)
With the new extension method feature of C# 3.5 it's now easy to extend your classes for additional functionality. Here are some useful functionalities to add to your favorite System.String:

1
2 // Sample namespace
3 namespace CompanyName.ProjectName.Common {
4 public static class StringExtension {
5 public static string Left(
6 this string text,
7 int length
8 ) {
9
10 if (text.Length < length) {
11 return text;
12 }
13
14 return text.Substring(0, length);
15 }
16
17 public static string Right(
18 this string text,
19 int length
20 ) {
21
22 if (text.Length < length) {
23 return text;
24 }
25
26 return text.Substring(
27 text.Length - length,
28 length
29 );
30 }
31
32 public static string Mid(
33 this string text,
34 int start
35 ) {
36
37 return Mid(
38 text,
39 start,
40 text.Length - (start - 1)
41 );
42 }
43
44 public static string Mid(
45 this string text,
46 int start, int length
47 ) {
48
49 if (text.Length < length + 1) {
50 length = text.Length - 1;
51 }
52
53 return text.Substring(start - 1, length);
54 }
55 }
56 }
57


Sample usage would be like this:

1
2 string text = "ABCDE";
3
4 Console.WriteLine(text.Left(1));
5 Console.WriteLine(text.Right(2));
6 Console.WriteLine(text.Mid(3));
7 Console.WriteLine(text.Mid(3, 1));
8
9 // Output:
10 A
11 DE
12 CDE
13 C
14

ASP.NET: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack
Posted @ Aug 29, 2008 01:52 AM | Permalink | 0 Comment(s)
ThreadAbortException:

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.


If you are using Response.End, Response.Redirect or Server.Transfer somewhere in your code and you encounter this error , please check this solution from Microsoft.
C#: "finally" block vs StackOverflowException
Posted @ Aug 26, 2008 06:59 PM | Permalink | 4 Comment(s)
Taken from the MSDN documentation:

The finally block is useful for cleaning up any resources allocated in the try block as well as running any code that must execute even if there is an exception.

So in other words whatever code you have in your "finally" block will always execute when an exception occurs, right? Wrong. The correct answer is - it depends on the error.

Let me give you a simple example:

1
2 static void Main(string[] args) {
3 try {
4 Console.WriteLine("Try block");
5
6 Recurse();
7 }
8 catch {
9 Console.WriteLine("Catch block");
10 }
11 finally {
12 Console.WriteLine("Finally block");
13
14 Console.ReadLine();
15 }
16 }
17
18 static void Recurse() {
19 Recurse();
20 }
21


The System.StackOverflowException is an exception that will NOT execute codes in your catch and finally blocks.

Hope this helps.
Blog changes
Posted @ Aug 26, 2008 10:13 AM | Permalink | 0 Comment(s)
I am re-organizing things on my blog so there might be some changes in the tags and links or maybe the layout.

I am also adding a new "Project" section where I will be posting some of the projects I created as open source. Feel free to use them without any limitations.
My Philippine Job Site Listings
Posted @ Aug 04, 2008 12:03 AM | Permalink | 1 Comment(s)
My bookmark of job sites and recruitment firms in the Philippines:

Philippine Job Sites


Philippine Recruitment Firms


Apologies to those firm/sites that are not on the list. If you want to be listed please send me an email containing your company name and website here.