The GitHub way of blog discussion and commenting

April 28, 2013 – software

Using the underlying power of GitHub, blog authors often take a step further and roll their own discussion and commeting systems.

The best examples are:

With the evolution of blog-aware static site generators, like Jekyll, GitHub is becoming a central part for hosting both blog content and comments.

Hackers, Developers, Programmers

April 18, 2013 – software

The definitions about Hackers, Developers, and Programmers, that I like best are:

“Hackers are generally loners who don’t care if others can figure out their code (at least while they are in the mode or role of hacking). Thus, they build their own little world in it that fits themselves nicely so that they can hack fast, but the rest of the world be damned.” — c2.com/wiki

“On the ‘programmer’ vs. ‘developer’ debate: ‘Programmer’ focuses on the ‘craft’. ‘Developer’ focuses on the business. Both are valuable.” — @ploeh on twitter

I am a programmer — You?

xUnit.net Attributes Execution Order

March 10, 2013 – unit testing

The test below uses the xUnit.net framework and executes twice, since it is decorated with two data sources. The first data source is the built-in [InlineData] and the second data source is the custom [StringData].

[Theory]
[InlineData("foo", "bar")]
[StringData]
[Intercept]
public void Test(string a, string b)
{
}

xUnit.net invokes in exact order:

Initialization

  1. [InlineData] consturctor
  2. [StringData] consturctor
  3. [InlineData] IEnumerable<object[]> GetData(MethodInfo, Type[])
  4. [StringData] IEnumerable<object[]> GetData(MethodInfo, Type[])

1st Run

  1. [Intercept] consturctor
  2. [Intercept] void Before(MethodInfo)
  3. [Theory] supplying values for a and b taken from either [InlineData] or [StringData]
  4. [Intercept] void After(MethodInfo)

2nd Run

  1. [Intercept] consturctor
  2. [Intercept] void Before(MethodInfo)
  3. [Theory] supplying values for a and b taken from either [InlineData] or [StringData]
  4. [Intercept] void After(MethodInfo)

Remarks

[Intercept] is defined as:

internal class InterceptAttribute : BeforeAfterTestAttribute
{
    public override void Before(MethodInfo methodUnderTest)
    {
    }

    public override void After(MethodInfo methodUnderTest)
    {
    }
}

It allows code to be run before and after each test is run.

[StringData] is defined as:

internal class StringDataAttribute : DataAttribute
{
    public override IEnumerable<object[]> GetData(
        MethodInfo methodUnderTest,
        Type[] parameterTypes)
    {
        yield return new object[] { "cow", "zoo" };
    }
}

XCOPY deployment for Code Contracts

March 4, 2013 – microsoft visual studio

If you don’t wish to install Code Contracts through the Windows Installer:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <CodeContractsInstallDir Condition="'$(CodeContractsInstallDir)'==''">CONTRACTS_PATH</CodeContractsInstallDir>
  </PropertyGroup>
  <Import Condition="'$(CodeContractsImported)' != 'true' AND '$(DontImportCodeContracts)' != 'true'" 
          Project="$(CodeContractsInstallDir)MsBuild\v4.0\Microsoft.CodeContracts.targets" />
</Project>

Legacy Code Risk

March 3, 2013 – legacy code

Taking the risk to adjust the architecture of a legacy system and extend it in a nice and clean way.

Creating a context:

(All the above yield sad customers, bugs, and slow performance.)

Against messy, tightly coupled, legacy code.

Why it is a risk?

The above require a few changes in the system architecture (e.g. in order to be possible to not use Service Locators, in order to be possible to use Services to query from the database instead of the Active Record way, etc.).

While the required changes are going to (initially) slow down the development process at the end the overall development is going to be faster.

Would you take the risk?

Database Schema Synchronization with SqlPackage.exe

February 11, 2013 – microsoft visual studio

SqlPackage is the descendant of VsDbCmd command-line tool. It creates, deploys, and packages SQL Server databases snapshots into a portable artifact called a DAC package, also known as a DACPAC.

Manual Database Schema Synchronization

Automatic Database Schema Synchronization

When there is no network access in production environment, the synchronization process can be automated.

Thanks to Dimitris Charalampidis who provided the steps below, the database schema synchronization can be automated as follows:

sqlpackage.exe /a:Script /sf:$Yourdatabaseproject.dacpac$ /tcs:"Data Source=$ServerName$;Database=$DatabaseName$;User id=$userid$;password=$password$;Trusted_Connection=false;" /op:DBSchemaCompareScript.sql /p:ScriptDeployStateChecks=True /p:BackupDatabaseBeforeChanges=True /p:IgnoreExtendedProperties=True /p:IgnorePermissions=True /p:IgnoreRoleMembership=True /v:Path1="$Path1$" /v:Path2="$Path2$"

At this point you may want to add also the /p:GenerateSmartDefaults=True switch to provide a default value when updating a table that contains data with for columns that do not allow null values.

After a few seconds a file named DBSchemaCompareScript.sql will be created (you can change the name with the /op: switch value).

After the query executes without errors, the database schema will be synchronized with the latest changes.

Remarks

The following files are required by the SqlPackage if the Microsoft SQL Server Data Tools is not installed in production environment:

« Previous Entries