Educating the world

Our blog has over 10,000 readers a month

Enable regedit

November 28th, 2009

Occasionally you may find that a nasty virus changed your desktop and removed your ability to run regedit.exe.

There are several ways to re-enable it which depend on your operating system and set up.

  • Start -> Run -> gpedit.msc -> User Configuration -> Administrative Templates -> System -> Prevent access to registry editing tools -> Right Click Properties -> Disabled
  • Run the following command:

    REG add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableRegistryTools /t REG_DWORD /d 0 /f

  • Create a .reg file that contains the changes to switch on the registry editor then run it.

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
    “DisableRegistryTools"="0″

[run registry files at your own rick]

Rules of a ThreadPoolExecutor pool size

November 27th, 2009

The rules for the size of a ThreadPoolExecutor’s pool are generally miss-understood, because it doesn’t work the way that you think it ought to or in the way that you want it to.

Take this example. Starting thread pool size is 1, core pool size is 5, max pool size is 10 and the queue is 100.

Sun’s way: as requests come in threads will be created up to 5, then tasks will be added to the queue until it reaches 100. When the queue is full new threads will be created up to maxPoolSize. Once all the threads are in use and the queue is full tasks will be rejected. As the queue reduces so does the number of active threads.

User anticipated way: as requests come in threads will be created up to 10, then tasks will be added to the queue until it reaches 100 at which point they are rejected. The number of threads will rename at max until the queue is empty. When the queue is empty the threads will die off until there are corePoolSize left.

The difference is that the users want to start increasing the pool size earlier and want the queue to be smaller, where as the Sun method want to keep the pool size small and only increase it once the load becomes to much.

Here are Sun’s rules for thread creation in simple terms:

  1. If the number of threads is less than the corePoolSize, create a new Thread to run a new task.
  2. If the number of threads is equal (or greater than) the corePoolSize, put the task into the queue.
  3. If the queue is full, and the number of threads is less than the maxPoolSize, create a new thread to run tasks in.
  4. If the queue is full, and the number of threads is greater than or equal to maxPoolSize, reject the task.

The long and the short of it is that new threads are only created when the queue fills up, so if you’re using an unbounded queue then the number of threads will not exceed corePoolSize.

For a fuller explanation, get it from the horses mouth: ThreadPoolExecutor API documentation

There is a really good forum post which talks you through the way that the ThreadPoolExecutor works with code examples:
http://forums.sun.com/thread.jspa?threadID=5401400&tstart=0

More info: http://forums.sun.com/thread.jspa?threadID=5224557&tstart=450

Most people want it the other way around, so that you increase the number of threads to avoid adding to the queue. When the threads are all in use the queue starts to fill up.

Using Sun’s way, I think you are going to end up with a system that runs slower when the load is light and a bit quicker as the load increases. Using the other way means you are running flat out all the time to process outstanding work.

I just don’t see why they have done it this way. So far I have not seen a satisfactory explanation of why Sun’s implementation works the way it does. Does anyone out there know?

Firefox add ons

November 26th, 2009

Firefox is ace! The plugin architecture means that you can increase the functionality by adding extras.

All-In-One-Gestures
Control browser operations with your mouse
https://addons.mozilla.org/en-US/firefox/addon/12

Out of all of them this makes navigation a dream. Imagine the following scenario: you are looking for something on the web and it is likely you will have to visit a lot of sites to find it. Typically, your hunt will start with a search on Google or some kind of specialist forum site. After you get your search results back you have 2 choices on navigation method.

  1. Click the first link read what it says, find it’s not what you want, click the back button then click the next link in the list, or
  2. Mouse gesture down on each link on the page, which opens that page in a new tab, then starting with the first tab scan each page, closing it if it isn’t relevant.

The choice is clear. One method uses twice the bandwidth, twice the processing power and takes 4 times longer; and the other method is what real men do (and by men I include computer women too).

British English Dictionary
Spell checker
https://addons.mozilla.org/en-US/firefox/addon/3366

