Pages

Thursday, 5 July 2012

Eating at Tossed

I got to try Tossed recently, totally by chance.

If you’re on a particular diet, Tossed is absolutely perfect because it allows you to fine tune what you eat. This is something you usually can’t do with places like Pret-A-Manger, where sandwiches always come with bread and salads with pasta.

Chipotle is not bad because if you’re targeting a slow-card diet, you can eliminate the tortillas, have more beans, peppers, a bit of guacamole, some lettuce and a choice of 4 meats. But you get bored after a while.

So I was happy to try something different. Tossed give you the option to include / exclude a base (the carbs). And most of the base options are slow carbs: whole wheat couscous, brown rice or whole wheat noodles… Then you choose 1 of 9 meats, 1 of 12 delis and 3 of 23 veggies. The create your own page is here.

You can also go for a ready-made salad and swap ingredients.

And they have peanut butter smoothies!

Thursday, 26 April 2012

How to set the Thread Pool Size in Quartz.Net?

By default Quartz.net creates a pool with 10 threads. How to change the size of the pool?

This is not obvious from the documentation, but burried inside one of the examples that come with the library:

            NameValueCollection properties = new NameValueCollection();
            properties["quartz.threadPool.threadCount"] = "1";

            ISchedulerFactory sf = new StdSchedulerFactory(properties);
            IScheduler sched = sf.GetScheduler();

 

Why did I need to change the pool size to 1? Well my jobs are executing third-party .NET wrappers around some native code that is not exactly thread-safe. I had a situation where I couldn’t schedule the same job twice: on first execution the job would run fine on thread 1. On second execution the same job would start on thread 2 then hang on a 3rd party method call. Forcing both runs to happen on the same thread fixed the problem.

Tutorial:

http://quartznet.sourceforge.net/tutorial/lesson_10.html

API Documentation

http://quartznet.sourceforge.net/apidoc/2.0/html/webframe.html

Monday, 12 March 2012

The End Is Nigh!

I was visiting Foyles the other day… Most books in the General Finance section have alarming-sounding titles. With the exception of a few books about Richard Branson or Warren Buffet it’s all about catastrophes, burns, falls, crashes, crunches, collisions, lies, delusions, failures, etc…

I’m not making this up, look at this list, all picked from the same bookshelf at Foyles:

Dark markets
How markets fail
When genius failed
When markets collide
When money dies
The end of money
How I caused the credit crunch

Market panic
Panic!

Bubbles and crashes
Why stock markets crash
The legacy of the crash
The great credit crash

No one would listen
A decade of delusions  
Masters of nothing
House of cards
Rigged money
Fool's gold
Devil's casino
Liar's poker
The wizard of lies
Biggest lies on wall street

Monday, 5 March 2012

Currently Watching…

...while brushing my teeth

GoingNative 2012

Misc

Thursday, 24 November 2011

Windows Service Gotchas

  • the current directory is not the location of the executable, it’s System32! But that’s easy to change.
  • anything logged to the console will be lost. You can redirect anything you output with System.Diagnostics.Trace. That includes for instance the internal debugging output from log4net (useful when you don’t know why your service is not logging anything).

Quoted from log4net documentation:

 

There are 2 different ways to enable internal debugging in log4net. These are listed below. The preferred method is to specify the log4net.Internal.Debug option in the application's config file.

  • Internal debugging can also be enabled by setting a value in the application's configuration file (not the log4net configuration file, unless the log4net config data is embedded in the application's config file). The log4net.Internal.Debug application setting must be set to the value true. For example:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <appSettings>
            <add key="log4net.Internal.Debug" value="true"/>
        </appSettings>
    </configuration>

    This setting is read immediately on startup an will cause all internal debugging messages to be emitted.

  • To enable log4net's internal debug programmatically you need to set the log4net.Util.LogLog.InternalDebugging property to true. Obviously the sooner this is set the more debug will be produced.

Internal debugging messages are written to the console and to the System.Diagnostics.Trace system. If the application does not have a console the messages logged there will be lost. Note that an application can redirect the console stream by setting the System.Console.Out. The Trace system will by default send the message to an attached debugger (where the messages will appear in the output window). If the process does not have a debugger attached then the messages are sent to the system debugger. A utility like DebugView from http://www.sysinternals.com may be used to capture these messages.

As log4net internal debug messages are written to the System.Diagnostics.Trace system it is possible to redirect those messages to a local file. You can define a trace listener by adding the following to your application's .config file:

<configuration>
    ...
    
    <system.diagnostics>
        <trace autoflush="true">
            <listeners>
                <add 
                    name="textWriterTraceListener" 
                    type="System.Diagnostics.TextWriterTraceListener" 
                    initializeData="C:\tmp\log4net.txt" />
            </listeners>
        </trace>
    </system.diagnostics>

    ...
</configuration>

