Archive

Archive for the ‘Uncategorized’ Category

Stimulate 2011

September 23, 2011 Leave a comment

Personally I don’t believe it is the place of the Government to be stimulating the economy. It is the place of government to make rules which allow for an efficient economy. I can see times were stimulation can return a positive ROI and in those situations it doesn’t bother me as much. What I really don’t like is an unbalanced budget with a debt to GDP ratio of 90%.
Right now President Obama wants to spend $500 Billion dollars to repair existing roads and bridges, and to pay for teachers salaries. I don’t find this to be real stimulus. There’s no way it will pay back the interest accumulated through the debt taken on to pay for it. The way to stimulate the economy will be to help community banks lend.
The Federal Government should guarantee up to $500 Billion in loans made by community banks to small businesses. This will get money into the hands of entrepreneurs and may save community banks; placing them in a better position for when the big banks disintegrate. I would be surprised is all of the loans default. Since they won’t default tax payers won’t be on the hook for all $500 Billion. While I don’t like it I can get behind it more so then the current proposed stimulus President Obama wants passed now.

Categories: Uncategorized

Flying car parts

October 7, 2010 Leave a comment
This morning as I was walking out to the bus a car pulling out of a side street caught my attention. It was a small commuter car and the piece of plastic which protects the front underside of the car was holding on by one screw. This large piece of plastic was being held on by a single screw on one side of the car, leaving the rest of it to drag along the ground. From anybody standing outside of the car it’s obvious that it is dragging a large piece of the car under it. How does the driver not notice this?
When the car accelerated upto about 20 mph I saw how the driver might not notice. There was enough of an air current being pushed under the car that the wing shaped like piece of plastic started "flying". I can hear the Car Talk conversation in my head right now.
Caller: "There’s a dragging sound everytime I accelerate, coming from under the car, but then it goes away once I get to street speeds. Any idea what it is?"
Car Talk Host: "I wonder if there’s a squirrel trapped under your car trying to get out."
Categories: Uncategorized

Warning, using Hotmail EAS will create duplicate contacts

September 1, 2010 Leave a comment
Last night I configured my phone to sync with Windows Live through the new Hotmail EAS service. My first attempt at configuring it was through the messaging app on the phone. Bad idea. That’s configured to always do hotmail email addresses through the older Windows Live App. So I uninstalled the Windows Live App and no luck. I then thought to see if there was an ActiveSync application on the phone and there was. I configured it through there. This cause a bunch of duplicate contacts to be created. Turns out I should have left the Windows Live App installed. That would have managed the incoming contacts better than Windows Mobile 6.1.
Lesson learned.
Categories: Uncategorized

Natural Born Hunter

January 20, 2010 2 comments

So I was watching a video on things to do with your cat. One of the things it mentioned was if the cat ate kibble (dry cat food) to put the cat food in a cup on the floor. That way instead of having it in an easy to access bowl, the cat has to knock the cup around the floor to get a little bit of food out. This appeals to cats, who are natural hunters. It’s not as strenuous as hunting, but it is more exciting than a boring bowl in the same place every day.

So I put some food for Isis in a cup on the floor. She wouldn’t even try to get any food out of it. I knocked the cup around a little bit to show her the idea. Eventually I gave in and put the food in her bowl, which she started eating right away. We did this for a few days, until one day Isis got hungry enough that she put her paw in the cup, scooped out some pieces of kibble onto the floor, ate the food, and repeated until she was done. We did this a few more times, and now I’ve given up on trying to give her any challenge to getting her food.

But if something has feathers, she’ll hunt for it.

Categories: Uncategorized

It wasn’t much of an execution

January 10, 2010 Leave a comment

I just finished playing Tales of Monkey Island 4: The Trial and Execution of Gybrush Threepwood. It was a fun game. I had plenty of times where I wanted to give in and look up the next clue online. Thankfully I never did. The title is a bit misleading though. Our protagonist, Guybrush Threepwood isn’t executed. That doesn’t mean though that there’s not a climatic ending. I actually want to get a screen shot of the ending for a computer wallpaper. It’s a very climatic and fun ending and I can’t wait to play the next Tales of Monkey Island game.

