Sunday 15 December 2013

Mobile UI frameworks

Good overview with some examples of mobile UI frameworks such as jQueryMobile etc.

Sunday 3 November 2013

Issues with booting via USB

After upgrading my MacBook Pro to OSX Maverics this week, my bootcamp stopped working (Windows 8.1). Long story short had to get USB recovery stick booted up. I have tried both;

1. Restarting MacBook and pressing and holding option to change boot manager to USB stick. This booted recovery stick, however for some reason I was unable to actually recover anything due to lack of access to Windows partition. 
Plot Boot Manager screen

2. Loading USB via Parallels. This didn't work for some reason either. It wouldn't even boot.

Note: I'm not sure why my BootCamp suddenly had some corrupted/missing files in Windows folder as it was working perfectly fine. I could not find anyone else with similar issues.

Solution: 

After some time on Google and countless hours trying I have found this little tool (Plop Boot Manager).

It allows you to first boot your machine (using CD/DVD ROM) to Plop Manager and from there to select the actual media you wanted to boot. In my case it was USB. Absolutely brilliant!

Thanks Jeroen @ http://superuser.com/questions/353407/boot-usb-from-parallels-vm-trick-with-iso-floppy

Note: Parallels 8 is not working with this. You will need to upgrade to version 9.

http://www.plop.at/en/bootmanager/download.html

Thursday 24 October 2013

Keep IIS App Pools warm with PowerShell script

Happy Friday!

Due to the fact that our CI deploys the site every single check-in, very often nobody actually bothers loading up the pages afterwards to make sure those are operational. We work on applications that take sometimes even 5-10 min to come back up after deployment (eg. Sharepoint).

Anyway, I decided it would be a good idea to have a script running every 5 min on one of the servers that will actually try loading pages for us. This in theory means that pools will be warm and ready to go and you will not be stuck with forever loading browser window.

Below is my PowerShell script that will do the job. You will also need XML file that will hold all URLs.

Your XML needs to follow structure below. It can contains as many URLs as you require.
<Urls>
<Url>http://test.com</Url>
<Url>http://test1.com</Url>
</Urls>


param 
param 
(
    [string]$ConfigFile = "config.xml",
    [string]$TransactionFile = "lastRun.log"
)


# Get Config file
$0 = $myInvocation.MyCommand.Definition
$env:currentDir = [System.IO.Path]::GetDirectoryName($0)
$env:parentFolder = Get-Item $env:currentDir | Split-Path -Parent

[xml]$cfg = Get-Content (Join-Path $env:currentDir $ConfigFile)

if($cfg -ne $null){
    $wc = new-object net.webclient;  
    $wc.credentials = [System.Net.CredentialCache]::DefaultCredentials;  

    Start-Transcript (Join-Path $env:currentDir $TransactionFile)

    Foreach($url in $cfg.Urls.Url){
        if($url -ne $null){
            try{
                Write-Host "Warming up $url"
                $pageContents = $wc.DownloadString($url);
            }catch{
                Write-Host "Warming up of $url has timed out!"
                #throw $_
            }
        }
    }

    Stop-Transcript 
    $wc.Dispose();
}

Configuration steps

Fig 1
Once you have both XML config file and ps1 script file in one folder we can setup Task Scheduler.


  1. Open Task Scheduler
  2. Right click to "Create New Task"
    1. Press "Change User or Group" button 
    2. Press "Advanced..." button
    3. Press "Find" and Select "NETWORK SERVICE"
    4. Fig 2
      1. We are doing this so that this script runs under a different account (system account) otherwise every time you change your password you have to update this job.
    5. Tick "Run with highest privileges"
  3. Change Tab to Triggers
    1. Press "New..." - here you setup your trigger. (ie. what causes this to run)
    2. In my case I wanted this to run every 5 min. So I have ticked "Repeat task every" and selected "5 min" then select for duration of "Indefinitely"
    3. I set it to run "One time", however due to the "Repeat task every 5 min" it actually runs once and then repeats indefinitely.
  4. Change Tab to Actions
    1. This is where we set ps1 to run by pressing on "New..."
    2. Fig 3
      1. Select action to be "Start a program"
      2. Program script to be "PowerShell.exe"
      3. Under Add arguments (optional) enter "-ExecutionPolicy Bypass -File D:\KeepWarm\keepwarm.ps1 -Path D:\KeepWarm". Change your paths accordingly.
  5. Press OK to close
  6. Press OK to finish setting up this task.
  7. Right click task you just created and click "Run"
  8. Open Explorer and browse to a folder where you keep your keepWarm.ps1 and see if there is a new file there called "lastRun.log". 
  9. You can open this file to see last run results.
  10. You are done!

