Andrew Maddison

Flowerchild.

Configuring Windows as Default in GRUB 2 in Ubuntu

I had a little trouble getting GRUB 2 configured in recent versions of Ubuntu linux (10.4 or 11.* at least). We needed some work machines to default to windows.

You can do it two ways, first is setting the boot order number - effectively the number of the OS you want in the menu Grub presents when you power up your machine. The problem is, when you update your kernal, you get new entries in the menu, so the number changes. Boo!

Alternatively, you can do it by OS name, you just have to find the precise string necessary. Command line chants follow.

First, find the exact name of the OS you want to be default (in my case Windows)
grep Windows /boot/grub/grub.cfg

Then edit grub’s default boot:
sudo gedit /etc/default/grub

Find the following line:
GRUB_DEFAULT=0

And replace “0” with the exact line (including quotes) which was output from grep. Mine looked something like this:
GRUB_DEFAULT="Windows 7 (loader) (on /dev/sda2)"

Finally, update grub to seal in the magic.
sudo update-grub

And that should be that.

comments

Ubuntu Path Environment Variables

Here’s how to set a persistant environment variable in Ubuntu (in this case, to intelli J)

Open up a shell and edit the file /etc/environment
sudo gedit /etc/environment

That will spawn a text editor, which should include a colon seperated list of paths. Add the install location (/bin) inside the intelli J folder to the list, and save the file. Mine looks something like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/SomeUserName/apps/idea-IC-107.587/bin"

Then refresh your environment variables by firing off the following command:
source /etc/environment

You can check that the variable has updated with:
echo $PATH
which should show you the path variable as you edited it.

Finally, check it’s all joined up by launching Intelli J from a random location:
idea.sh

With a bit of luck, IntelliJ will launch. In which case get a cup of tea to celebrate.
comments

IntelliJ Infinite Whitespace at End of Lines - Allow Caret After End of Line

I Just installed IntelliJ community edition on OSX Lion, and out of the box the editor has a strange behaviour that seems (to the uninitiated) that there is infinite whitespace at the end of each line. It turns out there is a setting to turn it off, go to… Settings (Preferences on Mac) -> Editor -> “Virtual spaces” and uncheck “Allow placement of caret after end of line”
comments

Symantec on OSX - Getting Silent Updates Working

Symantec “endpoint protection” (antivirus to you and me) came installed on my new work mac, and because I’m a subservient oik, I’ve not fettled with it before, but the updates have begun to irritate. Basically the updater seemed to be running on a schedule, resulting in a delightful bouncing ball in the dock every hour or so (certainly every time I restarted).

I found a fix over on symantec’s forums. open up a terminal window and you can edit the scheduling for all users on the box (as long as you have root permissions). Here are the magic words:

1
sudo symsched -l 

(Lists the current schedules)

1
sudo symsched -d all

(deletes all the current schedules)

1
sudo symsched LiveUpdate "Update All Daily" 1 0 -daily 07:17  "All Products" -quiet

(creates a new schedule, daily, with the quiet flag set).

comments

Importing Messages From IMAP to Gmail (Without Google’s Tool)

I recently moved most of my email accounts into Google apps (effectively gmail), and wanted to move all of my mail history across too (to make use of all that searchy goodness).

Unfortunately, Google Deprecated their Imap migration tool and recommend you use their Exchange tool instead (pah!). But there’s an easier way! Just use Thunderbird (or your imap email client of choice).

I simply setup two accounts in Thunderbird:
  • One imap account pointing at my old provider
  • Another IMAP pointing at Gmail (go to account settings in Gmail, and ensure IMAP is enabled first).
Then I simply dragged all my mail from one account to the other in Thunderbird. It’s slow, but seems to have worked fine.
comments

Mercurial Hg Rename After Resharper Rename

If you rename or move a file in Resharper as part of a refactoring (or bog standard visual studio, or evern just windows explorer) then Mercurial isn’t clever enough to figure it out alone (unless you tweak some settings to make it more like Git apparently).

So I tried the rename command:
hg rename OldFileName.ext NewFileName.ext
but got the response:
not overwriting - file exists
hg status reported that nothing had changed. Googling showed that you need to use the –after option, to specify that you don’t actually want Hg to move the file in your working copy, just track that is has moved.
hg rename --after OldFileName.ext NewFileName.ext

I think the same should work for Move too.

comments

Getting ASP.Net MVC 3 App Running on Windows 7 64bit.

I just had to re-setup IIS 7 on my local win 7 64 bit dev machine, these are roughly the steps I followed.

  1. Add IIS to windows - follow this guide here: http://www.howtogeek.com/howto/windows-vista/how-to-install-iis-on-windows-vista/
  2. Fire up Inetmgr (iis services manager) and delete the default website.
  3. Create a new website and point it at the root folder of my web project
  4. Browse to localhost
  5. See a permissions error and swear a bit. Then give the iis app pool account read permissions to the windows folder of your web project. In case you don’t know:
    • In window explorer right-click - properties
    • Security Tab - click “Edit” then “Add”.
    • Enter the name “IIS APPPOOL\yourapppoolname” where “yourapppoolname” is probably the same as your website name. This is the important incantation.
    • Click “check names” - OK, OK OK.
  6. Still get a permissions error - google a bit and follow these instructions:
    • open inetmgr again - click on your website.
    • Double click “authentication” under the IIS section.
    • right-click on “Anonymous authentication” and chose “Edit…” and choose “application pool identity”. OK.
  7. Get Error “HTTP Error 403.14 - Forbidden” “The Web server is configured to not list the contents of this directory.”
  8. Swear again, google again, follow these instructions:
    • Check which minor version of .Net 4 you have installed by looking in the folder “%windir%\Microsoft.NET\Framework64”
    • run the following command (64 bit):
      %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir
      or (32 bit)
      %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir
  9. Browse to localhost again. At least for me, at this stage it worked.