Categories: Uncategorized

A Resource Pool for use once objects

January 4, 2010 Leave a comment

At work today I had a meeting where we went over a scenario where it would be useful to have a bunch of objects ready to use, but we don’t trust other people to not misuse shared resources. So what they wanted was a pool that would have a minimum number of objects ready to go, but that nothing would be placed back into the pool. The idea being that they might grab a number of object from the pool, and then the pool should fill up again while the main code was doing work.

using System;
using System.Collections.Generic;
using System.Threading;

namespace PreFetchPool
{
    /// <summary>
    /// Class to precreate objects to ensure that there is a minimum of use once resources
    /// </summary>
    /// <author>jader3rd</author>
    public class PreFectchPool<T> : IDisposable where T : class
    {
        private ReaderWriterLockSlim poolLock;
        private Queue<T> pool;
        private Func<T> createFunc;
        private bool disposing;
        private readonly TimeSpan timeout = TimeSpan.FromSeconds(15);
        private ManualResetEvent poolHasItems;

        /// <summary>
        /// The amount of items which should exist in the pool. Default is 10.
        /// </summary>
        public uint Quota { get; set; }

        public PreFectchPool(Func<T> create)
        {
            createFunc = create;
            poolLock = new ReaderWriterLockSlim();
            pool = new Queue<T>();
            disposing = false;
            Quota = 10;
            pool.Enqueue(createFunc.Invoke());
            poolHasItems = new ManualResetEvent(true);
            ThreadPool.QueueUserWorkItem(checkPool);
        }

        /// <summary>
        /// Unblock any threads waiting on the pool. Dispose of any objects left in the pool.
        /// </summary>
        public void Dispose()
        {
            disposing = true;
            poolHasItems.Set();
            poolLock.EnterWriteLock();
            poolLock.ExitWriteLock();
            if (null != poolLock)
            {
                poolLock.Dispose();
                poolLock = null;
            }

            while (0 < pool.Count)
            {
                T item = pool.Dequeue();
                if (item is IDisposable)
                {
                    ((IDisposable)item).Dispose();
                }
            }
        }

