Category: Fun Stuff

Downfall: Hitler gets unhappy with his Agile team

This is hilarious! Hitler goes crazy when he learns that his team does not follow the tenets of the Agile Manifesto.

Expression Studio 4 is out and my 60-day tool

I was really excited last Monday after seeing Expression Studio 4 has been released (I have to admit that I’m one of those developers who logged in at MSDN at 12 midnight to check if the RTM bits are already out. hehe). I think this is great news for all XAMLers all over the world. On thing that I’m really sad about though is that our corporate MSDN license only has Expression Studio 4 Professional and not the Ultimate version. Bummed. So I ended up downloading the 60 day trial up until I can figure out how I can get a copy of the full version (OK, here’s the part that I ask donations to get a full copy but I’ll leave that out. LOL).

Sad, but still happy. At least I have 60 days to enjoy this new tool. ūüėČ

How To: Count the occurrence of a character in a string in SQL

Last night I was trying to cleanup the spammers from the database of devpinoy.org and while I was evaluating the result sets i was able to conclude that aside from using common spam text like ‘cheap’, ‘buy’, ‘free’, ‘deal’, ‘viagra’, ‘prozac’ that 30% of the false emails that spam accounts are using multiple dots on their email address. A good example is a subset below from the list of offenders that I found in the devpinoy db.

Having found that fact I immediately created a sql script that will delete users from the database if they have more than 2 dots in their email address.

Enough with the side note and here is some code.

What the code above is doing is that it is removing the characters that matched our search key and then subracts the length of that string to the original string to find the total occurrence of the character we are looking for.

Now, if you want to use this as a function you can use this:

The code above works great but there’s a catch. If you are concerned with case sensitivity then the code above wont work. The way around it is to use COLLATION which is supported by the SQL function below:

In order to use this in your query all you need to do is

Or if you want to put it to use to meet the criteria that I mentioned about dots on emails you can do it this way:

HTH

 

How To: Change table cell color depending on its value using jQuery

Here’s a nifty trick using jQuery on how to iterate on all rows of a table except the first row,
how to get the value of a column in the current row being iterated and how to change the table cell color depending on the value it contains.

In
this case we wanted to change the color of the 3rd column depending on
whether it is higher or lower than the second column. There are two examples in here. The first one is select the table via its ID and the second version is selecting the table based on its class name.

Below is the full source for this sample:


Iterating to the table via table id

Product Name Yesterday Today
Egg 1.95 2.10
Sugar 1.92 1.88
Milk 1.95 1.97
beans 3.15 3.06

Iterating to the table via class name

Product Name Yesterday Today
Egg 1.95 2.10
Sugar 1.92 1.88
Milk 1.95 1.97
beans 3.15 3.06

You can copy and paste the code above and put it on a new file to see it running or you can view this sample running here: jquery_change_table_cell_color_depending_on_value.html
(3.05 KB)

HTH

How To: Calculate Mathematical Expressions in .NET

Everyday you learn something new. You do. That is if you let yourself to be taught everyday.

I didn’t know that you could solve this expression string in .NET in one line of code: “4 + 5 + 10 – 4 / 5 * 2”

 

The result is 17.4. Nifty huh? You can also group the expressions to display a clearer evaluation instruction and it still will work.


string expressionToEvaluate = “(((4 + 5) + (10 – 4)) / 5) * 2”; //will result to 6

This is all cool but there’s a gotcha. DataTable.Compute() method can only evaluate simple expressions so your

string expressionToEvaluate
= “Tan(10) * 2”;
//error

Would throw an exception of type EvaluateException because it could not recognize the function Tan().

One solution you could take to solve this problem is to use a dynamic language in the DLR like IronRuby or IronPython.

 

You can check out Kirill Osenkov’s post for more info regarding this approach.

Another way which i think is the better way is using a third-party library that already support this like NCalc.

NCalc is an open source Mathematical Expression Evaluator for .NET that can parse any expression and evaluate the result, including static or dynamic parameters and custom functions.

Pretty cool huh?!

My MIX09 10K Contest Entry: Silverlight Pregnancy Calendar