comments

SQLite and NHibernate Have Defeated Me for Today…

I’m having a stab at setting up a (very) little ecommerce shop for a friend, and downloaded Suteki Shop by Mike Hadlow.

First impressions were good. I simply downloaded the full source from the read-only repo, built it in VS2010 (which required an install of MVC), tweaked the connection strings and ran the CreateDb console project. (I already had SQL 2008 express installed).

I could then build it in Visual studio, and fire up the website using Cassini, no problems. So I tried running the tests (from visual studio) which resulted in a fair number of failures (56 Failed, 332 Passed and 13 ignores to be precise). Of these, the majority were to do with initialising SQLite from Nhibernate, and it’s this that stumped me (never having used SQlite, and having only grazed NHibernate a little bit at work. The output from Resharper’s test runner looked something like this:

Suteki.Shop.StockControl.AddIn.Tests.Maps [MapsTestsSetupAndTeardown] : Failed

SetUp : FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


—-> NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
—-> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
—-> System.BadImageFormatException : Could not load file or assembly ‘System.Data.SQLite’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

Googling for answers throws up a lot of information, and it seems there are quite a lot of people having similar problems, and there are several different causes and solutions proffered. I’ve tried a few but without much luck.

First of all I attempted to install SQLite (although I’m still not sure this is necesarry, assuming it could instead have been incuded as some kind of reference). This is where the confusion begins, The SQLite download page has 19 (count ‘em) downloads to chose from. I’m on 64bit windows 7, and Suteki shop targets .Net 4, so that narrows the options down to a mere 4 choices - setup or binary, “mixed mode” or not. I stumped for the mixed mode setup. I guess this might have been wrong.

The web seems to suggest a config fix is often the way, so I’ve also tried adding an app.config to the test projects as follows with both of the two sections sugested by the internet.

<?xml version=1.0 encoding=utf-8 ?>
<configuration>
  <startup>
    <supportedRuntime version=v4.0 sku=.NETFramework,Version=v4.0 />
  </startup>
  <system.data>
    <DbProviderFactories>
      <remove invariant=System.Data.SQLite/>
      <add name=SQLite Data Provider invariant=System.Data.SQLite description=.Net Framework Data Provider for SQLite type=System.Data.SQLite.SQLiteFactory, System.Data.SQLite/>
    </DbProviderFactories>
  </system.data>
</
configuration>



This hasn’t worked. And dinner’s ready. If I find a solution (or if anyone suggests one) I’ll try and be good and write an update.
comments

SMTP on Windows Server 2008

A few weeks ago I nearly setup SMTP on my Windows 2008 box, but left it until now to finish it off. Once I’d got a bit of logging working, it seemed that no matter what settings I used in web.config, I recieved the following exception:

Email sent to: example@example.com subject: Username Reminder
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for example@example.com
   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at NRFLogic.Email..ctor(String toEmail, String subject, String body) in C:\path\to\project\Email.cs:line 24

The significant problem transpired to be read permissions to the metabase. Because the SMTP on server 2008 is basically an IIS6 service running in compatability mode, you have to download the IIS 6 resource tools pack (do a custom install, and untick everything except Metabase explorer.

You then need to give your app pool account read permissions to the following keys: LM/SmtpSvc and LM/SmtpSvc/1 (I also gave it read permissions to the root of LM).

Then in code I simply set the SmtpDeliveryMethod property of my SmtpClient object to “SmtpDeliveryMethod.PickupDirectoryFromIis” and deleted the <mailSettings> node from web.config completely. This seems to have done the trick.
comments

Exception Inspector - Stack Trace Explorer vs 2010

Being a soggy headed fellow - I just spent 5 minutes Googling in an attempt to find the “Exception Inspector” in Visual Studio 2010, which of course doesn’t exist.

I was in fact looking for the awesome Stack Trace Explorer provided by Resharper. I finally found it when a sleepy Neuron remembered the shortcut (ctrl + shift + e)

For any that don’t know (and a bit of SEO juice), the stack trace explorer let’s you paste in some text that contains a stack trace (for example from a log file), and Resharper will parse it, highlight it, and sprinkle it with useful links back to the code, such as the line of code which threw the exception in the first place.

A trivial sounding but useful feature, is that the pasted text can contain loads of other cruft as well, and the parser wont complain. So you really can just copy an ugly chunk of log file from your server, and find the line of code in your solution.

Edit: 9th March 2012
I’ve been doing a lot of Java at work recently, and am pleased to discover that IntelliJ has pretty much the same feature, it’s called “Analyse Stracktrace”, and can be found in the analyse menu.
comments