Monday, December 6, 2010

Virtualization

I don't want to use Hyper-V because it requires a separate machine (unless you're developing on Windows 2008 -- I'm not).
I don't want to use Virtual PC because it doesn't support snapshots.
I don't want to use VMWare player because it doesn't have a good api.
I don't want to use VMWare server because it just plain sucks.
I don't want to use VMWare Workstation because it isn't free.
I am using VirtualBox. It has snapshots. It can be automated with a very rich command line.

For Example:
.\vboxmanage guestcontrol execute [[TheMachineName]] \\vboxsvr\Public\InstallStuff.exe --username [[theUserName]] --password [[thePassword]]

Automatically installs the latest build of the software. InstallStuff.exe is an AutoHotKey script that gets the latest build from a network share then automates the installer. So this automates the deployment of the latest build on a virtual Machine.

Friday, December 3, 2010

WinDbg

I'm posting some notes from my latest debugging adventure.

The big advantage to WinDbg is easy deployment on a test machine. I don't have to worry about installing remote debugging with visual studio or correctly setting up the permissions.

The notes:

1) Although the download site says that you probably want to run 64 bit WinDbg on a 64 bit machine, the machine architecture is irrelevant. Most apps that I've been writing, and especially those that use legacy COM objects are x86 and WinDbg behaves poorly if you don't get the right version for your architecture. The download page is here.

2) Downloading WinDbg is still annoying. But this is only because I remember the good old days where I only needed to download the Debugging Tools for Windows and not some entire SDK.

3) sxe clr
This breaks the debugger whenever there is a CLR exception. I'm always after some .net bug. This is the first thing that I type in to get going, usually right after WinDbg attaches.

4) .loadby sos mscorwks
This loads the SoS Debugging extensions for .net. I wait until WinDbg breaks after the first CLR error, because this command won't work until mscorwks is actually loaded by the program.

5) !pe
This is short for !PrintException. It outputs information about a .net exception.

6) !CLRStack
This outputs the .net stack trace, ignoring the surrounding native code.

7) !dso
Dump Stack Objects. Helps you figure out what objects in memory are likely to be involved in any current problem.

8) !do
Dump Object. Information about a single object.

A cheatsheet

Friday, November 19, 2010

Kerberos Logging

I recently encountered a bug in a program that was using a Vb6 COM object to call the MAPI COM objects. There was very little information about what the problem was - no logging, nothing in the event log. The problem though, was a Kerberos authentication failure. I had to turn on Kerberos logging before I could see it. This powershell script is useful for doing that:

#Useful: http://support.microsoft.com/kb/262177
#Read the state of the Kerberos Loggin Registry Key
Get-ItemProperty -Path hklm:\\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters\ -Name LogLevel

#Turn on Kerberos Logging
Set-ItemProperty -Path hklm:\\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters\ -Name LogLevel -Value 1

#Turn Kerberos Logging off
#The KB Article said to turn it off so that performance was not adversely affected after the logging was obtained.
Set-ItemProperty -Path hklm:\\System\CurrentControlSet\Control\Lsa\Kerberos\Parameters\ -Name LogLevel -Value 0

#Retrieve Event Log Entries related to Kerberos
Get-EventLog System | Where { $_.Source -eq "Kerberos" }

Monday, November 1, 2010


This is a wireless thermometer. It transmits the temperature in the small greenhouse on my balcony to my computer. From there, I can email myself if the temperature in the greenhouse approaches freezing or just post the temperature on the web for fun.

There are three components here:

  1. An Arduino.
  2. An XBee wireless module.
  3. A Temperature sensor. 
The arduino is programmed to read the voltage from the temperature sensor, convert it to a text string, and then send it over the XBee transmitter to the XBee receiver which is connected to my computer's serial port. 

This is the arduino code:
#include <NewSoftSerial.h>

NewSoftSerial mySerial
= NewSoftSerial(2, 3);

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
Serial.begin(
9600);