        /// <summary>
        /// If the pool needs more objects, create one and add it to the pool.
        /// </summary>
        /// <param name="state">Not used, just there to satisfy QueueUserWorkItem</param>
        private void checkPool(Object state)
        {
            if (disposing) return;
            try
            {
                poolLock.EnterUpgradeableReadLock();
                if (pool.Count < Quota)
                {
                    T item = createFunc.Invoke();
                    try
                    {
                        poolLock.EnterWriteLock();
                        pool.Enqueue(item);
                        poolHasItems.Set();
                    }
                    finally
                    {
                        if (poolLock.IsWriteLockHeld) poolLock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                if (poolLock.IsUpgradeableReadLockHeld) poolLock.ExitUpgradeableReadLock();
            }
            ThreadPool.QueueUserWorkItem(checkPool);
        }

        /// <summary>
        /// Get an item from the pool
        /// </summary>
        /// <returns>The item</returns>
        public T Get()
        {
            if (disposing) throw new ObjectDisposedException(GetType().Name);
            T item = null;
            do
            {
                // If the pool doesn't have any items for the timeout period try to create an object
                if (poolHasItems.WaitOne(timeout) && !disposing)
                {
                    try
                    {
                        poolLock.EnterWriteLock();
                        if (0 < pool.Count)
                        {
                            item = pool.Dequeue();
                        }
                        if (0 == pool.Count)
                        {
                            poolHasItems.Reset();
                        }
                    }
                    finally
                    {
                        if (poolLock.IsWriteLockHeld) poolLock.ExitWriteLock();
                    }
                }
                if (null == item)
                {
                    if (disposing) throw new ObjectDisposedException(GetType().Name);
                    ThreadPool.QueueUserWorkItem(checkPool);
                }
            } while (null == item);

            ThreadPool.QueueUserWorkItem(checkPool);
            return item;
        }
    }
}
Categories: Uncategorized

Frozen Seattle Nights

December 15, 2009 2 comments

For all of those who don’t know the Seattle area has gone through two weeks of freezing weather. The temperature has stayed below freezing for most of the two weeks. The sky has been cloudless and there hasn’t been much wind. They kept on predicting snow, but it kept staying too cold for the moisture to move in. I don’t think that any records were broken for how cold it got, but what’s different this time is how long it stayed below freezing. It has been abnormal.

On Saturday night Amanda and I were in bed and just about ready to turn off the light when the fire alarm went off. It is very loud. Poor Isis, our cat, was scared to death. So Amanda took Isis outside. The fire alarm was going off for everyone in our building (16 units). Everybody else was coming outside too about this time, but with their freaked out dogs. Isis was not happy being taken into the cold and being surrounded by dogs. Amanda had to foil her many attempts to flee to a place with no alarm and no dogs.

What had happened was one of the external fire sprinklers had started pouring water, causing the fire alarm to go off. The fire department showed up, turned off the alarm, turned off the water and helped clean up. They said that they cold was causing fire sprinkler heads to freeze and burst. It was their ninth call that night for just the same reason. The buildings around here haven’t seen consecutive cold like this before and it’s showing.

The management company is going to take a few days to get to fixing our building because they are dealing with this all over. We were lucky in that it didn’t affect a unit, only the exterior stair well. I’m sure there are lots of other places where it’s causing burst pipes inside of units.

It made for quite a lot of excitement.

Categories: Uncategorized

Passwords and Windows 7

December 6, 2009 Leave a comment

In two of my recent posts I listed out things which I do not like about Windows 7. Another one cropped up a few days ago. The Windows 7 that I have is Home Premium. Why not? I’m using it at home. I didn’t see any feature that I would want in a more expensive version.

This week I started getting a notice that my password was about to expire. I look, and look and there’s no way in Windows 7 Home Edition to mark a user account with the attribute “Password never Expires”. I even tried opening MMC and adding the Local Users and Groups snapin, but there’s an error saying you can’t load that Snapin in Home Premium. Argh! That’s so stupid! Especially considering the fact that you can have a user with no password. Why am I not allowed to manage my own computer!

Categories: Uncategorized

What does a secure password make?

November 28, 2009 Leave a comment

I have a handful of user id’s and passwords which I use on a variety of websites throughout the internet. I recently felt that it was time to change the password to a bunch of the websites. I came up with a brilliant new password and tried it out but it didn’t work for a lot of the websites that I wanted to use it on. The reason was that it had a non alphanumeric character. So I emailed the help of the website and asked what’s wrong with the character. I received an email back saying that they restricted the password to alphanumeric characters for my security. My security! How does restricting characters to a certain subsets of characters increase my security? They also said that most server products do this. What server products? I worked as a security admin for Wal-Mart where they needed a unified log in system to all of their legacy as well as modern systems, and we enforced that passwords have at least one non alphanumeric character.

I was talking about this at work and my coworker Martin said they some websites do this to avoid SQL injection attacks. Holy cow, they process the passwords and are afraid of SQL injection attacks? They should just sanitize their input strings. They shouldn’t make me use a less secure password.

So I thought and I thunked and I came up with a new password, which I feel is less secure, but was accepted by most websites. There is one website though that I’d like to update, but it requires at least one alpha character, one numeric character and one non alphanumeric character. I like that system. Why can’t more websites be like that?

Categories: Uncategorized

Programming and Garbage Collection

November 21, 2009 2 comments

There are two managed code languages that I’ve programmed in with garbage collectors. Java and C# (.Net). In my basic understanding the Java garbage collector has a thread that runs periodically, checks the reference count for all of the objects and frees up the memory for objects which are unused. The .Net garbage collector is a bit more sophisticated (or bloated, depending upon your point of view). I am much more familiar with the .Net garbage collector, primarily because that’s what I’ve been working with for the last three years. I have to say that I like it. The .Net garbage collector has a Gen 0, Gen 1, Gen 2 and a large object heap. The idea is that most objects are small, and large objects are expensive to move around in memory. There is a dedicated finalizer thread with runs periodically and cleans up all of the objects that it can in the Gen 0 heap. If an object can’t be cleaned up that object gets bumped into the Gen 1 heap. Gen 1 collections happen less frequently than Gen 2, and Gen 2 collections happen less frequently than Gen 1, and large object heap collections happen less frequently than Gen 2. This system was designed under the idea that objects can be created quickly and then thrown away. This is awesome. There’s less of a worry that short lived objects will be actually taking up memory for significantly more time than they should.

So while the idea behind the .Net garbage collector is for objects to be created and thrown away quickly it is still doesn’t mean that a good programmer will allocate objects with wild abandon. For example, you create a method which creates a lot of small objects, calls some methods and then exits. The method even recreates identical objects because it was easier to recreate them than creating and managing a collection of objects. You test and profile your method and everything is happy. All of the objects got cleaned up in Gen 0, and nothing made it to Gen 1. Now let’s say that months go by and all of a sudden one day your profiling tests notice that there’s a lot more objects in the Gen 1 or Gen 2 heap. What happened? Nothing changed in your method. Perhaps another method you were calling was changed and started to do I/O, or perhaps started creating a lot of small, throw away objects itself. Because the objects allocated in your method lived through the call to the sub method (and now the sub method is generating a garbage collection) your objects are being considered longer lived objects and are being moved around the different heaps. So while there’s forgiveness for one layer of code to be wasteful there’s not forgiveness for multiple layers to be wasteful.

Managing memory is still something programmers should do in managed code. They just have to think about it differently than they would compared to native code. While the system was designed for throw away objects it doesn’t mean that you should program for that. It’s also important to note that while .Net made allocating objects cheap, it’s still not free. The three common ways programmers get caught in not managing their objects are string allocation, anonymous delegates and registered events.

Creating string objects in .Net is really easy. Concatenating strings in .Net is really easy. It’s a temptation for some to create strings by concatenating lots of strings together. I knew one programmer who would do it for strings which never even got used (in a code review I was told I was being Penny wise, but Pound foolish. The problem though was that while I was being Penny wise nothing in the code review was Pound foolish). The two ways to avoid this are to use the StringBuilder object or the String.Format() method. The one to use depends upon the situation. The other thing is that you should never create a string that’s never going to be used. This seems obvious, but it tends to happen a lot with strings and not other objects. A case of this would be trace statements. Don’t create a message for a trace statement when traces aren’t enabled.

Anonymous delegates are really cool and really powerful and can make for great eye candy (if your a programmer). They are absolutely vital for Linq. One of the things that’s nice about them is they do a lot of the tedious work for you when it comes to using delegates. The problem is that sometime you don’t know how much it had to do to get done what you wanted done anonymously. Under certain circumstances the anonymous delegate will create new classes and instantiate new instances of those classes. There’s just no other way for it to do what you wanted to do. But there are things that you can do in your code to create named delegates on existing classes which will take up less memory and use less objects.

Worrying about strings and anonymous delegates are issues were a heuristic should be used in how much you worry about them. If you take the easy way here or there, in a code path that’s rarely executed it might even be preferable to do it because there will never be a measurable impact on the system and it was quicker to code. But if the code ends up in a tight loop or frequently called code path, lazy programming can kill you. And by kill you, I mean users of your program will call the program slow, bloated and unresponsive. I prefer programming in the conscious of what I’m doing, so that I get in good habits and perhaps my code might end up at the bottom of somebody else’s stack one day.

On the other hand registered events can kill you if you do it wrong once. This trap hasn’t really affected me because I’m a big fan of the Asynchronous Programming Model instead of the Event Driven Asynchronous Model. The only thing that requires event driven is the GUI thread. Windows programs which have window frames have a dedicated GUI thread. Some consider this a feature, most consider it a mistake. I am in the later party. What happens is that most classes which deal with classes for which you have to register an event don’t unregister the event. It’s possible to, it’s built into the language to, but programmers forget about it all of the time. So what ends up happening is an object gets created, registers for events, stops getting used, would be garbage collected, but still has references through the registered events. As a result many Windows programs will take up more memory the more window frames get opened because programmers didn’t unregister the events.

In all of this remember Amdahl’s law and do what’s best for your program. Code what you mean and mean what you code.

Categories: Uncategorized