I had some free time during the holidays and saw at the MIX09¬†website that they have¬†a contest entitled MIX09 10K Challenge where they ask participant to create a web application¬†that¬†is¬†either using Microsoft¬ģ Silverlight‚ĄĘ or Windows Presentation Foundation, as a XAML Browser Application running in Partial Trust or as a ClickOnce application in 10 kilobytes or less. I decided to take a stab at it and this is what I’ve came up with

SilverCalendar: A Silverlight Pregancy Calendar

You can see the app live here http://2009.visitmix.com/MIXtify/TenKDisplay.aspx?SubmissionID=0051

Dont forget to vote when you’re there ūüėõ LOL

My primary motivation when I built the app is the idea of having something that is going to be useful and at the same time fun to build. My wife is currently 34 weeks pregnant and it made me think that a pregnancy calendar would be q great application to do since it relates to me and my current day to day life. I love pregnancy calendars because it gives you a good daily insight on the progress of your baby and what you might expected as you go along in your daily life as a soon to be parent.

The application that i¬†built is¬†using Microsoft Silverlight 2 with a backend WCF web service.¬†You can find the pregnancy calendar web service here. I wasn’t able to add any animations to the application because I decided to concentrate in adding functionality to app rather than the eye candy’ With that said, I’ll be posting the non-10K application this week.

Be sure to comeback on this blog in the coming weeks because I’ll be publishing the source code to both project¬†soon together with a 11 part tutorial and screencast walkthrough that i have prepared to show how to to build an application using .NET 3.5, WCF, WPF and Silverlight.

KeithRull.NBible: A WPF Bible Application

A week ago, I started a contest at DevPinoy.org about writing a Bible application and a few people have asked me if I tried my own challenge. I actually did took the challenge and built my own Bible application. I wasn’t able to post it as soon as I wanted to do it due to time constrainst. What I built is a WPF Bible application but still needs some polishing to truely call it a “WPF app”. 


Now let’s begin the tour of the WPF app that I built.


The screen below shows the main interface for the program. The first tab is the browsing tab that allows the user to select a Book and a Chapter they want and displays the contents of your selection on the list below the Comboxes



The bold letters on the upper right side of the list tells you what book and chapter you are currently reading



The second tab is the search tab. This tab has a textbox that allows you to enter your search parameters



It allows you to search by keywords



By book and chapter



or by specifying the Book, Chapter and Verse



There are a few more things that I wanted to add this app but wasn’t able to do so like building a TreeView similar to CryptoKnight’s implementation that allows you to see the Document Map and also a matching word highlighting on the search screen would be a great addition too. Another thing that could be improve is refactoring the code and making the service layer a little bit more generic. I wanted to refactor it a bit more after I finished it but never had a chance to do so. I’ll leave it as is for now and hope to update it in the future.


There’s a lot more improvements I could think of but I’ll leave it for you guys to check and comment on what I could do with this app to improve it. Maybe we could make it an OpenSource application someday.


Anyhow, you can get the source code for this project here. KeithRull.NBible.zip (1.84 MB)


Thanks to everyone who tried the challenge. I promise to do more of these type of contest in the future. 


Again, Thank you, God Bless and Mabuhay ka Filipino Developer!

How To: Make A Master-Detail View In ASP.NET

In part 3 of this 5 part series I am going to show you how to make a Master-Detail View in ASP.NET. I you weren’t able to see the two previous post you can check them out here:



This post is a continuation of what we started in the two previous post wherein i show you how to consume a webservice ins ASP.NET and present the values returned by the service to the user in a much more meaninful way.


To start off with this post lets look at how the application from our last article look-liked:



As you can see, we have a textbox that accepts a user-input asking for the symbol to lookup in our webservice, a button that triggers that query event and a DetailsView that displays the returned resultset. This works great.


But what if I have a list of symbols that I want the user to see information regarding them? The answer is to show them in a master-detail view so that the user can get a clearer view of the information on each symbol.


To start with this demo lets begin by deleting everything that we have on the page. Yup! we are starting from scratch so that we can get a clearer picture on how we can build a master-detail view screen. Once everything is cleared on the page let’s begin by adding a DataList control on our page with a Label control inside its ItemTemplate:


The first thing that you would notice on the code above is that we have assigned a value to the Text property of our Label control. This value signifies that we are binding the Container.DataItem value to the Text property. This DataItem will come from the value that we are going to set in the codebehind file for this page which in this case is just going to be a List<string>.


