A simple script that cleans and builds visual studio solution with psake

Posted on

psake is a simple build automation tool written in powershell, and works well on Microsoft platform.

This is a really simple example that cleans bin folder, run msbuild to build the solution, and clean up pdb and xml files afterward.


properties {
    $BuildConfiguration = if ($BuildConfiguration -eq $null ) { "debug" } else {     
        $BuildConfiguration }
    $BuildScriptsPath = Resolve-Path .
    $base_dir = Resolve-Path ..
    $packages = "$base_dir\packages"
    $build_dir = "$base_dir\Sushiwa\bin"
    $sln_file = "$base_dir\Sushiwa.sln"
}

task default -depends CleanUp, Compile

task CleanUp {
    @($build_dir) | aWhere-Object { Test-Path $_ } | ForEach-Object {
    Write-Host "Cleaning folder $_..."
    Remove-Item $_ -Recurse -Force -ErrorAction Stop
    }
}

task Compile {
    Write-Host "Compiling $sln_file in $BuildConfiguration mode to $build_dir"
    Exec { msbuild "$sln_file" /t:Clean /t:Build /p:Configuration=$BuildConfiguration 
        /m /nr:false /v:q /nologo /p:OutputDir=$build_dir }

    Get-ChildItem -Path $build_dir -Rec | Where {$_.Extension -match "pdb"} | Remove-Item
    Get-ChildItem -Path $build_dir -Rec | Where {$_.Extension -match "xml"} | Remove-Item
}

London Bus

Posted on

Recently, I’m playing with TFS’s countdown apis. As I am a bus commuter, I use bus arrival check app everyday. There are free and paid apps on iPhone and my Nexus 4. Paid ones are prettier than free ones, but the user interface, I think, can be much more improved. 

So, I started writing an simple mobile site that checks bus arrival time. It’s still primitive stage, but it works and it has features I wish other apps have. For example, when I stand at a bus stop, I want the check the arrivals of the stop, not anywhere else. I don’t want to select a bus stop on the map, touch it, and wait to see the arrivals. I’d like the app to find the bus stop with my location and just show me the arrival times. This mobile site has the feature, “nearby bus stop”.

It wasn’t difficult to Implement it. You get the latitude and longitude from the browser’s geolocation. You send it to countdown. Countdown returns various markers with their latitude and longitude. You check the values and find the closest one. Surprisingly, the location was accurate enough to locate the bus stop right in front of you.

Here is the website. http://www.londonbus.info/

It works best on mobile. I test it on Chrome on my Nexus 4. Hope it helps you too.  

 

Customising Mac’s terminal prompt

Posted on Updated on

You can colourise it, if you want.

Open .bash_profile in your editor (I used sublime)


sublime .bash_profile

Add this line


export PS1="\u@\h \w "

Each option means

\d – Current date
\t – Current time
\h – Host name
\# – Command number
\u – User name
\W – Current working directory (ie: Desktop/)
\w – Current working directory, full path (ie: /Users/Admin/Desktop)

Change Mac’s Computer name

Posted on

  1. Launch ‘System Preferences’
  2. Click the ‘Sharing’ icon
  3. Type in what you want your Mac’s new computer name to be
  4. Close ‘System Preferences’

Skipping IIS Custom Error pages

Posted on

By default, IIS7 intercepts 4xx and 5xx status responses with its own custom error pages. At work, we have a custom redirection module that checks if the status is 401 Unauthorized and spits javascript to redirect to the log in page. We use javascript in order to preserve # fragment in the return url.

The issue was 401. We set 401 to the response to send a meaninful response. The body contains a javascript redirection chunk. But it is intercepted by IIS7, so the user is not redirected but only see an dumb IIS 401 error page.

dumb_iis7_errror_page

 

 

After some googling, I found two ways to handle the issue. One is to let all response ignore IIS custom error pages. You can do that by setting existingResponse=”PassThrough” in the web.config.

<configuration>
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>

 

The other is to set response.TrySkipIisCustomErrors = true, and then the only that response will be passed through without being intercepted by IIS7 custom error pages.

The second option was appropriate, as we want to pass through only for redirection module.

public void OnEndRequest(HttpContextBase context)
{
    if (context.Response.StatusCode != 401)
        return;

    var response = context.Response;
    response.TrySkipIisCustomErrors = true;
    response.Status = response.Status;
    response.StatusCode = (int)HttpStatusCode.Unauthorized;
    response.TrySkipIisCustomErrors = true;
    response.ClearContent();
    response.RedirectLocation = null;
    response.Write(_buildClientRedirectionResponse.GetRedirectionScript());
    response.End();
}

For me, TrySkipIisCustomErros = true didn’t work until you set a value to response.StatusCode. It seems that response.TrySkipIisCustomErrors = true and response.Status = response.Status should be set together.

With the second option, you can benefit from Custom error pages and a temporal pass through for 401 for redirection. Hope this helps.