RE: IQueryable vs. IEnumerable in LINQ to SQL queriesMar27

Tuesday, 27 March 2012 by haemoglobin

I came across an interesting blog post today (admittedly an old one!) from Jon Kruger who experimented with some interesting behaviour differences between IQueryable<T> and IEnumerable<T>. The blog post can be found here, however the summary of the findings are below: 

NorthwindDataContext dc = new NorthwindDataContext();
IEnumerable<Product> list = dc.Products
     .Where(p => p.ProductName.StartsWith("A"));
list = list.Take<Product>(10);
Debug.WriteLine(list.Count<Product>());  //Does not generate TOP 10 !!

and

NorthwindDataContext dc = new NorthwindDataContext();
IEnumerable<Product> list2 = dc.Products
     .Where(p => p.ProductName.StartsWith("A"))
     .Take<Product>(10);
Debug.WriteLine(list2.Count<Product>()); //Works correctly

and

NorthwindDataContext dc = new NorthwindDataContext();
IQueryable<Product> list3 = dc.Products
     .Where(p => p.ProductName.StartsWith("A"));
list3 = list3.Take<Product>(10);
Debug.WriteLine(list3.Count<Product>()); //Works correctly

The first example will neglect the very important TOP 10 statement from the generated SQL query, returning all rows into memory and then returning the first 10 from there (obviously not ideal). The next two correctly include the TOP 10 statement returning only those rows from the database.

The reason the first statement fails is the call to Take is actually calling the IEnumerable<T> extension method from Enumerable. In ILSpy, this has the following implementation (TakeIterator being a private method returned from Take):

private static IEnumerable<TSource> TakeIterator<TSource>(IEnumerable<TSource> source, int count)
{
    if (count > 0)
    {
        foreach (TSource current in source)
        {
            yield return current;
            if (--count == 0)
            {
                break;
            }
        }
    }
    yield break;
}
 

In the second and third examples however, Take is called on a IQueryable<T> which executes the extension method defined in Querable. This has a totally different implementation as ILSpy shows below: 

public static IQueryable<TSource> Take<TSource>(this IQueryable<TSource> source, int count)
{
    if (source == null)
    {
        throw Error.ArgumentNull("source");
    }
    return source.Provider.CreateQuery<TSource>(Expression.Call(null, ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(new Type[]
    {
        typeof(TSource)
    }), new Expression[]
    {
        source.Expression,
        Expression.Constant(count)
    }));
}

As per the MSDN documentation, calls made on IQueryable operate by building up the internal expression tree instead.
"These methods that extend IQueryable(Of T) do not perform any querying directly. Instead, their functionality is to build an Expression object, which is an expression tree that represents the cumulative query. "

When Count is called in the last two examples, Take has already been built into the expression tree causing a TOP 10 to appear in the SQL statement. In the first example however, Take on IEnumerable<T> will start iterating the IQueryable returned from Where, which does not have “Take” in it’s expression tree, hence the behaviour.  If you are wondering why an IQueryable can be cast to an IEnumerable as in the first two examples, IQueryable extends IEnumerable, IQueryable hence being pretty much the same interface but provides a few extra properties to house the LINQ provider and internal expression tree. The actual extension methods off each of these interfaces however are quite different.

Another thing that helps when thinking about LINQ queries is they in effect execute from the last call in, not the other way around like most traditional method call chains. So for example, calling Count will start enumerating over the IEnumerable returned from Take, which itself will enumerate over the IEnumerable returned from Where and so on, depending on how many LINQ operators you chain together.

Categories:   Development
Actions:   E-mail | Permalink | Comments

Enabling TeamCity Push to GitHubMar26

Monday, 26 March 2012 by haemoglobin

The following documentation describes what is necessary to run commands such as git push to a GitHub repository from a build within TeamCity.
Without the correct SSH configuration, any call to remote git repositories in the build script will cause the agent to hang the build while it is attempting to ask the user to add the remote host to the ~/.ssh/known_hosts file.
This is the message that looks like the following (requiring user input), interaction which is not possible from the build:

    The authenticity of host 'github.com (207.97.227.239)' can't be established.
    RSA key fingerprint is d2:80:ef:7a:71:4b:92:89:c7:3d:fb:e6:f5:26:44:e1.
    Are you sure you want to continue connecting (yes/no)?

This text will also not be written to any build output or logs (due to the blocking call) making it difficult to diagnose.

Business Need

When we build our NuGet packages, we build them off a branch. This is because they are released libraries and we need a reference back to code that is in use in UAT/PROD etc. The source symbol paths that we write into the built PDB's (as per my last post on GitHub Source Symbol Indexing) are indexed with HTTP references back to GitHub on that branch, this is so source symbol stepping into our libraries will work for any developer using our libraries (and without them needing to have Git installed).

