Thursday, July 31, 2008

Do not display initia screen on emacs

To prevent the default GNU message on emacs
add the following line to your .emacs file.

(modify-frame-parameters nil '((wait-for-wm . nil)))

Friday, July 11, 2008

screen command

to switch off the startup message in the screen command,

sudo emacs -nw /etc/screenrc
and uncomment the line,
startup_message off

to enable scroll mode do Ctrl+A and ESC
Press ESC to return to normal mode.

To reattach a screen that is attached else where do:
screen -d

The following commands can be used for navigation purposes. Reference


h -    Move the cursor left by one character
j -    Move the cursor down by one line
k -    Move the cursor up by one line
l -    Move the cursor right by one character
0 -    Move to the beginning of the current line
$ -    Move to the end of the current line.
G -    Moves to the specified line 
       (defaults to the end of the buffer).
C-u -  Scrolls a half page up.
C-b -  Scrolls a full page up.
C-d -  Scrolls a half page down.
C-f -  Scrolls the full page down.
By writing the following line to .screenrc in $HOME you can change number of lines that are stored in the scrolling buffer.

defscrollback 5000

Enable mouse wheel in Ubuntu VMWare guest

If you are using guest Ubuntu under VMware, mouse scroll does not work.
To fix this, open terminal and type the following:
$ sudo gedit /etc/X11/xorg.conf
Then find "InputDevice" section with Identifier "Configured Mouse"
Change Option "Protocol" "ps/2"
to
Option Option "Protocol" "IMPS/2"
Last restart X using Ctrl + Alt + Backspace

create user/grant permission

login as root by....mysql -u root
create user 'username'@'hostname' identified by 'passwd';
create database mydb;
grant all on mydb.* to 'username'@'hostname';

now login as the new user and create table etc in mydb.
mysql -u username -p
enter password

emacs

TRAMP (opening remote files)
Add the followig to .emacs
(require 'tramp) (setq tramp-default-method "scp")

now you can open a remote file like this
/kin:~/re/test.py

Moving to buffers
Next : Ctrl+X+right arrow key
Previous : Ctrl+X+left arrow key

Word wrapping
To toggle the fill mode
M+x auto-fill-mode
If we are in the fill mode then "fill" will appear in the status bar.
At fill mode, line wrapping causes a new line char to be inserted.
(not good, have to reformat)

To format/wrap
M+q (do this on top of text)

Setting the scroll bar on the right
put the following two lines in the .emacs file
(setq scroll-bar-mode-explicit t)
(set-scroll-bar-mode 'right)

Enable backspace
(global-set-key "\C-h" 'backward-delete-char)

Markup/delete/insert
press Ctrl+space to start mark-up a region.
Now move the curser down/up left/right to mark a rectangle.
press Ctrl+x and then r then t now it will turn to
String-rectangle mode. Type what you want to insert

To delete,
markup the rectangle with Ctrl+space and then
Ctrl+x and r k
k is to kill

emacs fonts

To check all availabe font options run, xfontsel from the command line.
You can try diiferent fonts and their options.

One example would be,

(set-frame-font "-adobe-helvetica-*-r-normal-*-14-*-75-75-*-77-*-u")


Add this line to your .emacs file.
To set the geometry of the window (size) add the following line
to ~/.Xresources

Emacs.geometry:31x48

Then run,
xrdb -merge ~/.Xresources

The next time you start emacs, things will be nice!!!

installing/reinstalling/removal

Ubuntu packages: mysql-client-5.0. mysql-server-5.0
starting mysqld service... sudo /etc/init.d/mysqld start

to completely remove mysql do the following.
sudo apt-get --purge remove mysql-client mysql-server-5.0
you will loose all databases!!!

changing the directory in which mysql databases are stored

By default all databases are saved in /var/lib/mysql
Because this is in the root partition you might quickly use up root
partition if you create large databases. If you want to change this
directory to, for example, /home/mysql do the following.

creating the new datadir
sudo mkdir /home/mysql

stop mysql.
sudo /etc/init.d/mysql stop

edit my.cnf (mysql config file)
sudo emacs -nw /etc/mysql/my.cnf

change datadir under [mysqld] from /var/lib/mysql to /home/mysql

edit apparmour (Ubuntu speciality)
sudo emacs -nw /etc/apparmour.d/usr.sbin.mysqld
change lines that contain /var/lib/mysql/ to /home/mysql/

copy the databases to new directory.
sudo mv /var/lib/mysql/* /home/mysql/.

change file ownership (should be owned by user mysql and group mysql)
sudo chown -R /home/mysql

restart apparmour
sudo /etc/init.d/apparmour restart

start mysql
sudo /etc/init.d/mysql start

GNUPLOT

To plot CSV files do the following,
set datafile separator ","

to print to eps:
set terminal postscript eps enhanced "Times-Roman" 18
set size 1.0, 1.0
set output 'histo.eps'

Here, size is relative to the box

to generate histograms:
(actually gnuplot cannot cumulate the data for you.
use a program to do that. gnuplot only draws the bar chart)

set style fill solid 1.00 border -1
set style data histograms
set style histogram clustered gap 1
set xtics border in scale 1,1 nomirror rotate by -45 offset character 0, 0, 0

set xlabel "xxx"
set ylabel "yyy"
set yrange [0.00:1.00] noreverse nowriteback
set nokey #off the legend
plot 'datafile' using 2:xticlabels(1) #column one contains labels
pause -1 #wait until enter is pressed

Setting up WinShell and dviout with pLatex

Install pLatex using the installer at;
http://www.ms.u-tokyo.ac.jp/~abenori/mycreate/

install ghost script, ghost view and dviout

install winshell
http://www.winshell.org/modules/ws_download/

configuration in winshell
options->program calls
1. Latex
C:\pTex\bin\platex.exe
cmdline: -src-specials -interaction=nonstopmode "%s.tex"
[-src "%s.tex" worked for me]

2. bibtex
C:\pTex\bin\jbibtex.exe
cmdline: "%s"

3. dviview
C:\pTex\dviout\dviout.exe
cmdline:-1 %s.dvi "# %l '%c.tex'"

4. dvips
C:\pTex\bin\dvipsk.exe
cmdline:-D600 "%s.dvi"

set font; ms gothic size 14 script Japanese encoding sjis

set colors in syntax-colors

In dviout set the following settings;
option->set up parameters->common
src: C:\Program Files\WinShell\WinShell.exe^s-c "%s" -l %d

This will jump to the position in winsell editior when you double click on a word in the dvi file

check, options->continuous review
to stop opening dviout window everytime you run dviout from winsell.
Moreover, it will instantly show any changes that you have made to tex file when you compile it.

LaTex PDF Generation from DVI

To create a USLetter size pdf from dvi do,
dvipdfm -p letter mypaper.dvi

Write XML from Python

from xml.sax import saxutils
then use saxutils.escape("raw_string")
will give all exceptions escaped!

Thursday, July 10, 2008

HTML tooltip texts

<HTML>
<HEAD>
<STYLE>
.popup
{
COLOR: #9F14A;
}
</STYLE>
<TITLE>Test Page</TITLE>
</HEAD>
<BODY>
<SPAN title="popup text" class="popup">display</SPAN>
</BODY>
</HTML>

Python CGI programming

apache configuration
/etc/httpd/conf/httpd.conf is the configuration file. Open this as root (sudo emacs -nw httpd.conf)
To enable cgis
ScriptAlias /cgi-bin/ "/var/www/cgi-bin"
<Directory "/var/www/cgi-bin">
Allow Override None
Options FollowSymLinks ExecCGI
Order allow, deny
Allow from all
<Directory>

It is also possible to set per-user cgi-bin, html folders but this reveals the users in a machine.
public_httml settings are not good for this reason

/var/www/html html folder
/var/www/cgi-bin/ cgi-bin
Must have write permissions (root or su)

AddHandler cgi-script .cgi .pl .py
Now save and start httpd by,
sudo /etc/init.d/httpd restart

File permissions
cgi-bin should be 755 (4=read, 2=write, 1=exec)
scripts should be 705 (if this needs to write to a folder then set to 707)
chmod 705 my.py

#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()

print "Content-Type: text/html \n"
print "<HTML> \n"
print "<HEAD> <TITLE> Results </TITLE> </HEAD> \n\n\n"

(At least two lines should be there after the header. If not we get Internal Server Error 500)

Python float string formatting

z='%.15f' % x
gives a 15 decimal precision float converted to a string.
It is possible to get more than 15 decimals using %.20f and
%.80g etc. But the decimals after 15th are not reliable.

****incrementing integers in python
i+=1
i*=5
i-=1
i/=2
all works. Note i**2 means i to the power 2
***********************
Python have private class and module methods. To make a method private
to a class or a module use __before the name.
Ex;
def __privateMethod():
If you try to call this method outside the module or outside the class
declaration, python will generate a 'method not found' exception.
Python 万歳!!!

suppress the log-in message

create a file on the remote machine by,
touch .hushlogin

Symbolic links

ln -s /data/dvd5 dvd5
If dvd5 is a directory then we must create a soft link using -s option.
Do not use a trailing back slash after the directory name

firefox remote

to open firefox on a remote machine, in that local machine do;

firefox -no-remote&
If there is already a firefox opened in the remote machine then you
will have to first close it.
find the pid of the currently running instance of firefox by,
ps -ax|grep 'firefox'
and kill it by
kill -9 pid

Logitec Keyboard

The scroll bar makes a clicking noise during use. To turn the noise off/on, hold the 'FN' key and hit the 'pics' button next to it.
To turn the bar off altogether, since it is very sensitive, hold the 'FN' key and hit the 'X' next to it. To turn it back on, hold the 'FN' key and hit the flip-3d key next to it.

ssh X11 Forwarding not working!

In Ubuntu edit /etc/ssh/ssh_config file and set
ForwardX11 yes
do the same for secure tunneling X11 and agent forwarding.

Now delete all Xauthority file locks by
sudo rm .Xauthority*

Now log in again.

Adding another hard drive

http://wiki.linuxquestions.org/wiki/Add_a_new_hard_drive

Compressing/Uncompressing

to uncompress tar.bz2 files do:
tar jxvf filename

Add users set passwords and home directory

sudo useradd -d /home/usrname -m usrname
sudo passwd usrname
change the password

installing vmware tools on fetsity

install build tools first, they are not installed by default
sudo apt-get update
sudo apt-get install build-essential
howto

Terminal title

export PS1="[\u@\h \w]$ "
will print
username@first_level_host last_dir]$
as the prompt

check version

uname -a (gives the kernel)
cat /etc/redhat-release (gives redhat version)

System Bell

system->preference->sounds->system bell Disable

bashrc vs bash_profile

bash_profile is callled when a non-interactive log-in shell
is invoked (e.g., starting terminal in Gnome or emacs shell)

bashrc is called when an interactive log-in shell is invoked
(e.g., ssh shells)

Add the following to .bash_profile and write all things that
you need to do in .bashrc so that even when a non-interactive
log-in shell is invoked, still .bashrc will get invoked.

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

IE maximizing new windows

open IE and right click on a link and open it in a new window.
Now resize the new window (do not use maximize button) by dragging the edges to your
preference. Now close the first window by File->Exit
and do the same for the new window.
This works for IE7

Ubuntu Japanese IME/Emacs

set the root password by
sudo passwd root
Give a new root password

specify japanese ubuntu ring,
system->software sources->third-party software
Add the following two locations for feisty (7.04)

deb http://archive.ubuntulinux.jp/ubuntu-ja feisty/
deb http://archive.ubuntulinux.jp/ubuntu-ja feisty-ja/

close->reread
This will give an error because of public key mismatch, but
do not worry.
Install ubuntu-japanases-ring package

system->admin->synaptic package manager
ubuntu-ja-keyring
Apply->ok
This will download japanese packages and install.

To set up IME, first install Japanese language support by,
admin->language package

Now restart (logout X) and log in again, try
Ctrl+Space

If this does not trigger scim, then you need to add the following
to Xsession.d,

sudo touch /etc/X11/Xsession.d/74custom-scim_startup
sudo chmod 646 /etc/X11/Xsession.d/74custom-scim_startup
echo 'export XMODIFIERS="@im=SCIM"' >> /etc/X11/Xsession.d/74custom-scim_startup
echo 'export GTK_IM_MODULE="scim"' >> /etc/X11/Xsession.d/74custom-scim_startup
echo 'export XIM_PROGRAM="scim -d"' >> /etc/X11/Xsession.d/74custom-scim_startup
echo 'export QT_IM_MODULE="scim"' >> /etc/X11/Xsession.d/74custom-scim_startup
sudo chmod 644 /etc/X11/Xsession.d/74custom-scim_startup

You need to re-log-in to make the changes effective.
Now you can inset Japanese.

subversion control (SVN)

SVN is much easier to work with when compared to CVS.
Some useful commands are:
When you have first created SVN and want to submit the initial version of a project use import command.
1. svn import hmm http://ppp.berlin.ghost.de/svn/

2.To check out for the first time, do
svn co http://pp.berlin.ghost.de/svn/hmm newhmm
Files will be downloaded and saved as newhmm
If http fails, use svn://...

3. After changing a file, if you want upload the changes, do commit.
svn commit
(Remember to go out to the appropriate parent directory. Otherwise, you
may get a 'work directory not found' kind of an error.

4. Once you have checked out, but want the latest version, do, update.
svn update (alternatively, svn up)

if svn breaks down, do
svnadmin recover /home/svn
chmod -R g+w /home/svn

file permission and groups

u=owner
g=group
o=others

r=read w=write x=execute
+ add permissions
- remove permissions
= set permissions absolutely

Ex:
chmod go+rx mydir

separate multiple settings by a comma
chmod a=rx,u+w myhome
will set myhome to drwxr_xr_x

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1