Sunday, August 11, 2013

Bochs notes

Installation on Ubuntu:

sudo apt-get install bochs
sudo apt-get install bochs-x
sudo apt-get install bochs-sdl
sudo apt-get install bochs-term

BIOS ROM image is installed by package bochsbios to.
  -  /usr/share/bochs/BIOS-qemu-latest
  -  /usr/share/bochs/BIOS-bochs-legacy
  -  /usr/share/bochs/BIOS-bochs-latest

By default, /etc/bochs-init/bochsrc is NOT loaded.

To change display library to SDL: display_library: sdl

Make floppy image: dd if=Boot1.bin of=floppy-drive/floppy.img

If you use term, to quit simulation, run command "kill -HUP <process_id>" in a separate console

Wednesday, June 26, 2013

shell PS1 terminal escape sequence in linux

If you've seen string like this "\[\e[1;33m\]" in someone's PS1 (bash prompt) value, you may be curious about what it means. Or you may be using it, but not really know what it means (e.g. just copied and pasted from another bash config file). The format is weird. Isn't it?

PS1 bash prompt

run "man bash", search for PROMPTING, you will see that

  1. \[  begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
  2. \]  end a sequence of non-printing characters

You may wonder what "terminal control sequence" is. Generally "terminal control sequence" controls how the data and/or presentation maintained by terminal will be changed (e.g. move cursor, change color, delete line).

ECMA-48

The "terminal control sequence" is defined in ECMA-48 spec [1]. Here I will be focused on only one commonly used terminal control sequence called SGR (the detail is on page 75 of the pdf file, or page 61 of the spec content). SGR controls many graphics aspect of terminal display.

SGR - Select Graphic Rendition. You can think it as just a function which takes some parameters. We need to represent/serialize it so that it can be transferred and interpreted by terminal, etc. Its representation in the spec is "CSI Ps... 06/13". I break it down in the follow table:

Parts

full name

ascii code (hex)

breakdown of example "\e[1;33m"

CSI Control Sequence Introducer For 8-bit mode: 0x9b
For 7-bit mode: 0x1b5b("\e[")
"\e[" is CSI
Ps… parameters each control function can have one or more parameters. "1;33" are two parameters
    SGR can have multiple parameters. Each parameter is an integer represented in decimal notation. 1 means bold; and 33 means yellow foreground color
    Parameters are separated by 0x3b (';')  
06/13 control function SGR 0x6d ('m') "m"

You may wonder why parameter 33 means yellow and parameter 1 means bold. You cannot feed arbitrary parameter values to SGR. The allowed parameter values are (copied from [1]) shown below. The items marked as bold text are the commonly used parameters.

0 default rendition (implementation-defined), cancels the effect of any preceding occurrence of SGR in
the data stream regardless of the  setting of the GRAPHIC RENDITION COMBINATION MODE
(GRCM)
1  bold or increased intensity
2  faint, decreased intensity or second colour
3 italicized
4 singly underlined

5  slowly blinking (less then 150 per minute)
6  rapidly blinking (150 per minute or more)
7 negative image
8 concealed characters
9  crossed-out (characters still legible but marked as to be deleted)
10  primary (default) font
11  first alternative font
12  second alternative font
13  third alternative font
14  fourth alternative font
15  fifth alternative font
16  sixth alternative font
17  seventh alternative font
18  eighth alternative font
19  ninth alternative font
20 Fraktur (Gothic)
21 doubly underlined
22  normal colour or normal intensity (neither bold nor faint)
23  not italicized, not fraktur
24  not underlined (neither singly nor doubly)
25  steady (not blinking)
26  (reserved for proportional spacing as specified in CCITT Recommendation T.61)
27 positive image
28 revealed characters 
29  not crossed out
30 black display
31 red display
32 green display
33 yellow display
34 blue display
35 magenta display
36 cyan display
37 white display

