Monday, 27 July 2009

URL parsing in Javascript

There is very simple way to parse URL in Javascript. Just define new method in the prototype of the String. Of course, it has own shortcomings but in the most cases it covers the wide range of URLs and protocols (http(s), ftp, mailto, etc; the mandatory part of URL, host is considered as domain names, IPs, and localhost separately), and moreover it considers the more complex URLs like jdbc:oracle://localhost:1521.

Thursday, 9 July 2009

JS2BAT converter 2

Earlier to embed javascript codes into batch files the JS2BAT tool has ben implemented with batch features only. In this topic the same tool has been implemented in pure javascript. As opposed to the previous version the present one is the more functional and has optional parmeters. Previously the js2bat.js script has been implemented in javascript. After that it has been converted to the js2bat.bat batch script by itself with the following command:
cscript js2bat.js js2bat.js

Tuesday, 7 July 2009

JS2BAT converter

This script allows you to embed Javascript codes into the batch-script immediately. So you can stop to worry about creating of an additional batch-wrapper or lost of some specific parameters. Perl distribution has the same functional script pl2bat but for wrapping of perl-scripts with batch-scripts. I am not author of this idea, i just implemented this feature as the standalone tool. The main feature is to write the prolog code that is valid both in a batch and javascript. When launching the batch it runs as batch and calls the javascript interpreter with the same file as javascript file. But the second one skips this prolog as valid javascript comments.

Friday, 3 July 2009

Finest code syntax highlighter

Quotation from the Code Syntax Highlighter, the homepage of the project, allowing to embed colorizing of text and fully written on Javascript.
SyntaxHighlighter is a fully functional self-contained code syntax highlighter developed in JavaScript.
It is really true! It is very useful, very flexible and easy to customize. The main idea is to use so-named brushes to colorize codes within <pre /> tags (it is defined by default and customizable too!). Colorizing is simple. You have to link scripts and styles to your pages and add brush via class attribute (like this class="brush:js" for colorizing of Javascript codes).
I decided to use it in my blog and found that it works fine. Unfortunately there is no brushes for cmd/bat scripts and i have implemented this embedding to the blog's layout the code from below.

HOWTO turn a character case via CMD/BAT

Introduction

This example is amazing that fact that it can be extended by non-Latins with no pain. Just add your owned translation table at the end of script in the format UPPER lower. For example, the translation table for Cyrillic characters is following:
А а
Б б
...
Ю ю
Я я
Just remember that the capitals have to be the first with following lowercase letters.

Examples of usage

Capitalize all characters. Results to QWERTY.
CAPS qwerty /u
The first character is capital, and others are in lower case. Results to Qwerty.
CAPS qwerty /uf
Invert the result of the previous example. Both result to qWERTY.
CAPS qwerty /uf /l
CAPS qwerty /lf