GNU coreutils funny

Just had a look at the basename man page and found this:
AUTHOR
Written by FIXME unknown.
But they still claim to have the Copyright. Funny maybe the original author didn't approve with this.

Importance of dates

When browsing the web I don't want to look at old data, so when reading I try to find out when the page was last updated. Now blogging and wikis have become so popular there is normally a date associated with the post but otherwise you are normally left to guess based on version numbers of programs people used.
So if you are a web developer please never forget the date something was created.
Further I was looking for a tool which detects changes and dispays the last changed date. Google somtimes can display this but for about 80% of the pages this information is not available. Why has nobody written a tool that wgets pages and md5sums them to see it they have changed and displays this date. I know it is not always that easy, but a tool like that would be soo usefull. Maybe a firefox plugin could help.

A useful little bashrc addition

I really like checking if commands have executed successfully. This is something quite important if you are administering a machine. Normally I just echo $? but now I have added a new line to my .bashrc that will show me this in colour.

export PS1='\[\033[0;32m\]\u@\h \[\033[0;33m\]\w\[\033[${?/[^0]/31}m\]\$ \[\033[0;38m\]'

This will make the prompt green if everything went OK and red if the process didn't return 0. Nice little helper :)

CentOS help

Something people have asked me about is what to do when yum gives you the error
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
This is very simple

$ yum install yum-utils
$ /usr/sbin/yum-complete-transaction

Finished ;) Just a little cleanup of the completed transactions file

Howto reset your Windows Vista password

On my laptop I had forgotten my password because I always use the finger print reader. And I never really needed it because windows, once you are logged in, never really prompts you for it. But today I needed it and I didn't know it. So what do you do? Here are some simple steps.
  1. Create another user account with Admin rights
  2. Log in as that user
  3. Change your `real` user password
  4. Log in as your `real` user and delete the other account
Viola, password reset without knowing it. Thank you to Paul for this tip. Quite simple but I would have never thought about it.

detex for CentOS

So another little porting effort. This time it is detex
DeTeX is a filter program that removes the LaTeX (or TeX) control sequences from the input so that the real content can be passed to a spell or diction checker.
I am using this for my dissertation to count the words used
detex dissertation.tex | wc
Quite a useful little tool. When I get time I might rewrite it in perl to make it more portable.

Download the [RPM]

[SRPM] and spec file:

Summary: Strips Tex and LaTex commands from a file
Name: detex
Version: 2.8
Release: 1
License: BSD
Group: Applications/Text
URL: http://www.cs.purdue.edu/homes/trinkle/detex/

Source: http://www.cs.purdue.edu/homes/trinkle/detex/%{name}-%{version}.tar
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root

Patch0: mallocandtroff.patch

BuildRequires: flex
BuildRequires: groff

%description
DeTeX is a filter program that removes the LaTeX (or TeX)
control sequences from the input so that the real content can be
passed to a spell or diction checker


%prep
%setup
%patch -p0

%build
%{__make} detex man-page prefix="%{_prefix}" CFLAGS="%{optflags} -DNO_MALLOC_DECL"

%install
%{__rm} -rf %{buildroot}
#%{__make} install DESTDIR="%{buildroot}"
%{__install} -Dp -m0755 detex %{buildroot}%{_bindir}/detex
%{__install} -Dp -m0644 detex.1 %{buildroot}%{_mandir}/man1/detex.1

%clean
%{__rm} -rf %{buildroot}

%files
%defattr(-, root, root, 0755)
%doc %{_mandir}/man1/detex.1*
%{_bindir}/detex

%changelog
* Tue Apr 21 2009 Hoffmann Geerd-Dietger - 2.8-1
- Initial package.


You will also need the little patch file
--- Makefile.orig 2009-04-21 01:50:44.735919044 +0100
+++ Makefile 2009-04-21 01:51:18.237692007 +0100
@@ -49,7 +49,7 @@
# Compile time flags, just uncomment the necessary lines
# Some say GNU make does not correctly handle += -- you may have to use :=
#
-DEFS =
+DEFS += -DNO_MALLOC_DECL
#
# Add -traditional for GNU cc on ISC 386/ix system and possibly others
# (reported by pinard@iro.umontreal.ca)
@@ -116,7 +116,7 @@
mv detex.c lexout.c