Serial.println(
"Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println(
"Hello, world");
}

void loop() {
float voltage = 5.0*analogRead(0)/1024;
float temperatureC = (voltage - 0.5) * 100;
float temperatureF = (temperatureC * 9 / 5) + 32;

Serial.print(temperatureF); Serial.println(
" degrees F ");

mySerial.print(temperatureF); mySerial.println(
" degrees F ");

delay(
1000);
}

The SoftSerial library is very useful. It enables serial communications on any two digital io pins.

The following powershell code reads the temperature from the XBee module and uploads it to a WebService:

$portName = "COM4"
$url = "http://ogresoft.com/Temperature/Home/SetTemperature?Temperature="
$delay = 60

$serialPort = New-Object "System.IO.Ports.SerialPort"
$serialPort.PortName = $portName
$serialPort.Open()

while($true) {
$temperature = $serialPort.ReadLine()
Write-Host $temperature
$request = [System.Net.HttpWebRequest]::Create($url + [DateTime]::Now.ToString() + " " + $temperature)
$response = $request.GetResponse()
Write-Host ([DateTime]::Now.ToString() + " " + $response.StatusCode)
Sleep $delay
}


Thursday, October 14, 2010

??

The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.

return name ?? string.Empty;

It looks like its been around since 2005.

http://msdn.microsoft.com/en-us/library/ms173224%28v=VS.80%29.aspx

Friday, August 6, 2010

InternalsVisibleTo Attribute

Just ran across this while needing to test a private method. Useful.

Friday, June 25, 2010

Powershell Functions

CLIP

Very cool. It copies piped input to the clipboard.

Tuesday, June 1, 2010

Computer languages

I tend to use the following on a monthly basis:
C#
VB
Powershell
F#
Javascript - JQuery
AutoHotKey
Android (Java)
Regular Expressions