The source files that are downloaded into the developers Visual Studio debugging session (when stepping into our code) has an auto-generated file header describing when that file was built and what version of the library it is from.
The header looks similar to below, varying depending on the file:

    // YourLibrary SDK
    // YourCompany.YourLibrary\Config\ConfigureWindsorBuilder.cs
    // YourCompany.YourLibrary, Version 3.20.0.114, Published 07/03/2012 17:06
    // (c) Copyright YourCompany 
    // ----

If you are interested, the powershell script we are using to do this can be downloaded from here.

Since we do this as part of the build we need the build to push these changes back to the repository itself so the source stepping will download the file from GitHub with the added headers.
Build agents are able to interact with the repository if the TeamCity checkout mode is set to Automatically on agent.

The rest of this documentation will describe what steps are necessary to ensure the build agent is setup to support communicating with the remote repository and how TeamCity itself needs
to be configured.

The official TeamCity 7 documentation regarding git support can be found here: http://confluence.jetbrains.net/display/TCD7/Git+%28JetBrains%29
Mike Nichols has also written about TeamCity/GitHub interaction in his blog post here.

Configuring TeamCity for Agent Side Checkout

Steps

  • Attach a Git VCS root, configure the VCS root name, Fetch URL, Ref name (branch), User Name Style as usual.
  • Authentication Method needs to be set to "Default Private Key".
    • This is the only supported method for agent-side checkout with SSH.
  • Ensure "Ignore Known Hosts Database" is ticked.
    • This saves any potential hassle with the Java/Windows home drive mismatch below.
  • Everything else can be left as default, including "Path to git" which should be set to %env.TEAMCITY_GIT_PATH%.
  • Back in the main VCS Settings, ensure "Automatically on agent" is selected for the CVS checkout mode.
  • Currently, "Clean all files before build" needs to be checked to avoid a hanging build due to a TeamCity issue.
    • This should be solved in TeamCity 7.1 and there is already a patch available.

Configuring TeamCity Build Agent

Any agents that do not have git installed will appear *incompatible* with regards to this configuration, the incompatible agent requirement message env.TEAMCITY_GIT_PATH exists will be displayed until git is installed on the agent and the TeamCity agent service restarted.

Steps if Git is not already installed and configured on the Agent

  • Follow http://help.github.com/win-set-up-git/ to install msysgit on the build agent.
  • Choose the "Run Git from the Windows Command Prompt" option which enables us to call git commands easily from the build.
  • Using Git bash, generate ssh keys to the default "home directory" location (~/.ssh), with no passphrase (TeamCity does not support passphrases for Default Private Key authentication).
  • Add the public key to your GitHub account as per the instructions.
  • Run the following commands to ensure the agent appears correctly in the Git history when it makes commits (this is stored in the file ~/.gitconfig):
    • git config --global user.name "Build Agent"
    • git config --global user.email "buildagent@db.com"

NOTE: ~ above refers to the home directory, on Windows this is the concatenation of the HOMEDRIVE and HOMEPATH environment variables.

Bypass Known Hosts Check

It is the request to add the remote host to the list of known hosts that hangs the build during git calls involving remote repositories. If the remote host has not already been added by manual means on the agent (an entry will be in ~/.ssh/known_hosts if it has) then the following needs to be done so it is added automatically without requiring user interaction when the first request is made by the build.

Steps

  • Create a file named "config" (no extension) under ~/.ssh and add the following lines:
    • Host github.dbatlas.gto.intranet.db.com
    • StrictHostKeyChecking no

Check Java/Windows Home Directory Mismatch

Since TeamCity uses a Java implementation of SSH for the initial checkout, java considers the home directory (and hence the directory it looks for ssh keys) to be one level up of the the value of the registry key HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Desktop.

In a corporate environment this can sometimes be different to the HOMEDRIVE and HOMEPATH environment variables that git used above to write the ssh keys to.

This is described here. If there is a mismatch, you will likely see an Authentication failed error during the agent side git checkout since TeamCity will be looking for the SSH keys in the incorrect home directory location.

Steps

  • Within TeamCity, find the agent and view the "Agent Parameters". Under System Properties, check the variable *user.home* (this is the home directory that java considers it to be).
  • If this is different to where the ssh keys were created in the previous steps you have two options:
    • Copy the .ssh folder to this location as well, or
    • Create a blank .ssh folder here and add a file "config" (no extension) including the following line which maps to the private key created previously:
      • IdentityFile {path_to}\id\_rsa

NOTE: In the {path_to} replacement above, don't use any mapped networked drives, use the full network path instead. Also relative directory locations do not seem to work here.

Check Home Directory Variables Available to Agent

Since the git installation actually adds c:\Program Files (x86)\Git\cmd to the path, when you call git from a build script you are in
effect really calling c:\Program Files (x86)\Git\cmd\git.cmd which is another batch file.

