Handy reminders

mySQL

To create a database:
mysqladmin -u login -ppassword create databasename
To access a Database :
mysql -u 'username' -p'password' 'Database name' or -p and then password is asked
To create tables from a file containing table creation code:
mysql -u login -ppassword dbname < file.sql
Misc commands
use 'dbname';
SHOW tables;
SHOW columns FROM tbname;
CREATE TABLE tbname( firstname VARCHAR(25), lastname VARCHAR(25));
INSERT INTO tbname(field) VALUES (values);
UPDATE tbname SET field1='value1' WHERE field2='value2';
SELECT * FROM tbname WHERE field1='value1'
DROP DATABASE dbname;
DROP TABLE tbname;
ALTER TABLE tbname CHANGE field chgfield VAR ;
DELETE field FROM tbname WHERE afield=whatyouwant;

Java

Swing applets

The HTML code of a swing applet has to be modified in order to redirect the applet execution towards the java plug-in.
Javasoft provides the HTMLConverter class that would correctly modify the regular applet tag calls.

Package Management

Each source file part of a package has to contain the name of the package on top of the code.
Following the directory structure, files in directories above can 'use' these objects by importing them or the package.

To compile files that are in the same directory as the package name, the compilation has to be done from one layer up and called as:
javac -d 'dest' pack_name/filename.java

Compiling

To compile specifying a class directory and a set of classpath use:

javac -d 'dest' -classpath '.;%classpath%;/whatever/you/want/dir'

CVS notes

To import a source directory:
cd to this directory(where the source files are) and use
 cvs import -m 'my message' CVS/DESTINATION/DIR vendor_tag release_tag
If the destination directory doesn't exist yet it will be created.
This destination Dir name has to start from the CVSROOT dir not from the module name.
Import will create the entire directory structure and all the files that it contains but does not 'work' on single files, for that use add

Checking out a repository is the first step to perform modifications:
cvs co Module_Name
To add a file to the repository use
cvs add File_Name
To get status use
cvs status ModuleName
To update changes in the repository
cvs update ModuleName
Connecting to a remote CVS server using Cygwin
In .bashrc add:
export CVSROOT=:ext:username@comp.where.cvs.is:/path/to/cvs
export CVS_RSH=/path/to/rsh
Once this is done call
cvs co ModuleName


To commit changes in the repository=physically writing the file, use:
cvs commit


Using tcsh
foreach i (ls *.java)
rm $i
cvs delete $i
end

cvs commit
Using bash, the for loop has a different syntax than tcsh:
for i in `ls *.ext`
do
cat $i
cp $i $i.newExt
done

SED

To substitute a string in a file:
sed /s/first_String/replace_string/g
sed -e 's/ \(.*\) [1-9] .* \(.*\)/\1 \3 \2/g' 
The second command will replace a string such as:
vincent wants to go 4 never looking back
into vincent wants to go back never looking

Get Rid of characters

s/<ctrl-v><ctrl-M>/d 

How to get tag name off a bib file:
sed -e 's/@[a-zA-Z]*{\(.*\),/\1/' bibfile.bib | sed -e '/[,}%{]/d' | sed -e '/[a-z]/!d' 
You can chain commands using the -e option one after the other
For example:
sed -e /^$/d -e s/cat/dog/g file.f

Pattern templates can be allocated to a variable in order to make the regex shorter:
For example
T=[\']\(.*\)[\']
sed -e "s/$T.*$T.*$T/\1\t\2\t\3/g" file.f
This would match all items of the form 'abc12121','sdlfj122','32e13' and keep what's inside the quotes separated by tabs.

Renaming extension of file names

for i in *.wav
do
mv "$i" "`echo $i | sed s/wav/mp3/ `"
done
This replaces the last character if the octal value is 15 or 32, Control-m and Control-z respectively:
sed 's/'"$(printf '\015')"'$//
s/'"$(printf '\032')"'$//' filename

AWK

Get the number of Records in a bibfile:
awk 'BEGIN{RS="@"} END{print NR}' bibfile.bib
To print out a floating point number use the printf command, as in C:
awk '{print "%.2f",$1}' file.f
Simple addition (total number of lines):
awk 'BEGIN{i=0} {/pattern/;i=i+1} END{print i}' file.f

JavaScript

Window opening:

window.open('file.html','Name','widht=xxx,height=yyy,scrollbar=auto');
To send form information to a popup window use a function like : For example:
<A HREF="javascript:window.open('images/rediscover3.jpg','Redesign','width=705,height=850,location=no,resizable=yes,menubar=no');returntrue;">
<CENTER><IMG SRC="imAges/rediscover3.jpg" width=300></CENTER></A>
function popupform(myform, windowname)
{
if (! window.focus)return true;
window.open('',windowname, 'height=700,width=810,scrollbars=yes');
myform.target=windowname;
return true;
}
Redirecting a page:
frame.location='somewhere.html';


Perl

In Perl5, setting @INC variable:
[export,set] PERL5LIB=/dirs/to/add

Latex

Rotating tables and printing them as such:
To rotate a page one can use the lscape package and landscape environment. The advantage is that the entire page is rotated.
To rotate a figure/table/float, one can also use the rotating package and use the sidewaystable or sidewaysfigure or rotate environment (or even turn) to determine a rotation. sideways commands rotate by 90 degrees while rotate and turn rotate by a set degree.
To print the rotated page as actually rotated, avoid dvipdf which tends to ignore dvi specifics that contain information regarding postscript paper size and angles etc... instead use dvipdfm or dvips. In short:
\usepackage{landscape}
...
\begin{landscape}
\begin{table}
...
\end{table}

OR 

\usepackage{rotating}
....
\begin{sidewaystable}
...
\end{sidewaystable}

\begin{rotate}{-45}
\begin{figure}[h]
...
\end{figure}
\end{rotate}