Next, lets go the codebehind file and create the Page_Load event for our page:


All i did in the code above is create a list of strings, add some values to it and assign and bind that colletion of strings to our DataList. Running the application now would give us this result:



Nothing really impressive yet. Now let’s add the cool part wherein we call a web service and show the information for each stock symbol.


To do that we need to add another DataList inside the ItemTemplate of our first DataList. The second DataList will serve as the list that shows the imformation about the specified execution symbol. We also need to add an event that is triggered each time a ListItem is binded to a data. Below is our modified HTML page:


I modified the ItemTemplate of our second DataList () and added an html table to hold the values that the web service returns. This way the view that we are presenting is much more readable.


Next stop is looking at the code behind where all these magic is going to be wired. All the work for the detail view will happen on the stockDataList_ItemDataBound event and no further modification to our Page_Load event is needed. Let me show you the code for that event before I start explaining every bits and pieces of that code:


What we are doing on this blog of code is we are checking if the ItemType of the current item being binded-to is either a ListItemType.Item or ListItemType.AlternatingItem. If it passes this criteria we then read the DataItem that was binded to this ListItem which in this case is our executionSymbol. The next step is to find our stockInformationDataList control and assign the stockInformationDataSet to it. The stockInformationDataSet contains the values that is retrieved from our stock web service by passing the exection symbol to our StockQuoteHelper.GetStockQuoteDataSet method.


Running our completed application will result to this screen:



And that’s it! We’ve accomplished a master-detail view in ASP.NET. Pretty easy right? I hope you learned something from this tutorial. Next up we’ll update this project and implement some Asynchronous Web Service calls via ASP.NET AJAX and show you some fun ways to present a master-detail view in a much more interesting way.


As always, source code is available for download here: KeithRull.ConsumingWebServices.Part3.zip (6.9 KB)


As a side note, many thanks to John A. Miller from Trofholz Technologies, Inc. for reminding me about this series. I totally forgot about it already after being assigned to a large project the past few months. Thanks John!

DevPinoy Code Contest For October 2008

Whew! It’s been a long time since the last time that we had a cool contest here at DevPinoy and I think it’s about time to start giving away cool stuff those developers who are willing to take the challenge. This time around I’ve decided to make the contest a little bit more interesting than the usual…


Ok, enough with the teaser and on with the contest!


Our challenge this months is to build a Windows-based Bible application in  C#, VB.NET or Java. The idea is to build an application that reads from a Bible database and displays testaments, books, chapters and verses based on these simple requirements:



  1. The user should be able to search for books base on a selected Testament (Old and New).
  2. The user should be able to see the contents of each Book
  3. The user should be able to search the contents of the Bible based on different search criterias like “Luke”, “Genesis 1”, “John 3:16”, “love”, “Abraham” and the application should be able to return the matching results.
  4. The user should be able to jump from one book to another.
  5. The user should be able to jump from one chapter to another.

That is all that is required for the app and it’s up to you to add additional functionalities if you like. You can find the database for this challenge here: http://devpinoy.org/media/p/30310.aspx


Simple right? Here’s the caveat! You are not allowed to use any third-party library in your solution (Yup! No NHibernate or Hibernate for you buddy!). Everything should be straight up what your language of choice supports. The only acceptable third-party library is a testing and mocking framework as part of your test harness but this is not required.


So what’s the prize? Glad you asked! We are going to chose 2 winners for this contest and they will be able to chose 1 of these lovely prizes courtesy of JetBrains: IntelliJ IDEA, ReSharper, Team City(one Build Agent), dotTrace and JetBrain’s forthcoming Ruby IDE(they don’t have a name for it yet).


So who is entitled to join this contest? This contest is open to all Filipino developers who are willing to take the challenge regardless of location and ofcourse you should be a member of the DevPinoy website.


So how can I participate? All you need to do is finish the application and send it to keith.rull@gmail.com together with the source code before October 26, 2008 PST. Please include “DevPinoy October 2008 Code Challenge” on the subject line of your email when submitting your code. Please also include a screenshot of your application and your fullname in your submission email.. All submissions would be posted on October 27, 2008 PST in my devpinoy blog so the community can view your work. The announcement of winners will take place on October 29, 2008 PST.


Ready for the challenge? Stop reading, start typing and send your solution as quick as you can!