Git.cmd combines the %HOMEDRIVE% and %HOMEPATH% environment variables into a %HOME% variable which git.exe uses for the location of the
.ssh keys, .gitconfig and config file as configured above.

If the TeamCity agent is running as a service (as opposed to started from the command prompt through c:\BuildAgent\bin\agent start), these variables may not be available and our calls to git in the build script will fail.

Steps

  • In c:\BuildAgent\conf\buildAgent.properties add the line:
    • env.HOME={path to user home directory containing the .ssh folder and .gitconfig}

IMPORTANT NOTE: Remember to use escape backslashes in this file for TeamCity to process these correctly, so c:\Users\MyHomeDirectory becomes c:\\Users\\MyHomeDirectory.
Also, do not use any network mapped drive names as this does not seem to resolve, i.e instead of X:\, use \\\\SERVERNAME\\NETWORKSHARE\\USERSHOMEDIR

Considerations when calling Git from a batch file in the build

Always ensure you begin any calls to git in a batch file with call.

In a Windows batch file, any call to another batch file will not return unless you use the call keyword beforehand. So prefer to use call git push over git push for example.

Debugging

The log files in c:\BuildAgent\logs can all have useful information when trying to resolve the issues discussed above, specifically the files teamcity-vcs.log, teamcity-build.log and teamcity-agent.log.

Conclusion

As you might imagine, this all took quite a bit of fiddling around to see how to get this all going - and I must say the documentation available does seem to be vague in a lot of areas. I think it is perfectly reasonable to argue that the extra build complication may outweigh the potentially “nice to have” use case there happens to be for pushing into the repository from the build, at least until this becomes less difficult.

But I hope that this is helpful for anyone doing the same thing!

Categories:   Development
Actions:   E-mail | Permalink | Comments

TeamCity SpecFlow IntegrationJan11

Wednesday, 11 January 2012 by haemoglobin

For a recent project I introduced SpecFlow to automate acceptance tests in true BDD style which I have been rather pleased with. SpecFlow’s HTML output report is very good for reporting the current behaviour and state of the system to stakeholders – an example SpecFlow report can be seen here.

Using TeamCity as our Continuous Integration platform (highly recommended by the way, I’m a big fan of TeamCity and is free for smaller teams), what we wanted was to have the SpecFlow tests run by TeamCity after every check-in, and the SpecFlow output report displayed in an easily accessible tab of the build result.

In order to demonstrate how this can be done I’ve stripped it right back from the ground up using an example SpecFlow project which is available on GitHub.

These steps assume you have git installed, however the basic idea will work with any source control system.

  1. Download an install TeamCity, SpecFlow and NUnit.
  2. From a command prompt / git bash shell – navigate to where you want to clone/checkout the SpecFlow examples (e.g c:\git), and run:  
    git clone https://github.com/techtalk/SpecFlow-Examples.git
    This will create the directory c:\git\SpecFlow-Examples containing the repository’s source. Being a DVCS however, this directory is a git repository itself that we can point TeamCity directly at for our example.
  3. In BowlingKata\BowlingKata-Nunit add a new batch file RunSpecFlow.bat with the following contents:
    "C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console.exe" /labels /out=TestResult.txt /xml=TestResult.xml /framework=net-4.0 Bowling.Specflow\bin\Debug\Bowling.Specflow.dll 
    
    "C:\Program Files (x86)\TechTalk\SpecFlow\specflow.exe" nunitexecutionreport Bowling.Specflow\Bowling.SpecFlow.csproj
    
    IF NOT EXIST TestResult.xml GOTO FAIL
    IF NOT EXIST TestResult.html GOTO FAIL
    EXIT 
    
    :FAIL
    echo ##teamcity[buildStatus status='FAILURE']
    EXIT /B 1

    The first line will run the SpecFlow tests which in essence are standard NUnit tests under the hood. The reason we need to run it like this from the command line instead of using the TeamCity inbuilt NUnit runner is that we need to have TestResult.txt and TestResult.xml available to specflow.exe for it to generate the report in the next line.

    There are a couple of extra checks at the end to see if the output files exist otherwise fail the TeamCity build in case of catastrophic error running the commands. Step 10 will let TeamCity fail the build if any test fails.  

    Note that your installation locations to NUnit and SpecFlow may vary. In the real world, we actually included NUnit and SpecFlow as part of our repository so things would work on any build agent.
  4. Commit this new file to the repository with:
    git add RunSpecFlow.bat
    git commit –m “Added RunSpecFlow.bat”
  5. In TeamCity, add a new project “SpecFlow Integration Test”.
  6. Create a git VCS root called SpecFlow Examples with the Fetch URL of C:\git\SpecFlow-Examples or whatever you cloned the SpecFlow Examples repository to in step 2 above. All other settings can be left as the default.
    image
  7. In the VCS settings section, tick “Clean all files before build”.
    image
    The reason for this is due to the last lines in the batch file checking for the existence of the output files. If we don’t clean the agent first, the old test output files will still be hanging around from the time before (if running on the same build agent) so we won’t get a failure if the files failed to be created for some reason. It’s slightly slower having this option on, but in practice I’ve had less strange issues with build agents if I always start with a clean checkout.
  8. Create a configuration in the project called “Run SpecFlow Tests”. In the artifacts path, add the following:
    BowlingKata\BowlingKata-Nunit\TestResult.html=>.
    This will copy the SpecFlow output report into the artifacts for the build.
    image
  9. Add an MSBuild step to compile the BowlingKata\BowlingKata-Nunit\Bowling.sln solution using the .NET 4.0 MSBuild version.
    image
  10. Add a Command Line step using the working directory BowlingKata\BowlingKata-Nunit and our command executable RunSpecflow.bat
    image
  11. Add a Build Feature of type XML report processing with BowlingKata\BowlingKata-Nunit\TestResult.xml in the monitoring rules section. This will allow TeamCity to display the number of tests run (with pass/fail counts) and will fail the build if any tests fail. Without this, the build will always be green.
    image
  12. Navigate to TeamCity Administration (top right) –> Server Configuration –> Report Tabs
    Create a new Report Tab with:image

    This tells TeamCity that whenever it sees an artifact named TestResult.html at the root level of the output artifacts, add a new tab to the build output called SpecFlow Results, and display TestResult.html within it.
  13. Run the build!
    Have a look at the lovely output below (I purposely made a test fail to show how it would look): image
    image