man-page:
- troff -man detex.1l
+ nroff -man detex.1l > detex.1

# If you want detex available as delatex, uncomment the last two lines of
# this target

My word was accepted

When talking about c (as in programming) you normally hear happyland for undefined memory. So I decided to submit one of my favorite terms to the urban dictionary.

Some people claim I came up with this term. Patent pending ;)

Using eval to use a string as comparison

I am just writing a little compiler and interpreter and I have a method to check if 2 values are equal, not equal greater and so on. My code looked something like this

if typeOfCompare == "==":
return firstVal == secondVal

elif typeOfCompare == "!=":
return firstVal != secondVal

elif typeOfCompare == "<=":
return firstVal <= secondVal

....
But this was quite inflexible and I didn't like all the returns. As the type of the comparison was already checked by the parser I came up with a simpler method
return eval(str(firstVal) + typeOfCompare  + str(secondVal))
This might be a performance hit and not as clear but its easier to code and more extensible. You got to love python enabling something like this using a string as comparison operator.

Some research into what other people have done

So I thought I might have a look at what other people on my course have done in previous years as a final year project and how they structured it. So I though quite a few people must have put their projects online as a pdf. So I wrote a little scrip that would query the online list and then Google search for the topic. Here is the script:
#!/usr/bin/ruby
require "open-uri"
require 'rubygems'
require 'hpricot'

page = open("cit0708.html")
doc = Hpricot.parse(page)

(doc/"table.body_showcase").each do |link|
a = (link/"p")
puts "firefox \'http://www.google.co.uk/search?q=\"" + a.first.inner_html + "\"\'"
end

And off I went to look at Google. But only one guy had put his dissertation online. Some people would conclude some stuff about Bournemouth uni students but I will restrain from this. But I still think the projects should be uploaded to somewhere. I know other Universities print books with all the projects in them so their students get publications.
On anther note: I really like the hpricot library, makes parsing HTML really easy. Even if you are not a big fan of ruby you might want to have a look at it.

Jonathan is runnig Mac

Have a look at this http://blogs.sun.com/jonathan/entry/unified_computing what do you notice?
I am sure this is a picture of a Mac window. So are you telling me the CEO of Sun which actually produce two desktop operating systems has a Mac. No wonder they are going down hill. How can a CEO even post something like this. I wish someone would get rid of this idiot.

Some speedup

I started using pmwiki for www.ribalba.de a few weeks ago. I put pmwiki in a folder on my server and then needed a solution to redirect from the index page to that folder. Edd suggested a php secipt that would change the header.
<?php
header( 'Location: http://www.ribalba.de/pmwiki/' ) ;
?>
and this worked fine, but it took ages for the page to load. So I did some benchmarking
Static HTML
real 0m39.731s
user 0m0.206s
sys 0m0.659s

PmWiki with php redirect
real 4m16.862s
user 0m0.260s
sys 0m0.717s

Just PmWiki
real 4m7.132s
user 0m0.259s
sys 0m0.743s
So what can we conclude? pmwiki is not a fast wiki and that the redirect took just a little time.
So now I have the start page as static html and if someone want's more information he has to wait.

Update: Of course the time is the average of 100 Queries

Little cal dashboard app


I am to lazy to remember which month is which number in the year and how many days the month has. Normally I just fire up my dashboard on my mac and use the calendar there, but today I was playing about with Xcode and so I decided to write a little dash app that will show me the calendar information. And so I wrote my first mac app in HTML, what is the world coming too. 

Maybe if I get more time I will add a few more features but for now it does everything I need. Show me the number of months in a Year :P

Howto have a long itemize or enumerate split over many pages