38  (reserved for future standardization;  intended  for setting character foreground colour as specified in
ISO 8613-6 [CCITT Recommendation T.416])
39  default display colour (implementation-defined)
40 black background
41 red background
42 green background
43 yellow background
44 blue background
45 magenta background
46 cyan background
47 white background
48  (reserved for future standardization; intended for setting character background colour as specified in
ISO 8613-6 [CCITT Recommendation T.416])
49  default background colour (implementation-defined)
50  (reserved for cancelling the effect of the rendering aspect established by parameter value 26)
51 framed
52 encircled
53 overlined
54  not framed, not encircled
55 not overlined
56  (reserved for future standardization)
57  (reserved for future standardization)
58  (reserved for future standardization)
59  (reserved for future standardization)
60  ideogram underline or right side line 
61  ideogram double underline or double line on the right side 
62  ideogram overline or left side line
63  ideogram double overline or double line on the left side
64  ideogram stress marking
65  cancels the effect of the rendition aspects established by parameter values 60 to 64

More

PS1 is only one of the places where you can specify terminal control sequence. Many other programs also accept it. For example, in my .inputrc (config for readline), I have config like:

"\e[1~": beginning-of-line               # control sequence ending with '~' is for private use.
"\e[4~": end-of-line                        # In other words, we hope these control sequences are sent to terminal
                                                    # when we try to move cursor to the beginning/end of the line
                                                    # (e.g. press home/end key), and terminal can understand them

"\e[5C": forward-word                     # ECMA-48 section 8.3.20 CUF - cursor right
"\e[5D": backward-word                  # ECMA-48 section 8.3.18 CUB - cursor left
"\e[1;5C": forward-word                  # Other config is not specified in the standard.
"\e[1;5D": backward-word               # They may be extensions or just non standard compliant implementation
"\e\e[C": forward-word
"\e\e[D": backward-word
"\e[1;\e[C": forward-word
"\e[1;\e[D": backward-word

I added comments into the config so you can easily know the references.
If you are not sure what key sequence is sent when you press home/end key on your keyboard, run command "cat -v", and press the key. For me, cat shows "^[[1~" when I press home key. You can replace "^[" with "\e" and get the terminal control sequence.

References:

[1] http://www.ecma-international.org/publications/standards/Ecma-048.htm

Friday, June 14, 2013

openssh/git on Windows

You need to install msysgit with openssh first.

Basic ssh:

  1. Check whether environment variable HOME is set by running command "echo %HOME%". If it is not set, set it (for me it is C:\Users\<username>\)
  2. Put your private/public keys into directory: %HOME%/.ssh
  3. SSH config file should be %HOME%/.ssh/config
  4. open a windows cmd window and run "ssh -T <username>@<hostname> ".
    Or open git bash window, and run the same command.

ssh-agent

Unfortunately I could not make it work by using only native Windows env.

Instead, I ran it inside git bash. In git bash,

  • run command
    eval `ssh-agent`
    ssh-add <path>/<to>/<your>/<key>

Eclipse

Open preference dialog, search for "ssh2" and configure the path of private key, etc. accordingly.

git config

Download the git config file https://sites.google.com/site/jenvor/Home/.gitconfig?attredirects=0&d=1 to %HOME%/ and change it based on your info.

Initialize a local repo and push its content to an empty remote repo:

mkdir /path/to/your/project
cd /path/to/your/project
git init
git remote add origin <your_git_ssh_or_https_path>
# add/change files/directories
git add <file>
git commit
git push -u origin --all   # for the first time only

Set-up upstream branch: git branch -u origin/master

Sunday, May 12, 2013

Use bochs on Ubuntu

Install packages:

sudo apt-get install bochs
sudo apt-get install bochs-x
sudo apt-get install bochs-sdl
sudo apt-get install bochs-term

BIOS ROM image is installed by package bochsbios.
  -  /usr/share/bochs/BIOS-qemu-latest
  -  /usr/share/bochs/BIOS-bochs-legacy
  -  /usr/share/bochs/BIOS-bochs-latest
  -  …

/etc/bochs-init/bochsrc: is NOT loaded.

Multiple display libraries are supported (e.g. sdl, x, term). You can change it by setting "display_library".

if you use term as display library, to quit simulation, run command "kill -HUP <process_id>" in a separate console.

Create an empty floppy image: dd if=/dev/zero of=flooy-drive/floppy.img bs=512 count=1

Copy binary to the floppy image: dd if=<name>.bin of=floppy-drive/floppy.img