image

Of course, the next step is to just add a TeamCity trigger so all of this runs on every check-in to the repository.

I hope this shows how you can get SpecFlow integrated into TeamCity which I think is very effective, especially if your clients have access to your TeamCity server directly as a way of reporting progress or state of the system.

Categories:   Development Process
Actions:   E-mail | Permalink | Comments

GitHub Source Symbol IndexerJan9

Monday, 9 January 2012 by haemoglobin

Do you host your .NET library on GitHub?

Do you want to give developers who use your library the ability to step into your code while debugging, without them even needing to have git installed or your repository cloned on their machines?

Then the GitHub Source Indexer could be for you.

The GitHub Source Indexer is a powershell script that will recursively iterate over PDB files in the directory you specify, indexing the source symbol server links back to raw GitHub HTTP urls, which Visual Studio will load while debugging.

This powershell script was adapted from SourcePack (by Sebastian Solnica) which can be used if you have the full source on your machine and packed into a zip file. In his article, he also describes a lot of the science behind the source indexing of PDB files which is useful reading. Much of the source of the script is reused from SourcePack (also hosted on codeplex here) so credits and thanks to Sebastian.

There is another tool SourceServer-GitExtensions but will require Git and the repository to be installed locally (we also had trouble getting this tool working).

The first requirement before running the script is to have the Debugging Tools for Windows installed which is part of the Windows SDK which can be downloaded from here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=8279

As part of the installation, ensure the Debugging Tools for Windows option is selected as part of the install (install or deselect other options as you desire):

Untitled

Once complete, add C:\Program Files\Debugging Tools for Windows (x64)\srcsrv (or wherever it installed itself on your machine) into your PATH environment variable.

The essential steps of using the script are as follows – all from the command prompt:

  1. Find out what paths are currently indexed in the pdb file:
    srctool –r YourLibrary.pdb
    The output should have a original file path for every source file used in the compilation, lets assume the following for the example:
    C:\git\TestRepository\YourLibrary\LibraryClass.cs
  2. We want this to link to a GitHub URL such as:
    http://github.com/[username]/[RepositoryName]/raw/[branchtagname]/YourLibrary/LibraryClass.cs
    Confirm this URL matches the same version of the source that was used when the PDB file was created. An real example URL can be seen here: https://github.com/Haemoglobin/TestRepository/raw/release1.0/ExampleLibrary/LibraryClass.cs
    This is what the Visual Studio debugger will download into the IDE and step into.
  3. Take note of the beginning of the path in the first step, which will tell the script what to strip out to replace with the GitHub URL, i.e C:\git\TestRepository
  4. Run the powershell script as follows:
    powershell .\github-sourceindexer.ps1 -symbolsFolder "C:\git\TestRepository\YourLibrary" -userId "Username" -repository "RepositoryName" -branch "branchtagname" -sourcesRoot "C:\git\TestRepository" –verbose
    Where:
    • -symbolsFolder: Directory to recurse to source index all PDB files.
    • -userId: Your GitHub username.
    • -repository: Your project’s GitHub repository name.
    • -branch: The name of the branch or tag that matches the correct versions of the source files as when the PDB file was created. 
    • -sourcesRoot: The path that we will be stripping out from the beginning of the original file paths found in step 3 above to replace with the GitHub URL. 
    • -verbose: A optional powershell flag to have the script output more output information to the console
    • Note: Watch out for escaping backslashes! For example use "C:\git\TestRepository" not "C:\git\TestRepository\" as the latter will escape the ending quote of the powershell parameter.
  5. Run the following against the PDB file to confirm the GitHub source indexing information was written:
    pdbstr –r –p:ExampleLibrary.pdb –s:srcsrv
    Which will look something like the following:
    SRCSRV: ini ------------------------------------------------
    VERSION=1
    INDEXVERSION=2
    VERCTL=Archive
    DATETIME=01/09/2012 11:58:22
    SRCSRV: variables ------------------------------------------
    SRCSRVVERCTRL=http
    HTTP_ALIAS=
    http://github.com
    HTTP_EXTRACT_TARGET=%HTTP_ALIAS%/%var2%/%var3%/raw/%var4%/%var5%
    SRCSRVTRG=%http_extract_target%
    SRCSRVCMD=
    SRCSRV: source files ---------------------------------------
    C:\git\TestRepository\YourLibrary\LibraryClass.cs*Haemoglobin*TestRepository*
    master*YourLibrary/LibraryClass.cs
    SRCSRV: end ------------------------------------------------