Some of them I use daily (VB, C#).
Weekly (Powershell, Javascript - JQuery, F#)
Monthly (Android, Regular Expressions).

I find it interesting, just looking over the list and noting the vast differences in their purposes and their syntax,
even in the tools used to write them. That is by no means an exhaustive list of the computer languages which I know and have worked with, but it is the list of the languages that I am still learning and growing more proficient in.

More powershell

Here's what I wrote today:


1. Get-Item count.txt | Get-Content | Measure-Object -Line | Select-Object -ExpandProperty Lines
2. Get-Item count.txt | Get-Content | Select-String -Pattern "ThatObject\.Load\(\)" | Measure-Object -Line

In one, note the -ExpandProperty option. This returns an integer rather than a powershell object containing an integer.

In two, note the use of a regular expression.

Regular expressions are cool in general, but my regular expression skills and my powershell skills suffer from the same problem, and that is that I tend to use them rarely. But they're very useful when I do use them. When I get to combine the two, that's just a bonus.

Tuesday, May 11, 2010

Building with VS2010

The big change is the workflow integration in the build. Which is cool.

I'm very glad to see that they've minimized the use of MSBuild. MSBuild is retarded, I'm glad I don't have to touch it anymore.

If I have to do anything complex I launch a custom powershell script to do it.

Software that I use:

Slysoft Virtual Clone Drive
Office 2010
  OneNote
VS 2010
  Power Commands
  GIT SCC
Firefox
  Firebug
  Rikaichan
  Delicious
  StumbleUpon
  FireFtp
Chrome
Adobe Acrobat
Sql Server 2008 R2
PowerGui
AutoHotKey
Notepad++
Reflector
JQuery
TrueCrypt

I should put this in a static web-page, so I can provide linked commentary on each tool.

Monday, May 3, 2010

Week 9: MonoDevelop Hello World

I fired up Monodevelop for the first time, to see how hard it was to develop on Linux. I'm running Ubunto 9.10 and had it installed from ubuntu's cool software installation untilities. It wasn't hard. And the silly console program that I wrote ran just fine on Windows. Nifty.

Friday, April 9, 2010

ogresoft.com

I moved my japanese quiz programs out onto the internet, away from my local computer. I also put them into an MVC 2.0 project. It seems to have worked out well. ogresoft

Monday, March 1, 2010

Powershell Tail

I've often wanted to use tail in windows. This is the same thing:

get-content -wait

Sunday, February 21, 2010

Quiz program updates

I've added some new functionality to the japanese quiz program.

1. New history items are added to the top of the history list, not the bottom.
2. Chapter 3 vocabulary.
3. Minor improvements to the graphical layout (centering, sizing).
4. Corrected spelling error ("inorrect").
5. Added JQuery dialog on last quiz option that shows missed items and resets using only the missed items (last option only right now).

Todo:

  • Add the ability to dynamically add and remove words/questions.
  • Get the checkbox/tag filtering system working
  • Add freehand drawing as an answer style. Allow it to be manually graded.
  • Double check that the JQuery dialog works on a phone. 
  • Add the JQuery dialog to all options.

The freehand drawing is going to require another javascript library. I've been poking at processingjs a bit, and it looks like the way to go, unless I wish to tie myself to Flash or Silverlight, and I don't.

Telling IIS to serve up a file as a download

I created a virtual directory in IIS.
I put the file that I wanted others to download in it. In this case an *.apk file.
I turned on directory browsing.
I clicked on the file and got a 404 error.

I added the mime type *.apk, application\android to Mime-types in IIS.
I clicked on the file and it downloaded.

Week 8: Hello Android World

I wrote my first android program. It pops up a window that alerts you every time the gps coords of the device change. Okay, this isn't particularly impressive, especially since I copied the bulk of the code from this link. However, getting eclipse installed and the android environment working was a chore.
  • Download Eclipse
  • Download the Android SDK
  • Tell Eclipse where to find the android downloads
  • Tell eclipse about what Android Virtual Device you wish to use.
  • Figure out how to do anything in Eclipse.
  • Wait patiently for the Virtual Device to boot up. 
Getting the application signed for the first time was also a bit of a chore. It requires running two command line tools jarsigner and keytool. Keytool is used to create a keystore that contains the private key which is used by jarsigner to sign the application. After the first time though, the eclipse environment recognized the keystore and I did not have to repeat most of the steps. Once the application was built, copying it to my phone and installing and running it was easy. I had installed Astro File Manager and just clicked on the built file. It then prompted me to install it and then it ran it. Quite smooth.

The compiled application is located here.

Tuesday, February 9, 2010

Calling powershell from MSBuild

I don't understand MSBuild. I'd rather use a versatile language like powershell to do my work rather than a narrow xml-based language, that is unwieldy and non-transferable knowledge. Once you know MSBuild... well you just know MSBuild. Powershell can be used nearly anywhere.

This link shows how to do it:
http://blog.brianhartsock.com/2009/10/20/using-powershell-scripts-from-msbuild-scheduled-tasks-etc/

Week 7: Japanese Quiz Program

Currently it is here: http://www.ogresoft.com:83/MVC/HTML/Japanese111-1.htm.

There is no webservice - ajax stuff in here, the program, other than script includes, is self-contained. Of course, I used JQuery extensively. It was interesting to observer that most of the file is javascript, followed by css, and very little html.

From here, I need to add voice options: first converting the stock *.wav files into several *.mp3 files. The two *.mp3 files that I use for success and failure were converted from *.wav files using Sound Converter 1.4.4 in Ubuntu Linux. I made a few feeble attempts to download a useful freeware windows tool to do the conversion, but that didn't work. +1 linux; -1 Windows.

I made the viewable quiz area such that it would fit well on a cell-phone browser screen (landscape mode).

If I can get these programs to run well in a cell-phone browser, is there much use in creating cell-phone OS specific applications that do exactly the same thing, but in only a slightly more fluid manner? Probably not.

Week 6: Powershell Daemon

This is a program that runs a powershell script. It will put a notify icon in the task bar while the script is running. If you run a powershell script with a continuous loop in it, in order to monitor something, like the event log, this will do that without cluttering up the desktop with these "daemon" scripts. It clutters up the taskbar icons instead.

Some technical notes:

Get the powershell assembly reference from here: C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0

Instructions on how to run powershell from C# here: http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx

How to put a NotifyIcon in Wpf: http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx

The appropriate way to deploy this program is with ClickOnce. However, I was unable to get ClickOnce operational with this program (VS 2010). There were some cryptic notes on what could be going wrong, but the correct course of action for a lazy person, such as myself, is to wait for the next version of visual studio to come out and hope that they fix it.

Once that happens there is still something to do: Associate the *.daemon extension with this program so that double clicking a *.daemon script will launch it. This bit is simple enough to do using the registry, but I'm going to wait for the click once stuff to get straightened out before I waste time on installers.

Sunday, January 31, 2010

Week 5: Internet Stratego

There was a bit more of a leap between tic-tac-toe and stratego than I anticipated. I'm tired. I coded furiously, knowing that I had probably overpromised myself in choosing the project for this week. I could feel myself slowing down as the effort began to wear me down.

I typically don't go for mental marathons. I can feel my mind get tired and become less effective. I believe that everyone's mind does, but that most others who brag about their long hours are either in denial or can't judge the difference in their own work between when they are tired and when they are at their peak.

I'm lazy, you see. I don't want to waste more time than I have to on any particular task. My silly endeavor, 52 weeks of coding, has two purposes. One, to do in coding what is analogous to a long line in fishing. To bait the waters of business with 52 distinct pieces of possibility, and see which, if any, of them get bites. And two, to perfect the art of efficient coding. I want to get these projects done fast. I want to reduce, as much as possible, the time between when I have an idea, and the time when it is tangible enough to show to other people.

So marathon coding represents room for improvement. Next time, I will do it faster.

But lets go over some of the other things that I learned this week:

JQueryUI

This is where I got the drag and drop functionality. Very nifty, very concise.

Firebug

OK, I already knew about firebug, but the Console and the Debugger made this week possible. Yeah, they're that cool.

JQuery attribute selectors.

delete arrayName[elementIndex];

$('someselector').droppable('destroy')

Monday, January 25, 2010

Find the static methods on an object using powershell

[System.IO.Path] | Get-Member -Static

That "-Static" part took me way too long to find. My Google-Fu needs work.

Saturday, January 23, 2010

Week 4: Head to Head Tic Tac Toe

I've completed Tic Tac Toe head to head. "Complete" is of course relative. Right now, there are still serious usability issues, but they are all UI work. The back end and ajax calls won't need to change.

Same URL as last week. :)

How to scroll a textarea to its end using JQuery

var myHeight = $('textarea#TextArea1').height();
$('textarea#TextArea1').scrollTop( myHeight );

Tuesday, January 19, 2010

Week 3: Simple Chat integrated with MVC

The leap from simply having an MVC 2.0 project integrated with Sql Server to having the project do something moderately useful was a bit more work that I expected. Not that any bit is hard, mind you, but the sheer number of bits was interesting.

Bit 1: ASP.Net Web Services is different from WCF Web Services is different from MVC. Maybe if I hadn't come late into the web programming game, that would have been a bit more obvious. I had previously set up a simple program to act like a chat program using a JQuery/javascript web client and an ASP.Net Web Service back end. Once I tried to move the ASP.Net web service into my MVC project, I realized that well, you can't do that. An ASP.Net web service is its own project. Forcing them together seemed like a bad idea. It turns out it is a bad idea. MVC enables returning pure JSON to an ajax enabled web page, so in retrospect, that is the way to go, but I hadn't stumbled upon that piece of information yet, so I put a WCF Web Service in the MVC project and got it working. There were a number of gotchas in setting up the Web Service correctly and also aligning it with the correct JQuery syntax.

Bit 2: Connecting Entity Framework 4.0 to an external Sql Server. This was straight forward, and in retrospect, everything I did with the EF was straight forward. In retrospect that is. Being a total noob in EF cost me some time, but I'm becoming a huge fan. Note that I'm talking about EF 4.0. Not the single earlier version.

Bit 3: Hitting F5 is different from browsing to your site through the internet. The first time I hit it from the internet, it didn't pick up any of the stylesheets or the jquery files. So it wasn't very functional. I had to share the folders in windows explorer before it would allow them to load. I spent much time futzing with IIS settings hoping the answer was in them.

Bit 4: I don't know how the Publish menu item in the solution explorer works. Oh sure it looks cool, push one button and your web site is automagically made externally browsable. But setting up a Publisher or whatever it is has eluded me for the 5 minutes that I've allotted to investigating it.

Bit 5: I don't know how to get MVC 2.0 deployed on my web server. My web server is of course, a virtual machine running Windows 2008 R2, but theoretically, that shouldn't matter. I've also failed to deploy SqlServer on my virtual machines.

I have resigned myself to using both SqlServer and MVC 2.0 on a real machine. So I pointed IIS at the directory where my VS 2010 MVC project is, and it all seems to work for now.

Week 3

Sunday, January 10, 2010

Week 2: MVC integrated with Sql Server

This week looks quite unimpressive. I have simply integrated the IIS authentication with Sql Server. So it uses a Sql Server database and not a Sql Express database. There were a few hangups that kept this from being a trivial exercise.

1) I couldn't install Sql Server on one of my Hyper-V machines.

