Random Wisdom

How To …

Tesselated Cells

by on Feb.03, 2006, under How To ..., Software

Finally .. a script (link broken since 2007) that will generate a square field of tesselated cells in MATLAB. The script take as input the desired cell radius and the dimension of the square field.

Generating a cell is simple enough. The corners are simply R*exp(j*(-pi:pi/3:pi)+pi/6)/cos(pi/6). The additional pi/6 is needed to rotate the resulting hexagon. The real challenge is in the tesselation. In order to achieve that, two base vectors that govern the tesselation must be defined:

vi = 2*R;
vj = 2*R*(cos(pi/3) + j*sin(pi/3))

Using these base vectors, the centers of every cell in the tesselation can be defined:

for a = 1:x
    for b = 1:x
        centr(a,b) = a*vi+b*vj;
    end
end

One we have the centers, use the MATLAB repmat function to replicate the corners around each of the centers to get the tesselated cells:

cells = repmat(corners.', 1,...
               numel(centr))+repmat(reshape(centr.',1,...
               numel(centr)),length(corners), 1);

A plot of the cells can be achieved using:

plot(real(cells),imag(cells));

This will however, generate a tesselation that is skewed. The linked *.m file takes care of that issue to generate a square tesselated field.

2 Comments :, , more...


HTTP Access Control

by on Jan.25, 2006, under How To ..., Software

Finally figured out how to password protect individual directories on the server:

Authentication, Authorization and Access Control

It’s a simple 2-step process:

1. Create a passwords file for the users using “htpasswd“:

jsmith@server:~/public_html/db$ htpasswd -c ~/htpasswds jdoe
New password:
Re-type new password:
Adding password for user jdoe
jsmith@server:~/public_html/db$

2. Create a file “.htaccess” in the directory to be protected:

jsmith@server:~/public_html/db$ cat .htaccess
AuthType Basic
AuthName "db"
AuthUserFile /home/jsmith/htpasswds
Require user jdoe
2 Comments :, , , , more...

coLinux

by on Jan.19, 2006, under How To ..., Linux, Software

Recently, I needed to use Umbrello but didn’t have access to a workstation that had it installed. And since I’m stuck with a Windows PC, I thought I’d take a look at the KDE-Cygwin project. It seems that they’ve stopped working on the project since there is a better alternative: Cooperative Linux. It’s basically a modified Linux 2.6.10 kernel that runs on Windows — kind of a like a virtual machine but it’s different — it’s definitely a lot faster. Here’s a snippet from the coLinux homepage:

Cooperative Linux is the first working free and open source method for optimally running Linux on Microsoft Windows natively. More generally, Cooperative Linux (short-named coLinux) is a port of the Linux kernel that allows it to run cooperatively alongside another operating system on a single machine. For instance, it allows one to freely run Linux on Windows 2000/XP, without using a commercial PC virtualization software such as VMware, in a way which is much more optimal than using any general purpose PC virtualization software.

The project page had a preconfigured Debian image and so that’s what I’m using at the moment. The native X server does not work though — so the Cygwin based X server is needed to diplay all the GUI stuff.

Getting it installed was a piece of cake. The Wiki site for coLinux has a lot of helpful info.

Once the basic text-mode linux is up and running (must be able to reach the host via the network), we need to run some commands from the cygwin shell. First run


$ cygserver-config

to configure the cygwin server and then start the server with:


$ cygrunserver -S cygserver

Then, we need to set


$ export CYGWIN=server

And then start the X server in rootless mode. The easiest way is to just make a copy of the startxwin.bat file and then edit it to change the options to XWin.

Once the X server is running, we need to run “xhost +” from the xterm that had popped up. Then, we switch over to the coLinux console and run:


$ export DISPLAY=<ip of windows host>:0

And that’s it! Now you have a fully functional linux distro! I would have gone for a Fedora install but couldn’t find a proper image.

Leave a Comment :, , , more...

PSfrag for EPS Graphichs Text Manipulation

by on Jan.17, 2006, under How To ..., LaTeX, Software

There’s a nice package called psfrag that allows you to insert LaTeX constructs into EPS figures. This is specially useful with EPS files saved from MATLAB plots. The way it works is by replacing a given tag in the text of the EPS file with the LaTeX construct.

E.g. label the x-axis of of the plot as XLABEL and save the plot as an EPS file. Then, when you include that file, just put in the \psfrag{}{} tag:


\psfrag{XLABEL}{$\frac{\tau}{\sigma}$}
\includegraphics{file}

The most obvious disadvantage is that it only works with EPS figures — so no PdfLaTeX. So, to compile a document to PDF, you’ll need to go the old latex -> dvi2ps -> ps2pdf way.

More details can be found on CTAN.

Leave a Comment :, , , , , more...

Proxy Bypass

by on Jan.10, 2006, under How To ..., Linux, Software

I guess it’s usual for every institution to have a central firewall/proxy that all internal traffic must go through to reach the outside world. I am by no means paranoid about security/privacy but it got me thinking.

… And once again, SSH to the rescue! It almost feels like the possibilites of a SSH tunnel with Local port forwarding are limitless 😀

