Category Archives: Miscellanous

This would contain all post that can’t go to the other categories

Gamification

I’ve joined this online course in Coursera that discuss about gamification. Now even though i consider myself a gamer, and it’s true that the course title pique my interest in the first place. gamification is not something you study to make yourself better as a gamer or a game maker.

So what is gamification ?

Gamification is a concept where you use game elements and game designs in a non gaming context.

 

Major companies has started to implement gamification in their way of interacting with the consumer, take for example Nike Plus. Where you put your running shoes and then when you complete your running it will when have access to your phone or laptop update your achievement on twitter by saying how many km that you take. How does this matter to Nike, well of course it matters to them, they want to make more people run, the more people that run means more people will buy their product.

Taking the course have made me more aware on the gamification concept being implemented on my daily life. I noticed that my current company give virtual points to among employees to increase motivation and productivity. So it’s not just about major companies increasing their sales. It’s about taking the fun, challenges, and sense of accomplishment of gaming to non gaming context.

I’m having a great fun joining this course, and it’s free!. i get to expand my knowledge to other than just hitting the keyboard and produce awesome code  -self claimed Smile with tongue out

For those of you who want to join the course, you can still join as the first week homework deadline is on 9th September 2012.

See ya there.

The problem with writing to convey message

The problem is that it could be misinterpreted. I mean even by just talking the things that we meant to say could have been perceived differently by the person we are talking to. And trying to convey the same message through writing could make matters worse.

It’s especially true when the person trying to convey the message does not have the skill –yes it’s a skill- to deliver the message effectively. Have you ever encountered that smiley icon on your favorite messenger ?. that one picture could mean a lot of different things depending on the context of the conversation. it could be a warm smile, a fake smile, even sinister smile using the same icon!.

Or how about the symbol that we usually use to indicate strong expressions, yes I’m talking about the exclamation mark. Here’s how I feel if I have somebody text me a message like this:

Stop! – okay, he’s telling me to stop

Stop!! – okay, he’s starting to get pissed off, I must stop immediately

Stop!!! – he’s clearly stretching his veins in his neck to say that. and I better damn stop whatever I’m doing right now before he punch right through me.

Like it’s said on http://www.nationalpunctuationday.com

The sign used in writing after an exclamation or interjections, expressing strong emotion or astonishment, or to indicate a command.
AVOID OVERUSE!

So dear reader, be wiser and don’t type excessive symbol like this, because that would cause the person on the other end to interpret the message differently.. unless of course you do it knowingly the meaning of those exclamation marks.

Why am I writing this you might say ?. Just have a lot on my mind right now and thought writing some random blog post late night would do me some good. ha!

Creating a Dynamic Dictionary with C# 4 dynamic

In C# 4 there’s a new keyword introduced which is dynamic.

Here’s what msdn say about it

The dynamic type enables the operations in which it occurs to bypass

compile-time type checking. Instead, these operations are resolved at

run time.

combined with the var keyword.. anonymous method, and don’t forget anonymous object. I couldn’t help get the feeling that coding in C# is getting similar in a way coding in javascript Smile.

Right, let’s get back to the topic,  so I want to create a dynamic dictionary which enable me from doing this

to this

This is surprisingly quite easy to implement, as all we need to is extend our class from DynamicObject that reside in System.Dynamic and override couple of methods..two actually.

The trick is in the TryGetMember and TrySetMember method which set and get the property for dynamic object. There’s other method in DynamicObject that you can override such TryGetIndex and TrySetIndex which try to access the dynamic object by index.

You can read more about it in Aaron’s blog

Nuget uninstall package with dependencies

Thought i share a nice command of using nuget.

Let’s say you installed a package with a whole bunch of dependencies, but to found out later that that’s not the package that you want… how do we get rid of the package dependencies altogether without running uninstall-package command one by one.

for example, we’re installing jquery.ui.all package

look at that dependencies, after the painful wait due to my poor internet connection, i found out that i just need the jquery.ui.core package Sad smile

And i got all this packages installed

now, instead of running uninstall-package to each of dependencies

we could instead run

and that nice command take care it all

Happy new year 2012

Happy new year everyone!, this post arrive late Sad smile, well can’t help it since I got internet issues lately..

A lot of things happened for me in 2011, I got my first MCTS certification on web application using .NET 4, moved to a new boarding house with my wife, got a new job.. still in Bali though.

While some people on new years night go out partying or just hang out with friends, my wife and I decide to spend the night at Sanur beach. So we drove around 30 minutes away from home to get there, it was so crowded, a lot of people seems to had the same idea Smile. But we finally found a nice spot, where we spend an hour there watching the fireworks, to bad we didn’t bring any camera though, it was so beautiful.

Usually people make their new year’s resolution, well I got mine too.. one of them is to be able to post in this blog more frequently, looking back I only have around 6 post total in 2011 which probably because I think I should make a post related programming. Well.. that didn’t work too well for me, cause I didn’t know what to write, so hopefully I can post more frequently from now on even though is not about C# or ASP.NET.

