Odds and Ends


I’m adding this here as a reminder to myself. If you want to convert a dictionary in simple JSON format to a dictionary in .NET 4.0, you can’t use the DataContractJsonSerializerSettings that is available in .NET 4.5, so if you don’t want to use a 3rd party source (like JSON.NET), you need to be able to serialize/deserialize it yourself. Fortunately, this is fairly simple for a dictionary as follows:

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace x
{
    [Serializable]
    public class JSONDictionary<T> : Dictionary<string, T>, ISerializable
    {
        protected JSONDictionary(SerializationInfo info, 
                                 StreamingContext context)
        {
            foreach (SerializationEntry value in info)
                Add(value.Name, (T)info.GetValue(value.Name, typeof(T)));
        }

        public override void GetObjectData(SerializationInfo info, 
                                           StreamingContext context)
        {
            foreach (KeyValuePair<string, T> value in this)
                info.AddValue(value.Key, value.Value);
        }
    }
}

Then just use this in place of the dictionary in your serializable object.

[DataContract()]
public class Response
{
    [DataMember(Name = "my_dictionary", IsRequired = true)]
    public JSONDictionary<double> MyDictionary { get; set; }
}

And you’re all set. (Note that I haven’t dealt with dictionary keys of types other than string.)

Advertisements

Since we’ve been looking at air conditioning lately…

Watts = BTU / EER
Amps = Watts / Volts
Volts = Watts / Amps

The Voltage will normally be 230 if the Watts are higher than 1000 (generally units higher than 10000 BTU), otherwise 110. For amperage calculations, the rated value seems to use either 100 or 110 Volts for 110 Volt units and 225 Volts for 230 Volt units.

To calculate the cost of running, calculate the total kW h and multiply by the rate.
For example:

6 hours/day * 30 days * 950 Watts = 171,000 W h = 171 kW h
171 kW h * 0.10 $/kW h = $17.10

(BTU = British Thermal Units)
(EER = Energy Efficiency Ratio)

I’ve been enjoying the World Cup so far. The next game for the Netherlands is Friday against Brazil. It should be fun to watch – even though Brazil are the favorites.

“Hup Holland hup
Laat de leeuw niet in z’n hempie staan
Hup Holland hup
Trek het beessie geen pantoffels aan

Hup Holland hup
Laat je uit ‘t veld niet slaan
Want de leeuw op voetbalschoenen
Durft de hele wereld aan”

See also: Macropinna microstoma and the Paradox of Its Tubular Eyes (BioOne)