You can now distribute this PDB file along with your library’s DLL, and the developer will be able to step into your source library code to assist their debugging session. Alternatively to distributing the PDB file with your library, you could also make it available through a symbol server (which I may save for another blog post).

There are a couple of things that the developer will need to setup in Visual Studio however before they can step into the GitHub source your PDB files reference:

  1. Make sure the symbol cache directory is set to a writable location (if not running Visual Studio as administrator ensure that the non-elevated user also has permissions to write here):
    image
  2. Ensure source server support is enabled and Enable Just My Code is unticked:

DebuggingGeneral
That’s it!

To test this locally, copy and reference your library’s dll/pdb pair from another project, but make sure you rename your original library folder you compiled from. This is because the original file path is not actually removed in the source indexing process, so if it is still there Visual Studio will load the original path as opposed to downloading from GitHub.

Reference the library, write some code against it and add a breakpoint before the library call. Use F11 to step into the library code, and if the file correctly downloads from GitHub it should load from your symbol server cache directory, similar to below:

image

Good luck!

[Update: If you use Resharper, you will also be able to step into the library code on GitHub at development time as you are navigating around the code, so you don’t even need to be in a debugger session for this to happen. Nice!]

Categories:   Development
Actions:   E-mail | Permalink | Comments

Patterns for Accessing App.config SettingsJan6

Friday, 6 January 2012 by haemoglobin

Here are some patterns I have used for accessing App.config settings which I’ve found to be quite clean. If you introduce an interface over top of the class you will also be able to stub it out for unit testing.

Consider the following application settings:

<appSettings>
  <add key="DelaySeconds" value="15"/>
  <add key="EndDate" value="2013-02-01 6:30pm"/>
</appSettings>

In code, timers usually require millisecond values over seconds so we do a conversion here using the Lazy object showing how any calculations can be done once and when required. We can then access these with the class below:

public class AppSettings
{
    private readonly Lazy<int> _delayMilliseconds;
    
    public AppSettings()
    {
        _delayMilliseconds = new Lazy<int>(() => GetMilliseconds("DelaySeconds"), true);
    }

    public int DelayMilliseconds
    {
        get { return _delayMilliseconds.Value; }
    }

    private int GetMilliseconds(string configSettingName)
    {
        var seconds = GetSetting<double>(configSettingName);
        return Convert.ToInt32(seconds * 1000);
    }

    public T GetSetting<T>(string key)
    {
        string value = ConfigurationManager.AppSettings[key];
        if (value != null)
        {
            try
            {
                var converter = TypeDescriptor.GetConverter(typeof(T));
                return (T)converter.ConvertFrom(value);
            }
            catch(Exception ex)
            {
                var logError = string.Format("Unable to convert configuration value for {0} to type {1}", key, typeof(T).Name); 
                Console.WriteLine(logError);
                Console.WriteLine(ex.ToString());
            }
        }

        return default(T);
    }
}

You can either wrap each setting in its own property or access it directly based on the string key as below:

var appSettings = new AppSettings(); 
Console.WriteLine(appSettings.DelayMilliseconds); 
Console.WriteLine(appSettings.GetSetting<DateTime>("EndDate"));

The output being as below:

15000
01/02/2013 18:30:00
Categories:   Development
Actions:   E-mail | Permalink | Comments

Backup Firefox Bookmarks with DropboxDec31

Saturday, 31 December 2011 by haemoglobin