Monday 21 October 2013

ASP.NET Custom Error Pages

Found this great article that covers pretty much every possible way of getting it done with pros and cons. http://aspnetresources.com/articles/CustomErrorPages Thanks!


Monday 30 September 2013

TFS 2010 to SVN Migration

Brief introduction

Migration between TFS to SVN can be quite challenging as there are no tools* that I could find that actually work smoothly with Team Foundation Server 2010 and SVN. This brief how-to assumes that you know your way around Linux/SVN and TFS. 

* I have only found one tool for this tfs2SVN however it is heavily outdated and it hasn't been much use with Team Foundation Server.

Instead I have split this migration process into two.
  1. Migration from TFS to GIT - using GIT-TF
  2. Migration from GIT to SVN - using SubGit

Requirements for migration

  1. Linux box (Ubuntu) for SVN hosting (this is vanilla install purely for SVN hosting)
    1. SVN installed on Linux box
    2. GIT installed on Linux box
    3. GIT-TF (download ZIP file and chmod +x on git-tf file)
    4. SubGit (see Debian/Ubuntu section in Download for repository - otherwise ZIP is fine)
  2. Windows Server - Team Foundation Server 2010

Business requirements

  1. History of all file changes as well as who has made them need to be migrated.
  2. Some configuration (that only relates directly to TFS such as builds - we have migrated to Jenkins instead but that's not part of this how-to).
  3. Some cleaning and re-organizing repositories might be required to align it more with SVN standards.

Migration procedure

Migration from TFS to GIT

  1. Download & Unzip GIT-TF somewhere in your home directory (any directory will do). 
    1. In this example "/home/luke/gittf/git-tf-2.0.2.20130214"
    2. Make sure you "chmod +x on git-tf"
  2. Create a folder where you will keep your Git repository
    1. In this example I have ran following "mkdir /disk2/git/dnd" to create folder
  3. Run git-tf
    1. Run "/home/luke/gittf/git-tf-2.0.2.20130214/git-tf clone --deep http://tfs-server:8080/tfs/DnDCollection $/"
    2. Replace URL with your TFS URL. Also you can specify single project by changing "$/".
    3. This will prompt you for your username and password you need to connect to TFS.
  4. This step will take quite a while. This particular collection took over 48 hours.
  5. Test if all check ins are there by running "git log".
  6. Run "git status" to see if any files have been changed in the process. This should show you no pending changes to be commited. My git repository showed some files with extra character (hidden character) so I ran "git reset --hard" to discard all changes and get repository as its checked in.
Few notes;
  • Your developers can still use TFS as normal (it will be however slower). Simply once your clone is done you can run git-tf pull to get it up to date.
  • Make sure you run --deep otherwise only last checkin will be pulled from TFS.
  • More documentation here GIT-TF Documentation

Migration from GIT to SVN

To clean SVN repository
  1. Use aptitude to install SubGit
    1. Follow steps on SubGit to download and install SubGit on Ubuntu/Debian
  2. Create empty SVN repository (only if you don't already have one)
    1. In this example my SVN repository will sit in /disk2/svn/dnd to create it I ran
    2. "svnadmin create /disk2/svn/dnd
  3. Setup SubGit
    1. Go inside DND SVN repository by entering "cd /disk2/svn/dnd"
    2. Run "subgit configure"
      1. It will prompt you that new configuration file has been created and you will be required to modify it.
    3. Change settings to associate your repository with Git repository
      1. Open /disk2/svn/dnd/conf/subgit.conf by running "vim /disk2/svn/dnd/conf/subgit.conf"
      2. Find "[git "default"]" section.
      3. Change repository = .git to point to your location. In this case "repository = /disk2/git/dnd/.git"
    4. If your repository is customized you can modify trunk, branches, shelves and tags. I have left this with default settings. See SubGit Documentation for more information.
    5. If you are using existing SVN installation and you just want to migrate your TFS as a subproject then modify translationRoot. Eg. if your SVN already has folder called Clients\[Projects] then setup your translationRoot folder to be "translationRoot = /Clients/
  4. Run migration
    1. Run "subgit install" - it will pop up with progress bar.
    2. This takes a lot less than TFS to GIT. In this particular example it took about 2 hours.
  5. Test your SVN repository to make sure that all Logs are there and you can successfully checkout/commit etc.
  6. SubGit create tags folder with every single check-in in TFS showing as separate tag - I have simply removed it. I appears to be a biproduct of double migration. 
Addition to existing SVN repository
  1. Use aptitude to install SubGit
    1. Follow steps on SubGit to download and install SubGit on Ubuntu/Debian
  2. You will be required to have Bare GIT repository - to create one all you need is
    1. Move .git folder out of your git repository eg. mv /disk2/git/dnd/.git /disk2/git/dnd.git
    2. Then you need to mark it bare with "git config --bool core.bare true"
    3. See http://stackoverflow.com/questions/2199897/how-to-convert-a-git-repository-from-normal-to-bare for more info on this.
  3. Configure your dnd.git to be connected to SVN
    1. Run " subgit configure --svn-url http://svn.yoururl.com/yourfolder dnd.git"
      1. Your folder is any path that you want your git to be migrated to. Make sure it doesnt exist yet.
      2. Modify /disk2/git/dnd.git/subgit/passwd with your username and password for SVN. (if you require authentication for your repository)
  4. Go to physical location of your SVN repository and add a hook to enable all information to be migrated (such as authors of each check-in)
    1. In this example my SVN is under /disk2/svn/dnd
    2. Go inside /disk2/svn/dnd/hooks with "cd /disk2/svn/dnd/hooks"
    3. Create new file with "touch pre-revprop-change"
    4. Open it for editing "vi pre-revprop-change"
    5. All it needs to do is to return true - ie. exit with 0
      1. Follow http://subgit.com/book-remote/index.html#N2038E (section 5.8) for exact content of the file.
    6. Make sure you run "chmod +x pre-revprop-change" otherwise it will not be executed!
  5. Run "subgit install /disk2/git/dnd.git"
  6. Wait for the process to complete. 
  7. Test your SVN repository to make sure that all Logs are there and you can successfully checkout/commit etc.
  8. SubGit create tags folder with every single check-in in TFS showing as separate tag - I have simply removed it. I appears to be a biproduct of double migration. 

Disclaimer

Please follow this procedure at your own risk. I strongly recommend doing a test run on empty TFS collection with empty SVN repository. I'm not responsible for any loss of data or damages caused by tools or procedures in this How-To.

Sunday 8 September 2013

ASP.MVC failed after deployment - works fine on my local!

I have been working on a site for a while that has been working fine on our local dev machines as well as our CI (DevTest). However, when I have deployed it to production it exploded with 

Server Error in '/' Application.
Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Solution

This will make sure all DLLs that are required at run-time are included with the assets, therefore you will NOT need to install MVC3/4 on production server.
  1. Open your Solution (*.sln file)
  2. In each of the projects that use "MVC" open "Reference" 
  3. Right click System.Web.Mvc and select Properties
  4. Change "Copy Local" to True
  5. Save solution and rebuild.
  6. Check Bin folder for System.Web.Mvc.dll
Note: Dependable on what other parts of MVC you use you might also need following DLLs 
  • Microsoft.Web.Infrastrucutre.dll
  • System.Web.Helpers.dll
  • System.Web.Razor.dll
  • System.Web.Webpages.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.Razor.dll

Tuesday 13 August 2013

Moving SQL Server database onto another machine

I have had a pleasure of moving databases onto different machine. I decided it will be good to write down quick step by step guide. This is just simple migration between development machines - so no complex stuff!

Requirements

  • SQL Server (I used 2008 - it also works for 2012)
  • SQL Management Studio (2008 - 2012 will also work)

Steps


  1. Grab a notepad and write down all users & passwords you will require on the other machine. (Otherwise systems that depend on those database could fail!)
  2. Right click every Database and select "Tasks->Backup"
    1. Point .bak file to some directory that you can later on move to new machine.
    2. As a rule of thumb (sanity check) always go to Options and tick
      1. Verify backup when finished
      2. Perform checksum before
        writing to media.
  3. Move folder with all .bak files to new machine.
  4. Open SQL Management Studio on new database server.
  5. Create all users noted in step 1.
  6. Right click Databases 
    1. Select Tasks -> Restore
    2. Point it to your .bak file.
    3. Press Restore.
    4. Repeat the process to restore all databases.
  7. Due to how SQL managers users, even though users do match (name wise), it will still not associate them with database.
    1. User that associated with database yet doesn't exist is called "orphaned user". (FYI if you need to do more googling)
    2. We can fix it by opening new Query
    3. Select Database that you want to run this query on 
      1. EXEC sp_change_users_login 'Auto_Fix', 'UserName'
      2. Replace UserName with a user that you want to re associate with database. 
      3. Note: This will not create new user, which is why you had to create all your users above. All it does is looks for new user and orphaned user and matches their names and if match is found it will associate new user and remove orphan. 
  8. Run few tests to make sure that 
    1. Database are running in recovery mode of choice (Simple or Full)
    2. See if there are any maintenance plans that need to be moved across (not part of this guide).
    3. Check if users can log in and query their database just like they could on old one.
      1. Note: On new install of database it will not allow TCP connection, you can run SQL Server Configuration Manager to enable TCP for specific database instances.  
    4. Check if backup is necessary.
Good luck!


Thursday 25 July 2013

Twitter Card Validator - server error and automatic retry

I have been implementing Twitter Cards on our sites in last few days. I'm at the stage where everything is implemented however, I do need to get them validated and request for approval.

This you would think is the easiest part of entire development process - that's until you get "Server error, please try again." error and the only reply I have got from Twitter is "we know... keep trying".

So after retrying by hand few times I have decided that I have better things to do with my time; hence the script.

What it does?

  1. Every 10 seconds retry (push retry button).
  2. If you hit rate limiter wait for 10 turns (10 x 10 seconds)
  3. If you pick up that there is no error message then you are finished.

Warning: I have used this to validate some of my Twitter Cards, however I do not give any guarantee that this will work for you and not block your twitter account or cause any other damage.

var tries = 0;
var rateLimit = 10;
var int=self.setInterval(function(){
var button = $("div.icon-refresh");
if(button.length>0){
 var error = $("span.error-label-text:contains('Server error'):visible");
 var rateLimiter = $("span.error-label-text:contains('Rate')");
 
 // Retry function
 var retryNow = function(){
  button.click();
  tries++;
  
  console.log("Attempt: "+tries);
 }
 
 if(error.length>0){
  retryNow();
  
  if(rateLimit <= 0){
   rateLimit = 10;
   console.log("Rate limiter reset to 10 seconds");
  }
 }else if(rateLimiter.length>0){
  console.log("Rate limiter - wait for " + rateLimit + " seconds");
  rateLimit--;
 }else{
  // Final check for any errors
  if($("span.error-label-text:visible").length==0){
   console.log("Success!");
  }else{
   console.log("Another error detected re-trying anyway!");
   retryNow();
  }
 }
}
},10000);


Requirements

  1. Twitter Account
  2. Chrome / Firefox with Firebug
Figure 3.1

Steps

  1. Open your browser (Chrome is my browser of choice) 
  2. Go to URL https://dev.twitter.com/docs/cards/validation/validator
    1. Figure 6.1
      Figure 7.3
    2. It might require you to log in, so use your twitter account and login then use the URL to login again.
  3. Pick a card from "Card Catalog" once the page loads. (See Figure 3.1)
  4. Select "Validate & Apply" tab
  5. Enter your site's URL
  6. Wait for "Error to show up" (See Figure 6.1)
  7. Now we are set for running the script
  8. Figure 7.6
    1. Right click the page and select "Inspect Element"
    2. Development tools will appear at the bottom of the page.
    3. Go to the Console tab
    4. Copy / Paste script from above to the console.
    5. Press Enter to start retry.
    6. See figure 7.6 for example output.
    7. Figure 7.7
    8. Once its validated you will get success message. (See figure 7.7)

Wednesday 24 July 2013

Installing EPiServer 6 R2 on Windows 8

Great step by step guide on how to bypass some nasty error messages (that aren't actually errors) while installing EPiServer 6 R2 on Windows 8 machine.

Thanks Paul!

http://dotnetcake.blogspot.com.au/2012/06/installing-episerver-6-r2-on-windows-8.html

Tuesday 23 July 2013

Creating a branch out of your pending changes on Trunk in TFS

I have been working on our Trunk branch when I have been told that my changes aren't going to be in this release. Luckily I haven't checked in, however I wanted to move all my stuff onto a separate branch so I can do my daily check-ins as per usual.

This is very easily solvable in SVN, however in wold of TFS not so much.

After some Googling I found this:
Unshelve changes onto another location
It is a very good guide however it misses some vital steps.

  1. Create a shelve out of your pending changes.
    1. Open your pending changes.
    2. Click Shelve (make sure you tick all files you want to move across). Make note of shelve name.
    3. Now you will need to do a full backup of your code in form of another shelve set.
    4. This time create shelve but check all files.
  2. You will be required to revert all your changes on branch/trunk that you have just used to create shelve. (You can also create a physical folder copy if you really worried about loosing your changes).
    Note: Without this step (ie. changes still pending on trunk) power tools wouldn't un-shelve to my new branch.
    1. Open your pending changes.
    2. Select all files
    3. Right click and select Undo...
    4. Make sure that there are no pending changes.
  3. Create another branch based.
    1. Right click your current branch and select "Branching and Merging"
    2. Select "Branch"
    3. Name it accordingly.
  4. Follow guide on Unshelve changes onto another location to restore to newly created branch.
I hope that works for you!

Wednesday 19 June 2013

Did you think you can simply remove cookie and be done with it? Nope. You are wrong.

I have been researching for few hours now different ways I could secure voting polls so that people would not be able to spam them with fake votes. So far I have been unable to come up with anything (due to infrastructure - load balancer, lack of sessions, no registration or captcha being available).

However, I have found one thing that blew me away. EverCookie. It is a library that inserts "a cookie" to every single possible storage so that even when person removes cookies or clears the cache you can still retrieve it from somewhere.

EverCookie Website


Monday 10 June 2013

Free Limited Team Foundation Server - TFS with Visual Studio 2010

Intro

I'm not sure if people are aware but Microsoft for a while now been trying to compete with sites such as "BitBucket" or "GitHub" when it comes to source control. At my previous work place we used TFS with our internal infrastructure which could be expensive. What Microsoft is offering is "cloud based" TFS. I have decided today to give it a shot.

Team Foundation Server - TFS

http://tfs.visualstudio.com/

Limitations that I have found - you can only share your project with up to 5 users for free. Apart from that I haven't found anything that would bug me yet.

Account creation

Very easy. Follow link above and use your existing live account or create new one.

Visual Studio 2010 setup

Visual Studio 2010 is currently unable to connect to TFS out of the box.
You need to install SP1 and a patch for TFS2012.

If you get an error of "Team Foundation services are not available from server https://xxx.visualstudio.com/tfs. Technical information (for administrator): HTTP code 203: Non-Authoriative Information." - Install a patch.
  1. Install Visual Studio 2010
  2. Install Visual Studio SP1
  3. Patch for VS2010 to let it connect to TFS http://www.microsoft.com/en-us/download/details.aspx?id=29082
    1. Details:
    2. Version:
      Date Published:
      1
      3/8/2012
      File name:
      File size:
      VS10SP1-KB2662296.exe
      19.3 M
  4. Start Visual Studio 2010
  5. In the toolbar
    1. Click Team -> Connect to Team Foundation Server ...
    2. Click "Add"
  6. In the Add window
    1. Name: your tfs link (without https://)
    2. Path: tfs
    3. Protocol: HTTPS
  7. Click OK and wait for Login screen to appear.

Long weekend goal - Create your first game!

Long weekend here in Sydney so I have decided it would be cool to do something fun for once since I just didn't feel like cleaning/catching up on some work etc.

So I have decided to create my first game - after quick research Unity 3D was my choice and below is one of the best tutorials I have watched in a very long time.
http://vimeo.com/51410700

Enjoy!


Monday 6 May 2013

How to restore BACPAC onto MS SQL 2008 R2

I have been struggling with restoring databases from Azure onto my local machine. At first I thought it is because my SQL Management Studio is outdated, but even after updating to 2012 I was getting
The internal target platform type SqlAzureDatabaseSchemaProvider does not support schema file version ’2.5′.


Solution: 1. Quick Google research showed an update on SQL Server Data Tools 2012 update 2. You can use a tool inside
C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin
called SQLPackage.exe 3. Example:
.\SqlPackage.exe /a:Import /sf:D:\backups\testdatabase.bacpac /tdn:MyDatabaseName /tsn:MyDatabaseInstanceName


Alternatively, you can try to use Import/Export inside SQL Server Management Studio 2012 - however I had more problems with it than SQLPackage tool.

Sunday 28 April 2013

How to run Visual Studio's Publish equivalent in command prompt using MsBuild

I struggled to get MSBuild to do exactly the same thing that right clicking solution and selecting "Publish" does.

I have finally found it!


%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
     HostingSample\HostingSample.csproj /
     t:ResolveReferences;_CopyWebApplication /
     p:WebProjectOutputDir=C:\HostingSample /p:OutDir=C:\HostingSample

Friday 22 March 2013

Security vs Conversion rate - where is the balance?


Very interesting article about fraud detection and security vs usability of the site and conversion rate.

http://www.techrepublic.com/blog/security/making-online-payments-safe-from-fraud-conversion-rate-vs-security/9203?tag=nl.e036&s_cid=e036&ttag=e036