Monday, December 27, 2010

Delayed Push Notification Service for Windows Phone

This is a multi part blog post the other posts in this series are: Overview – you’re reading this now.The push notification service – how to implement the delayed push notification serviceThe client library – not yet written.In this post I discuss push notifications, and share my web service which implements a delayed push notification.Push notifications are a web service that MS provides that can send a message to the phone. There are 3 flavors of push notifications:Raw notification: Raw bytes...

Tuesday, December 14, 2010

PsychicDebugging - You can browse to www.google.com, but you can't ping it.

In my last message to the world I though I'd fixed my networking, but turns out I hadn't. Here's the state of affairs: IE; Chrome and Firefox work perfectly. ping www.google.com fails instantly with hostname not found nslookup www.google.com works From python socket.gethostaddr ('www.google.com',80) fails instantly. This had me stumped, I assumed the web browsers must be calling different apis from ping.  A few invocations of cdb, and I realized the apps that worked are all 32 bit. That was the trick, my 64 bit NSP catalog was also corrupted; and thus all 64bit apps couldn’t resolve networking.  ...

Saturday, December 11, 2010

Set a System Restore Point

Start -> Create a  restore point -> Create A few days ago my event viewer service failed to start, and I went on a crazy goose chase that was most unpleasant.  I suspect my life would have been better if I had a working restore point, so I'm sharing my wisdom with you: create a restore point now. Some surprising things I found on my journey: Eventlog not starting because The Authentication Service is Unknown (Error:1747) => Winsock Catalog corruption. netsh winsock reset should fix said corruption but didn't in my case. Rumor is when netsh winsock reset doesn't...

Tuesday, November 23, 2010

The Scunthorpe problem

I ran across an obscure reference to Scunthorpe problem and had to investigate what this “problem” is.  It turns out Scunthorpe is a town in England, as are the following towns which share the same problem: Penistone, Lightwater. No idea? Perhaps this interview question will make it clear: Design a simple system that can determine if a user name is obscene....

Friday, October 15, 2010

Facebook, OpenID and Decrypting SSL

I was excited to see Facebook (FB) supporting login via OpenID (FB is a relying party), and I decided to give it a whirl. Here I list the results of my investigation, which describe the odd use of OpenID, as well as my wire level analysis which I hope you find informative. This post doesn't go into details of how OpenID works, if you're interested in that leave a comment and I'll put up such a post. FB uses OpenID in a way I've never seen before. In the "common" OpenID login model, you get a login...

Friday, October 8, 2010

Taskmgr to PowerShell: Kill A Process

You know the drill, some app freezes. You try to close it, that doesn’t work.  You fire up taskmgr, sort by name, type in the name, and then hit the delete key to kill the process.  Easy with powershell: Get-Process | ? {$_.Name -eq "firefox"} | killThe real power here is the composability of powershell, for example you could also debug the process. Get-Process | ? {$_.Name -eq "firefox"} | Debug-ProcessOr if you’re not sure what’s going to happen you can always pass the –whatif qualifier: PS C:\Users\igord\Downloads> Get-Process | ? {$_.Name -eq "firefox"} | Debug-Process -whatifWhat...

Wednesday, October 6, 2010

Photo Fusing in Windows Live Photo Gallery

On my camera, I can make the self timer take 8 photos 2 seconds apart. This leaves me with a 1 in 8  chance of getting a good picture. However, using the photo fuse tool in Windows Live Photogallery, I can do a visual merge of the photos to pick my favorite part of each photo.  For example, I used the following source photos: To created this composite photo, (To which I also applied straiten and auto fix) That’s seriously cool!...

Saturday, September 18, 2010

PowerShell: Tab Complete History

If you haven’t tried PowerTab or haven’t tried PowerTab recently stop, and check it out .  PowerTab makes powershell a real pleasure to use, and might be the feature that gets me over the powershell dip.Once you’ve installed PowerTab , you can history complete by starting your command with a #, typing some letters and then hitting tab. For example:...

Saturday, August 14, 2010

Batch to Powershell: Title

If you try to set the title of the window in powershell, 'title' won't work; but you can set the title using the $host object PS C:\> $Host.UI.RawUI.WindowTitle = "Donkey" You can also mess with other fun things like colors eg: PS C:\> $Host.UI.RawUI.BackgroundColor = [ConsoleColor]::Red If you're a big title user and have title burned into your muscle memory you can always create function called title e.g.: PS C:\Temp> function title ($t) {$host.UI.RawUI.WindowTitle=$t }PS C:\Temp> title Donkey2 Have fun moving into powershell....

Wednesday, August 4, 2010

Powershell: Returning ScriptBlocks and Closures

