Posts

Android : Properties for SHAPE xml

What are the properties you can use when you're creating a SHAPE xml for styling your layout such as gridview or button? Please check this link out :- http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

Android Programmatically apply style to your view

Applying style to your view (button in this case) dynamically is pretty easy. All you have to do is place the following in your layout folder (res/layout) Let's call this file : buttonstyle.xml <?xml version="1.0" encoding="utf-8"?> < selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape> <solid android:color="#449def" /> <stroke android:width="1dp" android:color="#2f6699" /> <corners android:radius="3dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> <item> <shape> <gradient android:startColor="#449def...

RhinoMock to return different value based on method parameter

How do you return different values based on different parameter in a mocked object using RhinoMock? Maybe there are other ways of doing the same thing. These are the two methods that i know. Lets say i have the following interface that i wanna mock. public interface ITest { int Test(string data); } [TestMethod] // Method #1 public void ExpectConditionalMethodInputParameter() { var mock = new MockRepository(); var subject = mock.DynamicMock (); int result; With.Mocks(mock).Expecting ( delegate { Expect.Call(subject.Test(Arg .Is.Equal("1"))).Return(100).Repeat.Any(); // Set expectation input parameter1 Expect.Call(subject.Test(Arg .Is.Equal("2"))).Return(200).Repeat.Any(); // Set expectation input parameter2 } ).Verify( delegate { result = subject.Test("2"); // Returns 200 if parameter is 2, return 100 if parameter is 1 } ); } [Tes...

Efficient way of representing Date

What is an efficient way of representing date? Try the following code (Taken from Art of Computer Programming Vol 4) var y = 2012; // Year 2012 var m = 6 // June var d = 30 // 30th day on the calendar month // Efficient representation (packing) var result = (((y Breaking this down further, we have (y Binary representation for 2012 is : 11111011100 Left shift by 4 : 111110111000000 Next we have, ((y 111110111000000 + 110 (m = 6) = 111110111000110 Left shift 5, becomes 11111011100011000000 Next we add the days to it which bring us to the following equation 11111011100011000000 + 11110 = 11111011100011011110 ( Decimal : 1030366) So our final result is : 1030366 // Unpacking var day = result%32; 1030366 % 32 = 30 (once you have this, the rest is pretty straight forward) var month = (result >> 5) %16; var year = result >> 9; Is there any other alternative for doing this? Maybe for other data types such as telephone.

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly

It is quite often that developer encounter the following error when creating WCF application in IIS 7. Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Resolution : goto your Microsoft.NET Framework folder and run aspnet_regiis /iru The switch /iru - Reinstall this version of ASP.Net without forcing existing application to use this version. More information from this link .

Nuget quick guide

Create your own package using nuget.exe. At this point, you need to have your .nuspec file and the files (.dll/static files) organized in folders that you wish to deployed. Sample command line that you might use is as follows: c:\nuget pack test.nuspec You may have folders as follows lib --\NetFramework 4.0 --\NetFramework 1.1 Sample layout of your .nuspec file are <?xml version="1.0" encoding="utf-8"?> <package> <metadata> <id>sample</id> <version>1.2.3</version> <authors>Kim Abercrombie, Franck Halmaert</authors> <description>Sample is an example package that exists only to show a sample .nuspec file.</description> <language>en-US</language> <licenseUrl>http://sample.codeplex.com/license</licenseUrl> <projectUrl>http://sample.codeplex.com/</projectUrl> </metadata> <files> <file src="lib\*.dll" targe...

.Net v4 vs v2 - In-Process Side-by-Side

In-Process Side-by-Side, or In-Proc SxS is a process whereby assemblies written in .NET4 and .NET2 co-exist together in runtime. This is possible because a process is able to host multiple version of .NET CLR in a single process. This means if an application is recompiled to run against the .NET Framework 4 runtime and still has dependent assemblies built against .NET 2.0, those assemblies will load on the .NET 4 runtime transparent to the user. It faces problem (if .NET4 runtime is used) in the following areas: a) Shell Extension support is limited. Application built with earlier version wil fail. b) C++/CLI section which specifically states that a pre-2.0 mixed mode assembly can only load in a v2 CLR. The v4 CLR does not support this scenario. There is no solution to this problem. You have to recompile the mixed mode assembly under v4 or switch back to v2 for your application. http://msdn.microsoft.com/en-us/magazine/ee819091.aspx

Building Mongodb on Fedora

The documentation provided by mongodb to build on Fedora is pretty accurate. Here is the link to the document . Just have to make sure that you have got all the required tools like boost and scons that is vital for the build. Build can be trigger using the following command: scons all

Compiling mono on Fedora 12.

It is really easy, just following the instruction from here and set the prefix to your preferred build directory; For example, set the mono binaries to /tmp/mono_build. ./configure --prefix=/tmp/mono_build; make; make install That's it.

Enterprise Library configuration without using App.config / Web.config

