-(unichar) fn: (unichar)n{ return n ^ 0xFFFF004B == 0? n : [self fn:(n-0x1)]}

Archive for the ‘Principle’ Category

Merry X’mas

Saturday, December 25th, 2010

Merry Christmas.



furniture pickup for free!

Tuesday, December 14th, 2010

http://webdevwarehouse.com/

One week left! Shaun is a great man and he got a lot of furniture (table, chairs) for free, can pickup after arranging a time with him, don’t miss out!

He also got a ping-pong table, but it is too big for me. and sell it for $150, almost brand new.



bing! site wide search plug-in for wordpress

Sunday, December 5th, 2010

It’s somehow a little bit useful to have bing search engine integrate to your website. I just create a plug-in for wordpress regarding this. This plug-in is designed to be a right panel widget. If you need, just download the ZIP file and upload to your wordpress plug-in, activate it, then you can arrange the widget on your right panel.

You can also define the title for this plug-in: you need to setup the search site, if you don’t, then will be the current site. Please note that “http://” is not needed as shown below:

On the right panel, you can see the bing site search widget is activated:

And when you type in the search bar with your keyword,  you will see the search result:

Simple and easy, just go to open source section: http://blog.koumei.net/open-source/#bing



Enterprise Boat Display on Docklands

Saturday, September 4th, 2010

Melbourne Day: 30 August 2010 (175 Years Anniversary)



ASP.NET MVC Whole Site 301 Permanent Redirect

Thursday, August 12th, 2010

For some reasons, we need to permanently redirect the whole website to another website. It would be much easier that you are the owner of the server. But most of time you just host your website on the server out there. It wouldn’t be a big problem that your hosting company will support you to do some simple 301 redirect or may you have enough privilege to do it yourself. Is it possible to redirect permanently the website to other website by programming a little bit?

Sure you can. With MVC routing facilities, you can define your customized redirect logic: CREATE AN EMPTY MVC PROJECT, MODIFY GLOBAL.ASPX.CS FILE ONLY ON THIS EXAMPLE:

First of all, define two objects which implemented IRouteHandler and IHttpHandler, you can feel free to define those two objects on Global.aspx.cs file:

//@Implements IRouteHandler
class RedirectRouteHandler : IRouteHandler
{
private string newUrl;
public RedirectRouteHandler(string newUrl) { this.newUrl = newUrl; }
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new RedirectHandler(newUrl);
}
}

//@object implements IHttpHandler
class RedirectHandler : IHttpHandler
{
private string newUrl;

public RedirectHandler(string newUrl) { this.newUrl = newUrl; }

public bool IsReusable { get { return true; } }

public void ProcessRequest(HttpContext httpContext)
{
httpContext.Response.Status = “301 Moved Permanently”;
httpContext.Response.StatusCode = 301;
httpContext.Response.AppendHeader(“Location”, newUrl);
return;
}
}

Then add one line on RegisterRoutes(RouteCollection routes) method (in Global.aspx.cs):

routes.Add(new Route(“{*pathInfo}”, new RedirectRouteHandler(@”http://koumei.net”));

Now all request to the website will redirect to “koumei.net” permanently. :)



Koumei New Domain!

Saturday, July 31st, 2010

Koumei got a new personal domain: koumei.co which is the same as koumei.net though. :)

Gonna make a page: koumei.co/ol :) cool !



An Experimental Html5 Drama

Sunday, July 25th, 2010

After reading through all useful articles about Html5 and CSS3, I try to create a new Html5 template for my blog. If you would like to see something new about html5 and css3, have a look at this article:
70 Must-Have CSS3 and HTML5 Tutorials and Resources

Koumei’s experimental page is available here: http://koumei.net/html5.html

Nothing much currently. I am quite interested in creating the gradient background and rounded corner.

This page will be kept updating.



Say Hello to koumei.net on HelloVPS

Friday, July 23rd, 2010

Yesterday koumei.net was condemned due to bring down the whole hosting server for harmful scripts, according to the server support. Not easy to contact them since they are in states. I am desperate to stay on their server without any secure. I would rather move to another server than to explain I am innocent. So I will move out from their server, I don’t like their service as well. How come they close down my website so suddenly without 1 day or 2 days notice?

Thanks to Howie from states who provides me a shelter at this moment. koumei.net is homeless, desperate and depressed last night, but because of his kindly help that make me home again. Now let us say hello to koumei.net again on HelloVPS (HelloVPS.com).

hellovps

hellovps



MVC2 Bug on Data Binding in Listbox?

Wednesday, June 23rd, 2010

Seems MVC and MVC 2 don’t realize that there is an issue when binding the data on the view:

Given an extension on HtmlHelper: this extension will generate a list box in view based on the collection “cakes”. (Because I like cake, so I use dessert object as example :)

public static MvcHtmlString MyDropDownList(this HtmlHelper target, string controlName, IQueryable<Cake> cakes, object htmlAttr)
{
if (cakes== null)
return MvcHtmlString.Empty;
var cakesList = new SelectList(cakes, “Id”, “CakesName”);
return target.ListBox(controlName, cakesList, htmlAttr);
}

It is okay, but the main issue is if the when I specify the Model data on control name, it IS SUPPOSED to generate the list box with the data which retrieved from database are selected. Yes.  IT IS SUPPOSED TO BE. But, unfortunately, MVC fail to automatically bind data for us…  The data “cakesList” is showing properly, but with no preselect options. In most of the business logic, it’s not gonna work, because it is no point for user to re-select the options every time before save the data.

In this case, MVC is not gonna auto-bind the data for us, we just need to figure out another way to display and manipulate the data properly. So we will change something on the extension, view and the controller:

1. On the view, don’t specify the name to model’s name, For example, the data which will be weaved to list box is CakeViewData.CakeList, the data related to database is CakeViewData.Dessert.Cakes. Normally, we will use the extension to weave the data:

<%=Html.MyDropDownList(“Dessert.Cakes”, Model.CakeList, new { @class = “multiselect”, size = 5 })%>

Since MVC is not gonna take care of the data binding, The name (on parameter controlName) should and NEED to use other name instead. Change “Cakes” to any other name, for example, change to “MyCakes”:

<%=Html.MyDropDownList(“Dessert.MyCakes”, Model.CakeList, new { @class = “multiselect”, size = 5 })%>

2. Extension is changed to:

public static MvcHtmlString MyListBoxWithSelectedList(this HtmlHelper target, string name, IQueryable<Cake> cakes, List<string> selected, object htmlAttr)
{
if (interests == null)
return MvcHtmlString.Empty;
var cakeList = new MultiSelectList(cakes, “Id”, “CakeName”, selected);
return target.ListBox(name, cakeList, htmlAttr);
}

I just add a parameter “List<string> selected” in the extension which will be used in MultiSelectList object that can be bind to the the items to be selected.

3. In controller, before saving the data, need to use FormCollection or Request["Dessert.MyCakes"] to obtain the data “MyCakes” manually.

string myCakes = Request["Dessert.MyCakes"];
Dessert dessert = new Dessert{Cake = myCakes};

It might not be a bug actually. And in this example you can feel how flexibility that MVC can bring you: the way to manipulate the model or data varies!  :)

Happy programming in MVC 2!



Hailstorm Late Updates

Thursday, March 11th, 2010

All photos are copy-right by David Jones.



Profile

Submit Your Site To The Web's Top 50 Search Engines for Free!