Make sure that the process running your application has permission to write to this file.

Tuesday, 22 November 2011

Your Home Address on the Web

image

 

I’ve always thought privacy concerns over Facebook were exaggerated -they usually come from your parents who have been publishing their home address and phone number on the white pages for decades anyway. There is much much worse.

The mere act of voting in the UK ends up in having your home address published on the web.

If you registered to vote on the Electoral Roll and ticked the wrong box, the one with the confusing caption, something like “tick here if you don’t want your details to appear in the private listing”, then all your past addresses are on the web, year by year. Yippee!

It’s not just your home address, but also the list of people who lived with you. That must be the most blatant breach of privacy I’ve ever seen. It’s like Facebook for flatmates with privacy settings set to ‘Everyone’.

Look at this. Only the first part of the postcode is available. To get the full info all you have to do is register at 192.com.

Tuesday, 1 November 2011

Currently Reading or Watching…

Sunday, 16 October 2011

TeamCity, msbuild and Version Numbers

How to automatically set all your solution’s projects to the same version number with msbuild and TeamCity?

We have a number of solutions mixing native and managed projects.

The mechanism we use to ensure all DLLs and EXEs have the same version number relies on modifying 2 files:

  • A VersionInfo.h file for native projects
  • A VersionInfo.cs file for managed projects

The .h file contains something like this:

#define PROJECT_VERSION 3,9,0,1234
#define PROJECT_VERSION_STR “3.9.0.1234”

All native projects in the solution have a resource file (.rc) that includes this unique VersionInfo.h.  This is how the exe/dll obtain their version info.

On the .NET side, the VersionInfo.cs file contains:

[assembly: Assemblyversion(“3.9.0.1234”)]
[assembly: AssemblyFileversion(“3.9.0.1234”)]

All managed projects in the solution compile this VersionInfo.cs file (using a soft link, no duplication necessary).

So all we have to do in order to ensure that the 30+ binaries have exactly the same version number is to get our build script to modify the .h and the .cs just before building the solution.

Sounds easy!

Then there is the question of where to store the “3.9.0.1234” version. It should be in one single place of course. An obvious choice seems to be the TeamCity build number.

From Major.Minor.Build.Revision, we can set Major.Minor.Build by hand in TeamCity and have the Revision set automatically to the current SVN revision number, which is a handy way to relate builds to SVN revisions.

In the TeamCity project settings, the build number format field looks like this:

3.9.0.%build.vcs.number.MyProject_SVN_Root%

ScreenHunter_01 Oct. 15 18.37

Then within our msbuild XML file we refer to the build number set in TeamCity like this:

$(BUILD_NUMBER)

The following msbuild lines update the version number stored in the VersionInfo.cs.

    <FileUpdateFiles Files="VersionInfo.cs"
      Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
      ReplacementText="$(BUILD_NUMBER)"/>

This regex does wonders to replace “1.2.3.4” with “3.9.0.1234”. But now, more tricky: when doing the string replace in VersionInfo.h (it’s always the native projects that cause trouble Winking smile), how do you replace

#define PROJECT_VERSION 1,2,3,4

with

#define PROJECT_VERSION 3,9,0,1234

given the string in $(BUILD_NUMBER) “3.9.0.1234”.

Can’t do anything a bit subtle with msbuild without having to download and install third-party tasks… So I’m currently looking into the TextString task from the MsBuild Extension Pack to tokenise the version string and then concatenate it back to the appropriate format. It’s all a bit complicated, there must be an easier way to do this…

Update (16/10/2011):

It’s actually not that bad, here is the code that formats $(BUILD_NUMBER) and updates the .h /.cs VersionInfo files.

    <TextString TaskAction="Replace"
                OldString="$(BUILD_NUMBER)"
                OldValue="."
                NewValue=",">
      <Output PropertyName="FormattedBuildNumber"
              TaskParameter="NewString"/>
    </TextString>
    <Message Text="Replacing version in VersionInfo.h with $(FormattedBuildNumber) and $(BUILD_NUMBER)">
    </Message>
    <FileUpdateFiles Files="VersionInfo.h"
      Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
      ReplacementText="$(BUILD_NUMBER)"/>
    <FileUpdateFiles Files="VersionInfo.h"
      Regex="(\d+)\,(\d+)\,(\d+)\,(\d+)"
      ReplacementText="$(FormattedBuildNumber)"/>
    <Message Text="Replacing version in VersionInfo.cs with $(BUILD_NUMBER)">
    </Message>
    <FileUpdateFiles Files="VersionInfo.cs"
      Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
      ReplacementText="$(BUILD_NUMBER)"/>

Tuesday, 4 October 2011

Getting Ready For FOWA London 2011

This is the schedule for tomorrow’s first day of FOWA (Forum of Web Apps) at the Brewery between Shoreditch and Whitechapel.

http://futureofwebapps.com/london-2011/schedule/