Thursday, November 1, 2007

Bibliography without linebreaks in Latex

I wanted to have a bibliography without any linebreaks in a Latex document so instead of:

[1] A.Person Why everything I do is great, Nat. Ret., 22-55, 11 2007

[2] An.Other Why everything A.Person does sucks, J. Coolness, 34-42, 1, 2008

[3] I.nsert Why including witty puns in journal articles is morally unjustified, J. Boring, 23-32, 23, 2023

I wanted:

[1] A.Person Why everything I do is great, Nat. Ret., 22-55, 11 2007 [2] An.Other Why everything A.Person does sucks, J. Coolness, 34-42, 1, 2008 [3] I.nsert Why including witty puns in journal articles is morally unjustified, J. Boring, 23-32, 23, 2023

All on one line.

Turns out that the bibliography is a list, and each reference is a \item. \item automatically adds a linebreak (and a linespace) at the end of each item. To get round this I change the thebibliography environment to use a 'paralist'. This is a type of list which doesn't adds linebreaks. I also redefine \cite to reference the paralist labels. There are a couple of drawbacks. First \cite{article1,article2} doesn't work anymore, this is a pain but was an acceptable trade off for me. Secondly you need to edit your bbl file (which bibtex outputs) becuase that has linebreaks between the bibitems as well. A quick awk script to remove all the blank lines for the bbl file should do the trick.

Anyway, here's the code I added to my preamble (remember you need \usepackage{paralist} too).

