Archive for the ‘Uncategorized’ Category

Post

Microsoft Mathematics – An Amazing Freebie

In Uncategorized on 2011/10/30 by phejndorf

I know some people want to spell Microsoft with a $ instead of the s, and certainly some of their products are not cheap. But today my daughter (who is a 14 year old 8th grader) pointed me to Microsoft Mathematics 4.0, a fantastic free program that does math, plots etc etc.

To think that for little more than 350 USD you can get a small PC that will run this beauty and more – back in its day the Texas Instruments TI-59 was 300 USD!

The Microsoft Mathematics even features a Word plugin, that will actually let you do part of your Math (and other) homework directly within Word.

On the left hand side of the Mathematics screen is a calculator like device, that is really just a shortcut to the various formulas that are supported.

image

It is the worksheet window where the real lifting is done. Here you can see how the system explains how a simple equation is solved:

image

It sounds like a cliché, but there are just too many features to easily explain, so you really have to have a go yourself and download it!

image

If you happen to run Mac or Linux there is of course the (also free) option of GeoGebra

Post

Setting A Default Recovery Model For Sql Server

In Uncategorized on 2011/10/12 by phejndorf

Changing the default recovery model (and other settings) for every new database you create on a server is managed by setting the attributes of the “Model” database.

As the documentation states: “A new database inherits its recovery model from the model database.”

In my case, working mostly with test-servers in VMware, it means that I generally change the installed defaults like this:

USE [master]
GO
ALTER DATABASE
[model] SET AUTO_SHRINK ON WITH NO_WAIT
GO
ALTER DATABASE
[model] SET RECOVERY SIMPLE WITH NO_WAIT
GO

image

Post

Virtualizing Windows 8 Developer Preview – Now Playing On VMWare Player 4

In Uncategorized on 2011/10/06 by phejndorf

VMware Player version 4 is now available, and can be used with the Windows 8 Developer Preview.

However, you can’t just install it as Windows 7 as there is no serial available, but the installation is still pretty simple.

I found a good introduction to the steps here: http://www.eightforums.com/tutorials/2899-vmware-player-install-windows-8-developer-preview.html

Note that there is an issue with the VMware tools in 64 bit mode.

Post

A lookup table of Visual Studio Keyboard Shortcuts (KeyBindings)

In Uncategorized on 2011/07/30 by phejndorf

I’ve really wanted to be faster at my VS 2010 work, and to that end I think that getting to know and and practice the keyboard shortcuts is a good idea….

I know there are quite of overviews out there like Scott Guthrie’s and DoFactory’s, but I wanted my own structured data to be able as filter, group and search as I please.

Much googling took me here at MSDN where Kevin Buchs has added a nice VS 2010 macro for extracting the data.

I’ve modified Kevin’s implementation a bit, in order to be able to import it more easily into an Excel sheet (download sample here with the default bindings), so here’s my version of the macro:

Sub GetAllCommands3()
        ' http://msdn.microsoft.com/en-us/library/ms247076.aspx#1

        Dim new_window = DTE.ItemOperations.NewFile("General\Text File")
        Dim doc = new_window.Document
        Dim textDoc = CType(doc.Object("TextDocument"), TextDocument)
        textDoc.StartPoint.CreateEditPoint() ' Creates an "edit point" at the beginning of the document

        ' Tab-separated per command / binding
        For Each cmd In DTE.Commands
            If Not cmd.Name.Trim().Equals("") Then
                Dim line1 = cmd.Name.ToString().Split(".")(0) + vbTab + cmd.Name.ToString()

                For Each binding In cmd.Bindings
                    Dim split = binding.ToString().Split("::")
                    Dim line2 = line1 + vbTab + split(0) + vbTab + split(2) + vbCrLf
                    textDoc.Selection.Insert(line2)
                Next
            End If
        Next
    End Sub

Post

Implementing your own Linq “equals” join operator

In Uncategorized on 2011/07/20 by phejndorf

