HOWTO Unixify your Windows cmd.exe with AutoRun registry and cygwin

On Windows XP I use cygwin but sometimes I need to use the native cmd.exe and since I am used to my unix look and feel (and tools) I also want to create cmd environment that resembles my cygwin and my Mac OS X prompts, at least a little bit. That little bit is setting up a custom prompt and some aliases as well as (the most important) accessing unix tools from cmd terminal as well as having access to windows command line tools at the same time from the same prompt.

Let’s dive in. Let’s say your username on windows is ‘marekj’ and your cygwin home variable points to windows %userprofile% environment variable folder which is ‘c:\Documents and Settings\marekj’ (I believe default cygwin points usually to c:\cygwin\home\username but I changed it to use my windows xp userprofile path) and that’s where I have my .bash_profile for my cygwin prompt and that’s where I will create a profile for me cmd.exe as well.

AutoRun setup

I first create a .bat profile file which I name ‘.AutoRun.bat’ (you can name it whatever you want as long as it ends with .bat) This .bat file will be executed at runtime upon starting cmd.exe (it actually is executed when starting cygwing.bat as well but will not affect cygwin).

In this file which full path is “%userprofile%\.AutoRun.bat” I’ll put all the initialization stuff at the time of cmd.exe execution.

Then I need to tell registry to use this file at runtime. Open registry editor (regedit) and create (or modify) this key:
“HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor\AutoRun\REG_EXPAND_SZ”
(this is a key of type Expanded String Value)
Why make it Expandable string value? Because we are going to stuff this value there:
“%USERPROFILE%\cmd.exe.bat” (make sure you include the quotes)

If your user name is ‘marekj’ your %userprofile% value will probably be
c:\Documents and Setting\marekj
If we don’t include quotes in our value then we’ll fail because we have an empty space in our path.

Now when you start cmd.exe it will automatically execute everything in your .AutoRun.bat file.

My .AutoRun.bat file looks like this:

@echo off
REM Set this: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor\AutoRun\REG_EXPAND_SZ
REM to hold this value "%USERPROFILE%\.AutoRun.bat"
prompt $+$M$P$_$_$$$S
chdir %userprofile%
doskey ls=ls --file-type -1
doskey l=ls -l -Ggh --file-type
doskey x=exit

As you can see I unixfy my cmd.exe eprience a bit by creating a simple custom prompt (run prompt /? in cmd.exe to get the values and their meanings) and assigning an alias (by using doskey in windows xp) to run unix ls commands instead of dir (I haven’t figured out how to define COLORS by file type to run ls --color --file-type. Currently it’s using 16 windows colors but I am not sure where they are defined. if you do then let me know.)

