All posts by Rikard Ottosson

About Rikard Ottosson

.NET developer. Father. Couch potato. Old, cynical, willing to learn, but quick to judge. Likes old hard rock. Hope to buy more guitars.

Posh Git

I have tried to get my head around PowerShell for a while, and I’ve read blogs by Scott Hanselman about PsReadline and PoshGit and decided to finally get on with it and use it properly.

This post is just a repository of my current setup.

Install PsGet if you don’t have it:

(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex

Install PsReadline:

Install-Module PsReadline

Install Git for Windows

http://git-scm.com/download/win

Install posh-git

Install-Module posh-git

Update the profile.ps1 file

Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

# Load posh-git module from current directory
Import-Module PSReadLine
Import-Module posh-git

# If module is installed in a default location ($env:PSModulePath),
# use this instead (see about_Modules for more information):
# Import-Module posh-git


# Set up a simple prompt, adding the git prompt parts inside git repos
function global:prompt {
 $realLASTEXITCODE = $LASTEXITCODE

 # Reset color, which can be messed up by Enable-GitColors
 $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor

 Write-Host($pwd.ProviderPath) -nonewline

 Write-VcsStatus

 $global:LASTEXITCODE = $realLASTEXITCODE
 return "> "
}

Enable-GitColors

Pop-Location

Start-SshAgent -Quiet

set-alias -name np -value "C:\Program Files\Sublime Text 2\sublime_text.exe"

function vsh() {
 Write-Output "Opening first solution..."
 $sln = (dir -in *.sln -r | Select -first 1)
 Write-Output "Found $($sln.FullName)"
 Invoke-Item $sln.FullName
}
 
function title($str) {
 (get-host).ui.rawui.windowtitle = $str
}
 
function ga() {
 Write-Output "Staging all changes..."
 git add -A
 git status
}

function gs() {
 git status
}

function gsd() {
 Write-Output "Pushing changes to subversion..."
 git svn dcommit
}

function gsf() {
 Write-Output "Checking subversion for recent changes..."
 git svn fetch
}
 
function gco() {
 param([switch]$amend, [switch]$a)
 
 $argstr = $args -join ' '
 $message = '"', $argstr, '"' -join ''
 
 if ($amend -or $a) {
 Write-Output "Amending previous commit with message: $message"
 git commit -m $message --amend
 } else {
 Write-Output "Committing with message: $args"
 git commit -m $message
 }
}
 
function gca() {
 $argstr = $args -join ' '
 $message = '"', $argstr, '"' -join ''
 
 Write-Output "Amending previous commit with message: $message"
 git commit -m $message --amend
}

Links

Windows 10 tech preview

So, later than everybody else I installed Win10 tech preview.

I am not agreeing with the versioning strategy and feel like Windows 8.2 had been a more fitting identifier given the limited changes, but the ill-deserved but yet pervasive stigma of the new-fangled Windows 8 had to go away, so I see why going with a major version increase might have made sense.

Multiple desktops is easier to use than Sysinternals Desktops, with the isolation being less complete, so you can Windows Tab between all apps irrespective of desktops and easily move windows between them.

The semi transparent console window thingy is pretty neat but I’m surptised by the limited font choices. Copy / Paste and proper selection just worksTM and I suspect that just like after Ctrl-S arrived in Notepad on Windows 2000 it will probably be inconceivable that it ever worked differently. I installed the operating system on VMWare player and threw in VS14 which diesn’t compile the ASP.NET vNext, but I have spent literally 0 seconds figuring out why and I suspect I haven’t configured something right. The MS Twitter app doesn’t work on my VM, neither does OneGet specifically because Chocolatey is not a provider and no methods of adding providers worked.

I resorted to install Git like a barbarian, downloading the installer from git-scm.com/downloads, but posh-git and psreadline worked as expected. Finally I had a very neat git environment set up in a few moments. I like.

The start menu feels a bit weird, but does make more sense with a desktop OS and I will probably find it more useful as time goes by.

So anyway, if you have an extra computer laying around, get Win10 and try it out. I’ve reported my gripes to the feedback tool, I suggest you do the same. Don’t believe they hype, it’s just a really nice Windows 8.1 Update 2/ Windows 8.2, not  a revolution by any means, just good small improvements overall.

MOVSXD

I have relocated to the Southeastern outskirts of London with my family since I last posted. After 5 years with Jayway it was strange to leave, but a new adventure in a new country awaited. I started working at Cloudhouse Technologies that are developing application virtualisation- and data access virtualisation products. A whole heap of very clever developers work here and we are looking for more such people. We provide ways for companies to leverage new technologies to run applications developed for earlier platforms and network topologies and the work ranges from analysing network logs, designing distributed systems, playing with various low-level API:s and sometimes smithing some websites. I couldn’t believe the job spec when I saw it, it’s like a kinder surprise with all fun things rolled into one. Anyway, so that’s what I have been doing and what has kept me busy.

Microsoft, Apple and the future

I have seen a bunch of uninformed blogs on LinkedIn about the state of large corporations with conclusions based only on hardware preferences of the author, loose speculation and nothing else. I thought why don’t I blog uninformedly on the same subject? I am going to take some of my opinions and state them as fact because let’s face it, I’m right.

Apple vs Microsoft. In a recent study of cool companies people want to work for, Apple scored on top and MS dropped out of the top 20. That seems perfectly reasonable. Microsoft got labelled boring and the wrong kind of evil in the nineties and gradually being proven a lot less evil than both Google and Apple doesn’t help them become cool. Their products are good, not cool. Granted not the best, but better than a lot of them out there, but definitely not cool.

Apple meanwhile deliver decently specified hardware with good margins, iffy software with while showing sub par security conscience. Their iWork Office killer is far from MS Office in terms of features, but sadly for Microsoft, that doesn’t quite matter as much as they would hope. People will take iffy build quality of a laptop (yes), a few missing features of an office suite and a not-very-successful cloud solution if they get a cool laptop that has good battery life. I am not being bitter or sarcastic her. I for instance want the dustbin (the Mac Pro) with very little supporting technical data that would make it win over a traditional tower.

Microsoft just let Nokia fork Android. I’ve said this before, but this would have been the ideal thing to do in the first place. Making several operating systems from scratch just because you think you can is maybe not the most profitable solution. Especially since throughout the early life of Windows Phone, the patents around Android were Microsoft’s top revenue source in the mobile space. Instead having went with an Android fork, focussed on providing excellent gateways towards Microsoft services, driving revenue in Bing/Azure/Office365 could have been far more efficient in my not so humble or well grounded opinion.

Microsoft have always done well in providing API:s and documenting them thoroughly, knowing that engaging developers to extend and combine your products really helps you in the long run. Eventually Apple realised the same thing and overcame Jobs’ doubts and created the AppStore for iOS and that was a roaring success obviously.

Yes, Microsoft made API:s and an awesome development environment Visual Studio and they brought forth evangelists to tell people what to make with their products, but Apple and Google were on a roll. Quickly scores of .NET developers, that still felt that they could never go Apple because they detested the brand and all it stands for, instead found that switching to Java was a survivable pain to get to develop for a mobile platform that essentially is Windows XP for mobile, a platform where you can do whatever you want with the phone and put it in the store.

The problem is that Microsoft desperately wanted to provide the entire foundation of the ecosystem. While Steve Jobs even back in 1985 was overseeing work on the Big Mac that was UNIX based – what later became NeXTStep and OSX, Microsoft soldiered on making everything themselves from drivers to OS to apps, and they were big enough for a while to get away with it, but it is easier if you take things that exist and work and build on them.

This is where Satya Nadella comes in. His division of Microsoft were forerunners in Microsoft working with open source, as in opening their own projects as well as adhering to external open source standards (OWIN, for instance). Apple, Google and others have a far bigger legacy in Open Source, of course, but Microsoft has been turning around, slowly but surely, and Nadella’s org as been the driving force behind this development. Perhaps this can be an opening for Microsoft getting a little leaner. focussing on a few key revenue sources allowing other areas of significant spend to be dropped, adopting open standards and simply contributing to existing community projects.

The only reason the security problems Apple have faced have been so limited despite the complete non-action from Apple over the decades is that they based their OS:es on a core that other people kept going for them. They made it easy for developers to harness the power of what I like to call the dark side, the *nix open source community, which is as vast as the universe itself, In a way that Windows doesn’t.

As an example of the MS of old: When MS started dogfooding Windows Server in large scale clusters they realised that they need a secure file transfer mechanism and a scripting environment that had a bit more muscle than CMD.exe. They could have implemented an SSH server and gotten both – in a standard way no less, but instead they made Powershell and MS Deploy. Purists would have argued in favour of a proper Bash shell and a unified file system with mount points instead of the unfashionable disk drive system, but that even today can be implemented or at least simulated for the desperate among us.

Maybe the course that Nadella set out is one that will lead to a turnaround for Microsoft. The shrinking OS license revenue will be a problem for a while, but I think there is a way out on the other side, and I am suspecting Nadella might know it.

Finding dependent columns in SQL Azure

When fiddling with database relations in an Azure database you quickly notice you are on your own in terms of tooling in a way that you’re not used to from Microsoft. Metadata however is available so you can work around these things relatively easily.

So: when you are dropping and recreating tables as you design them – here’s a quick snippet to see which columns are depending on the particular table you are editing now:

create procedure show_referencing_relations 
@schemaname sysname, 
@tablename sysname 
as 
select 
 [DropSQL] = 'ALTER TABLE [' + @schemaname + '].[' 
 + ptbl.name + '] DROP CONSTRAINT [' + fks.name + '];',
  [AddSQL] = 'ALTER TABLE [' + @schemaname + '].[' 
 + ptbl.name + '] ADD CONSTRAINT [' + fks.name + 
  '] FOREIGN KEY (' + pcol.name + ') REFERENCES ['
 + @schemaname + '].[' + @tablename + '] (' + col.name + ')',        [ConstraintName] = fks.name,
[Source Column Name] = col.name,
[Parent Table Name] = ptbl.name,
[Parent Column Name] = pcol.name 
from sys.foreign_keys fks 
 inner join sys.all_objects ao on fks.referenced_object_id = ao.object_id 
 inner join sys.foreign_key_columns fkc on 
fks.object_id = fkc.constraint_object_id
 inner join sys.all_columns col on 
 col.object_id = ao.object_id and 
 fkc.referenced_column_id = col.column_id
 inner join sys.all_objects ptbl on fkc.parent_object_id = ptbl.object_id
 inner join sys.all_columns pcol on 
 fkc.parent_column_id = pcol.column_id and 
 pcol.object_id = fkc.parent_object_id
 --inner join sys.all_objects pcol on fkc.constraint_column_id = pcol.object_id
 where ao.name = @tablename

Run it with schema and table names, and you get some SQL to use before and after your planned change. First one to remove the constraints and the second one to restore them. The results of the stored procedure show the name of the constraint, the column in your table that is being referenced plus the parent table and column involved in the relationship.

Then you can quickly write code to drop and recreate these relations.

F# for fun and profit

(I am in no way affiliated with the brilliant blog of the name http://fsharpforfunandprofit.com/. I wish I was, but no, I just remembered the phrase and used it as a headline, sorry.)
It is no secret that Øredev 2013 will be rich in terms of F# content. Recently there has been a surge in interest for this Functional First .NET-language with lucrative opportunities in many fields, finance especially. The conciseness and correctness of F# code makes it attractive for work that features clever algorithms and as a .NET language it of course benefits from the general richness of the platform.
You should, if you haven’t already, check out the following sites and the links from there.
http://tryfsharp.org
http://fsharpforfunandprofit.com/

Øredev 2013 – it is drawing near

Since I last wrote about our most excellent conference Øredev, there have been a few announcements. Go check out the program for all details as it is now time for you to register if you have not already done so.

After the Build conference, the key takeaways, in my most humble opinion, were vastly improved performance and features in multi-monitor, multi-DPI  support  in XAML in Windows 8.1 as well as the enormous paradigm shift in ASP.NET 4.5.1 which unifies all view engines and paradigms into one ASP.NET, which will help users cherry pick the things they need to create apps that leverage all things that comprise ASP.NET. WebForms, MVC, SignalR and WebApi.

To demonstrate those things from Build, Mads Kristensen, Sr. Program Manager on the Web Platforms & Tools team, will grace us with his presence and do a talk entitled What’s new in Visual Studio 2013 for Web Developers, while one of our old favourites, Tess Ferrandez will return to do a session called What is new in XAML for Windows 8.1.

We will also, as you may have read on the Internets, feature keynotes from Anna Beatrice Scott, Randall Munroe and Jens Bergensten have been added to the lineup.

In other words, we are pretty excited about our conference, and believe you would be too, so get started with your reservations.

Tip: Clearing QueryString when using RadControls and ASP.NET WebForms

I had to google myself silly and the page I ended up finding was so hard to find I couldn’t actually find it again to link to it properly. The below code is not my idea, so if you feel wronged, submit your link and I shall attribute properly.

The problem is: I want to be able to navigate, or find my way back if you will, to a certain MultiPage and TabStrip that is nested inside a Telerik RadGrid. As it is a view and not a state change, I would like the querystring to handle this. However, to be nice, or obnoxious, depending on how you see it, Telerik will resubmit the same querystring when you navigate the tabs yourself, which will make it so that after changing tabs via querystring once, you cannot navigate to a different page by clicking anymore.

Anyway: People on the Internet, especially Telerik forums tell you to do Request.QueryString.Clear(), but that just doesn’t work because it is a readonly Collection and although it compiles, you will get a runtime error. So: What to do?

The post that I found simply used violence and Reflection to force the collection into being Read/Write, and then when Telerik reads from Request.Querystring to needlessly resubmit the exact previous query, it actually, accidentally, posts the correct, cleaned querystring. This enables my expected scenario where you by using GET can change tabs in a TabStrip/MultiPage.

        private void ClearQueryStringParam(string paramName)
        { Continue reading Tip: Clearing QueryString when using RadControls and ASP.NET WebForms 

Early Bird campaign ends in two weeks, Aug 15

Early Bird campaign ends in two weeks, Aug 15

We are proud of the program we have put together for Øredev 2013 and we are quite confident you will find the content interesting enough to at least consider coming to Malmö in November.

The thing is, our very lucrative early bird campaign is ending in two weeks, so if you are on the fence, this is the time to pull the trigger and make that reservation. It is easier to beg accounting for forgiveness than to ask for permission. It can’t hurt to at least ask.