Cygwin notes

mount a windows directory: mount -o noacl -f "c:/Program Files" "/mount/programfiles"

Disable permission check when accessing Windows files:
  - Add the following line to /etc/fstab:  none /cygdrive cygdrive binary,posix=0,user,noacl 0 0 

Symbolic links:

A useful script:

#! /bin/bash

function conv() { 
  file="$1" 
  target="$(readlink $file)" 
  echo "file is $file; target is $target" 
  rm "$file" 
  #ln -s "$target" "$file" 
  # mkshortcut -n "$file" "$target" 
  winEscapedTarget="${target//\//\\}" #convert to windows path separator 
  winEscapedTarget="${winEscapedTarget//\\\\/\\}" #change \\ to \ 
  winEscapedFile="${file//\//\\}" #convert to windows path separator 
  winEscapedFile="${winEscapedFile//\\\\/\\}" #change \\ to \ 
  echo /cygdrive/c/Windows/System32/cmd.exe /c mklink "$winEscapedFile" "$winEscapedTarget" 
  /cygdrive/c/Windows/System32/cmd.exe /c mklink "$winEscapedFile" "$winEscapedTarget" 
  echo "re-link is done!" 
}

if [ $# -gt 0 ]; then 
  basedir="$1" 
  if [ -d "$basedir" ]; then 
    cd "$basedir" 
    if [ $? -ne 0 ]; then 
      echo "cannot cd to $basedir" 
      exit 1 
    fi 
  elif [ -f "$basedir" ]; then 
    cd "`dirname $basedir`" 
    file="`basename $basedir`" 
    echo "pwd is `pwd`" 
    conv "$file" 
    exit 0 
  else 
    echo "parameters are invalid" 
    exit 1 
  fi 
fi

Tuesday, April 16, 2013

File Associations in Windows Regsitry

See [1] for the description of HKLM, HKCU, and HKCR. According to [2], HKCR provides a merged view of HKCU and HKLM. For ProgID, see [3]. For file extension, see [5].

File extensions config examples (see [7] for valid keys/entries):

for .rar:

  • HKLM/SOFTWARE/Classes/.rar has a key "(Default)" with ProgID "7-Zip.rar"
  • HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/.rar
    • child: OpenWithProgids has a key named "7-Zip.rar" (appear in "open with" menu)
for .txt:
  • HKLM/SOFTWARE/Classes/.txt (apply to all users)
    • keys: (Default)=txtfile; Content Type=text/plain (txtfile is ProgID)
    • child: OpenWithProgids (appear in "open with" menu)
    • child: ShellNew
  • HKCU/SOFTWARE/Classes/.txt (apply to the interactive user)
    • Does not exist in my case
  • HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/.txt (apply to the interactive user)
    • child: OpenWithProgids has a ProgID "txtfile"
    • child: UserChoice has a key named "Progid" with value "Applications/notepad++.exe" (!important)

Applications with ProgID:

  • HKLM/SOFTWARE/Classes/7-Zip.rar/shell/open/command (7-Zip.rar is ProgID)
  • HKLM/SOFTWARE/Classes/txtfile/shell/open/command: the value of "(Default)" is the command used to open files.

How a file extension (e.g. .txt) is mapped to a file type?

  • "UserChoice" takes the first precedence. If it is not set, key "(Default)" stores the ProgID which can be found under [HKCU|HKLM}/SOFTWARE/Classes/.

For gvim.exe, you should have HKLM/SOFTWARE/Classes/Applications/gvim.exe/shell:

  • edit/command[(Default)] = command
  • open/command[(Default)] = command
    Notes: "gvim.exe" is ProgID, see [3] for more detail.

How to change the default app when a file is double-clicked? (Take .c as an example)

  • Solution 1 (use entries for Explorer)
    1. For HKCU/Software/Microsoft/Windows/CurrentVersion/Explorer/FileExts/.c/UserChoice, set the value of key "UserChoice" to "Applications/gvim.exe".
    2. For HKLM/SOFTWARE/Classes/Applications/gvim.exe/shell/edit/command, set the value of key "(Default)" to '"C:\Program Files (x86)\Vim\vim73\gvim.exe" -p --remote-tab-silent "%1" "%*"'
    3. Open "Control Panel\Programs\Default Programs\Set Associations", you will see .txt has been associated with gvim.exe.
  • Solution 2
    UserChoice should not be set in this solution (you can delete it first).
    1. make sure HKLM/SOFTWARE/Classes/.c has the key "(Default)" set to "cfile".
    2. For HKLM/SOFTWARE/Classes/cfile/shell/open/command, set "(Default)" to the gvim command above.

References

[1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms724475%28v=vs.85%29.aspx
[2] http://msdn.microsoft.com/en-us/library/windows/desktop/ms724498%28v=vs.85%29.aspx
[3] http://msdn.microsoft.com/en-us/library/windows/desktop/dd542719%28v=vs.85%29.aspx
[4] http://msdn.microsoft.com/en-us/library/windows/desktop/ms690440%28v=vs.85%29.aspx
[5] http://msdn.microsoft.com/en-us/library/windows/desktop/ms678415%28v=vs.85%29.aspx
[6] http://msdn.microsoft.com/en-us/library/windows/desktop/hh127445%28v=vs.85%29.aspx
[7] http://msdn.microsoft.com/en-us/library/windows/desktop/cc144148%28v=vs.85%29.aspx#fa_optional_keys_attributes

Sample reg file

Be careful, it will overwrite the current value!!!
============================================

Windows Registry Editor Version 5.00 

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.c] 
@="cfile" 

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\cfile\shell\open\command] 
@="\"C:\\Program Files (x86)\\Vim\\vim73\\gvim.exe\" -p --remote-tab-silent \"%1\" \"%*\"" 
============================================
Note: the value must be a string put in double quotations!
  

