Friday, December 16, 2011

Boot-Repair

If Windows power management is bad, Ubuntu's is even worse.  I have two computers which are unfortunate enough to run on Intel Graphics.  The graphics cards on both failed to resume after they went to sleep.

One way to fix it is to edit the GRUB options.  You can do it the hard way by looking up options for GRUB and editing the GRUB setting file.  Alternatively, there is a graphical utility to make you life easier.

https://help.ubuntu.com/community/Boot-Repair

Friday, December 2, 2011

Retrieving personal details from Active Directory

If you are programming in C#, you can access information held on Active Directory easily using the code below.

Below uses the libraries provided in DirectoryServices namespace to query the Active Directory such as a user's telephone number, email address, etc.  As you can see, it is very straight forward (at least compared with tutorials I have seen using LDAP)

<% System.DirectoryServices.DirectoryEntry directoryEntry
= principal.GetUnderlyingObject() as
System.DirectoryServices.DirectoryEntry; %>


<%: principal.DisplayName %>

Tel: <%: directoryEntry.Properties["telephoneNumber"].Value%>

Email: <%: directoryEntry.Properties["mail"].Value%>


Although it looks like classes in DirectoryServices are wrappers to equivalent LDAP calls, it is certainly a lot cleaner and easier to understand (in my opinions)

The full list of properties you can retrieve can be found on

Sunday, November 27, 2011

Ubuntu and power saving

With Ubuntu 10.04, there was one thing that really bugged me.  Every time when I unplugged the power, the netbook would go into a sort of sleep mode.  I needed to reboot the machine at twice to get back.

With Ubuntu 11.10, I can report this problem has been fixed.






Friday, November 25, 2011

EAC is crashed by Adobe Drive ...

I have been using EAC for a long time and have never had a problem before until today.  I had installed EAC on my laptop with 64bits Windows 7.   Everytime I ran it, it crashed miserably.  Initially I thought it is the problem with compatibility or permissions, so I tried to run EAC as Windows XP compability mode and as administrator.  Needless to say both failed.

After a bit of searching, it seems th culpit is Adobe Drive in CS4 as suggested on

http://www.digital-inn.de/exact-audio-copy-english/37892-eac-crash-vista-x64.html

I did as suggested to deregistered the two Adobe Drive DLLs, and my problem fixed.

regsvr32 /u "%CommonProgramFiles%\Adobe\Adobe Drive CS4\ADFSMenu.dll regsvr32 /u "%CommonProgramFiles%\Adobe\Adobe Drive CS4\AdobeDriveCS4_NP.dll

Intel CPU Whines ...

I have a Clevo N540R laptop and it has been doing well with one exception it makes high pitch noise occasionally.  I have checked the cooling fan and it seems okay.  After checking all the usually suspects, I ran out of ideas.  Then I hit Google and search for the term "laptop high pitch noise".  Guess what, I am not alone.  This seems to be quite a common problem, and surprisingly it is related to the Intel processor.  It seems it is something to do with the processor goes to C1 idle state.

see: http://superuser.com/questions/121883/any-way-to-disable-specific-cpu-idle-cx-states

Initially I thought, it can't be, can it?  I followed the instructions posted on one of the forum as below:




1) Typing in the command line "regedit", you go to the registry key:


HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Power \ PowerSettings \ 54533251-82be-4824-96c1-47b60b740d00 \ 5d76a2ca-e8c0-402f-a133-2158492d58ad


2) To enable one or another hidden parameter, it is necessary to find and edit the value DWORD, changing its value SettingValue from 1 to 0.

3) Then, through the control panel – power – in the settings mode select power management processor.
There will be an option disabling idle processor and high pitched noise immediately disappears.

Guess you can guess the result.  My problem went too!