I think it is time I start blogging about all the LaTex stuff I discover all the time. This one was a little tricky. I had a 3 page long enumeration that was bound to a table. So in latex:
\begin{longtable}{|p{\textwidth}|} \hline
\begin{enumerate}
\item ....
\repeat 500 times
...
But of course the enumeration could not be split so it just went off the bottom. What to do? After some thinking I came up with this bodge. If you know a nicer way of doing this please tell me. 
I defined a new command \breaktable
\newcommand{\breaktable}{%
\setcounter{enumi_saved}{\value{enumi}}
\end{enumerate}\\
\begin{enumerate}
\setcounter{enumi}{\value{enumi_saved}}
}
which I now enter every time I see a sort of logic end to the enumeration. This saves the current counter stops the enumeration adds a new cell and starts the enumeration with the correct value again. You have to define
\newcounter{enumi_saved}
somewhere. Works quite nicely.

change ssh port

The server I mainly work on has been the target of many port scan attacks. Further as soon as these script kiddies notice that the SSH port is open they try all sorts of username and password combos. This is quite annoying as it clogs up the log files and if something serious happens you might not see it due to all the clutter. So we (the server users) decided to put SSH on some weird port. Now I had the problem that all my scripts and my svn repositories where relying on SSH to be the standard port. Changing this in all my machines would have been a massive pain. So I remembered that you can specify some information in ~/.ssh/config 
And here we go. This is all you need to change the port. As my home directory is synced between all my machines this change made the server available over the weird port but it still looks as if it would be the standard one to all the programs.
$ cat ~/.ssh/config
host mysnvserver.net
Hostname mysvnserver.net
Port 54321

A very good tool

I am always looking out for good tools. But this one just blew my mind. At first it looks quite simple and not as special, but once you start using it it just works.
http://vue-dev.uit.tufts.edu/index.cfm
Give it a try.

http://www.typealyzer.com/

The analysis indicates that the author of http://computingfunnyfacts.blogspot.com is of the type:

ISTP - The Mechanics

The independent and problem-solving type. They are especially attuned to the demands of the moment are masters of responding to challenges that arise spontaneously. They generally prefer to think things out for themselves and often avoid inter-personal conflicts. 

The Mechanics enjoy working together with other independent and highly skilled people and often like seek fun and action both in their work and personal life. They enjoy adventure and risk such as in driving race cars or working as policemen and firefighters. 

Worlds you can create with Hex

While walking to Uni this morning Edd and me though about how many words you could spell with only using Hex chars {a..f}. I was thinking about this all day so I sat down and wrote a little program that would solve this problem for me:
First we have to generate all possible char combination:
From http://ribalba.de/geek/proj/hexword/wordcreate.py
 1: #!/usr/bin/python
2:
3: #We want to create all possible combinations out of these chars
4: # a b c d e f ' '
5: #Somehow '' is not handeld correct so we have to remove it later
6: wl = ['a','b', 'c', 'd', 'e', 'f', ' ']
7: out = []
8:
9: def recLoop(txt):
10: if len(txt) >= len(wl):
11: #Add to list and remove space
12: out.append(txt.replace(' ',''))
13: else:
14: for i in set(wl):
15: recLoop(txt + i)
16:
17: #Start the recursion
18: recLoop("")
19:
20: #So we remove duplicates
21: outset = set(out)
22:
23: #And print
24: for w in set (outset):
25: print w

The output file can be found here : http://ribalba.de/geek/proj/hexword/outfile this file has 335923 lines and is 2.5M big. So now we have to find out how many words are actually 'real' English words. To make it easy I just used aspell and some perl.
Source can be found here: http://ribalba.de/geek/proj/hexword/findwords
 1: #!/usr/bin/perl
2:
3: use Text::Aspell;
4:
5: my $speller = Text::Aspell->new;
6:
7: die unless $speller;
8:
9: # Set some options
10: $speller->set_option('sug-mode','fast');
11: $speller->set_option('clean-words','true');
12: $speller->set_option('ignore-case','true');
13:
14: open FILE, "outfile" or die $!;
15: while (my $line = <FILE>) {
16: chomp $line;
17: # check a word
18: if( $speller->check($line)) {
19: print $line . "\n";
20: }
21:
22: }

And this outputs us a nice list of all the words you can spell in English with the Hex chars, see here: http://ribalba.de/geek/proj/hexword/hexwords
There are some freaky words there.
--------------------
CAFEBABE :)