Posts

Showing posts from 2011

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...