... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2011-11-16

Iterating Over Tables/Databases in SQL Server

SQL Server provides an undocumented stored procedure that is handy for applying commands to all of the tables within a catalog, sp_MSforeachtable:

sp_MSforeachtable 'print ''?'''

The question mark will be replaced by the table name. In a similar vein, we can iterate over all databases using sp_MSforeachdb. These procedures could disappear at any time, but they have been present in all versions from 7.0 to 2008R2 so far.

Both procedures accept the following arguments:

  • @command1 - the command to run for each table
  • @replacechar - the placeholder character for the table name (default '?')
  • @command2 - another command to execute for each table
  • @command3 - another command to execute for each table
  • @precommand - a command to execute before iterating
  • @postcommand - a command to execute after iterating

2011-08-19

Lambdas In Java

With Oracle's takeover of Java, interest in functional programming appears to be renewed. As the Java language evolves in this direction, perhaps it needs a new name. How about one of these names?

  • Visual J++
  • C#
  • !C#
  • C##
  • OpenC#Beans

:)

2011-04-08

git am vs. Windows

Using git on Windows you may find that if you create a patch using git format-patch and try to apply it using git am, the patch file will fail to apply. The error message is "patch does not apply". If you inspect the patch file, you might be baffled because the patch does apply, that is, the context lines in the diff exactly match (byte for byte) the file being patched.

The problem is that git am invokes git mailsplit to split the patch file into individual patches -- and the latter component strips carriage-return characters by default. Consequently, the patch context fails to match the target files and the patch fails.

If you use git am --ignore-space-change to apply the patch, then it will succeed but any newly added lines will not conform to the Windows newline convention. The lines will end with a linefeed only.

A better solution is to use git am --keep-cr. This arranges to pass the --keep-cr option to git mailsplit, leaving the Windows-style line-endings in place. The patch will then be applied successfully. You can make this behaviour the default through a configuration variable in the am section of the git configuration file:

[am]
        keep-cr = true

2011-03-01

View dangling GIT commits in GITK

You can use GITK to view commits that have no external references by using this command:

gitk --all $(git log -g --pretty=format:%h)

Blog Archive