(original solution from : http://forums.whirlpool.net.au/archive/1526684)


Tuesday, November 22, 2011

Permission ... NTFS

Today I came across this handy command prompt tool Xcacls.exe which allows user to view and set permission in command prompt. GUI is great for most situations, but there are time you can do it easier and faster with a single command rather than thousand clicks.


http://support.microsoft.com/kb/318754



Tuesday, November 15, 2011

WCF and Windows Authentications

Lately, I need to write a desktop application that needs to use a web service protected by Windows Authentication.

Most of the tutorials show you how easy it is to use a web services, and it is really easy till you hit the way of Windows Authentication.  To get around it, you can try to want to check out this blog I found.  It shows you how you can setup BasicHttpBinding to pass the Windows Authentication.

WCF BasicHttpBinding with Windows Authentication & a 2.0 Client

Monday, October 31, 2011

Security Groups and Policies for a Windows User

In Windows environment, resources authorizations are usually done by checking a users security policy.  When you are writing a program, you often need to find out your own security group/ policy, so you can test your program with your own credentials.   However, it isn't always convenient to bother the system administrators to get details of your settings.

In a situation like this, you may want to try the tool gpresult

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/gpresult.mspx?mfr=true

With it, you can see settings about yourself.

v-tools and Access

If you have inherited an Access database from someone, one of the problems you may face is finding your way round.  As things can be done as queries, forms and modules etc., it can be a bit difficult to find your ways.

I have recently come across this tool called v-tools.  It offers many features for Access database, but the one I found it most attractive is the ability to do "deep searches" on all objects.  For example, if you search for the "Orders", it will look for all objects such as tables, queries, modules etc and show you any involved.

Did I also mention it is free?

Wednesday, October 19, 2011

Routing paramaters in MVC

In .NET MVC, you can access the routing parameters by using RouteData property of the ViewContext object similar to below.

ViewContext.RouteData.Values["id"]

Saturday, October 15, 2011

Ubuntu 11.10 ... and its problems

Ubuntu 11.10 seems to be the worst I have tried so far.  Since my graphics card isn't new enough to support the new graphics features, I can tell the visual part of the system.  However, it broke my sound.  Now my system is "silent"

After upgrade, the system failed to detect my


00:1f.5 Multimedia audio controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) AC'97 Audio Controller (rev 02)

I am a system user, and I just want a system work.  Guess with Ubuntu ... it seems it is still too much to ask!

Update:

At last I found this website.

http://ubuntuforums.org/showthread.php?t=205449

By following the instructions, I at least managed to get sound back (sort of).

For some unknown reason, snd-intel8x0 was backlisted. Once I comment out the snd-intel8x0 in the /etc/modprobe.d/blacklist-alsa.conf , I got my sound back (well on speaker out jack anyway. My tower is a business machine with internal speaker. Still have no sound with the internal speaker. Nevertheless, it is a progress)

# blacklist snd-intel8x0

Friday, September 23, 2011

Ubuntu, KVM and Resolution

Ubuntu is a nice alternative to Windows.  I have tried few distros like Redhat, SuSe, Mandrive, and Ubuntu is the distro I finally settle mainly because of the APT package system.  I do like to use Linux but I don't like to "fix" Linux.  Flexibility and customizability of Linux to me is a double edged sword, it is great for enthusiasts, but terrible to people just want to use.  Ubuntu is closest I can found (mind you, there is always something better in Linux world)

However, there is one essential thing I really hope can get fixed that is setting the resolution of a monitor.  Yes, there are GUI tools for it but they all seem to work only if the auto detection work.  For instance, if the monitor is connected through KVM, you are out of luck.  You are most likely need to set it manually, and doing so it isn't not nice at all.

For instance, I have recently moved to a newer version of Ubuntu which uses a newer implementation of XOrg.  Unfortunately, the changes made in the new XOrg breaks the driver of my old AGP GeForce graphics card.  I don't really bother too much about all these 3D thing, but one nice feature of a property GeForce driver is its ability to force a resolution and a refresh rate graphically (okay I am still using a CRT monitor).  Without the nVidia driver, I need to do things manually.  To make things even more complicate, the old xorg.conf has been demoted in favor of something else (though you can still use it)

Anyway, cutting a long story short, I had tried a few settings combinations and with my limit knowledge and impatience, I gave up after ending up many times in recovery mode (so I can change my xorg.conf settings)  I finally gave up on my GeForce 400MX card and replaced it with a Radeon 9600 card.  And this time, things is a bit easier.  I can use the xrandr to set the resolution and refresh rate using the instructions from this site:

http://www.ubuntugeek.com/how-change-display-resolution-settings-using-xrandr.html

Except, I put all these commands in a script file, and call this script file within the /etc/gdm/Init/Default

As I said at the beginning, I would prefer this can be done graphically so average users like myself can do simply basic things such as setting resolutions and refresh rate easily without the need of editing setting files with text editors.

Wednesday, September 21, 2011

I was testing my MVC2 application on a new IIS server setup by my colleague.  However, when I tried to run it, I got error said it can't locate the file.  Then I poked around the server to see if there were any setting mistakes.  When I hit the .NET Compilation option on the Site settings, I got an error.  After a bit of research on Google, it seems this problem was caused by the order of installation.