This technique will make use of the mklink command that is available with Vista and Windows 7 which will essentially just link to a folder outside of your Dropbox directory so that Dropbox will include it in its backup routine. There are downloadable tools available for XP however if you are on that.

  • In the Firefox navigation bar, type about:config and press enter (accept the warning message).
  • Search for browser.bookmarks.autoExportHTML and change this value to true. This will create a bookmarks.html file containing your bookmarks in your Firefox profile directory every time you close Firefox.
  • Open a command prompt in Administrator mode (in Windows 7 you can do this by hitting the windows key, typing cmd, then ctrl-shift-enter, then Alt-Y to accept the elevation prompt).
  • Navigate to your drop box directory with cd [Dropbox directory path].
  • Find out where your Firefox profile is located by opening Firefox and finding Help->Troubleshooting Information in the menu. Beside where it says Profile Directory, click the button Open Containing Folder.
  • Copy this folder location (you can do this by typing Alt-D then Ctl-C).
  • Back in your command prompt, where “FirefoxProfile” is the name of the folder you are creating in your Dropbox directory (change this if you wish), type:
    • mklink /D FirefoxProfile then right click and choose paste to insert your Firefox profile location and push enter.
    • You should have something that looks like the following:

image

Your bookmarks along with your entire Firefox profile will be backed up to Dropbox automatically whenever you close Firefox.

If you don’t already have Dropbox, I highly recommend getting it – if you sign up with the following link: http://db.tt/qZpeNIFp you will get an additional 250MB of storage space than the normal 2GB.

Further Reading

At the beginning of doing this, I really only wanted to backup the single bookmarks.html file that Firefox produces when you turn the autoExportHTML option on by creating a hard link to this using the mklink /H option. This would work great normally – however, the way Firefox handles the bookmarks.html file is it will delete it and recreate it again when Firefox closes. This causes the hard link to be disassociated and you end up with a stale copy of the bookmarks.html file in your Dropbox folder that never updates. I then thought that I might as well be backing up my entire Firefox profile anyway.

Also, it’s not compulsory to turn on the autoExportHTML option as your bookmarks will still be in your profile – but I think it’s nice having that there for a rainy day – plus it will also allow Launchy if you use it (which I spoke a bit about here) to index your bookmarks by turning on the following option in the Weby plugin:

image

Categories:   Technology
Actions:   E-mail | Permalink | Comments

Windows Quick Launch for Remember the MilkDec16

Friday, 16 December 2011 by haemoglobin

Lately I am using Remember the Milk (RTM) more and more to keep track of all my tasks, and I am looking forward to writing a blog post about what I think is a great way of using it day to day – I will continue fine tuning the process first however.

For now I thought I would share how to set things up for rapid task entry. Remember the Milk has a nice stripped down entry page you can access to add tasks, the URL to this can be found here: http://www.rememberthemilk.com/services/ext/addtask.rtm

It would be nice though to have this appear as a small popup in the middle of your screen, launched through a keyboard shortcut such as CTL-ALT-T to pop the following window up:

RTM

I found the best way to do this is to make use of the Chrome Application feature as I talked about in my last post, associate a keyboard shortcut to it through the windows shortcut and optionally do some trickery to get the window size right.

Just follow the steps below:

  1. Browse to http://www.rememberthemilk.com/services/ext/addtask.rtm in Chrome and create a Chrome application shortcut by clicking on the wrench->Tools-"Create application shortcuts".
  2. On the next screen, choose where you want the shortcuts to be placed.
  3. Find a new shortcut created, right click->Properties, assign a keyboard shortcut such as CTL-ALT-T as in the screen shot below:

    RTMProp

And you are done.

Note that if on Vista, the keyboard shortcut key will not work if you set it on the quick launch bar shortcut.

Optional Window Size Adjustment

At the moment Chrome does not seem to remember window positions of chrome applications so I have opted to follow the approach of Eddie in his article here to size the window appropriately.

Essentially you are changing the –app part in your target field in the shortcut from:
C:\Users\HamishG\AppData\Local\Google\Chrome\Application\chrome.exe --app="http://www.rememberthemilk.com/services/ext/addtask.rtm"

To something like this:
C:\Users\HamishG\AppData\Local\Google\Chrome\Application\chrome.exe --app="C:\Users\HamishG\Desktop\Dropbox\RTMAdd.htm"

Where RTMAdd.htm is a file with the following contents - I have extended the javascript logic a bit however so the window will always centre on the screen no matter the resolution:
    <html> 
    <head> 
    <script language="JavaScript"> 
    var width=500;
    var height=300;
    window.resizeTo(width,height);
    window.moveTo((window.screen.width/2)-(width/2),(window.screen.height/2)-(height/2)); 
    window.location = "
http://www.rememberthemilk.com/services/ext/addtask.rtm";
    </script> 
    </head> 
    <body> 
    <h1>Please enable javascript.</h1> 
    </body> 
    </html>  

Hope this is useful,
Hamish

Categories:   Productivity
Actions:   E-mail | Permalink | Comments

Productivity Tip 4: Chrome Application ShortcutsNov27

Sunday, 27 November 2011 by haemoglobin