I just picked up a public German proxy from this page:

http://www.publicproxyservers.com/index.html

And then setup a SSH connection to forward local port 8080 to proxy:port. Then for the browser I just set localhost:8080 as the proxy.

Well, the speed is a little short of astounding but it’s very much usable 😀 Now all that the central firewall/proxy should be seeing is a bunch of encrypted traffic.

Leave a Comment :, , , , , , more...

Command line search utility

by on Dec.27, 2005, under How To ..., Linux, Software

While studying for one of the finals this year, I felt the need for a CLI search utility that would search on Google, Wikipedia, Google Images, etc. I didn’t know of any tools that would already do this so I decided to write my own little bash script:

#!/bin/bash
#Needs the htmlview package

opt="$1"
str="$2"


#Create the search string
until [ -z "$3" ]
do
  str="$str+$3"
  shift
done

case "$opt" in
    "google"  )
    htmlview http://www.google.com/search?hl=en\&q="$str"&btnG=Google+Search &
    ;;

    "image"   )
    htmlview http://images.google.com/images?q="$str"\&safe=off &
    ;;

    "wpedia"  )
    htmlview http://en.wikipedia.org/wiki/Special:Search?search="$str" &
    ;;

    "scholar" )
    htmlview http://scholar.google.com/scholar?q="$str"\&ie=UTF-8\&oe=UTF-8\&hl=en\&btnG=Search &
    ;;

    "ieee"    )
    htmlview http://ieeexplore.ieee.org/search/searchresult.jsp?queryText=\%28\%28"$str"\%29\%3Cin\%3Emetadata\%29 &
    ;;

    *         )
    echo "Usage: search engine searchterm [searchterms]"
    echo
    echo "Engines: google    Basic Google websearch"
    echo "         image     Unfiltered Google image search"
    echo "         wpedia    Wikipedia (English)"
    echo "         scholar   Google Scholar"
    echo "         ieee      IEEE Xplore (needs subscription)"
    echo
    echo "Example: search image batman"
    ;;
esac

echo

exit 0

It makes use of the htmlview package to discover the default browser and display the results. The use of the script is quite straightforward:


[darkknight@darkworld bin]$ search image batman begins

As is, it considers all search terms. Fancy things like Boolean expressions are not supported (yet :)). A copy of the script can be found here.

1 Comment :, , more...

Time synchronization using NTP

by on Dec.27, 2005, under How To ..., Linux

I’ve been having some trouble getting the system clock to sync. with time servers using ntpd. The method that works at the moment is the use of the CLI utility ntpdate:

[darkknight@darkworld ~]$ sudo su -
[root@darkworld ~]# ntpdate time.nist.gov
27 Dec 12:25:17 ntpdate[5743]: adjust time server 192.43.244.18 offset 0.002806 sec
[root@darkworld ~]#

Unfortunately, the man page of ntpdate says that it’s set to be removed from the distro. — hopefully ntpd will work again once that happens.

[Update] It seems the ntpd daemon was missing. The RPM was installed but the daemon was no longer in /usr/sbin/. So, I reinstalled the ntp package and now time sync. works as is should.

Leave a Comment :, , more...

The wonders of gdmflexiserver

by on Oct.31, 2005, under How To ..., Linux, Software

If you’re using GDM, this is the easiest way to get the “Fast User Switching” seen on Windows XP. All you have to do is type:

[darkknight@darkknight ~]$ gdmflexiserver

and you get a brand new login on Virtual Terminal (VT) #8. Successive runs of gdmflexiserver will open up logins on VT#9, VT#10 and so on. Just in case you don’t know how to switch VTs, its done through the Ctrl+Alt+F<1-12> key combinations. The main login is on VT#7. Once you exit/logout from any of the sessions on VT#<8-12>, it will simply close. If you’re not automatically returned to the original session, just switch back manually using Ctrl+Alt+F7.

One useful option of gdmflexiserver is the ability to run in a nested X server. The command in that case is:

[darkknight@darkknight ~]$ gdmflexiserver -n

Now, instead of opening up a login in a brand-new VT, it will just open up a Xnest window with the login. The new X-Server is then a nested (child) server under the main X server on VT#7.

By default the Xnest window opened has a geometry of 1024×768 pixels. This can be changed by adding the -geometry option to the Xnest command in /etc/X11/gdm/gdm.conf :

...
# the X nest command
Xnest=/usr/X11R6/bin/Xnest -audit 0 -name Xnest -geometry 1280x1024+0+0
# Automatic VT allocation.  Right now only works on Linux.  This way
...

The geometry is specified as WidthxHeight+XCoord.+YCoord. After saving the modified gdm.conf, gdm must be restarted for the changes to take effect. This is done by logging in as root into one of the text VTs (VT#<1-6>) and issuing the commands:

[root@darkknight ~]# telinit 3; telinit 5; exit
Leave a Comment :, , more...

AVG and GMail POP3 Forwarding

by on Oct.25, 2005, under How To ..., Software

The general directions on getting them to play nice are here.

2 Comments :, , more...