Tuesday, March 22, 2011

Setting up Unity in a new project

Using the Common Service Locator and Unity is fairly simple with Nuget. This post records the steps in case I need them again.


  1. Add the CommonServiceLocator and Unity packages to the project using Nuget.
  2. Add the following initialisation code (for example in Application_Start):
    UnityContainer container = new UnityContainer();
                
    //configure container
    ...
    
    var unityServiceLocator = new UnityServiceLocator(container);
    ServiceLocator.SetLocatorProvider(() => unityServiceLocator);
    
  3. Use the IServiceLocator and ServiceLocator interface and class for DI and service location, respectively.

Monday, March 21, 2011

Retrieving streamed Flash video on Linux

This blog post on commandlinefu.com shows a fantastic one-liner to retrieve a streaming Flash file as it is being played. It seems that Flash writes to a file, but then deletes that file even as it is being used.

Reproduced here in case the other blog disappears one day:
for h in `find /proc/*/fd -ilname "/tmp/Flash*" 2>/dev/null`; do ln -s "$h" `readlink "$h" | cut -d' ' -f1`; done

Tuesday, March 8, 2011

Finding all explicit ACLs in NTFS

Sometimes file permissions can become a little messed up, so this script will list all the explicitly set (i.e. not inherited) ACEs. I suggest that you use the Out-GridView, Format-Table, or ConvertTo-Csv Cmdlets to better visualise the result.

function Get-ExplicitAcl
{
    [CmdletBinding()]
    param([string]$Path, [switch]$Recurse)
 
    Process
    {
        $allFiles = Get-ChildItem $Path -Recurse:$Recurse | select -ExpandProperty FullName
        $allFiles += Get-Item $Path | select -ExpandProperty FullName
        $result = $allFiles | % {
            $current = $_
            try 
            {
                $acl = get-acl -path $current
                if($acl)
                {
                    $dacl = $acl.GetAccessRules($true, $false, [System.Security.Principal.NTAccount])
                    foreach($ace in $dacl)
                    {
                        $detail = new-object psobject -Property @{ 
                            Path = $current;
                            FileSystemRights = $ace.FileSystemRights;
                            AccessControlType = $ace.AccessControlType;
                            IdentityReference = $ace.IdentityReference;
                            InheritanceFlags = $ace.InheritanceFlags;
                            PropagationFlags = $ace.PropagationFlags;
                        }
                        $detail | select Path, AccessControlType, IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags
                    }
                }
            }
            catch [System.UnauthorizedAccessException]
            {
                Write-Error "Failed to read DACL from $current.FullName."    
            }
        }
        $result | sort path
    }
}