Monday, March 18, 2013

Eclipse shortcuts

   
Ctrl+Shift+O organize imports
Ctrl+Shift+M Add imports
Ctrl+Alt+H Show call hierarchy
Ctrl+T Show type hierarchy
Ctrl+1 quick fix
Alt+Shift+J Add comments
Ctrl+I correct indentation
Ctrl+Shift+Space show parameter hints
   
Ctrl+D delete a line
Ctrl+Shift+Delete Delete to the end of line
Alt+Up/Down move current line
Ctrl+Q jump to last-edit place
Alt+/ auto-completion
Ctrl+Alt+J Join lines
Shift+Alt+Up Select Enclosing Element
Shift+Alt+Left Select Previous Element
Shift+Alt+Right Select Next Element
   
Ctrl+O open outline dialog
Ctrl+Shift+R open resource dialog
Ctrl+E show opened files
Ctrl+Shift+E open a dialog showing opened files
   
Ctrl+Shift+P jump to matching parenthesis
   

Saturday, October 13, 2012

Git cheatsheet


My random notes on Git use.

   
   
   
g checkout path for path, reset WT to Index (change WT)
g checkout tree-ish path for path, reset WT and Index to tree-ish (change WT and Index)
g checkout branch switches branch by updating the index, working tree, and HEAD to reflect the specified branch (current branch is switched)
g checkout commit_id check out a commit for inspection and discardable experiments.
(current branch is switched)
g checkout -p commit_id don't switch branch; update working tree and Index interactively.
E.g. g checkout -p HEAD
g checkout -b branchname\
    start_point
create a new branch from start_point and switch to it.
(current branch is switched)
g checkout not sure yet!
   
