Sunday, January 24, 2010

Scheduled Chimes in Windows XP and Vista

I like quarter of an hour chimes - they give a good reference of the course of time. There are some computer programs available which do the task, but it's a pity I was not able to find a nice one for Windows XP which would be free of serious disadvantages.

Some of the programs I tried made latent attempts to connect to unknown internet IP through FTP port for unknown purpose - thanks to Comodo firewall, it caught them all. Others took abnormally big memory after a couple hours of running (memory leak?). Nevertheless the task is very simple to solve it by means of tools already available in Windows: scheduling and playing sound.

One of the easiest way to play a WAV sound file from command line is to use "Sound Recorder":

C:\WINDOWS\system32\sndrec32.exe /play /embedding /close "D:\Misc\Chimes\chime.wav"

The option "/embedding" keeps the program running in background, the other keys make it play the chime.wav file and then close.

Now the task should be scheduled: go to menu Start/Control Panel then open Scheduled Tasks/Add Scheduled Task and set it, for example, like this:









That's it for Windows XP - choose a ding-dong sound pleasant to your ear and set up the scheduled task to play it. More complicated variants when, for instance, it plays a different sound for a different quarter can be done easily too.

In Vista sndrec32.exe was replaced with SoundRecoder.exe which does not play WAV files, so the way I made it working was:
  1. to copy sndrec32.exe from an XP machine to the box with Vista;

  2. run it for the first time as Administrator to let it get registered;

  3. start Task Scheduler from Start/All Programs/Accessories/System Tools/ and setup the scheduled task similarly to the procedure in XP.
Read more...

Sunday, January 17, 2010

Formatted Code - Internet Explorer's Copy Issue

Not a new thing but just for the record: copying formatted text from a web-page in Internet Explorer to plane editors as Notepad or Notepad++ leads to a problem - all line breaks and/or indentations are lost in spite of preserving them with <pre> </pre> tags.

A way around is to paste it into WordPad first and then copy from WordPad to any other editor you want. There is no such a trouble when FireFox is used either in Windows or Linux.
Read more...

Saturday, January 16, 2010

Source Code Syntax Highlighting for Web Pages

Highlighting code syntax has become a common way to improve the code readability and is used broadly in different programming language editors. There are some approaches how to show highlighted code in a web page.

I would divide all of them into the three categories:
  1. If the web-site is on ASP (Active Server Pages) or PHP (Personal Home Page) host and all the files and the web page generating code are under your control then highlighting can be handled by a PHP or ASP routine. In PHP, for example, there are GeSHi (Generic Syntax Highlighter) and CHIP (Code Highlighting in PHP); Actipro CodeHighlighter is ASP.NET Control.

  2. If there is no total control over the web-site as it is, for instance, with Blogger then JavaScript highlighter can be a solution. There are many JavaScript highlighters available, here are some popular ones:
    They all support pretty long list of languages, easy to install and customize.
    In general scripts should be kept either on a host or directly in the page and the drawback with the approach is that too many scripts can degrade a web-page performance.

  3. The straight forward way is to use a highlighting tool which generates HTML code, so the code can be copied and pasted directly in a web-page. There are some online tools of this kind, for example:

    Another possibility is to use offline converters:
    • Notepad++ and SciTE are editors both based on SCIntilla, highlight syntax of many languages and have an option to export the highlighted code as HTML.

    • Pygments is a generic syntax highlighter and it can be used by many different ways including as a standing along converter.

    The direct HTML highlighting approach, for example, seems to be the best suitable for this blog since not so many posts are going to have any code to highlight. Here is a small Python example:
    import Tkinter as tk

    def keycodess(event):
    if event.keysym == 'Escape':
    root.destroy()
    x = event.char
    if x == "a":
    print "A done"
    elif x == "b":
    print "B done"
    elif x == "c":
    print "C done"
    elif x == "d":
    print "D done"
    else:
    print x

    root = tk.Tk()
    print "a. Menu choice A"
    print "b. Menu choice B"
    print "c. Menu choice C"
    print "d. Menu choice D"
    root.bind_all('', keycodess)
    # hiding the tk window
    root.withdraw()
    root.mainloop()

Keep in mind that copying formatted code from Internet Explorer can be an issue - Formatted Code - Internet Explorer's Copy Issue.
Read more...