Everone shud spel propaly, evan the Amerikans.

Fetch Text URL
Text manipulator
https://addons.mozilla.org/en-US/firefox/addon/518

This is a simple little utility that allows you to take a piece of plain text and launch it as a new web page. Not all webmail, forums or pages, spot URLs properly and don’t automatically encase them in the appropriate <a hef= tags to create a link. The plugin lets you highlight a piece of text and launch it in a new browser or tab.

Firebug
Developer Tools
https://addons.mozilla.org/en-US/firefox/addon/1843

No self-respecting web programmer should be with out this. It does everything from debugging Javascript, manipulating the DOM to breaking apart CSS and much more. If you’ve never seen it, check it out!

FireFTP
FTP Client
https://addons.mozilla.org/en-US/firefox/addon/2200

Splits the screen in two to display local and remote files. Allows multiple file downloads.

Advanced URL Builder
Text manipulator
https://addons.mozilla.org/en-US/firefox/addon/1399

Highlight some text and create a URL with it. Highlight a postcode from someone’s “Contact Us” page and look it up on Google Maps.

Setting your PC clock to network time

November 4th, 2009

Windows support the Network Time Protocol (NTP).

This article gives you the steps you must take in order to make your client pickup the time from the network and set your local clock.

net time /setsntp:myhostname
net stop w32time
net start w32time

Where myhostname is the name of your NTP server.

C:\Documents and Settings\myuser>net time
Current time at \\MYHOSTNAME is 11/4/2009 1:13 PM

The command completed successfully.

You can find more goodies relating to the registry settings here.

Producing billing reports using MantisBT

October 28th, 2009

Each quarter I do my VAT (Value Added Tax) return. This is the tax that gets added on to each purchase in the UK. It’s a little reminder that I must do my billing. Honestly, I have so much fun doing the work I do, that I forget to bill people sometimes!

Using my current technology, it’s a little long winded so I thought I’d document how I do it, to remind me to find a way to do it better.
Obviously this method is going to be terribly geeky, but hay - I am who I am &amp;#58;&amp;#41;

All my time accounting is handled by MantisBT which is the issue tracker I use. I wrote the current implementation of the billing feature so I thought I’d better use that! I have it on good authority that I’m not the only one!

The applications needed for this work are: web browser, PuTTY and Open Office, so load then in now!

  1. Login to MantisBT.
  2. Select Billing from navigation bar.
  3. Select the Project you are going to prepare the billing for. The page will automatically reload.
  4. Select the data period you are billing for. Leave the Cost as zero.
  5. Click Get TimeTracking Information
  6. Cut the text in the results page; starting before the first issue identifier and drag down to the end of the time on the last issue line.
  7. In PuTTY and jump to you nearest unix box.
  8. Load Vi.
  9. Paste copied text into Vi’s session.
  10. Remove all references to my user name.

    :%s/David Newcomb//

  11. Jump to the top of the page.

    gg

  12. From the start of the line create a macro to format the data.

    qawr,lxJr,0jq

  13. Do control+g to get the number of lines. Divide it by 2 then, to give say 20. Then repeat macro for each line: 20@a.
  14. Clean up additional spaces:

    :%s/, \([0-9]\)/,\1/

  15. Select all the text and paste it into Open Office spread sheet.
  16. The Text Import dialogue will appear, so select Separated by Comma and click Ok.
  17. Highlight the column containing the time information.
  18. Right click and select Format Cells…
  19. Set category to Time and choose 13:37 which is HH:MM.
  20. Hit Ok and the cells will be changed to the correct format.
  21. Select the cell underneath the last time.
  22. Enter:

    =SUM(

  23. After the opening bracket the cursor changes so you can select all the cells you want to be in the summation. Hit return when you have finished selecting them.
  24. Select the cell again and add the formatting.
  25. Now you can cut and paste the report anywhere you like.

I have used some Vi macro’s. Take a look at my article Vi’s super commands to see an example of how to set up a Vi macro.