g reset path for path, reset index to HEAD (WT and branch are not touched)
g reset commit path for path, reset index to commit (WT and branch are not touched)
g reset --option commit reset HEAD to commit, and reset index or WT according to option
(http://www.kernel.org/pub/software/scm/git/docs/git-reset.html)
--soft only reset HEAD
--mixed (default) reset HEAD and index
--hard reset HEAD, index, and WT
--merge reset HEAD and index;
for each file:
    HEAD != commit, then reset WT;
    Index != WT, then don't reset WT;
    HEAD != commit && Index != WT, then abort.
--keep reset HEAD and index;
for each file:
    HEAD == commit, then don't reset WT;
    HEAD != commit && WT == Index && Index == HEAD, then reset WT;
    HEAD != commit && has local changes, then abort.
   
git rebase -i upstream interactively rebase. You can choose to squash commits.
E.g. git rebase -i HEAD^4, git rebasei HEAD@{4}

Friday, September 14, 2012

Jabberd2 and OpenFire notes

Resources:
http://www.24100.net/2009/11/federate-google-wave-sandbox-with-your-own-fedone-server/

If you have a pkcs12 that contains your private key and certificate chain, use following command to convert it to pem:

openssl pkcs12 -in startssl.p12 -out startssl.pem –nodes

Maybe you need to manually adjust order of certificates in the generated pem file. You client cert should appear first, then certs from intermediate CAs, and root CA cert.

Read comments in file http://codex.xiaoka.com/svn/jabberd2/trunk/etc/c2s.xml.dist.in

<id register-enable='true'
    require-starttls='true'
    pemfile='/home/gerald/ongoing/jabberd2/startssl.pem'>129-79-49-197.dhcp-bl.indiana.edu</id>

Don’t put it this way for readability:

<id register-enable='true'
    require-starttls='true'
    pemfile='/home/gerald/ongoing/jabberd2/startssl.pem'>
129-79-49-197.dhcp-bl.indiana.edu</id>

You will get “Host Unknown” error :-(

FedOne

router.xml
local –> secret

run-config.sh
XMPP_SERVER_PORT=5347

sm.xml: sm->id

c2s.xml: c2s->local –>id

Certificate for you domain

openssl genrsa 2048 | openssl pkcs8 -topk8 -nocrypt -out wave1.example.com.key
openssl req -new -nodes -sha1 -days 365 -key wave1.example.com.key -out wave1.example.com.csr
Note: Common Name (eg, YOUR name) []: wave1.wave.zhenhua.info

DNS

SRV

Settting
_xmpp-server._tcp.wave1.example.com               wave1.example.com 5269
_xmpp-server._tcp.wave.wave1.example.com      wave1.example.com 5269

Priority and weight are not so important in our SRV settings.

Testing
dig +short -t SRV _xmpp-server._tcp.wave1.example.com
dig +short -t SRV _xmpp-server._tcp.wave.wave1.example.com

A

wave1.example.com    your_server_ip_address

FedOne server config

WAVE_SERVER_DOMAIN_NAME=wave1.example.com     # not wave.wave1.example.com

XMPP_SERVER_PING=initech-corp.com

Use ./check-certificates.sh to check your certificate settings.

 

Hostname used set in OpenFire and FedOne server should match (wave1.example.com in our example).

edit /etc/openfire/openfire.xml, change <setup>true</setup> to <setup>false</setup>. restart the server.

Server Manager –> Server Information, section “Server Properties”:
Server Name: wave1.example.com

OpenFire

Add a user named “username”. Your users will have accounts like username@wave1.example.com

Test

Open client console: ./run-client-console.sh username

type /new, /open 0, /add your_wavesandbox_account, then type a message. You should see the message in your wavesandbox page. There is delay (for me about 1 minute).

In google wave sandbox, add user@wave1.example.com to your address book

windows migration notes

Bakcup
Following is the default profile/configuration file locations for some programs. It may vary because of your customized setting during installation.

  • Messenger
    c:\Users\gerald\Documents\My Received Files\jenvor381158107\
  • WLW
    c:\Users\gerald\Documents\My Weblog Posts\
    c:\Users\gerald\AppData\Roaming\Windows Live Writer\
  • Skype
    c:\Users\gerald\AppData\Roaming\Skype\
  • Filezilla
    c:\Users\gerald\AppData\Roaming\FileZilla\
  • Totalcmd
    c:\Users\gerald\AppData\Roaming\GHISLER\
    Change file wincmd.ini: to add a section for your resolution (like [1024 x 768])
  • Firefox
    c:\Users\gerald\AppData\Roaming\Mozilla\
  • SecureCRT
    c:\Users\gerald\AppData\Roaming\VanDyke\Config\
  • Outlook
    pst files: c:\Users\gerald\AppData\Local\Microsoft\Outlook\
    Accounts: go to registry Current_User/Software/Microsoft/WindowsNT/Messaging Sub Systems/Outlook/Profile, export and import it
  • FileZilla server
    The installation directory. cert