I also set up to have my prompt start up in my home folder. (I am not using ‘command prmpt here’ registry tweak. I think if I did I would need to comment this line out since it will just change Dir back to home no matter where you started the prompt from.

Using cygwin tools in cmd.exe

Of course it will work only if you have cygwin installed and your %path% includes a pointer to the folder where cygwin bin so when you execute something from cmd.exe it will be found. (default cygwin tools live in c:\cygwin\bin so I append this path value to my %PATH% environment variable)

After setting up the path value to cygwin you can use pretty much every cygwin tool inside cmd.exe box, even ssh or rsync (I mean cmd.exe is just a dumb terminal that runs smart tools)

So in conclusion I am using an AutoRun registry key to hold the value of initialization bat file where I set prompt, doskey and my default working directory for my cmd.exe and accessing cygwin tools from cmd.exe

In The Kingdom of Java Verbs are Nouned

Stevey’s Blog Rants: Execution in the Kingdom of Nouns

The King, consulting with the Sun God on the matter, has at times threatened to banish entirely all Verbs from the Kingdom of Java. If this should ever to come to pass, the inhabitants would surely need at least one Verb to do all the chores, and the King, who possesses a rather cruel sense of humor, has indicated that his choice would be most assuredly be “execute”.

The Verb “execute”, and its synonymous cousins “run”, “start”, “go”, “justDoIt”, “makeItSo”, and the like, can perform the work of any other Verb by replacing it with an appropriate Executioner and a call to execute(). Need to wait? Waiter.execute(). Brush your teeth? ToothBrusher(myTeeth).go(). Take out the garbage? TrashDisposalPlanExecutor.doIt(). No Verb is safe; all can be replaced by a Noun on the run.

Software Tester is like

Based on this old post: Complex world of testing. Need for First-Class Testers

To define a tester is to see someone whose job it is to bridge the gaps of disparate worlds, to switch vocabularies, languages; from taking code to talking design to talking measures; communicating with different worlds in their own native vocabulary.

I conclude that Software Tester is like a self-aware ROUTER who constantly updates her ROUTING TABLES definitions to find the best shortcuts to connect all the worlds and make them talk to each other as if there was no translations whatsoever.

Test for leap year

Leap year is an integer such that for modulo for division by 4 is 0 and modulo for division by 100 is NOT 0 OR modulo for the division by 400 is 0.

roll your own simple test for leap year in java (int year;)

if ( ((year % 4 == 0) && !(year % 100 == 0)) || (year % 400 == 0)){
	System.out.println(" Leap Year!!!");
	} else {
	System.out.println(" Not a Leap Year");
	}

Some resources:
Leap year

GregorianCalendar Java Class

isLeapYear method

public boolean isLeapYear(int year)

So we can make GregorianCalendar (no need to set it’s value) and do something like this:

GregorianCalendar cal = new GregorianCalendar();
for (int year = 1998; year<2007; year++){
	if (cal.isLeapYear(year)){
		System.out.print(year);
		System.out.println(" Leap Year!!!");
		} else {
		System.out.print(year);
		System.out.println(" Not a Leap Year");
		}

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

SQLite3 INNER JOIN LEFT JOIN notes

Here is your UseCase Narrative with examples of sql design of INNER JOIN and LEFT JOIN and some confusion that may arrise from using it.
You just opened a shop which sells instruments. To determine if you have any clients you call Chopin, Mozart, Bach and Picasso to see if they will be your clients. They all say yes, Picasso was unsure if would buy an insrument from you but he’ll be happy to be on the list of your clients.

Here is your code for sqlite3 sql
(NOTE: First sqlite3 and set up test.db.
Set your parameters for sqlite3 as such: .mode column, .headers ON and you can also set BLANK as a string instead of getting empty field but setting .nullvalue BLANK)

create table clients(id integer primary key, name varchar(20));
insert into clients values (1,"Chopin");
insert into clients values (2,"Mozart");
insert into clients values (3,"Bach");
insert into clients values (4, "Picasso");
select * from clients;

  id          name
  ----------  ----------
  1           Chopin
  2           Mozart
  3           Bach
  4           Picasso

You decide to carry the following products. Piano, Violin, Cello and Flute based on your clients list. You wanted to get some paint for Picasso but you are not sure when that will arrive and maybe you think you will only sell to musicians and not painters.

create table products(id integer primary key, name varchar(20));
insert into products values (1, "Piano");
insert into products values (2, "Violin");
insert into products values (3, "Cello");
insert into products values (4, "Flute");
select * from products;

  id          name
  ----------  ----------
  1           Piano
  2           Violin
  3           Cello
  4           Flute

You now call each one of the clients and see who will buy what from you. You make a third table that refers to the first two tables you created.

create table orders (id integer, cid integer, pid integer);
insert into orders values (1, 1, 1);
insert into orders values (2, 1, 1);
insert into orders values (3, 2, 1);
insert into orders values (4, 3, 2);
insert into orders values (5, 3, 3);
insert into orders values (6, 2, 2);
select * from orders;

  id          cid         pid
  ----------  ----------  ----------
  1           1           1
  2           1           1
  3           2           1
  4           3           2
  5           3           3
  6           2           2

So now we have three tables.
Instead of clientid we want to know the name of a client who ordered the product
so we can use INNER JOIN.

select orders.id as orderid,
clients.name as customer,
products.name as instrument
from orders
inner join clients
on clients.id=orders.cid
inner join products
on products.id=orders.pid;

  orderid     customer    instrument
  ----------  ----------  ----------
  1           Chopin      Piano
  2           Chopin      Piano
  3           Mozart      Piano
  4           Bach        Violin
  5           Bach        Cello
  6           Mozart      Violin

INNER JOIN will not tell you who did not make an order from CLIENTS table.

So Picasso did not order anything but he is not listed here. To make him appear as a client who didn’t place an order we need to use LEFT JOIN. (NOTE: RIGHT JOIN is not supported in SQLite3)

select orders.id as orderid, clients.name as customer, products.name as instrument
from orders
left join clients
on clients.id=orders.cid
left join products
on products.id=orders.pid;

The above sql will produce the same table even though we changed from INNER JOIN to LEFT JOIN. Picasso is not listed becasue we do LEFT JOIN clients and it is ORDERS table that determines what shows up first. Lets start with CLIENTS table and then LEFT JOIN on ORDERS to fix this (btw: I think this is a testCase to run in DB testing to check how sql is created)

select orders.id as orderid, clients.name as customer, products.name as instrument
from clients
left join orders
on clients.id=orders.cid
left join products
on products.id=orders.pid;

  orderid     customer    instrument
  ----------  ----------  ----------
  1           Chopin      Piano
  2           Chopin      Piano
  3           Mozart      Piano
  6           Mozart      Violin
  4           Bach        Violin
  5           Bach        Cello
              Picasso

Now Picasso shows up but as you can see since this was a CLIENTS table that started the select statement we go by CLIENTS records first and for each client we list order id and instrument.

So finally, who ordered from us?

select distinct clients.name as customer
from clients
left join orders
on clients.id=orders.cid;

  customer
  ----------
  Chopin
  Mozart
  Bach
  Picasso

WOW. Incorrect. We know Picasso didn’t make any orders so why is he here?
Well, because of LEFT JOIN. We should use INNER JOIN instead now.

select distinct clients.name as customer
from clients
inner join orders
on clients.id=orders.cid;

  customer
  ----------
  Chopin
  Mozart
  Bach

Application Map and Vocabulary to Navigate

Some notes to work on later:
Communication on software project in a context of a game requires creating Domain Map, an Application Object Map and Vocabulary set for naming Object and Moves you can do with those objects. It’s an ontological work, conceptual schema distinction that needs to happen before any work can be done. Without immersing a newcomer to the team in that vocabulary and the map they are lost, do not speak the language and end up inventing new worlds of schemata that noone else but them will understand. In doing so their world is their alone and any communication is 90% guessing as to the meaning conveyed by sentences.
 
This is a big time waster for a team. There needs to exist a language. I am not talking about UML. Something more about humans communicating to master the moves in a game they are playing and you can’t really win by guessing alone. – more thoughts on that later.

Regex Cheets

Building blocks for making Regular Expressions.

REGEX PATTERNS
\w		alphanumeric character
\w+		alphanumeric string
\W 		NOT alphanumeric character (special character)
		 `! " # $ % & ‘ ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~’
\W+ 		NOT alphanumeric string (special character string)
[x] 	character x
[^x] 	NOT character x
[x-y] 	range [0-9] [a-z] [A-Z]
^ 		blank at beginning of line
$ 		blank at end of line
^$ 		blank line (blank beginning of line followed by blank end of line)
\b 		blank at beginning AND end of alphanumeric string
\B 		NOT \b
\< blank at begin of string
\> 		blank at the end of string

REGEX REPETITION OPERATORS
?		matched at most once (optional)
*		matched  zero  or  more times (have not figured out how to use it)
+		matched one or more times. (same as in {1,})
{n} 	matched exactly n times.
{n,} 	matched n or more times.
{n,m} 	matched at least n times and not more than m times. {min, max}

Example:This regex matches email address
\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b

Replace the Coordinates in Rational Robot scripts with Jedit Regex

I have a problem with Rational Robot sometimes. For every object it deals with it puts coordinates. If you click in edit box it creates coordinates where you clicked it. A lot of times I want to standarize playback where I don’t care where Robot clicks my objects. I just want it to set focus. In those times I use regex to change the entire string that denotes coordinates.
 
I usually use jedit and it’s search and replace all functionality. I open all the .rec files I need to modify strings and load them in buffers. Then I run search and replace all using string "[0-9]{1,3},[ ]{0,1}[0-9]{1,3}" including quotes. Then I save all files.
 
It’s done.

Unicode Parts List

Brush up on Unicode knowledge:
 
If we are playing software games then it is important to know the bits and piceces we use to build the tools with which to play those games.
Unicode is a collection of parts. It’s like a parts list when putting together a larger piece.