Today I needed to do a Linq join on two sets of class that needed to have a custom join, ie the concept of equality had to be determined by a rule in the class.

The problem is, that .Net doesn’t have an interface that facilitates this, and that you have to have knowledge about the inner workings of the Linq join/equals.

Here is how it works:

1. Linq will call the two compared classes GetHashCode() method to determine if they have the same hash-code.

2. If they don’t they are assumed to be unequal.

3. If the hashcodes are equal, Linq goes on to the class’s Equals(object o) method to determine equality.

This is implemented by reasons of performance. The hash-metod only confirms – as a truly unique hash-code doesn’t exist in reality – that the two classes might be equal, and not until then is the presumably costlier Equals executed to determine acutal equality.

So because of this you need to implement both a GetHashCode() and an Equals() method. By implementing the IEquatable<T>() interface you get the Equals() method, but then you must implement GetHashCode() by overriding it, otherwise your Equals() method may not ever be called as the base GetHashCode() method will be different for all (most) instances, and to Linq all classes will be different!

You can do several things in your GetHashTable() method – the simplest of which is to return a constant, in which case Linq will always quickly move on to the Equals() method. You can also select one or more fields of the class to hash on, I guess it is a design choice based on your knowledge of the actual data that will get the best performance.

Stackoverflow has a good posting here on how to do the hash generation. I personally think this one looked pretty neat:

return new { A = PropA, B = PropB, C = PropC, D = PropD }.GetHashCode(); 

But, as mentioned, it’s all about speed (and memory), and a question whether most elements are actually unequal or equal, so some testing will be in place in each case.

Post

WCF Web Api: oData format doesn’t mean oData service

In Uncategorized on 2011/07/15 by phejndorf

Over the years I must admit that the WCF acronym to me has had the effect of instilling huge amounts of fear and loathing. We have inhouse some really complex stuff that requires gargatuan declarative angle-bracketed configuration monsters that are next to impossible to figure out for most people. One makes changes, fearing both life and mental health. WCF, in short, is one of those Microsoft inventions that make you wonder why you didn’t train to become something else – a plumber for instance.

Recently I’ve been playing a bit with the WCF Web Api, however, and it seems like a really easy way to get some REST-ful data over the wire. When you return a collection of data from Web Api, you can elect to return it  as an IQueryable in which case you will, as it says,  be “Enabling OData query support” .

Mark that phrasing carefully: You are not enabling OData as such – it’s just that you can now use the OData URI syntax when you retrieve data. So don’t fall into the same hole that I did and think that you have full blown OData!

Other than that misconception on my part, it’s all thumbs up for this initiative to focus (and tame) the WCF monster into something more immediately  useful. The WCF Data Services (OData) effort is the same story. Now I just have to convince the rest of my fellow devs and customers that the days of heavyweight WCF/SOAP are coming to a an end in a lot (most) scenarios…

With that said, do go check out Glenn Block’s speech at Mix 11: "There’s a URI for that".

PS. I just discovered that we have one SOAP implementation where all data is exchanged with a mobile client as delimited strings, in order to conserve bandwith by eliminating a lot of XML tags!

Post

A test-message for AppsGeyser

In Uncategorized on 2011/07/11 by phejndorf

I’ve generated an Android App from my blog, so I’m wondering if this message will automagically show up, or all I got was a static snapshot!

Post

Running MacBuntu – A Poor Mans OSX

In Uncategorized on 2011/07/07 by phejndorf

It’s been a good many years since I was last on Linux – back then using it for web-servers, MySql and, believe it or not, homegrown Token-Ring to Ethernet bridging (saving the company a lot of money).

However, the last couple of days I’ve been playing around with a fun thing: A Mac OSX lookalike skin for Ubuntu! I like the Apple stuff, but it really pains me to have to fork out the price of a Mac. I like “free” much better :)

