Author: DMR

Software developer and consultant at Geodata AS, Norway
Calendar
<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
romslo , Posted at 7. November 2010, 20:28

romslo , Posted at 2. September 2010, 11:38

Here are some macros copied from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=37871 to simplify bit manipulation in C:

#define bit_get(p,m) ((p) & (m))
#define bit_set(p,m) ((p) |= (m))
#define bit_clear(p,m) ((p) &= ~(m))
#define bit_flip(p,m) ((p) ^= (m))
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
#define BIT(x) (0x01 << (x))
#define LONGBIT(x) ((unsigned long)0x00000001 << (x))

romslo , Posted at 30. August 2010, 13:17

I always end up googling for this information. Therefore I add it on my own blog as a personal note.

~ Invert
& AND
| OR
^ XOR
<< Shift left
>> Shift right

Use these in combination with = to store the result to a variable.

Examples (using AVR-GCC)

PORTB |= (1<<PB5);                     //Put Port B bit 5 HIGH
PORTB = (1<<PB2)|(1<<PB5);      //Put Port B bit 2 and 5 HIGH

PORTD ^= (1<<PD6);                   // Toggle PortD bit 6

PORTD &= ~(1<<PD5);                 // Put PortD bit 5 LOW

romslo , Posted at 30. July 2010, 16:55

I’ve just bought a new laptop, and need to do the initial installation routines. If you want to speed up the process of installing basic software, you should take a look at http://ninite.com/

Here you select the programs you want to install, and you download a tailor-made installer package that includes all the programs selected. The installer automatically says ‘NO’ to all toolbars questions and other junk.

You will find many of the applications mentioned in My toolbox at Ninite.

I don’t use TSQL enough to have even the simplest commands “in my fingers”. When I do performance debugging of a procedure, I often use datediffon datetime variables.

Here is an example, so that I can use this posting the next time i forget the syntax:

 

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
CREATE PROCEDURE MyProcedure
    
AS
BEGIN
    
    declare @timer datetime;
    set @timer = GETDATE();
    
    -- DO YOUR REAL WORK    
    waitfor DELAY '00:00:02' -- Sleep two seconds
 
    print 'Timings: ' + cast(datediff(ms, @timer, GETDATE()) as char(10)) + 'ms'
 
END
GO

 

When this procedure is executed it prints out:

Timings: 1996      ms

We know from the ASP.NET Configuration File Hierarchy and Inheritance that configuration of child applications is inherited from the root web.config. This may lead to unwanted behavior and/or runtime configurations errors.

One solutions to this, is to explicitly mark sections in your root web.config not to be inherited by child applications by using the <location> element. E.g. if you want to make sure that the entire <system.web> section won’t be inherited, the root web.config should look something like this:

   1: ...
   2: <location path="." inheritInChildApplications="false"> 
   3:  
   4:     <system.web>
   5:         <!-- Configuration that won't be inherited by child applications -->
   6:     </system.web>
   7:  
   8: </location>
   9: ...

 

For more details on InheritInChildApplications see MSDN.

romslo , Posted at 15. October 2009, 21:00

As a follow-up to my previous TC posting, I also noticed that the default Total Commander configuration does not show icon overlays on files and folders, e.g. files under source control administered by TortoiseSVN.

To enable icon overlays, go to Configuration > Options… and check ‘Show overlay icons, e.g.for links’ under Display > Icons:

tc_overlay

romslo , Posted at 6. October 2009, 21:48

I assume every (.NET-)developer today uses unit tests and do TDD (Test Driven Development) at some degree.

I have used NUnit and Visual Studio Unit Test Framework. NUnit is very simple to use and requires little extra coding. Visual Studio Unit Test Framework is also very simple to use, but I think Visual Studio does too much for me when a create a new test project by the wizard. E.g. it generates empty test methods for the assembly to test. I never use this “feature” anyway because:

1. It only create one test per method to test. Usually I want to test methods under different conditions/states, and want to create one test per condition/state.

2. I don’t agree with the naming of the methods.

Probably there are a lot of TDD gurus out there having an opinion about unit test naming conventions and where to write the tests. One of them is definitely Roy Osherove, who has written the book The art of unit testing. It is important to follow the same patterns and conventions within a development team, so I suggest to follow Osherove’s conventions.

 

Test project naming

I think it is a good idea to separate unit test from integration tests. (Take a look here for definitions and an explanation of the differences)

By placing these test categories in different projects (assemblies) with proper naming conventions, it is easier to configure a CI build server to e.g. run only unit tests on each check-in and all tests on nightly builds.

For unit test projects, use:

[ProjectToTest].Tests.Unit

For intergration test projects, use:

[ProjectToTest].Tests.Integration

Test class naming

Usually I make one test class per class to test, and I use the following naming convention for the class and file name.

Class name:

[ClassToTest]Tests

File name:

[ClassToTest]Tests.cs

Test method naming

I like the naming conventions described here.

The basic naming of a test comprises of three main parts:

[MethodName_StateUnderTest_ExpectedBehavior]

Examples:

Divide_DivisorIsZero_ExceptionThrown()

Divide_DividendIsZero_ReturnZero()

 

For happy-day scenarios, use:

[MethodName]_HappyDay

Example:

Divide_HappyDay()

Recently I decided to use a standard ADO.NET typed DataSet as a container for caching, before data were serialized to XML. I have done this several times before, and haven’t met any trouble. What was new in this scenario, was that the cache was used quite intensively and had to handle thousands of entries. I experienced that the application cache became very slow when the number of items reached around 5000 entries.

The solution to this, as the title of this post indicates, was to call the BeginLoadData method on the tables in the typed DataSet on cache initialization. This gave a performance boom. The reason is documented here (http://msdn.microsoft.com/en-us/library/system.data.datatable.beginloaddata.aspx):

Turns off notifications, index maintenance, and constraints while loading data.

 

I wrote a simple performance test for adding entries to a DataSet; one with default usage and one that calls BeginLoadData before entries were added.

dataset_performance

The above graph tells that this was absolutely necessary. (Note that the interval for number of items (on the x axis) grow exponentially.)

romslo , Posted at 3. October 2009, 21:09

After a long break from blogging, I’ll try to start on again. I’ve met many interesting programming challenges during the last months, so I have a list of topics that will make the foundation for my coming postings. I’ll also try to lower the bar (even more) for topics that qualify for a blog post.

My toolbox is actually a little bit bigger than the current version. I’ll put a posting when I add new tools to it.

Since my last posting in April, Twitter has become the new hype. I haven’t discovered the usefulness of this, but had to give it a try and created an account. You can also follow my latest tweets through the Twitter-widget in the right column of this blog. I would appreciate some discussion on my first tweet.