It seems if IIS server was installed after the .NET installation, the IIS will not pick up the necessary changes made by .NET Framework installer to run the MVC2.  To fix it, you can run the aspnet_regiis tool within the .NET folder (located in %windir%\Microsoft.NET\Framework\v4.0.30319) with the iru option as suggested in Scott Hanselman's blog http://www.hanselman.com/blog/ASPNET4BreakingChangesAndStuffToBeAwareOf.aspx.

In Scott's blog, he suggests to enter the command as

aspnet_regiis -iru

However, on my Windows Server 2008 (NOT R2), I found the -iru didn't work, but /iru works, e.g. aspnet_regiis /iru.  Therefore, I would suggest you to try using /iru if -iru did not work for you.

Further references can be found at: http://msdn.microsoft.com/en-us/library/k6h9cz8h%28v=VS.100%29.aspx

Tuesday, September 13, 2011

Access ... thanks Microsoft for another problem!

Today I have this funny problem which Access and OleDB gave me two different results for the same view.  After hours of puzzling, finally found out it is because of the wild card used in the LIKE clause.

The story as follow, I have a view in Access similar to the below

select * where code like '*fun*'

This works fine within Access, i.e. only result contains "fun" returned.  However, when I accessing this view within VisualStudio via OleDB, the conditional clause was ignored.  Since I am accessing the same view within the same Access database, it really puzzled me why the different results returned, especialy there was no errors returned.

Initially I thought it was because of caching, so I restarted my machine.  Run the query within Visual Studio after restart, same problem.

Then I removed the connection within Visual Studio and recreate it as I thought it may caused by wrong settings.  Again, same problem.

Finally, I  replaced the * with % as I would write my LIKE in standard SQL. Bingo, everything works as intended.

Thanks Microsoft.  Can you not try to be special and screw things up?!

Tuesday, August 30, 2011

Session and .NET application

It seems session ID does not created until it is first used, i.e. you may get an error when you are trying to retrieve it the first time. To avoid this, you may consider to put something similar to below in your Global.asax file if you are using .NET


protected void Session_Start(object src, EventArgs e)
{
// http://stackoverflow.com/questions/904952/whats-causing-session-state-has-created-a-session-id-but-cannot-save-it-becaus
// This is needed in order to maintain a stable session id
// it seems the session only got created at its first used. The line below just does that!
string sessionId = Session.SessionID;
}

source: as stated in the comments of the codes.

Tuesday, August 16, 2011

MVC2 Ajax and Date

With .NET MVC2/3, you can serialize an object into JSON easily by using the JSON(object) function. However, there is a minor issue you may want to watch out. In .NET, DateTime object is serialized as an signed long integer of the milliseconds sing the January 1, 1970. If you use the normal eval() method to convert the JSON string into objects, you will get the date evaluated wrong.

Instead you should use the Sys.Serialization.JavaScriptSerializer.deserialize() function (as below) instead.

var a = Sys.Serialization.JavaScriptSerializer.deserialize(context.get_data());




Also see: http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx

Friday, July 22, 2011

JQuery UI Autocomplete and MVC

Today I have my fun with the Autocomplete feature of JQuery with .NET MVC back-end.

For once the Microsoft solution is not the trouble, but the JQuery is. To cut the story short, here is what I wanted to do:

  1. a textbox allowing a user to enter a post code
  2. use this post code to locate matching address from the database
  3. display the address NOT the post code on the drop down list.
  4. when an address selected, complete the post code and the address on the form.
As I am using MVC2 framework for my server side programming, it is trivial to do the query and to pass back the data in JSON format.

[HttpPost]
public ActionResult GetAddresses(string term)
{
AddressEntity _en = new AddressEntity ();
var addresses = _en.Addresses
.Where(p => p.PostCode.Contains(term))
.OrderBy(o => o.StreetName)
.ToList();

// .net is quite happy to serialize an object to
// json representation.
return Json(addresses);
}
The Json() function will nicely serialize the object in JSON format for you. To prove this work, I use IE9's developer tool to check the response body



Now, the tricky part. There are so many different tutorials on this very subject, and some are a bit out-dated. For example, to use the Autocomplete, you do not need to use the plug-in anymore, but to include the JQuery UI library as it is part of the standard UI library.

Anyway, here are things that works for me.

Firstly, include the following library and styles in the head section of your HTML page

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"></script>
<link rel="stylesheet"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css" type="text/css" media="all">

Next, create a Textbox and give it a unique ID