Powershell lets you return scriptblocks (aka anonymous functions) from functions, for example: function generateAdder ($n){ { param ($x) $n+$x }} PS C:\> $add4 = generateAdder 4PS C:\> & $add4 77If you've used languages with closures you'd have expected to get back a function that adds 4 to a passed in value. You'd expect that because $n=4 was in lexical scope when we created the scriptblock to be returned. Recall powershell is dynamically scoped so we don't need to bind ($n) to a lexcial location, instead we can pick up $n from our current environment: PS C:\>...

Sunday, August 1, 2010

Batch to Powershell: dir /s

I often go looking for a file in batch, aka c:\Program Files (x86)>dir /s fsi* Volume in drive C has no label. Volume Serial Number is 8EDE-D64E Directory of c:\Program Files (x86)\Microsoft F#\v4.0 03/19/2010 02:02 PM 230,216 Fsi.exe 09/30/2009 08:08 PM 158 Fsi.exe.config 2 File(s) 230,374 bytesUnfortunately this doesn't 'just work' in powershell. A quick search on the internet shows in powershell 'dir /s' becomes 'dir -r', but the following doesn't work either: PS C:\Program Files (x86)> dir -r fsi*PS C:\Program Files...

Saturday, July 17, 2010

F# Tricks: Concise BoolToInt

As a C# programmer, you'd probably write BoolToInt as follows in F#: let boolToInt3 b = if b = true then 1 elif b = false 0Not a big win over C# yet, but a few things to point out about the concise syntax: Indentation implies blocks. There is no 'return' keyword. This function is statically typed, you don't see types since the compiler infers the types.As a novice F# programmer a trick you learn is pattern matching. Pattern matching is like a case statement, but it's an expression and it's really powerful. I'll go into more details on pattern matching in future posts. For now, notice...

Thursday, June 10, 2010

F# Tricks: Collecting Some Optional Values

Skip this post if you have no idea what F# is, and think LINQ is stupid.When you map inputs to outputs with a function that can return None, or Some Output, you get an annoying issue of having a list containing Nones, and Somes. For example: // Contains both encrypted and un-encrypted files: let listOfFiles:Seq// Return a decrypted File, or None if the file can't be decrypted.let decryptFile file match file with | isFileDecryptable file -> Some DecryptFile file | _ -> None// decryptedFiles contains Nones, intertwined with some Some DecryptedFileslet decryptedFiles = listOfFiles |> Seq.map...

Friday, May 21, 2010

The power of shift clicking – Copy As Path

  Have you ever been in explorer and needed to get the path of a file? Turns out that feature is built into Windows 7! If you shift right click on a file, the menu contains a copy as path link.  Sweet!...

Saturday, May 15, 2010

Making the FSharp interpreter (fsi) run in 64bit!

I love F#!  It’s all the power of functional programming with the training wheels of c# when you need it. All the prototype/REPL power of powershell and python, with the built in test cases I like to call static typing. All the power of static typing, with out the hassle of specifying types every where thanks to implicit typing. But, there is one annoying problem, I crunch very large data sets and fsi.exe runs as a 32 bit application. This means when I load my data sets and iterate through them FSI takes up 1.6 GB of RAM (maximum for a 32bit app), and spends 100% of its time in GC. An...

Friday, May 7, 2010