\renewenvironment{thebibliography}[1]
{\section*{References}\begin{inparaenum}[{[}1{]}]}{\end{inparaenum}}
\renewcommand{\bibitem}[1]{\item \label{#1}}
\renewcommand{\cite}[1]{[\ref{#1}]}

Saturday, October 13, 2007

Joining ps files to make a quick report

Often I need to join a bunch of postscript graph files so I can print and review them. When you've got 100 odd graphs this is a pain. You could just join the ps files with gs, but if the graphs don't have titles and are only identified by filename your kind of screwed. The solution I used was to create a C++ program to generate a latex file which includes the postscripts and a note showing their filename. This program takes a list of postscipt files and an output tex file as it's arguments so I'd typically do:

find . -name *.ps > list
./makereport list report.tex
latex report.tex
dvips report.dvi


Below is the C++ source code to makereport.cpp. Paste it in to a text file and compile it using g++ i.e.:

g++ makereport.cpp -o makereport


#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>

using namespace std;

int addEscapes(string &input);
int findAndReplace(string &input,char find,string replace);
int findAndReplaceS(string &input,string find,string replace);

int main(int argc,char **argv) {

if(argc < 2) {
cout << "makereport <file list> <tex file>" << endl;
cout << "tex is written to tex file standard output" << endl;
return 0;
}

// start texFile
ofstream texFile (argv[2], ios::out);

ifstream listFile(argv[1], ios::in);

vector<string> filenames;
for(;!listFile.eof();) {
string temp;
listFile >> temp;

if(!listFile.eof()) filenames.push_back(temp);
}

sort(filenames.begin(),filenames.end());

texFile << "\\documentclass[11pt,a4paper,english]{report}" << endl;
texFile << "\\usepackage[T1]{fontenc}" << endl;
texFile << "\\usepackage[latin1]{inputenc}" << endl;
texFile << "\\usepackage{graphicx}" << endl;
texFile << "\\usepackage[left=2cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}" << endl;
texFile << "\\begin{document}" << endl;
texFile << "\\title{Report}" << endl;
texFile << "\\author{Report}" << endl;

texFile << "\\maketitle" << endl << endl << endl;

vector<string>::const_iterator iter = filenames.begin();
for(;iter!=filenames.end();iter++) {
string currentInputName=(*iter);

texFile << "\\noindent" << endl;
texFile << "\\begin{minipage}{\\textwidth}" << endl;
texFile << "\\includegraphics[width=0.98\\textwidth]";
texFile << "{" << currentInputName << "}" << endl;
addEscapes(currentInputName);
texFile << "{\\footnotesize " << currentInputName << "}" << endl;
texFile << "\\end{minipage}" << endl << endl;

}

texFile << "\\end{document}" << endl;
}

int addEscapes(string &input) {
findAndReplace(input,'\\',"\\\\");
findAndReplace(input,'_',"\\_");
findAndReplace(input,'{',"\\{");
findAndReplace(input,'}',"\\}");
findAndReplace(input,'%',"\\%");
}

int findAndReplace(string &input,char find,string replace) {
string::size_type s;
s = input.find(find,0);
for(;s != string::npos;) {
input.replace(s,1,string(replace));
s = input.find(find,s+2);
}
}

int findAndReplaceS(string &input,string find,string replace) {
string::size_type s;
s = input.find(find,0);
for(;s != string::npos;) {
input.replace(s,1,string(replace));
s = input.find(find,s+find.size());
}
}



It's crap quickly hacked together code but it worked for my application. It's yours under GPL. If you make a better one, find this useful, have a better solution I'd be interested.

Sunday, September 23, 2007

Nokia 6630 & Obextools

How to get your stuff off of your nokia 6630 onto your linux computer. I realise its now an old phone and probably no-one cares but I thought I'd stick it up anyway. Its a decent phone, worth picking up second hand.

Get Obextools. I managed to get a few of the other tools like Kmobiletools working with the phone but they couldn't actually do a while lot.

Add the following to your apt sources.list
#Obex/ Mobile Phone stuff
deb http://www.stud.uni-karlsruhe.de/~ubq7/debian extra main
deb-src http://www.stud.uni-karlsruhe.de/~ubq7/debian extra main


Then run apt-get and install the following:
apt-get install tcllib tablelist bwidgets obextool

You may have to get tablelist separately. I got my copy from the ubuntu forums as a .deb package and installed it separately.

Now run obextools:
obextool --obexcmd "obexftp -u 1"  

I had to run this as root for reasons that are beyond me. I guess its probably some sort of group permission thing for my user account. But I had accessed the obexftp fine using the command line, so I'm not entirely sure.
Anyway its working now - so that I can download pictures from the phone. Woo hoo.

Tuesday, September 4, 2007

Suicide or Wireless?

A well used phrase in the Linux community. When fighting against wireless drivers that don't work you have to ask yourself - do I really need wireless or would it be better to stab myself in the eyes with a large needle instead. After spending the last days repairing my computer after "upgrading" to a more recent kernel version - gotta love configuring X; I finally found some hope of getting my fscking wireless card to work.

The most frustrating thing is that I know it will work eventually. Its just matter of application. Unfortunately my time presently is a rather precious commodity so I'd rather not read through reams of linux "help" forums reading stuck up nerds look down on n00bs. Cunts.

Anyway - details. To check the card is registered type lsusb. You will see a list of other usb devices plugged in, your Microsoft 3 button mouse for example. A nice mouse. I have a Dlink DWL-G122. Hardware Version C1 and Firmware 3. Apparently - the correct driver is the RT73. The rt2500 and rt2570 make the system hang and ultimately freeze when the stick is removed. Nice - cunts.

You can download the source (with your non-existent internet connection) here:
http://www.ralinktech.com/ralink/Home/Support/Linux.html

Full credit to Ralink for their commitment - fuck you to Dlink to making an incomprehensible and un-navigatable website from which to find this information. Cunts. Also - a really well documented README - one with like actual instructions and stuff. A lesson for you all - you non-documenting pricks. You will need dos2unix as well. Part of the sysutils package on debian. Also known as tofrodos - just you know to make it easier. Whilst this package is available on a bunch of freeware sites I dislike using these places - e.g. softpedia. But fuck it - I got it from here:
http://www.thefreecountry.com/tofrodos/index.shtml
Obviously if you have an ethernet connection just use apt-get. I had to set the man dir and the tar will spill its contents into the current directory so its best to create a new one for this program. In debian the man dir is /usr/share/man/man1.

So after the detour to get the dos2unix (or fromdos) working. Go back and follow the excellent instructions from ralink. make the driver. Copy to /etc/Wireless/RT73STA do the dos to unix on the data file. And then add the module to the kernel - all in the readme from ralink. Obviously connect the thing before typing ifconfig up but you know apart from that it actually fucking works.

Well - actually only sort of. Now you're going to have to work out how to work out how to connect to some crappy WEP/WPA encrypted home network - but at least your computer has stopped crashing.

VERDICT: Suicide narrowly averted. Death has finally removed himself from outside my window. The cunt. Apologies for the language.

Thursday, August 30, 2007

channels.conf for Hotbird

This channels.conf file has a channel for most of the transponders (is that the right word) on Hotbird (13 East). I import this in to MythTV then do a "Full scan of all transponders" and that loads in a bunch of channels.

Mediatel:10949:v:0:27500:5001:5011:7401
Tele Lumiere:10949:v:0:27500:5101:5111:7402
Adjara TV:10949:v:0:27500:5401:5411:7405
Suryan Radio:10949:v:0:27500:0:5711:7448
IRN:10949:v:0:27500:0:5811:7449
Sun KTV:10949:v:0:27500:5901:5911:7450
ANB:10949:v:0:27500:6101:6111:7452
Sun TV +442083356780:10949:v:0:27500:6401:6411:7455
Al Mustakillah:10949:v:0:27500:6501:6511:7456
Cartoon Network:10949:v:0:27500:6601:6611:7457
DMC TV:10949:v:0:27500:6801:6811:7459
Prime TV:10949:v:0:27500:7001:7011:7461
Tapesh 2:10949:v:0:27500:7101:7111:7462
IRIB:12437:h:0:27500:7901:7901:7901
AlJameela:11013:h:0:27500:355:611:1379
AlJazeeraEng:11034:v:0:27500:1714:1420:1430
MITV:11054:h:0:27500:8025:57:58
Pentagon:11096:h:0:27500:8:810:800
ArianaAfgan:11117:v:0:27500:14612:7101:7111
ANN:11137:h:0:27500:7324:3524:3644
AlJazSport:11179:h:0:27500:4910:5303:5304
AlJazKids:12558:v:0:27500:9362:2821:2822
BBCWorld:12597:v:0:27500:8204:163:92:
AldiyarSat:10723:h:0:29900:4623:1010:1210
AlHiwar:10949:v:0:27500:7456:6501:6511
BBCWorld2:11334:h:0:27500:5:516:690
IPN:11411:h:0:27500:14206:2942:2947
BBCWorld3:11431:v:0:27500:25:516:690
OmidEIran:11470:v:0:27500:10:257:260
OmanTV:12654:h:0:27500:7:1760:1720
Med1Sat:12673:v:0:27500:8:2050:2051
BBCArabic:11727:v:0:27500:13919:6781:6782
DubaiTV:11747:h:0:27500:9501:4130:4131
IqraaTV:12015:h:0:27500:474:520:730
CCTV4:12149:v:0:27500:7224:224:225
CCTV4Test:12169:h:0:27500:355:516:690
Kurdsat:12207:h:0:27500:116:1151:1152
AlHurra:12225:v:0:27500:190:5060:5020
VOA:12225:v:0:27500:295:4760:4720
AbuDhabiTV:12380:v:0:27500:3004:3024:3034
AlAlam:12437:h:0:27500:7915:165:90

MythTV .xsession and irxevent file for Myth

By now I'm sure my imaginary reading are tiring of my constant MythTV related ramblings probably good that they are imaginary then (they are also all hot girls)...




Anyway here's my MythTV account .xsession. It has a work around for a bug in the Nvidia driver (that puts a blue border round overlay videos), runs an xterm in the background (in the unlikely event that you need to fix the amazingly stable MythTV) and runs irxevent (which processes Infrared signals and throws out key presses). Finally it runs mythwelcome (a program which runs the mythtv frontend):

#!/bin/bash
xvattr -a XV_COLORKEY -v 66048
metacity&
xterm&
./irxevent --daemon ~/irxevent.conf
mythwelcome


Here's the irxevent.conf I use with MythTV (and the lirc.conf I previously posted):

begin
prog = irxevent
button = keyChanUp
repeat = 3
config = Key Up CurrentWindow
end

begin
prog = irxevent
button = keyChanDown
repeat = 3
config = Key Down CurrentWindow
end

begin
prog = irxevent
button = keyPower
config = Key Escape CurrentWindow
end

begin
prog = irxevent
button = Menu
config = Key M CurrentWindow
end

begin
prog = irxevent
button = MenuUp
repeat = 3
config = Key W CurrentWindow
end

begin
prog = irxevent
button = MenuRight
repeat = 3
config = Key D CurrentWindow
end

begin
prog = irxevent
button = MenuDown
repeat = 3
config = Key S CurrentWindow
end

begin
prog = irxevent
button = MenuLeft
repeat = 3
config = Key A CurrentWindow
end

begin
prog = irxevent
button = keyPlay
config = Key KP_Enter CurrentWindow
end

begin
prog = irxevent
button = key0
config = Key 0 CurrentWindow
end

begin
prog = irxevent
button = key1
config = Key 1 CurrentWindow
end

begin
prog = irxevent
button = key2
config = Key 2 CurrentWindow
end

begin
prog = irxevent
button = key3
config = Key 3 CurrentWindow
end

begin
prog = irxevent
button = key4
config = Key 4 CurrentWindow
end

begin
prog = irxevent
button = key5
config = Key 5 CurrentWindow
end

begin
prog = irxevent
button = key6
config = Key 6 CurrentWindow
end

begin
prog = irxevent
button = key7
config = Key 7 CurrentWindow
end

begin
prog = irxevent
button = key8
config = Key 8 CurrentWindow
end

begin
prog = irxevent
button = key9
config = Key 9 CurrentWindow
end

begin
prog = irxevent
button = keyVolDown
config = Key F10 CurrentWindow
end

begin
prog = irxevent
button = keyVolUp
config = Key F11 CurrentWindow
end

begin
prog = irxevent
button = keyPause
config = Key P CurrentWindow
end


lirc config for a random remote

Obviously this isn't going to be useful for anyone but me. But I have this remote:





It's either from a Avermedia DVB-T receiver, a Twinhan DVB-T receiver or a Twinhan Starbox 2 DVB-S receiver. Anyway here's it's lirc config file which was a pain to create so I'm sticking it here in case I need it again. In order to create the config I needed to hold the remote right next to the receiver and cover it so no stray UV interfered with the signal. I used irrecord to record the button presses and create the config file. The following options were used:

irrecord  -f --device /dev/lirc/0 unknown1.conf


Here's the resulting config:


# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.8.2(default) on Thu Aug 30 16:02:47 2007
#
# contributed by
#
# brand: unknown1.conf
# model no. of remote control:
# devices being controlled by this remote:
#

begin remote

name unknown1.conf
flags RAW_CODES|CONST_LENGTH
eps 30
aeps 100

ptrail 0
repeat 0 0
gap 107774

begin raw_codes

name key1
9104 4366 693 438 672 439
692 433 668 464 671 438
694 433 668 464 671 439
693 1564 672 1565 694 1548
692 1566 671 1565 668 1574
694 1563 673 1564 667 1575
694 1563 673 438 694 432
691 440 673 437 694 432
668 464 673 437 694 432
668 1575 694 1563 674 1562
694 1548 694 1563 674 1564
667

name key2
9103 4368 691 440 671 438
694 434 692 439 671 438
694 433 692 440 671 437
694 1567 670 1565 693 1548
694 1565 671 1565 692 1548
694 1565 672 1566 691 1548
694 434 692 439 672 437
694 434 667 464 671 438
694 434 667 465 671 1565
692 1549 693 1565 672 1565
692 1548 694 1565 671 1565
693

name key3
9105 4362 692 440 673 437
694 432 692 439 672 439
692 435 692 439 671 439
693 1565 671 1565 692 1550
694 1563 672 1566 691 1550
694 1563 671 1566 692 439
674 1563 692 1550 694 432
693 438 671 440 694 431
692 440 671 1565 694 438
673 438 694 1563 673 1563
692 1550 694 1566 671 1563
692

name key4
9130 4341 694 432 694 437
672 439 694 432 668 464
671 439 694 432 668 463
672 1567 692 1548 692 1565
672 1567 665 1575 694 1565
671 1566 691 1549 694 1564
672 438 694 432 667 1575
694 432 694 437 674 436
694 434 666 466 671 1566
691 1549 694 433 692 1548
694 1565 672 1565 692 1548
694

name key5
9104 4367 691 438 671 440
692 434 692 439 672 439
692 433 693 439 669 442
691 1567 670 1568 691 1549
692 1568 668 1567 692 1548
692 1567 670 1567 692 1548
694 434 692 1548 694 1565
669 1568 691 440 669 440
692 435 691 439 672 1567
692 439 669 440 692 435
690 1551 692 1567 669 1568
691

name key6
9108 4361 671 438 694 434
692 439 670 439 694 434
693 438 669 440 692 435
692 1549 694 1565 671 1566
694 1546 694 1565 671 1566
694 1546 694 1565 671 1565
694 1546 694 1566 671 1565
694 1547 694 433 692 439
672 437 694 434 692 439
672 437 694 434 692 440
671 1565 694 1546 694 1565
672

name key7
9109 4363 669 440 694 431
694 438 672 439 692 433
694 438 645 466 692 434
694 1548 692 1565 645 1591
694 1548 692 1566 671 1565
694 1549 691 1565 672 1565
694 437 672 1565 694 1548
693 433 694 437 672 439
692 434 694 437 671 1567
692 439 671 439 692 1565
672 1565 694 1548 694 1563
673

name key8
9131 4339 693 434 692 440
671 437 695 433 668 464
671 438 693 434 668 464
671 1565 693 1547 694 1565
672 1565 667 1574 693 1566
671 1565 667 1573 694 1565
671 438 694 434 668 1572
694 1565 671 438 694 433
668 464 672 437 694 1565
671 1566 667 464 671 438
693 1566 671 1565 668 1573
694

name key9
9130 4341 692 434 694 437
672 439 692 434 693 438
671 440 692 433 695 437
671 1565 694 1549 692 1565
672 1565 694 1548 691 1566
671 1566 693 1549 694 1563
673 1563 695 436 674 1563
694 1548 694 432 694 437
672 439 692 434 694 438
671 1565 694 437 671 440
692 1565 671 1565 695 1548
694

name key0
9107 4363 671 438 694 433
692 440 645 464 692 436
692 439 645 464 692 435
668 1572 694 1566 644 1592
695 1545 694 1566 671 1565
694 1547 693 1566 671 1565
694 437 672 1565 694 437
671 1566 694 437 672 437
694 434 692 440 669 1567
694 437 672 1564 694 438
671 1566 694 1546 694 1565
671

name keyRec
9104 4366 692 438 671 438
692 435 693 439 645 467
664 460 693 439 645 464
692 1567 669 1567 694 1549
692 1565 671 1566 693 1546
694 1565 672 1565 694 1548
692 434 692 439 672 437
694 1565 672 439 692 434
692 439 670 441 692 1565
672 1565 694 1548 692 434
691 1551 692 1566 670 1566
694

name keyFav
9109 4364 665 443 688 440
662 469 666 443 689 439
662 469 666 443 688 439
662 1579 690 1569 668 1569
688 1552 690 1569 667 1569
688 1552 691 1569 670 1566
688 1552 691 1568 668 441
691 1569 667 441 691 437
662 470 665 443 689 439
662 470 665 1571 688 443
666 1571 688 1553 689 1569
668

name keyRewind
9100 4368 661 470 666 445
686 439 662 470 666 445
686 439 662 469 666 445
687 1570 668 1569 662 1580
689 1569 667 1569 662 1580
688 1569 668 1571 660 469
666 445 687 439 661 470
666 445 686 439 662 1581
688 437 663 1580 688 1570
667 1569 661 1581 688 1569
667 1571 660 470 667 1572
659

name keyForward
9131 4340 689 439 662 470
663 446 688 439 662 470
665 443 689 439 662 470
666 1570 662 1578 688 1571
666 1571 662 1578 689 1571
665 1571 662 1578 688 440
662 1579 687 440 662 469
666 1570 662 470 665 443
689 439 662 1578 689 440
661 1579 688 1571 665 443
689 1571 665 1571 662 1579
690

name keyChanUp
9106 4365 664 445 684 441
661 473 662 446 685 441
634 498 664 447 684 443
632 1609 686 1573 664 1573
631 1608 687 1573 663 1573
632 1608 687 1573 663 1573
631 498 665 1574 632 498
663 447 685 443 607 524
662 447 685 443 629 1611
686 441 657 1584 686 1573
664 1573 607 1633 686 1573
663

name keyChanDown
9105 4363 665 445 687 439
662 469 667 444 687 439
660 472 665 445 687 439
662 1580 687 1571 665 1571
662 1580 687 1571 665 1571
661 1581 686 1571 666 445
686 1571 666 445 687 438
662 470 665 445 687 439
662 470 665 1571 662 470
666 1570 662 1581 686 1571
667 1569 662 1580 689 1568
668

name keyVolUp
9126 4343 686 441 660 471
664 445 686 442 658 473
664 446 686 441 658 473
664 1573 660 1580 686 1573
664 1573 658 1582 686 1573
664 1572 658 1583 686 442
660 1580 686 1573 663 1573
632 1608 687 441 658 474
664 445 686 1573 663 445
687 441 660 471 664 445
686 1573 664 1574 631 1608
688

name keyVolDown
9103 4369 659 472 663 445
687 441 660 471 664 445
687 441 660 472 663 446
686 1573 665 1571 660 1581
687 1571 666 1571 660 1580
689 1570 666 1571 660 471
664 1573 659 472 664 1572
660 472 664 445 688 440
660 471 666 1571 659 472
663 1573 660 472 663 1574
659 1581 688 1572 664 1571
660

name keyPlay
9102 4367 688 443 668 443
688 437 664 468 667 443
689 438 663 468 667 443
688 1570 667 1569 688 1554
689 1569 668 1568 690 1552
688 1569 668 1569 688 443
668 443 688 1570 667 443
688 1569 667 444 688 437
664 468 668 1569 688 1554
688 437 664 1578 689 438
663 1579 688 1569 667 1569
689

name keyRecall
9101 4368 688 443 667 444
687 438 664 467 668 443
688 438 664 467 668 443
688 1569 668 1569 690 1552
688 1569 668 1569 690 1552
690 1567 667 1570 690 441
667 1569 690 1552 691 1567
669 442 688 437 664 468
667 443 689 1569 669 441
689 437 664 467 668 1569
691 1551 691 1567 669 1567
690

name keyStop
9128 4343 688 438 662 469
665 445 687 439 662 470
668 443 688 437 662 470
668 1570 662 1579 688 1568
668 1572 686 1553 689 1571
665 1571 686 1555 687 438
664 1578 688 440 661 1580
687 1571 666 443 689 439
659 470 667 1572 686 445
665 1571 687 443 667 443
689 1571 665 1571 687 1554
688

name keyPause
9127 4341 689 438 661 470
666 443 690 438 661 470
668 441 691 437 662 469
666 1571 688 1552 690 1569
667 1569 689 1552 690 1569
668 1568 688 1553 690 437
662 470 667 1570 687 1552
690 438 662 469 668 1569
688 444 667 1571 690 1554
690 433 661 469 668 1570
687 1554 688 438 662 1580
688

name keyMute
9102 4367 688 443 667 441
691 437 664 468 665 443
691 437 664 467 669 441
690 1569 667 1570 689 1552
688 1569 668 1569 691 1551
689 1569 667 1569 690 441
668 441 690 438 663 468
668 1568 691 441 668 443
688 437 664 1579 690 1567
669 1567 691 1551 691 435
664 1579 690 1567 670 1566
691

name keyCancel
9106 4364 666 443 688 440
662 469 666 443 688 440
662 469 641 468 663 464
662 1579 690 1569 666 1571
688 1552 690 1569 665 1572
688 1552 690 1569 667 441
689 439 664 1576 690 1569
668 441 689 440 661 470
665 444 687 1571 668 1569
688 443 666 443 688 1571
668 1569 688 1552 690 1570
666

name keyCapture
9127 4343 689 438 664 467
666 443 688 440 662 469
666 443 688 440 662 469
666 1571 688 1552 690 1569
668 1568 689 1552 690 1569
668 1568 689 1552 690 437
664 468 667 1570 688 443
668 1568 689 443 667 1569
689 443 667 1569 688 1553
690 437 689 1552 690 437
688 1553 690 437 688 1552
690

name keyPreview
9107 4363 667 441 691 437
665 467 667 442 690 437
664 468 665 443 690 438
664 1576 690 1569 668 1569
688 1552 691 1568 668 1569
688 1552 690 1570 667 441
690 438 663 468 668 1568
689 443 667 442 690 1569
668 441 690 1569 667 1570
688 1551 691 437 664 1577
690 1569 668 441 690 1569
668

name keyEPG
9106 4365 663 445 687 441
660 472 664 445 686 441
660 472 664 444 687 441
660 1581 686 1573 663 1573
660 1580 689 1571 665 1571
661 1579 688 1571 666 443
686 442 660 1580 688 1571
665 1571 660 472 663 445
687 441 660 1580 689 1571
665 443 687 441 660 472
664 1572 660 1581 687 1571
666

name keyRecList
9106 4363 668 443 688 437
662 470 665 445 689 437
662 470 665 445 687 441
660 1580 688 1572 665 1571
686 1555 687 1571 666 1571
660 1580 688 1571 666 443
689 439 660 1580 688 440
659 470 666 445 688 439
660 472 663 1573 660 1581
688 439 660 1581 688 1571
665 1571 660 1581 688 1571
665

name keyTab
9104 4367 668 464 645 463
668 460 668 463 645 464
668 460 667 464 645 464
668 1591 646 1591 668 1573
667 1591 645 1592 693 1547
667 1592 645 1592 694 437
645 464 667 460 668 464
645 464 667 460 668 464
646 462 668 1592 645 1591
694 1546 670 1590 645 1591
695 1545 668 1592 644 1592
694

name keyTeletext
9102 4367 694 438 645 464
669 458 669 462 645 464
671 458 668 463 644 466
666 1593 643 1592 694 1548
667 1590 646 1591 694 1548
667 1590 647 1590 695 1546
668 1590 647 1589 697 1546
667 458 670 462 646 465
667 458 669 462 647 464
668 458 669 462 645 1592
694 1548 668 1590 646 1590
696

name keyPower
9105 4366 669 462 618 493
665 460 670 462 645 466
666 460 667 464 645 466
665 1592 618 1618 670 1572
640 1618 618 1618 670 1573
639 1618 618 1618 669 462
646 1591 670 1573 638 487
669 1573 639 487 669 462
645 466 666 1592 618 492
666 460 669 1573 639 487
669 1573 639 1618 645 1592
669

name keyFullScreen
9106 4363 669 439 692 437
665 466 643 466 667 460
666 465 644 467 664 462
666 1576 691 1567 669 1567
692 1551 689 1567 670 1567
692 1550 690 1568 668 1568
692 439 669 1568 692 1550
690 436 665 466 670 1567
691 440 669 441 691 1567
669 441 691 436 665 1577
690 1568 668 442 690 1567
669

end raw_codes

end remote


Fascinating!

My LIRC startup script

For lirc compiled from source version 0.8.2. For Debian Lenny with serial lirc device, goes in /etc/rc2.d/S99lirc. You also need to load the lirc_dev module, add it to /etc/modules to load it automatically.

#!/bin/bash
setserial /dev/ttyS0 uart none
setserial /dev/ttyS1 uart none

/sbin/modprobe lirc_serial
/usr/local/sbin/lircd --device /dev/lirc/0 /etc/lircd.conf

Wednesday, August 29, 2007

Making a program automatically restart

Mythbackend crashes a lot, well at least until you get your configuration stable (which has never happened to me). To create a usable system I wanted to configure myth to restart automatically when it crashes. Here's how I did it. First locate the mythbackend binary, mines in /usr/bin (Debian Lenny, debianmultimedia.org install). Rename it to mythbackend.real. Create a file in the same directory called mythbackend.run with the following contents:

#!/bin/bash
myvar=0
while [ $myvar -ne 10 ]
do
echo $myvar
mythbackend.real
myvar=$(( $myvar + 1 ))
done


Make sure it's executable. This script runs our renamed mythbackend ten times in a row (we're only going to restart mythbackend 10times). Then create a file called mythbackend with the following contents:

#!/bin/bash
mythbackend.run&


Again make it executable. This just fires off our mythbackend.run script in the backround. So there you go!

Lazy mans udev fixed device names

One of the constant annoyances of USB devices under Linux is that they don't get assigned fixed names. In my case I have two USB digital TV receiver cards, one for satellite and another of digital terrestrial. They can be accessed though the device directories: /dev/dvb/adapter0 and /dev/dvb/adapter1. However you never know which will be which and in order for MythTV to work correctly they need to fix these. For example adapter0 must always be the DVB-T and 1 the DVB-S. There is a long and complicated explanation of how to modify the udev rules to do something not entirely unlike this here: http://mythtv.org/wiki/index.php/Device_Filenames_and_udev
however, I can't figure out how to get it to work in my case (dvb devices have a more complicated directory structure) so I made this quick hack.


First you need to make sure that udev no longer maps your DVB cards to /dev/dvb/adapter0/1 but rather /dev/dvb/adapter_real0/1. On Debian you can do this by modifying /etc/udev/rules/udev.rules changing the line that reads:

KERNEL=="dvb*",                 PROGRAM="/bin/sh -c 'K=%k; K=$${K#dvb}; printf dvb/adapter%%i/%%s $${K%%%%.*} $${K#*.}", ACTION=="add", \
NAME="%c"


to:

KERNEL=="dvb*",                 PROGRAM="/bin/sh -c 'K=%k; K=$${K#dvb}; printf dvb/adapter_real%%i/%%s $${K%%%%.*} $${K#*.}", ACTION=="add", \
NAME="%c"


Now create an rc script to assign the fixed device names and place it somewhere in your startup directories. In my case I needed to make it start before mythbackend so I created the file /etc/rc2.d/S23dvbsyms (remember to make it executable) with the following contents:

#dvbs
if [[ `udevinfo -a -p /class/dvb/dvb0.frontend0 | grep UDST702X -c` == "1" ]]
then
echo "DVBS is adapter 0"
ln -s /dev/dvb/adapter_real0 /dev/dvb/adapter1
fi

if [[ `udevinfo -a -p /class/dvb/dvb1.frontend0 | grep UDST702X -c` == "1" ]]
then
echo "DVBS is adapter 1"
ln -s /dev/dvb/adapter_real1 /dev/dvb/adapter1
fi

#dvbt
if [[ `udevinfo -a -p /class/dvb/dvb0.frontend0 | grep VP7041 -c` == "1" ]]
then
echo "DVBT is adapter 0"
ln -s /dev/dvb/adapter_real0 /dev/dvb/adapter0
fi

if [[ `udevinfo -a -p /class/dvb/dvb1.frontend0 | grep VP7041 -c` == "1" ]]
then
echo "DVBT is adapter 1"
ln -s /dev/dvb/adapter_real1 /dev/dvb/adapter0
fi


udevinfo -a -p /class/dvb/dvbX.frontend0 dumps a bunch of information about the device, including product codes. I then grep for these and create a symlink to the real device accordingly. You can find the class path to use with udevinfo with:

udevinfo -a -p $(udevinfo -q path -n /dev/video0)


Where /dev/video0 is the device your after in /dev. One you've put these scripts in place the devices will get fixed names as boot. Of course this doesn't help much if you are plugging in and removing devices but it's a hack that works well enough for me.

Sunday, August 26, 2007

dvb-usb-vp702x-02.fw

This is the firmware file for a Twinham Starbox 2 USB DVB-S receiver. For some reason it's not on the linuxtv website. It's closed source, and I'm probably not allowed to distribute it. However you'll need it if you want to get a Twinham Starbox working under linux. Here is it: http://www.gamesrant.com/linuxjunk_pics/dvb-usb-vp702x-02.fw

Saturday, August 25, 2007

Nvidia TV Out xorg.conf

The following xorg works with my TV. It outputs to the TV ONLY (no dual display stuff):

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 1.0 (buildmeister@builder3) Wed Jun 13 18:39:30 PDT 2007

Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0"
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Mouse0" "CorePointer"
EndSection

Section "Files"
RgbPath "/usr/X11R6/lib/X11/rgb"
EndSection

Section "Module"
Load "dbe"
Load "extmod"
Load "type1"
Load "freetype"
Load "glx"
EndSection

Section "InputDevice"
# generated from default
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto"
Option "Device" "/dev/psaux"
Option "Emulate3Buttons" "no"
Option "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
# generated from default
Identifier "Keyboard0"
Driver "kbd"
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Unknown"
ModelName "Unknown"
HorizSync 30.0 - 50.0
VertRefresh 60
EndSection

Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
Option "TVOutFormat" "Composite"
Option "TVStandard" "PAL-I"
Option "ConnectedMonitor" "TV"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "640x480"
EndSubSection
EndSection


Nvidia driver installation on Debian Lenny 2.6.21-2

Using the Nvidia driver installer you get the error:

   FATAL: modpost: GPL-incompatible module nvidia.ko uses GPL-only symbol 'para
virt_ops'


This basically means Linux people don't like you compiling non-GPL code against the kernel. I guess that's fair I blame Nvidia. Anyway from what I understand it's all being put back so we can install evil code nice an easily in 2.6.22. But for now you need to patch some of the kernel build scripts. Here's a list of instructions for Debian, bastardised from the Redhat version at: http://www.nvnews.net/vbulletin/showthread.php?t=87541:

apt-get source linux-image-2.6.21.2-686
cd linux-2.6-2.6.21/
cd scripts
cd mod
vi modpost.c

# delete the lines reading:
#if (!mod->gpl_compatible)
# check_for_gpl_usage(exp->export, basename, exp->name);

make mk_elfconfig
make empty.o
cat empty.o | ./mk_elfconfig FORCE > elfconfig.h
gcc modpost.c file2alias.c sumversion.c -o modpost.new
cp modpost.new /usr/src/linux-headers-2.6.21-2-686/scripts/mod/
mv /usr/src/linux-headers-2.6.21-2-686/scripts/mod/modpost /usr/src/linux-headers-2.6.21-2-686/scripts/mod/modpost.old
mv /usr/src/linux-headers-2.6.21-2-686/scripts/mod/modpost.new /usr/src/linux-headers-2.6.21-2-686/scripts/mod/modpost

sh NVIDIA-Linux-x86-100.14.11-pkg1.run --extract-only
cd NVIDIA-Linux-x86-100.14.11-pkg1
cd usr/src/nv
make module
PARAVIRT_OPS=`grep "D paravirt_ops" /boot/System.map-2.6.21-2-686 | colrm 9`
ld -m elf_i386 --defsym paravirt_ops=0x$PARAVIRT_OPS -r -o nvidia.ko nvidia.o nvidia.mod.o
cp nvidia.ko /lib/modules/2.6.21-2-686/kernel/drivers/video/
modprobe nvidia
dpkg-reconfiugre xserver-xorg


You will also need to install the X11 nvidia driver the easiest way to do this is to run the nvidia installer with the "--no-kernel-module" flag ie:


./nvidia-installer --no-kernel-module


Then update your xorg.conf (you can use nvidia-xconfig to do this for you). It appears to be working... but I'm now trying to get it configured to do TV Out...

Friday, August 17, 2007

error: cannot compute sizeof (char) with configure

I received the error "cannot compute sizeof (char)" from a configure script when using the Pathscale compiler. Turned out I was using pathcc (I guess the c compiler) instead of pathCC (I guess C++).

Tuesday, August 7, 2007

Resuming a crashed scp transfer

Mercilessly robbed from here: http://joen.dk/wordpress/?p=34

scp doesn't have a resume option, so continue the transfer with rsync:

rsync --partial --progress source dest


This isn't encrypted like scp though, in order to do that you need to tell rsync to use ssh as it's shell. The following example uses rsync to transfer a file over ssh with ssh running on a nonstandard port on localhost (like you might setup with a tunnel):


rsync --partial --progress --rsh="ssh -p 2250 " -r  MyDirectory new@localhost:/media/stuff

Monday, August 6, 2007

iPod Shuffle 2nd Gen USB Dock pinout

yea, not Linux related but it is junk!

For USB I'm using the pin assignments from here. If your using this for anything important you might want to check I did it right....



Saturday, August 4, 2007

Nokia 770 Dual MMCs

Looks like the 770 will recognise 2 MMC cards connected to the MMC bus. However according to fanoush on the internettablettalk forum this may not be a great idea as: "they will run in legacy MMC mode (max 20MHz) and there may be bugs since this was never widely used." post here.



Anyway, here's how the wiring looks. Obviously if you intend to do this you need to figure out how to mount everything:





dmesg output:





and mounting:





again, this is currently with the stock tablet 2006 kernel. I also tried with an SD card and an MMC, that didn't appear to work, only the SD card to recognised (the other card didn't appear in dmesg). I've not yet tested how stable this is, just mounted the cards to check it works in principle.

Thursday, August 2, 2007

Tuesday, July 24, 2007

Saturday, July 21, 2007

Remove all nonalphanumeric characters from a file

sed ':a; $!N;s/[^a-z,A-Z,0-9]//g;ta' myfile

Wednesday, July 4, 2007

useful bash shortcuts

ctrl-a: jump to beginning of line
ctrl-e: jump to end of line
alt-f: jump forward a word
alt-b: jump back a word

alt-d: delete word
alt-t transpose two words

ctrl-r: search back for a command, hit ctrl-r again to search back further
ctrl-xx: jump back to your last edit, again to get back to original position

For ctrl and alt commands press control AND the key indicated at the same time. More random bash here:
http://blog.webhosting.uk.com/2007/04/08/using-bash-shell-shortcuts/

Sunday, July 1, 2007

Extracting part of a field in awk

I had a file where the lines look like this:

all_initstring0010010100111000/1dca.rule118.iter100.score all_initstring0010010100111000/1dca.rule140.iter100.score: 0
all_initstring0010010100111000/1dca.rule128.iter100.score all_initstring0010010100111000/1dca.rule122.iter100.score: 122312
all_initstring0010010100111000/1dca.rule113.iter100.score all_initstring0010010100111000/1dca.rule143.iter100.score: 3213


I wanted to extract the value after rule and before the . in the 1st and 2nd fields and also print the third field. I used awk and the substitution function to replace everything but the required value using a regular expression. Here's the code:

gawk '{gsub(/^.*rule/,"",$1); gsub(/[^0-9].*/,"",$1); gsub(/^.*rule/,"",$2); gsub(/[^0-9].*/,"",$2); print $1 " " $2 " " $3}' myfile


There is actually another solution which is probably nicer:

awk '{ split($1,a1,/\./) ; split($2,a2,/\./); print substr(a1[2],5), substr(a2[2],5), $NF; }' myfile 

Friday, June 29, 2007

VM Player

Download kernel-headers and kernel-sources packages first.

Then get VM Player from the interweb, using the rpm installer.

Run the vmware-config.pl script and tell it where the relevant bits and pieces are.

I struggled to find the kernel-source files. Its important to have a good look around for these and trying to update the kernel headers and sources match - i.e. have the same version number.

In SuSE I eventually found them here:

/usr/src/linux-2.6.18.8-0.1-obj/x86_64/default/include

or here:
/usr/src/linux-2.6.18.8-0.3-obj/x86_64/default/include

run: uname -r first to see what version of the kernel you are running.

Next you have to download the vmx file. This contains the OS and the configuration for VM Player to use it. Look around on the VMWare website or here:
http://www.tuxdistro.com
EG Kubuntu
http://www.tuxdistro.com/torrents-details.php?id=283

Be aware - most seem to be torrents - so perhaps a work policy may be a problem.

After downloading the file unrar it and then start the VM Player. Give it the files it needs - that were extracted from the torrent. And then viola - your new VM Player is working with ubuntu.

Monday, June 18, 2007

Place for Tomcat Notes

Some general notes on getting tomcat working. After installing the relevant packages from yast - a few commands needed to be run - and then I had to find out how to test the installation. Its all pretty well documented - I just thought I'd save a few notes here.

Check status of your server:
/etc/init.d/apache2 status


Check if tomcat is running - and the output:
ps -def | grep tomcat
tomcat 31388 1 0 11:53 pts/0 00:00:05 /usr/lib64/jvm/java/bin/java -Djava.endorsed.dirs= -classpath /usr/lib64/jvm/java/lib/tools.jar:/usr/share/tomcat5/bin/bootstrap.jar:/usr/share/tomcat5/bin/commons-logging-api.jar:/usr/share/java/mx4j/mx4j-actions-1.1.1.jar:/usr/share/java/mx4j/mx4j-jmx-1.1.1.jar:/usr/share/java/mx4j/mx4j-tools-1.1.1.jar:/usr/share/java/mx4j/mx4j-jmx.jar -Dcatalina.base=/srv/www/tomcat5/base/ -Dcatalina.home=/usr/share/tomcat5 -Djava.io.tmpdir=/srv/www/tomcat5/base//temp org.apache.catalina.startup.Bootstrap start
root 31806 29163 0 12:13 pts/0 00:00:00 grep tomcat



Add tomcat module to the apache (or something):
a2enmod jk 


More to follow here.

Thursday, June 14, 2007

eps2latex

quick and dirty bash script to create a latex document from a bunch of eps files.

#!/bin/bash

echo "\documentclass{article}"
echo "\usepackage{graphicx}"
echo "\begin{document}"

for file in $1/*.eps
do
echo "\begin{center}"
echo "\begin{minipage}{\textwidth}"
echo "\includegraphics{$file}"
echo "\end{minipage}"
echo "\end{center}"
echo "{\footnotesize $file}"
done

echo "\end{document}"

Wednesday, June 13, 2007

Run preview easily from bash on Mac OS X

add the following to your .profile:

preview(){
open -a /Applications/Preview.app/ "$1"
}

useful vim commands

Timetravel



Vim 7 lets you move forward and backward a duration in time. For example:

:earlier 1h
:later 5m
:earlier 10s


What's also neat is that vim stores undo branches. So say you undo something, make some edits, then decide that you didn't really want to undo you can still go back to the previous state. Simply type:

:undolist


to view the various buffers and:

:undo <number>


to go to the buffer

Spell checking



To enable spell checking type:


:set spell


All your spelling errors will be highlighted. From command mode use:

]s - next spelling error
[s - previous spelling error
z= - correct spelling from close matches


Record a macro



press q followed by one of 0 to 9 or a to z in command mode. do stuff... press q in command mode. Then press @ followed by 0-9 a-z (as you entered before) to play the macro. Press @@ to repeat the last macro.

Simple search and replace with a number in it



Search for all argv[NUMBER] and replace with plotprefix. Where NUMBER is um a number:

%s/argv\[\d\]/plotprefix/g


Replace something with somethingelse over the next 4 lines from the current cursor position:

.,+4s/something/somethingelse/g


Replace whatever.cpp with ../whatever.cpp where whatever is any character string:

%s/\<\a*.cpp\>/..\/&/g


Delete every other line, no idea how it works, in command mode:

%norm jdd



See: http://www.geocities.com/volontir for a load of useful vim regular expression stuff.

Tuesday, June 12, 2007

Remote browsing

Say your trying to access regionalised content or may be a journal a different university has access to and you happen to have a box on that remote network, how do you access websites as if you were coming from there network?

There are a few solutions:

1. Just run firefox over an X session. ssh will setup your environment variables making this straight forward. Simply do: ssh my.computer.com -X -l username (unfortunately this is usually very slow)

2. Run lynx! Because text based browsing rocks! (no, no it actually sucks ass)

3. Run a proxy on the remote workstation on a local port (such as squid). Then use ssh port forwarding to redirect the proxy to a local port for example: ssh -L 3128:localhost:3128 my.computer.com -lusername. Then reconfigure your webrowser to use a proxy at localhost port 3128. All done!

4. Use ssh remote port port forwarding to forward port 80 on a specific host to a port on your local computer. Unfortunately this means you can only browse that host (basically this sucks)

Right now those are all the solutions I know of. It would be great if you could forward all outgoing connections from a given application using ssh port forwarding, but as far as I can see... you can't. Another nice solution would be to use a simple user mode proxy server, if anyone konws of one leave a comment.

Monday, June 11, 2007

Wii 50Hz reset

My TV Card only supports 50Hz and I set my Wii to 60Hz. To reset the Wii to 50Hz press reset on the Wii while pressing down on the directional pad on the wiimote.

Thursday, May 24, 2007

powerTop

Really just a link to this site:
http://www.linuxpowertop.org/powertop.php

Worth a look though.

Wednesday, May 9, 2007

Debugging an install

I was trying to install a program and couldn't work out what was going wrong. It looked like it compiled okay but when I tried to run it the linked shared objects weren't there.

./exa_c: error while loading shared libraries: libdislin.so.9: cannot open shared object file: No such file or directory



So, in order to find out what was happening I had to run the following to check out the compiled program.
ldd exa_c
libdislin.so.9 => not found
libm.so.6 => /lib64/libm.so.6 (0x00002ba378eeb000)
libc.so.6 => /lib64/libc.so.6 (0x00002ba379141000)
/lib64/ld-linux-x86-64.so.2 (0x00002ba378ccd000)




This tells me that although the program compiled okay there the first library isn't found in the LD_LIBRARY_PATH. Now I had set this variable in my own bash profile, but not in apache's. So when I ran this program in a server through cgi the fucking thing didn't work. Adding the right environment to /etc/profile enabled everyone access to the correct path for the library. Success.

Tuesday, May 8, 2007

openBSD 3.2 Sucks

Just in case there was any doubt. I then went and asked one of the BSD admins about my problem and he just shrugged saying "That's odd, it normally just works". Wankers.

pkg_add - its like apt-get but for gays. That will be all the bsd commands you'll get from me.

Wednesday, April 18, 2007

Add a user to a group

Add a user to the mysql group. Or well, any group.

usermod -Gmysql username

Monday, April 16, 2007

Syncing calendar across applications

I want to be able to sync my calendars, which are kept on a number of different locations. Lets say one on my phone (Nokia, running S60 symbian), one on my MacBook (work), one on my workstation at work (work, OpenSuSE) and one on my home computer when it finally arrives (debian).

So how does one do this? Well luckily, sort of, I may most of the changes on one computer - the laptop. So all I have to do is push to the other calendars. However, given they all use different applications I don't really want to have to use SunBird on the mac when it comes with a really nice app already.

So I used SunBird in the linux computers and iCal in the mac and whatever the symbian one is called on the phone. In order, to get them to sync I had to get access to a webDAV server. You can sign up for a free account on www.sharemation.com. Its not exactly high throughput but it will allow you to share you calendar between your mac and your linux computer. The rather frustrating thing is that they sit about 30 centimetres away from each other.

Process: Set up webDAV account on www.sharemation.com
Publish calendar on the mac putting https://www.sharemation.com/username as the server. It is offered as https so you might as well use it.
Then subscribe on Sunbird as a remote location. Putting the same information in the dialogues now.

I'll update this post to see how making changes on all the various combinations goes, and also once I start playing with google calendars I'll let you know how that goes. Otherwise it looks good so far and was easy to set up.

Wednesday, March 21, 2007

Counting the number of instances of a letter in a file

To explain why this might be necessary:

First I have an xml file with some sequences in it. I grep the xml file finding the instances I am interested in and save these to a file, stripping out the xml using vim.

grep -A 5 \<type\>Dis filename.xml | grep \<sequence\> > file_raw_seq.txt
Alternatively I could use the fasta file and strip the headers using grep -v \>.

I am now left with the raw text of the sequences from the xml file that I am interested in.

I can now run the following command to check out the number of times say M appears in the file;

tr -dc M < input.fa | wc -c


Easy. The alternative was to write a C++ program to do all this - which would have taken considerably longer. Especially given that some people haven't committed working versions of their code. I'm looking at you Mr. TreeCreate and Mr IntVector.

Thursday, March 1, 2007

Sticky

Further to the back up stuff I been documenting recently, I was told of this useful (?) little titbit. I have a spare disk called /dataStore that is mounted locally on my workstation. Other people log in to my computer to compile stuff, maybe run some stuff etc. So I am letting them back their stuff up locally on my computer. In order to give them the appropriate permissions on the data disk I have made a directory in this disk called imaginatively enough backup.

I have made this directory group writable so that everyone can use this disk. However, in order to ensure that no one fucks up anyone else's data I have made the directory a sticky. To do this type:

chmod +t dir

This is as close to an explanation as I could find:
http://www.uwsg.iu.edu/UAU/files/sticky.html

Wednesday, February 28, 2007

Monday, February 19, 2007

Crontab

This is a useful program for scheduling routine tasks initiated by scripts. Developing on the search installation from last week, we will write a crontab entry to update the namazu index daily.

First of all check which jobs are currently scheduled:

user@compy:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXX8NR6OC installed on Mon Feb 5 17:51:55 2007)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
0 5 * * * /home/user/.backup.sh


This is the rsync job from the other week. So, next we need to create a script to run the namazu index. This is a simple shell script with the following command in it:
#!/bin/bash
mknmz -O ~/.namazu/index/ ~/work/articles/

Save this file somewhere like in ~/.namazu/.index.sh. Append this to the crontab in the same way as the rsync script was added - i.e. type crontab -e and add the following line:
0 5 * * * /home/user/.namazu/.index.sh

Then, type crontab -l to check that it has been added. You should now have a namazu index that updates everyday at 5AM.

Wednesday, February 7, 2007

Namazu Config

Namazu is a search engine. Whilst its no replacement for find and grep in most cases, it is useful for searching a directory of pdf files, and this can be made available through a web interface - which is quite useful if you have a lot of pdfs.

Download and install the program - its available for most distributions. You will need to edit the config file namazurc and the index config file mknmzrc. I needed to change the max file size variable to accommodate my pdfs.

In the mknmzrc file I changed the following lines:
# The max file size for indexing. Files larger than this
# will be ignored.
# NOTE: This value is usually larger than TEXT_SIZE_MAX because
# binary-formated files such as PDF, Word are larger.
#
$FILE_SIZE_MAX = 10000000;

#
# The max text size for indexing. Files larger than this
# will be ignored.
#
$TEXT_SIZE_MAX = 6000000;



I then created an index directory in my home directory. If you are setting this up for a web server you may wish to keep the index files elsewhere. So then I ran the mknmz program:

mknmz -O ~/.namazu/index/ ~/work/articles/


This creates the index of the articles directory and stores it in the .namazu/index directory. From the command line you can now enter:
namazu "epitope not cell"


Not that that search makes any sense but you get the idea.

Friday, February 2, 2007

ssh bash completion in Ubuntu

SSH bash completion doesn't currently work in 6.10. This is because hostnames are now stored as hashes in ~/.ssh/known_hosts. To disable storing hostnames as hashes and allow ssh hostname completion to work correctly you need to edit: /etc/ssh/ssh_config and change HashKnownHosts to No.

Thanks to Ubuntu forums for the answer.

Thursday, February 1, 2007

Set up subversion

If you are comfortable with CVS - changing over to svn shouldn't be too hard. First make sure you download the latest version of svn from your package manager.

Then to create the new svn repository type:
svnadmin create /foo/bar/repo


Then to check it out, you need to create a working directory and know the url of the svnserve. In my case this is a local server running on just my machine so the following will work:
mkdir svndir

svn checkout file:///foo/bar/repo svndir


You can now move into the svndir and start working.

Its probably well worth reading up on the differences between cvs projects and svn directories. Its probably easiest to think of creating a new svn repository for what would have been a cvs project. Also its worth bearing in mind that changes in a svn repository tag the whole project rather than a single file.

Friday, January 26, 2007

vector can not hold reference to a pure virtual base class

I had three classes, a template pure virtual base class, a template
derived class and a third which I would like to use to store copies of
the derived class. The code looked like this:

#include <iostream>
#include <vector>

using namespace std;

template <class _prec> class Base {
public:
_prec i;

Base() {
i = 12;
}

virtual void f() = 0;

};

template <class _prec> class Derived : public Base<_prec> {
public:
void f() {
std::cout << this->i << std::endl;
}
};

template <class _prec> class Collect {
public:
vector <Base<_prec> *> vec;

Collect() {
}

void g(Base<_prec> &in) {
vec.push_back(&in);
vec[0]->f();
}
};

int main() {
Derived<int> *d = new Derived<int>;
Collect<int> c;

c.g(*d);

return 0;
}



And resulted in errors such as:

/usr/lib/gcc/x86_64-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:256: error: cannot allocate an object of abstract type ‘Base<int>’
base_vector_test.cpp:6: note: since type ‘Base<int>’ has pure virtual functions
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:256: error: cannot declare variable ‘__x_copy’ to be of abstract type ‘Base<int>’
base_vector_test.cpp:6: note: since type ‘Base<int>’ has pure virtual functions



The problem is that vector creates a copy of the object you pass it. If you pass it a reference to an abstract base class it can't create a copy, just as you can't do: Base b; The solution in my case is to use pointers. This however means you'll have to manage their allocation and deallocation of the objects yourself. The fixed code looks like this:

#include <iostream>
#include <vector>

using namespace std;

template <class _prec> class Base {
public:
_prec i;

Base() {
i = 12;
}

virtual void f() = 0;

};

template <class _prec> class Derived : public Base<_prec> {
public:
void f() {
std::cout << this->i << std::endl;
}
};

template <class _prec> class Collect {
public:
vector <Base<_prec> *> vec;

Collect() {
}

void g(Base<_prec> &in) {
vec.push_back(&in);
vec[0]->f();
}
};

int main() {
Derived<int> *d = new Derived<int>;
Collect<int> c;

c.g(*d);

delete d;
return 0;
}



My original thread on comp.lang.c++ where I got help with this problem can be found here: http://groups.google.ie/group/comp.lang.c++/browse_thread/thread/c4cad258a9a94540

Thursday, January 25, 2007

Inheritance appears to break when deriving a template class

If you have a base template class from which you derive another template class inheritance can appear to break, i.e. you don't appear to be able to access the base classes variables and methods directly. For example take the following code:


#include <iostream>

template <class _prec> class Base {
public:
_prec i;

Base() {
i = 12;
}

virtual void f() {
std::cout << i << std::endl;
}

};

template <class _prec> class Derived : public Base<_prec> {
public:
void f() {
std::cout << i*2 << std::endl;
}
};

int main() {
Base<int> b;
Derived<int> d;

b.f();
d.f();

return 0;
}



On gcc 4.1.2 this gives the following error:

derive_test.cpp: In member function ‘void Derived<_prec>::f()’:
derive_test.cpp:20: error: ‘i’ was not declared in this scope



The problem is caused because the base class is not in scope, why I find unclear, and the work around a little messy. But basically if you change
std::cout << i*2 << std::endl;
to
std::cout << this->i*2 << std::endl;

All will be well.


More info at: http://www.parashift.com/c++-faq-lite/templates.html#faq-35.19 and
http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html

Friday, January 19, 2007

You don't exist, go away!

This post has moved: HERE

Thursday, January 18, 2007

Information about your session

Tips for finding out about your permissions and rights in a session, either on your own computer or a server.

whoami: Displays the username that you are currently logged in as.

who: Displays a list of users currently logged in to the computer. Useful for getting the ip address of the computer you have logged into from.

ifconfig: Displays the ip address of your computer

groups: Displays group membership for the current user.

echo $ENV_NAME: Display the setting for the environment setting ENV_NAME. For example to check which cvs server/root you are currently using type:

echo $CVSROOT

This will display the cvsroot information you are currently using. (CVS commands to follow in a new post)

uname -r

Displays the current kernel version.

More to come here.

Default editor

To change the default command line editor from say vim to nano/pico enter the following in the .bashrc file in your home directory.

export EDITOR=/usr/bin/pico

or you can do this by issuing a setenv command during a session.

eg:

setenv EDITOR=/usr/bin/pico

Backing up your home directory to a remote server using cron

install cron:

sudo apt-get install cron

Allow all users to use cron:

sudo touch /etc/cron.deny

Add a job to rsync your home directory:

crontab -e

nano should pop up, add the following line, replacing username with your username and server with the server you are backing up to:

0 1 * * * rsync -r ~ username@server:~

Exit (Ctrl-X) and say yes to save when prompted.

Because the backup script will need to login to the remote server you need to setup ssh to allow you to login using your ssh key. If you don't have an ssh key create one with the following command, accepting defaults when prompted (do not set a passphrase):

ssh-keygen

Now copy your public key to the server to allow you to login automatically:

scp ~/.ssh/id_rsa.pub username@server:~/.ssh/authorized_keys

Now test the backup by running, replacing username with your username on the server:

rsync -r ~ username@server:~

and see if your home directory is copied to the server correctly. Note with default settings rsync will not delete files that you have removed locally from the backup.


In order to solve that you can write your own script to handle the backup of the home dir. Here is an example:

#! /bin/bash
USER="username"
HOME="/home/$USER"
TARGET="/path/to/backup"

echo "Backing up files from $HOME"
echo "Backing up files to $TARGET"
rsync -Cavz --delete --delete-excluded --exclude-from=$HOME/.exclude_backup.txt $HOME $TARGET

echo "Completed"

exit 1;




This is the exclude file:
demo
tmp
.beagle
.kde
.gnome
.mozilla

Making a PDF file out of a bunch of JPEGs

1. Convert JPEG files to PS, use jpeg2ps (apt-getable)

1a. If you have a lot of files you can convert them all like this:

find . -iname "*.jpg" -print0 | xargs --replace -0 jpeg2ps {} -o {}.ps

2. Convert all the files of pdfs

find . -iname "*.ps" -print0 | xargs --replace -0 ps2pdf {} {}.pdf

3. Join pdf files with pdfjoin (arg-getable in pdfjam package)

If the files are in the correct order use:

pdfjoin *.pdf

otherwise list the files in order:

pdfjoin file1.pdf file2.pdf...