// this will generate HTML equivalent
// <input id="postTags" type="text">
<%: Html.TextBox("postTags") %>

Lastly, include the script similar to below:

$("#postTags").autocomplete(
{
source: function (request, response) {
$.ajax({
url: '<%=Url.Action("GetAddresses", "Home") %>',
type: "POST",
dataType: "json",
data: {
term: request.term
},
success: function (data) {
response($.map(data, function (item) {
// remap the object to the structed used by Autocomplete
return { label: item.FullOfficialName, value: item, id: item.ID }
}))
}
}); // end .ajax
},
minLength: 2,
select: function (event, ui) {
$("#Street").val(ui.item.value.StreetName);
$("#postTags").val(ui.item.value.PostCode);
// according to the documentation, cancelling the event, i.e. return false
// will prevent the default replacement action.
return false;
}
});

Here are some explanations.

In this example, the source is from an external source, and is obtained through AJAX. The source: function (request, response) specifies where the source is.

For the source option, you may notice the URL is generated dynamically using
<%=Url.Action("GetAddresses", "Home") %>
Effectively, it generate a URL similar to this "/Home/GetAddresses"

Another important option is the dataType. It is important to set it to json, so the response will get handled correctly.

Now, the most important part. It seems the array used by the Autocomplete is an array of object which has 3 fields, label, value, and id. Since our object may carry more (or less) information, we need to do some transformations, hence the function:

success: function (data) {
response($.map(data, function (item) {
// remap the object to the structed used by Autocomplete
return { label: item.StreetName, value: item, id: item.ID }
}))
}
The purpose of this function is to use the map function to transform the objects in the array retrieved from the server to the objects with the format used by Autocomplete array.

The label field is used by Autocomplete for the text displaying to the user, the value is the value used when an option is selected and finally, the id is the ID of the option.

As stated before, in my situation, I need all the information from the server, therefore I decided to set the value as the object itself. However, this causes a problem. When an option is selected, the value inserted to the textfield is [object] rather than the post code I wanted because the system do no know how to render my object.

In order to overcome this, I customize the select event handler as following

select: function (event, ui) {
$("#Street").val(ui.item.value.StreetName);
$("#postTags").val(ui.item.value.PostCode);
// according to the documentation, cancelling the event, i.e. return false
// will prevent the default replacement action.
return false;
}
This handler is invoked when a selection is made, and it will retrieve and use the correct fields in my object for various part of my form. One important note, at the end of this function, you need to return false to stop the default behavior, otherwise, the #postTags will still be shown as [object] as before.

Wednesday, July 6, 2011

Composite keys

If you have a database table which holds keys from another two tables and you do not want duplications, you may want to do the following


ALTER TABLE
ADD UNIQUE (, )


Now the database will ensure not entries have the same key1+key2 combination!

Friday, June 24, 2011

Describe the structure of a table in SQLServer

You can get the structure of a table on SQL Server using the query

exec sp_help 'tablename'

Thursday, May 26, 2011

Google Code University

Just came across the Google code University, and find the materials there are very useful to refresh the distance memory of "Programming Lectures" had in University years years ago ... and something new too

http://code.google.com/edu/courses.html

Sunday, March 6, 2011

DVD Writers

I am a big fan of NEC/Sony DVD drives as they can easily be made region free. However, while they are good DVD writers for single layer disks, they seems to be a bit of hit and miss when it comes dual layers disks. I have also tried Samsung DVD writers both the desktop and laptop version. Needless to say, they are even worse (okay the models I have anyway). They are slow to read, rubbish at writing. Anyway, at the end, it seems the best writer I have for DVDs (both single and dual layers) is the LG writer I have.

Recently, I have got myself a netbook for its portability, so I am getting a new portable writer to go with it. I was thinking to get a LG writer but the review seems not so good for its reliability (hardware not writing reliability). Hence, I took my chance and ordered an LiteOn writer instead (LiteOn ... it is a mix big on reliability too) as I have already had writers from NEC/Sony, Samsung and LG. LiteOn is the only brand that I haven't own yet. Guess I just need to wait and see ...

Update: With the original firmware came with the drive, it is bad. However, after the drive with the latest firmware from LiteOn, it is okay. I have two brands of DVD+DL. It can burn on some of them okay.

Friday, January 21, 2011

Remote Desktop Through Router

I have been told this wonderful software called Ammyy for remote desktop today, and it works great as said on the tin (even behind the router) So, if you have lucky enough to be nominated as the family IT guy and can't stand to talk to them over the phone, you may want to try it.