July 14, 2006

Populating Windows Registry from Ruby hash

require 'win32/registry.rb'

#
# Populates registry keys with values given in a hash
#   h = { ".c" => { nil => "source_code_file",       # default
#                   "Content Type" => "text/plain" },
#         '.txt\shell\edit\command'=> { nil, 'editor.exe "%1"' } }
# 
#   populate_registry HKCR, h
#
#   # From an open key:
#   Win32::Registry::HKEY_CLASSES_ROOT.create(".c", KEY_ALL_ACCESS) do |reg|
#       populate_registry reg, {nil => "source_code_file", "Content Type" => "text/plain" }
#   end
#
def populate_registry( root, registry_hash )
    registry_hash.each{|k,v|

        # Make a copy of a String because hash keys are frozen and ...
        key = k.frozen?  ?  k[0..-1] : k    # ... Registry tries to modify them
        
        if v.kind_of? Hash
            root.create(key, KEY_ALL_ACCESS){|reg|
                populate_registry reg, v
            }
        else
            root[key] = v
        end
    }
end


Posted by laza at 01:30 PM | TrackBack

Review of Power Up 1GB MP3/WMA Player and USB Drive

Summary: Audio poor, memory large, good bang for the buck

The audio quality of this player is NOT the greatest because:
1. volume is low
2. barely audible electronic crackling noise is generated by display circuitry
The headphones that come with the player further decrease the volume, so I threw them out and used other headphones. I listen to recorded radio shows - this player works well inside home or in a quiet waiting room. But on New York City subway or on the street the engine noises drown out the player sound.

User interface is not great, but it offers the minimum you need (prev/next, ff/rev, browsing folders/files) if you can figure it out (hint: use short press or long hold on each control). The prev/next, ff/rev lever is tiny, so I often accidentally go to next when I mean to fast forward. The monochrome LCD screen barely does its job, as it displays only one line (one song title, 1st 16 chars).

The player appears as a USB hard drive. For US $30 on TigerDirect, it is a good deal if used only as 1GB drive. The body of the player is bulky, so it cannot be plugged into stupidly recessed USB ports on the front of my Dell machine.

Voice recorder quality is excellent (records into .WAV format), but I don't know if I will ever need to use it.

I use the player with Logitech Wireless Headphones for iPod with Integrated Volume Control ($25 after rebate). If I could get louder sound, the combination would be awsome for so little money.

Photo of MP3 player and wireless headphones


Update: Shortly after posting this entry, I dropped the MP3 player and the playback became chopped and noisy (un-listenable). Oh, well.

Posted by laza at 01:14 PM | Comments (0) | TrackBack

July 06, 2006

Registry Entries for Language Keyboards

Below are my registry settings on Windows XP for using Input Language Keyboard. Included are keyboards and hotkeys: English (US) Left Alt+Shift+1, Serbian (Cyrillic) Alt+Shift+2, Serbian (Latin) Alt+Shift+3
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\00000200]
"Key Modifiers"=hex:03,c0,00,00
"Target IME"=hex:00,00,00,00
"Virtual Key"=hex:47,00,00,00

[HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\00000201]
"Key Modifiers"=hex:03,c0,00,00
"Target IME"=hex:00,00,00,00
"Virtual Key"=hex:4b,00,00,00

[HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\00000202]
"Key Modifiers"=hex:03,c0,00,00
"Target IME"=hex:00,00,00,00
"Virtual Key"=hex:4c,00,00,00

[HKEY_CURRENT_USER\Software\Microsoft\CTF\LangBar]
"ExtraIconsOnMinimized"=dword:00000000
"ShowStatus"=dword:00000004
"Transparency"=dword:000000ff
"Label"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\CTF\MSUTB]
"Left"=dword:00000482
"Top"=dword:00000000
"Vertical"=dword:00000000
"ShowDeskBand"=dword:00000001

[HKEY_CURRENT_USER\Software\Microsoft\CTF\TIP\{DCBD6FA8-032F-11D3-B5B1-00C04FC324A1}\LanguageProfile\0x0000081a]

[HKEY_CURRENT_USER\Software\Microsoft\CTF\TIP\{DCBD6FA8-032F-11D3-B5B1-00C04FC324A1}\LanguageProfile\0x0000081a\{09EA4E4B-46CE-4469-B450-0DE76A435BBB}]
"Enable"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\CTF\TIP\{DCBD6FA8-032F-11D3-B5B1-00C04FC324A1}\LanguageProfile\0x00000c1a]

[HKEY_CURRENT_USER\Software\Microsoft\CTF\TIP\{DCBD6FA8-032F-11D3-B5B1-00C04FC324A1}\LanguageProfile\0x00000c1a\{09EA4E4B-46CE-4469-B450-0DE76A435BBB}]
"Enable"=dword:00000000

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
"CTFMON.EXE"="D:\\WINDOWS\\System32\\CTFMON.EXE"
Posted by laza at 11:42 AM | Comments (0) | TrackBack

July 02, 2006

My HTTP utilities

require 'html/htmltokenizer'    # for HTMLTokenizer.getTag('a','area') 
require 'net/http'              # for Net::HTTP::Get
require 'cgi'                   # for CGI.escape()

class String
    def ends_with?(substr)
        len = substr.length
        self.reverse() [0 .. len-1].reverse == substr
    end
end

#
# get_all_links - Get all links on a web page.
#
#   response = Net::HTTP.get(uri)
#   array_of_link_urls = get_all_links response
#
#
def get_all_links( html_string )
    tokenizer = HTMLTokenizer.new(html_string)
    t = nil
    links = []
    link = nil
    while t = tokenizer.getTag('a','area') 
        # next if t.tag_name != 'a'
        link = t.attr_hash['href']
        next if link.nil?       # for <a name="download" id="download"></a>
        link = CGI.unescapeHTML link
        m = link.match(/[^\?]*/)    # strip everything after "?"
                                     # "e.g. http://www.s.com/m01.mpg?1234"
        links << link
    end
    links
end

#
# A shortcut for getting a page when cookie is required.
#
#   page_body = get_page_with_cookie "http://server.com", "user=john"
#
def get_page_with_cookie( url, cookie )
    uri = URI.parse url
    req = Net::HTTP::Get.new(url)
    req["Cookie"] = cookie
    res = Net::HTTP.new(uri.host, uri.port).start{|http| http.request(req) }
    body = res.body 
end
Posted by laza at 01:24 AM | Comments (0) | TrackBack