I generally use Firefox as my default web browser mainly because the plugins still seem to have much more polish, and it’s speed is catching up to Chrome after every release, however one useful thing Chrome has that doesn’t seem to exist in Firefox yet is the “Create application shortcuts” feature.

A web application, as opposed to a web site, is rich in client side functionality and keyboard shortcuts, much like a desktop application. Gmail is a good example of this, or your online to-do list application such as Remember the Milk. Since these are like desktop applications, they should really exist on your PC like any other application would with their own icon in the task bar, on your desktop and start menu etc.

You end up with something that resembles the following:

image

The 2nd and 3rd icons there on my desktop open a new stripped down chrome window with remember the milk and gmail inside, as opposed to a tab lost in amongst all the other web pages you happen to have open within your browser session. I know you can “pin as app tab” in both Firefox and Chrome but there is a benefit to be able to hit WindowsKey-3 wherever you happen to be on your PC to bring up your Gmail – or the ability to alt tab to it just like any other application.

The following steps create the application shortcut from Chrome:

  • Browse to the web application
  • Click the wrench icon in the top right
  • Choose Tools then “Create application shortcuts”

image

You then have the following options, choose what you wish:

image

And you are done. I’ve tried all sorts of hackery to get something similar going with Firefox (with shortcuts to firefox.exe and the url to load etc) but didn’t have much luck with the web application always grouping into the same Taskbar group icon in Windows 7 – even after trying to set the application id appropriately on the shortcut etc.

I am however quite happy that using Chrome I can have my favourite web applications fire open independently from my taskbar – and chrome being fast is also a good candidate for the job.

p.s I had a slight issue with the chrome applications not remembering the size of the window when I launched it next as it was always appearing in a strange location and a funny size. You may not need to do the same, but I fixed this by changing the properties on the shortcut to always open as Maximized.

image image

Cheers,
Hamish

Categories:   Productivity
Actions:   E-mail | Permalink | Comments

Productivity Tip 3: Mouseless Browsing and Password ManagementNov8

Tuesday, 8 November 2011 by haemoglobin

A couple of Firefox plugins that I have been playing with recently which I think are worth mentioning:

Mouseless Browsing

The more you get used to the keyboard, the more reaching for the mouse seems like a burden. Browsing the web tends to be quite a mouse happy activity, but there are times when you are in the keyboard “groove” and you don’t want to leave it. The mouseless browsing addin for Firefox (there are similar ones for Chrome) allows you to navigate the web just using the keyboard.

This Firefox plugin can be obtained from the following link https://addons.mozilla.org/en-US/firefox/addon/mouseless-browsing/

Once installed, you can configure a hotkey to display a special code beside each link on the page you are looking at, that you can type the id to navigate to that link.

An example screen shot of what I am talking about is as below:

image

After installing, I have modified the extension with the following settings. This is just my personal preference, the plugin itself is very customisable.

Display Ids only on demand

The webpage tends to look ugly when the ids are displayed so I prefer not to have these visible all the time:

image

Use standard characters instead of numeric

Like the mouse, I find the numeric keyboard too far away from where my hands are, so I’ve defined the ids to be standard alphabet characters instead:

image

Redefine Toggle visibility and Postfix keys

Since I don’t have the ids visible by default, I use Ctl-J to bring them up (only because of it’s natural touch typing finger position).

Turning off the numeric ids in the second step unfortunately means you can’t use modifiers anymore for opening in new tabs or windows. You can however have Postfix keys which I have setup to be the convenient keys J and N:

image

Example

Now when viewing a webpage I can use Ctl-J to bring up the ids which will all be standard letter combinations.

In the screenshot above of my site I would type ‘B’ to go to the archive section - I could also follow this by J or N if I want to open in a new tab or window respectively.

I don’t use this plugin all the time for browsing as sometimes I am just feeling mousy, but it is a handy alternative for sure !

Password Management – LastPass

As we all know, it isn’t recommended to have the same password for everything – but if you are going to have a new password for everything, how on earth do you remember them all? I have been using LastPass for a good year now and it has been great.

With LastPass, all you need to remember is the one master password, and then it will keep track of all the other passwords for you so you don’t have to remember them plus keeping them all different from each other.

When you sign up for a new website, last pass will suggest an auto generated password for you. It will then register your username and password for the site when you go to login so you don’t need to type these in for the next visit (you can specify that you always need to type your master password if you like before autocompleting the login). Their business model is a small amount per month to make use of their smart phone apps to access your passwords etc, otherwise it’s free!

The passwords are all stored on the server so you can access these anywhere you have an internet connection, but they are encrypted with your master password so no-one else including LastPass employees will be able to decipher your passwords, and all communication to LastPass is over SSL for security.

It really has streamlined my online experience - Recommend !

Categories:   Productivity
Actions:   E-mail | Permalink | Comments