The joy's of batch - Delayed Expansion

  If you can, skip batch and move strait to powershell. If you don't believe me, maybe this blog post will change your mind. In batch %ErrorLevel% is how you know if the last command succeeded: C:\>echo %ERRORLEVEL%0It turns out if you set a variable that doesn't exist, this sets error code to 1. So C:\>set DONKEYRIDINGEnvironment variable DONKEYRIDING not definedC:\>echo %ERRORLEVEL%1Makes sense, batch isn't that bad you think. Now here's a pop quiz - What will you get when you run this batch file? C:\>type foo.batif NOT "BATCH"=="OBVIOUS" ( echo %ERRORLEVEL% ...

Saturday, February 27, 2010

How to determine the server certificate given an https wcf proxy?

One day when you are using https transports in WCF you might try to figure out what certificate the server is using. That is going to be the day you're glad you found my blog. namespace WebClient{ using System; using System.IdentityModel.Tokens; using System.ServiceModel; using System.ServiceModel.Channels; /// /// Interface implemented by a random https bound web service I found on the web. /// [ServiceContract (Namespace="http://arcweb.esri.com/v2")] interface IVersion { [OperationContract] string getVersion(); } class Program { ...

Saturday, February 13, 2010

PowerShell, PowerTab and Certificates

Powershell is good, but with an awesome tab completer Powershell is great.  Luckily said awesome Tab completer exists, and it is called PowerTab.  Powertab didn't work quite right in the certificate provider (and some other places) so I made some fixes and threw them up on CodePlex. A small demo below:  ...

Saturday, February 6, 2010

Better Certificate Management in Powershell via CertificateHelper

If you’ve read my previous post here, you know powershell can do some basic certificate management via the certificate provider. However, the certificate provider has some limitations. The certificate provider can’t create,delete,copy or import/export certificates. This annoyed me so I’m creating a powershell module called CertificateHelper that will provide these missing features. So far the module implements: New-Certificate Remove-Certificate  CertHelper can be found on codeplex. You install it like this: (You must have hg installed)PS C:\>cd $home\Documents\WindowsPowerShell\Modules...

Saturday, January 30, 2010

Using tshark to find the man in the middle

This post is targeted at people that understand ip addresses, default gateways and have heard of arp, but don’t play with them often enough to realize how vulnerable we are to man in the middle attacks. Back in the old days, the network hardware was often a hub, and hubs had a property that all the computers connected to a hub could see each others traffic.  This meant if my computer and tori-the-lori were on the same hub tori-the-lori could see all my network traffic. This sound like weak security.  In time the world invented switches, and now almost all networking uses switches. Switches...

Saturday, January 23, 2010

The whitespace and indentation debate

Nothing annoys me more than having to argue over whitespace and indentation. Where should we stick the braces? Spaces vs Tabs? Can't we find something more useful to argue over? Long ago I read the only to end the pointless whitespace debate, is to have the compiler reject random whitespace. I thought that was a very good idea, and today I'll talk about it. In the beginning whitespace didn't matter, it was there for the human, and the program ignored it.   But that caused an annoying problem - you ended up needing tokens like '{' ';' and '(' and then you needed to argue about how...

Friday, January 15, 2010

Salting your hash, chasing rainbows and cracking passwords

Henry Ford takes 3 of his division presidents out for diner to decide which of them will be the new CEO. As soon as they start eating Mr. Ford chooses Bob, the man to his left, to be the new CEO. The other division presidents are shocked, and ask why Bob was picked over them. Henry replies: Bob was the only man who tasted his food before salting it. Unlike at dinner time, hashes should always be salted. A hash is a one way function that maps something, for this discussion a password, to a short string. The point of a hash is if you're given the hash, you can't figure out the password. A common...

Thursday, January 14, 2010

How do you thumbprint a certificate?

You often use thumbprints to find certificates, but what is the thumbprint?  The thumbprint is the hash of the certificate. In the case of the CLR’s X509Certificate2 class, the thumbprint is the SHA1 hash of the certificate. If you want to compute the thumbprint of a certificate yourself it’s pretty simple: function get-CertThumbprint ($cert){ $sha = new-object System.Security.Cryptography.SHA1CNG $hashOfRawBytesOfCertificate = $sha.ComputeHash($cert.RawData) ( $hashOfRawBytesOfCertificate| % {"{0:X}" -f $_} ) -join ""} PS cert:\LocaLMachine\My> dir Directory: Microsoft.PowerShell.Security\Certificate::LocaLMachine\MyThumbprint...

Sunday, January 10, 2010

A better blog editor - Windows Live Writer

I've been complaining about the blogger online blog editor forever. Today I took Windows Live Writer out for a spin and I like it. It's free, and it works with blogger without a hitch. My favorite feature is its preview pane which shows an actual preview of your post in the blog, which the blogger editor doesn't do at all. In my heart of hearts I’ve always believe a rich client application should be more powerful then web applications, and in this case it is....

Saturday, January 9, 2010

Keyboard shortcuts in Windows WYSIWG editors

I have a day job, and in that job I use Word, OneNote and Outlook.  For style I only use bold, italics, underline, headings 1-3 and lists. For some reason, I never learned the keyboard shortcuts for some of these, and thus I need the mouse to apply these styles. In case you suffer like me, here’s are the shortcuts that will set your mouse free. Style Word OneNote Heading 1 C-A-1 C-A-1 Heading N C-A-N C-A-N Bulleted List C-S-L C-....

Powershell is dynamically scoped, and that will confuse you.

Lets start with an example, as the concept of dynamic scoping is a big string for most programmers. Python Program x = 5def printX(): print xdef setAndprintX(): x=7 printX()printX()setAndPrintX()printX() Output From Python 555Powershell Program $x = 5function printX() { echo $x } function setAndprintX(){ $x=7 printX}printXsetAndprintXprintX Output From Powershell 575 What is this dynamic scoping? Most programs use static, also called lexical, scoping because it's easy to understand. You figure out what is in scope by looking at the source code. In the python example,...

Sunday, January 3, 2010

Syntax Highlighting Take 2

Readers of my blog complained that they can't see the code I was syntax highlighted in RSS readers like Google reader. The reason is moderately interesting so I'll explain it: HTML likes to gobble up white space, so if you're pasting in source code you use the PRE (preformatted text) tag. PRE shows up in fixed width font and preserves spacing; however you can't place < or > in PRE tags since they denote HTML tags, instead you need to use &lt or &gt (character entity references if you speak techno babble). This is annoying, especially given the blogger text editor gets confused when...

Page 1 of 2312345Next