Realtime web application with SignalR

A couple of weeks back i got a task to develop a chat application for an existing application that we have. The idea was so that the existing members could chat with each other without requiring any external IM services such as YM, Skype or MSN messenger. Seems quite simple.. well let’s see about that.

I did some research on how would be the best way to do this, there are a couple of ways that I found:

  1. AJAXpolling
  2. Comet/ AJAX long polling
  3. HTML 5 Web Socket

AJAX Polling

Before AJAX, websites page where not as interactive as of now, imagine that you open your favorite news site and then you got a list of news up until that time displayed on the page, left the tab open for an hour, and if you go back to that tab and need to see if there’s any new news since you left you need to refresh the page. Well with AJAX, a JavaScript could run in the background firing every n minutes to check if there’s any new data and display, this approach is called AJAX polling.

Using this idea of AJAX polling, people start to experiment on creating a real-time apps for web application such as chat application. The drawback of it is because it check to the server every n seconds/minutes it will put the server under heavy load, and imagine that if you have hundreds or even thousand users using the chat application and each of them do a check on the server to see if there’s any new data.. it will be a nightmare.

Not to mention the bandwidth consumption that this approach uses, people that see the weakness of this approach then seek a better approach

Comet / AJAX long polling

It’s a method, improvement if you like, from learning the weakness of AJAX polling, the idea of Comet is the client browser maintain a persistent connection to the server, and instead of the client checks every n second/minutes to the server to check new data, the server itself will tell the clients if there any new data and sent it to them.

HTML 5 Web Socket

This is a new feature in HTML 5 to provide a real two way communication between server and client, we don’t need to any workaround such as AJAX polling or Comet to create real-time apps it will natively provided by the browser as a feature of HTML 5. So as long the client’s browser support it and the server also support it we all set to go.

Back to the chat application, after taking a look at the available approach it seems that Web Socket would be the way to do it.. however currently –at the time of writing- it’s not supported by IE 9, even though FF7 and Chrome 15 does support it the IIS doesn’t support the Web Socket protocol yet.. bummer. So it seems i at this point i could only use Comet to develop my chat application.

Here’s where SignalR come to action, SignalR is async signaling library for .NET to help build real time web application. It’s an open source library under MIT license that’s developed by Damian Edwards and David Fowler, folks from Microsoft. It’s very easy to use, here an example taken straight from the documentation page.

Setup

Go to NuGet and install the SignalR package into a WebApplication:

Server

Create a class the derives from Hub:

Client

Javascript + HTML

If you didn’t notice, in the JavaScript code above it assign a click event handler to button with id broadcast which call a server method Send in Chat class.. and if we take a look at the Send method it will trigger the JavaScript addMessage() function for all connected clients. Pretty awesome isn’t it, this approach make it easy for client and server to communicate since they can call each other methods.If you run this code in multiple browsers and try it you will notice that if you press the broadcast button in one browser, then all the browser will all get the “Success!” message, a simple example of SignalR broadcast capability.

The other awesome thing about SignalR is that it will support Web Socket when IIS supports it, so at the moment i could just develop my chat application, and when IIS does support Web Socket, presumably on IIS 8 and .NET 4.5 i could just update the transport mechanism from Comet to Web Socket, and from what i read on the documentation page this could be done by just setting a single property, awesome !

Edit: Paul Batum has made a nice article of using Web Socket in Windows 8 developer preview with some example including chat.

The SignalR team hang out on http://jabbr.net/, you’ll notice that it’s a chat application Smile, previously this chat app is meant to be an example for SignalR,  however with people keep adding new features into it, it slowly becomes a rich chat application, another good thing about open source. So if you want to know more about SignalR, download the source code at https://github.com/SignalR/SignalR,  got any question or suggestion just go to their chat room, the nice folks there will help you.

Failed to load viewstate. The control tree into which viewstate is..

I got this error message when i was working with dynamic control earlier. It seems this exception is thrown when some control in the control tree can not successfully load it’s viewstate.

Let’s take a look at the code,

i created a dynamic list view, set the templates and add the listview to a placeholder control. So far everything works fine, i can add a data and it display it, delete also works but the problem arise when i tried to edit the item. Let’s take a look at the item template and edit template

It’s pretty straight forward, i have a literal control that display the value in view mode and a texbox control to display the value in edit mode. But everytime i try to edit it i got the same error again and again. And then a thought cross my mind.. what if i set all the controls in the item template and edit template but control their visibility property. Will that do the trick, let’s see..

Above is the modified item template, i include all controls that are used in both item template and edit template and basically just handle their visibility property. The edit template has simillar contruct but with different controls being hidden, you get the idea. And so.. compile, run the code.. fingers crossed.. and it works!. It has the same control hierarchy when on view mode and edit mode but display different controls, i guess using dynamic controls can be quite tricky.

Hope this helps.