To start out I used the Ubuntu installation with Wubi, however this installs Ubuntu 11.04 – and not Ubuntu 10.04 for which the Mac skins are designed. Luckily LangIT has a recipe for making this work. Otherwise you can turn to LiberianGeek for a Wubi that supports 10.04.

The Wubi install plays along very nicely with your Windows, and isolates Ubuntu in a separate directory on the PC, default booting Windows and not touching any Windows vitals. You can access the PC disk from the Ubuntu /host directory.

After Ubuntu is up and running, it’s time to look for MacBuntu. Follow the instructions for downloading, unpacking and installing it.

All looked very nice, but – what – no wobbly windows… Who can live without that? Turned out that my NVidia graphics card wasn’t supported natively, but needed closed source drivers – the instructions for that are here.

Voila, a jolly nice OSX UI experience right on my trusty old Windows 7 laptop!

Oh, and one final thing: I found out that getting video from DVD’s works really well with Handbrake in Ubuntu, but it was kind of hard to find the whole install story in one place, so here is my version for the enjoyment of your Terminal window:

sudo add-apt-repository ppa:stebbins/handbrake-releases
sudo apt-get update
sudo apt-get install handbrake-gtk

Post

Use your keyboard in Windows Phone 7 emulator – and a caveat

In Uncategorized on 2011/06/29 by phejndorf

Even if you’re “only” developing and demo-ing mobile web applications the Windows Phone Emulator (the “7” is gone for the new Mango) is a great place to start. Of course lots of testing still needs to be done on Androids, iDevices and what have you – but still, the WP emulator, running as it is in a virtual machine using the actual compiled Phone code, is probably the best available. It’s emulation of positioning and orientation is great!

To depend on simulators is always risky even in the best of times and Android emulation seems awfully slow. In my case WordPress could not recognize the Fennec (the mobile Firefox) desktop version as a mobile device. Apple’s Safari for Windows seems fairly true to the iPad, but did mislead me for iPhone/iPod capabilities.

However one thing I missed (or thought I missed) in the WP emulator was the keyboard. I really hated keying with the mouse on the screen keyboard until I came across this link, entitled “Keyboard Mapping for Windows Phone Emulator”: http://msdn.microsoft.com/en-us/library/ff754352(v=VS.92).aspx – it is as easy as PgUp and PgDn to enable and disable a hardware keyboard.

And now for the caveat:

If you’ve enabled the hardware keyboard, the browser won’t autorotate if you tilt the emulator window. Remember to disable the hardware keyboard with PgDn before you use the emulators rotate function!

Post

Convert to SQL Date from decimal DDMMYY

In Uncategorized on 2011/04/26 by phejndorf

As it says – I’ve come across this before, so now I’ll dump my memory here having reinvented this old wheel.

The basic steps look like this, using April 1st, 2011 as a sample:

declare @orgvalue decimal(8,0)
set @orgvalue = 10411

select @orgvalue % 100 * 10000 + FLOOR(@orgvalue / 100) % 100 * 100 + FLOOR(@orgvalue / 10000)

 

First the year is isolated, then the month and then the date, and the result is obtained adding 110000 + 400 + 1 = 110401.

There is absolutely no error-handling here, so suppose you want to be absolutely sure that the result is actually a date, the easiest way is to actually cast it to a Date – but then you hav to cast via a char value to get it right.

select Convert(Date, 
        Convert(char(6), @orgvalue % 100 * 10000 + FLOOR(@orgvalue / 100) % 100 * 100 + FLOOR(@orgvalue / 10000),112))

 

This will not handle single digit year numbers, however, so in case you need that – and you’re sure about the century – you can do it like this:

select Convert(Date, 
        Convert(char(8), 20000000 + @orgvalue % 100 * 10000 + FLOOR(@orgvalue / 100) % 100 * 100 + FLOOR(@orgvalue / 10000),102))

 

Hope I won’t have to figure this out all over again next ime I need it…

Follow

Get every new post delivered to your Inbox.