Sometimes you might want your Enterprise Library logging configuration file to kept separately and maybe you're not going to put an entry even in your web.config using [Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection]. The following codes shows how this can be accomplished:- // Assuming the configuration file is default [loggingConfiguration] and in your current .exe directroy FileConfigurationSource fileSrc = new FileConfigurationSource("Test.config"); // If you would like to validate your configuration // var loggingSection = fileSrc.GetSection("loggingConfiguration"); LogWriterFactory wfac = new LogWriterFactory(new FileConfigurationSource("Test.config")); var Writer = wfac.Create(); LogEntry logEntry = new LogEntry(); logEntry.Message = "Life"; Writer.Write(logEntry); Your new configuration file is ca...

.Net Performance notes

Some performance notes that i got from MSDN. JIT compiler performs the following optimization given the small amount of time: •Constant folding •Constant and copy propagation •Common subexpression elimination •Code motion of loop invariants •Dead store and dead code elimination •Register allocation •Method inlining •Loop unrolling (small loops with small bodies) Value types, including integral types, floating point types, enums, and structs, typically live on the STACK. Reference types and boxed value types live in the HEAP. They are addressed by object references, which are simply machine pointers just like object pointers in C/C++. NGEN, a tool which "ahead-of-time" compiles the CIL into native code assemblies 9 million allocation Type Size of Allocation Execution Time string 575,783 00:00:2739811 int 8620 bytes - 40 instances 00:00:2515444 short 10472 bytes - 238 instances 00:00:2538425 employee 1,440,457,523 ...

Network Monitor MSI / Setup give Error Opening log file

When you try to install using Microsoft MSI, you bump into the following message “Error Opening Installation log file. Verify that the specified log file location exists and is writable” Workaround, extract the .exe file by using the following command below NM33_x86.exe /c /t:c:\tools\networkmonitor the /t switch is used to tell installer where to extract the file. Then try to run netmon.msi to install network monitor. I tried it with Network Monitor 3.3 and it works (Netmon.msi and Microsoft_Parsers.msi)

Streaming Algorithm

This is going to be an ongoing update to some interesting streaming algorithm that i found over the web. If anyone have any input, please let me know. -- Haven't really work on it yet --

Recommendation algorithm

This is going to be an ongoing update to some interesting recommendation algorithm that i found over the web. If anyone have any input, please let me know. Contextual-Bandit algorithm - Li Long, Wei Chu, J.Langford, R.Schapire -Adapting machine learning approach for recommending advertisement, news and other articles to users. Nearest Neighbour Algorithm - To be updated :) Resources : Nearest Neighbour Algorithm ( This give a really easy to understand overview of the algorithm - far better than alot of the lecture notes given by professors ) http://people.revoledu.com/kardi/tutorial/KNN/index.html

Case sensitive in JQuery class selectors

When you're using jquery's class selectors for example, $('a.lookupScript'), it will work in Mozilla but not on IE. So you gotta make sure that you got the case right. :)

Determining IIS version your server is running on.

I got this from Microsoft Support site... :) Version Obtained from Operating System 1.0 Included with Windows NT 3.51 SP 3 (or as a self-contained download). Windows NT Server 3.51 2.0 Included with Windows NT Server 4.0. Windows NT Server 4.0 3.0 Included with Windows NT Server 4.0 Service Pack 3 (Internet Information Server 2.0 is automatically upgraded to Internet Information Server 3.0 during the install of SP3). Windows NT Server 4.0 4.0 Self-contained download from www.microsoft.com or the Windows NT Option Pack compact disc. Windows NT Server 4.0 SP3 and Microsoft Internet Explorer 4.01 5.0 Built-in component of Windows 2000. Windows 2000 5.1 Built-in component of Windows XP Professional. Windows XP Professional 6.0 Built-in component of Windows Server 2003. WIndows Server 2003 7.0 Built-in component of Windows Vista and Windows Server 2008. Windows Vista and WIndows Server 2008

Illegal character in Firefox

Firebug detected an illegal character while loading javascript, to fix this just have to open up the javascript with a proper texteditor and remove those illegal character. Pretty simple i guess. You can find more info from here

JQuery binding / unbinding event in Firebug

This article provides a good overview of what's going on in Jquery during bind/unbind of an event in firebug. http://ajaxian.com/archives/jquery-bondage#comments

WCF: This collection already contains an address with http scheme.

Ran into this problem earlier. The solution can be located here http://social.msdn.microsoft.com/forums/en-US/wcf/thread/12003fe3-917b-47fa-b768-a7914a374e66/ and http://geekswithblogs.net/robz/archive/2007/10/02/WCF-in-IIS-with-Websites-that-have-Multiple-Identities.aspx o

User control event/viewstate missing during postback

User control event/viewstate missing during postback Question : Some of your web control's events goes missing or cannot be caught when you load it in a user control? Answer: Always use the Control.UniqueID generated for you by ASP.Net when assigning it to a NAME property of your control. The complete Control.UniqueId is available when you assess this in OnPreRender stage. Check your Control.UniqueID which is render into the NAME property of your control on a HTML page. ASP.Net keeps track of the control using Control . UniqueID which makes events / viewstate works. If you override your UniqueID (for javascript manipulation) you might get this problem. Why does it work on your Page but not in user control? On a page, when your control is renders, it probably use name like “MyControl” but in user control this is automatically change to “ctl$_MyControl”. ASP.Net is no longer able to resolve your control id if you override your Control.ID. For example, I created a...