Archive for July, 2011

Udder Chaos for Windows Phone

Now available on the Windows Phone marketplace, Udder Chaos!

“Protect your cows from Alien hordes as they try to abduct your precious livestock. Alien hordes too hard? Upgrade your weapons and gain smart bombs to blow them out of the sky.

Includes global leaderboards, endless mode, easier kid-mode, and option to remove ads.”

The trial is completely fully featured and ad-supported … and if you purchase the game, all ads are removed.

If you’ve got an XBox 360, you can also download Udder Chaos on the XBox Live Indie Games channel!

Comments (3)

SequentialActionQueue in C#

A while ago, I created a clone on Google Code of the Stateless library because I wanted to use it in a .NET 4.0 project, and the current distribution was using VS 2008. After I did that, I started playing around with the library. Specifically, I wanted a way to have multiple state machines, and be able to process triggers and state changes in parallel. The problem of course is that although you can usually easily process state changes from different state machines in parallel, you can only process multiple triggers for a single state machine sequentially.

So I added a ParallelExample project to the solution and started experimenting. The end result is an easy to use class called SequentialActionQueue. Usually when you need to synchronize access to a resource, you end up putting a lock section around your code so that only one thread may access it at a time. However things get more complex if you need to synchronize multiple sections of the code (ex. multiple methods in a class where only one may run at a time). This is classic thread-safety issues, and the dragons that lie in those waters. However, With the SequentialActionQueue, you can simply instantiate the class and proxy all actions through it and be guaranteed that everything will run safely one after the other.

private SequentialActionQueue queue = new SequentialActionQueue();
private int counter =0;

public void Add(int i)
{
    queue.Enqueue(() => counter += i);
}

public void Subtract(int i)
{
    queue.Enqueue(() => counter -= i);
}

The above is a simplified example which emulates the ability to use Interlocked to safely increment/decrement a number. I’d love to get some thoughts on the class … I wrote a few tests in the sample project, but that’s not to say there won’t be bugs in it, would love to hear your feedback :-)
 

Comments

Exec-Sql PowerShell Function

And the hits just keep on coming … here’s a simple little function which executes a query against a database and pipelines the results as PSObjects.

.SYNOPSIS
Executes SQL against the supplied connection string.
.DESCRIPTION
Executes SQL against the supplied connection string. The result set is then pipelined as a PSObject which can subsequently be formatted and filtered any way you choose.
.PARAMETER query
The query to execute
.PARAMETER connstring
The connection string to use
.EXAMPLE
PS C:\> Exec-Sql -q "select top 1 * from common.country" -conn ""
.EXAMPLE
PS C:\> Exec-Sql -q "select * from common.country (nolock)" -conn "" | where {$_.Code -eq "AX" } | select code, name
#>
function global:Exec-Sql
{
param ([Alias("q")]$query, [Alias("conn")]$connstring)

[system.reflection.assembly]::LoadWithPartialName("System.Data")
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection

$connection.ConnectionString = $connstring
$connection.Open()

$command = New-Object -TypeName System.Data.SqlClient.SqlCommand

$command.Connection = $connection
$command.CommandText = $query
$reader = $command.ExecuteReader()

$fieldcount = $reader.FieldCount

while ($reader.Read())
{
$o = new-object psobject

for ($i=0;$i -lt $fieldcount;$i++)
{
$o | add-member -membertype noteproperty $reader.GetName($i) $reader[$reader.GetName($i)].ToString()

}

write-output -inputobject $o
}

$connection.Close()

}

Comments

Minor PowerShell Prompt Customization

Having recently started using PowerShell a lot more, I wanted to share a minor customization I made to my powershell prompt.

function prompt
{
    $loc = $(get-location).ToString()
    $usr = ($env:userprofile).ToString()
    if ($loc.StartsWith($usr, $true,[System.Globalization.CultureInfo].CurrentCulture)) {
	$loc = "~"+$loc.SubString($usr.Length, $loc.Length - $usr.Length)
    }
    Write-Host ("PS " + $loc +">") -nonewline -foregroundcolor Yellow
    return " "
}

all it does is that when I’m in my user profile directory, it shortens the prompt to something like: PS ~>. Since you can use the ‘~’ character as a shortcut for your user directory, may as well shorten the path to give you more space. Also, it makes the prompt yellow so that it can be more easily distinguished from the rest of the output.

Comments