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.