I would get most of the way through the installation process and then it would fail, with "an external component has thrown an exception." I tried several variations, including virtual machines and real machines, virtual drives and real drives. All were on Athlon dual core machines.

Eventually, I gave up and installed Sql Server on my dev machine, which is an intel quad core.

2) I had to prep the Sql Server as descrbed in this article: How To: Use Forms Authentication with SQL Server in ASP.NET 2.0.

The salient bit is that one has to run aspnet_regiis.exe. This launches a wizard that does most of the work.

3) I had to make sure that the local user that had the same name as the domain user had the same password locally and on the domain, even though I explicitly specified the domain user. Confused? Just don't have a local user with the same name as a domain user and you shouldn't have to worry about this.

I wish I hadn't floundered so much getting this all set up. I'm still not happy with the set up since I want the whole thing deployed in virtual machines and it isn't right now. Next week I should have the boggle, chat, and MVC working together.

As for now, they are separate:
MVC integrated with Sql Server as the backing for Forms Authentication

Boggle Clone



And the Chat program isn't exposed yet. :(

Saturday, January 2, 2010

Chat program

This week, and I think I'll try to write an application per week, I wrote a very simple chat program using JQuery, Entity Framework, and Sql Express. I'd put up a link to it, but I've spent the last two nights trying to get it deployed. I finally decided that it isn't worth it. The goal was to write the application not spend an infinite amount of time fiddling with IIS to get it deployed.

The actual application is still quite rudimentary. Just a few text boxes on an HTML page. The server side, while simple, should elegantly suffice. The single function takes username, message, and a conversation guid as arguments and returns the entire conversation. I figure that should continue to work at nearly any scale.

JQuery and Ajax are still very cool.

Entity Framework was also mostly painless. I'm rather impressed with it and will be using it again soon.

Some problems that I encountered during this week's exercise:
1) How do you get a text box to scroll to the bottom in HTML and Javascript these days?
2) Deployment was a total failure.

What's Next?
1) Use MVC 2.0 to log in and capture the username automatically.
2) Tic Tac Toe in JQuery
3) Figure out how to get any of this .Net 4.0 stuff deployed.