Productivity Tip 2: Window and File ManagementOct16

Sunday, 16 October 2011 by haemoglobin

This is a continuation from my post Productivity Tip 1: Application Launch . When you start documenting it, it’s amazing how many little things you come to realise you are doing day to day, and it tends to end up looking quite convoluted. I will try to keep things from now on more simple!

Window Management

If you are using Windows 7 – please learn the great commands for shifting and positioning windows. (Note that whenever I use the word Win, I mean the windows key on the bottom left of your keyboard).

These are:

  • Win-Down: Minimise. 
  • Win-Left: Dock window to left half of your screen.
  • Win-Right: Dock window to right half of your screen.
  • Win-D: Minimise everything to show desktop.

If you have a second screen:

  • Shift-Win-Right: Move window to your right screen.
  • Shift-Win-Left: Move window to your left screen.

If you are not running Windows 7, you can have all the commands above plus more by installing Winsplit Revolution (note you can remap the default shortcuts to the windows 7 ones above so the transition when you upgrade will be smooth).

Just to iterate from my last post, getting your favourite apps up from pinned items in your task bar is done fastest using the Win-[# location in taskbar] shortcut. Keep pressing the number while holding the windows key to iterate through items that have grouped onto the same taskbar location. 

Alt Tab Replacement – VistaSwitcher

The Alt-Tab window switcher in Windows 7 is much better and have improved a lot since XP.

However, I am still preferring to use VistaSwitcher. The main benefit I get from using VistaSwticher is a larger window preview, and also being able to clean up and close my open windows directly from there.

To do this:

  • Alt-Tab
  • Up and down arrows to navigate
  • Press ‘s’ when over an item you want to close, to select it.
  • Press ‘x’ to close these items (note that the item you are currently over will also close)

If you have two screens, make sure that in the VistaSwitcher settings you choose a particular monitor for it to always display on for consistency, as by default it will show up on the monitor where the currently active application is sat and is just confusing.

File Management

QTTabBar

There is one major problem with windows and doing work that requires access to a multitude of folders across your machine.
You end up with something that looks like this:

image

This in my opinion is pretty hopeless for productivity.

Folders should be tabbed, just like your web browser is and any other application that opens multiple items.

Enter QTTabBar – this free open source explorer enhancement will insure that you will only ever have one explorer instance open and have lovely neat tabs for your open folders instead.

After installing, the first thing you should do is go to View->Toolbars and untick the space greedy QTTab Standard Buttons.

Now, right click the area beside the tabs to choose options:

Under “Window”:

  • Tick “Capture new Explorer processes”
  • Untick “Do not capture window as a new tab when opened from outside”

The options above will ensure you will only ever have the one explorer window no matter how you go about opening folders on your PC (the right click ‘Open folder in Windows Explorer’ option of Visual Studio for example).

Under “Tab

  • I like to have “Show tab switcher by Ctl+Tab” unticked.

Under “Shortcut Keys

  • Untick “Open current folder in new window”

The above keyboard mapping conflicts with Windows 7 create new folder shortcut.

You can now:

  • Ctl-Tab through tabs
  • Ctl-W to close tabs
  • Shift-Enter to open selected folder in a new tab

Also note the following handy Windows 7 explorer shortcuts:

  • Ctl-Shift-N – create new folder.
  • Alt-Up – navigate up one level.
  • F2 – rename (of course!)
  • Alt-D – puts the cursor in the address bar.

I then recommend pinning explorer to your taskbar for easy access using the Win-# shortcut mentioned above.

Alt-F4 Replacement with AutoHotKey

For hardcores only – I find Alt-F4 the most awkward keyboard combination for something that I need to do quite regularly (remember though that many windows respond to Esc for closing, especially modal type windows). This awkwardness of course must go.

I have instead mapped the very easy keyboard shortcut Win-Q to Alt-F4 using AutoHotKey.

Once installed, browse to the Startup folder in your start menu, right click and choose Open.

Create a text file in here with the extension .ahk and the following contents:

  • #q::   Send, !{F4}

Double click the file to start the script (this should also start when windows starts).

Other interesting lines I have in my AutoHotKey file:

  • #w::    Send, ^{F4}     (maps Win-W to Ctrl-F4 for apps that don’t follow the Ctl-W custom for closing tabs – not quite as cool as Win-Q however)
  • ^+4::Send,{ASC 0163}    (this types a ‘£’ symbol with the keyboard combination Ctl-Shift-4, useful if you are on a US keyboard).


This will do for now!
Hope this helps,
Hamish

Categories:   Productivity
Actions:   E-mail | Permalink | Comments

Powered by BlogEngine.NET 1.6.1.0 | Design by styleshout | Enhanced by GravityCube.net | 1.4.5 Changes by zembian.com | Adapted by HamishGraham.NET
(c) 2010 Hamish Graham. Banner Image (c) Chris Gin