Archive

Archive for January, 2010

Getting rid of fake directory names in Windows 7

January 27, 2010 Leave a comment

In Windows Vista if you open up your users profile Explorer windows you will see subdirectories like Contacts, Documents, Videos, etc. If you browse to the same directory with a command line utility (my preference is PowerShell) and list the contents of the directory you see Contact, Documents, Videos, etc. When you upgrade to Windows 7 one thing that stands out pretty quickly is that a couple of the directories are renamed to My Documents, My Music or My Videos. It’s kind of annoying because, of course they’re the items of the owner of the profile. But it doesn’t do the renaming for all of the directories, just some of them. So when I’m not in Library view (whose primary feature is that it is the easiest way to get to Public Documents in my mind) I would look for the Documents directory between Downloads and Desktop. But it wasn’t there. It was “My Documents” between Links and “My Music”. What really threw a wrench into my Windows experience was the fact that I spend most of my time in the command line and if I listed out the directories none of them began with “My ”. All of the directories had the name they had in Vista. So depending upon the view they changed name. How annoying.

I asked around and someone showed me that I could rename the directory, but that didn’t help when viewing the directory from another computer.

I was able to get help and want to share the solution on how to get rid of miss named directories in Windows 7.

If you open up folder options and select “Show hidden files” and then open up your Documents directory you’ll see a Desktop.ini file. Right click and edit the file. There will be a line that begins with LocalizedResourceName. Delete that line. Repeat for My Music, My Videos, etc. The next time you log in the directories will have the correct names in an Explorer window. Now the name of the directory will be the name of the directory.

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