Thursday, October 05, 2006

Perl in-line edits...

If you'd like to be able to run a command like:

$ inline "TEXT TO REPLACE" "REPLACE WITH" filename

Make a shell script with this:

#!/bin/sh

MATCH_STRING=$1
REPLACE_WITH=$2
EDIT_FILE=$3

perl -pi.$$ -e "s{${MATCH_STRING}}{${REPLACE_WITH}}g" ${EDIT_FILE}

It will rename the files to the original filename with the current process ID on the back, and leave an edited copy in the new file.

Alternatively instead of the process ID, a timestamp (of the time now) might be more useful.

You could use:

DATE=$(date +'%Y%m%d%H%M%S')

perl -pi.${DATE} -e "s{${MATCH_STRING}}{${REPLACE_WITH}}g" ${EDIT_FILE}

or perhaps more usefully, for a timestamp based on the last modified time of the file before editing:

TIMESTAMP=$(date '+%Y%m%d%H%M%S' -r ${EDIT_FILE})

Like: 20061005151552

You might want the unix timestamp of the last modified time of the file:

TIMESTAMP=$(date +%s -r ${EDIT_FILE})

or

TIMESTAMP=$(stat -c %Y ${EDIT_FILE})

Both give: 1160057752

then:

perl -pi.${TIMESTAMP} -e "s{${MATCH_STRING}}{${REPLACE_WITH}}g" ${EDIT_FILE}


To just remove a line you can do this with the -n option:

perl -ni.$$ -e "print if !~ /^${MATCH_STRING}:/;" ${EDIT_FILE}


But this is shorter:


perl -pi.$$ -e "s/^${MATCH_STRING}:.*?\n//g;" ${EDIT_FILE}

Monday, October 02, 2006

NX on Etch

Sorry if this is a bit random... I'm tired! I'll try and fix it later.

From home before I left:

ssh -R 1234:localhost:22 mywebserver.net

and left something running that kept the session active (and therefore alive)


vi /etc/apt/sources.list

Added the text from here...

# In case you only want NX related packages,
# the following repository lines are sufficient:
deb http://debian.tu-bs.de/project/kanotix/unstable/ sid nx
deb-src http://debian.tu-bs.de/project/kanotix/unstable/ sid nx

then did:

apt-get update
apt-get upgrade

For good luck I did this, because I'd been messing around with it over the past 3-4 days:

apt-get remove --purge nxserver nxnode nxclient nxlibs nxlibs-dev nxdesktop nxagent nxagent-dev

Then I did:

apt-cache search NoMachine | less
apt-get install nxagent

And downloaded and installed the other .debs from nomachine.com

wget -N http://64.34.161.181/download/2.1.0/Linux/FE/nxserver_2.1.0-7_i386.deb
wget -N http://64.34.161.181/download/2.1.0/Linux/nxclient_2.1.0-6_i386.deb
wget -N http://64.34.161.181/download/2.1.0/Linux/nxmanager_2.1.0-5_i386.deb
wget -N http://64.34.161.181/download/2.1.0/Linux/nxnode_2.1.0-7_i386.deb
wget -N http://kanotix.com/files/debian/pool/main/f/freenx/freenx_0.4.4+0.4.5-4_all.deb

dpkg -i nxclient_2.1.0-6_i386.deb
dpkg -i nxnode_2.1.0-7_i386.deb
dpkg -i nxmanager_2.1.0-5_i386.deb
dpkg -i nxserver_2.1.0-7_i386.deb

less /usr/NX/var/log/install

/etc/init.d/nxserver start
apt-get install nxserver freenx
nxsetup --setup-nomachine-key
nxserver --status



# dpkg --list | grep nx
ii freenx 0.4.4+0.4.5-4 The FreeNX application/thin-client server ba
ii nxagent 1.4.92+1.5.0-11 NoMachine NX - nesting X server with roundtr
ii nxclient 2.1.0-6 NX Client
ii nxlibs 1.4.92+1.5.0-11 NoMachine NX - common agent libraries
ii nxmanager 2.1.0-5 NX Server Manager.
ii nxnode 2.1.0-7 NX Server Node
ii nxserver 2.1.0-7 NX Server


I run fluxbox:

# which fluxbox
/usr/bin/fluxbox

I did this in the client:

General tab:

Host: localhost
Port: 1234
Desktop:
Dropdowns: Unix [v] Custom [v]
[Settings]
Application
Run the following command: /usr/bin/fluxbox
Options
New virtual desktop
[OK]
ADSL
Display: Available area

Advanced tab:
[x]Enable SSL encryption of all traffic.

PuTTY:

Connection
SSH Tunnels
L1234:localhost:1234

Once you get NX working you may find this useful: How to setup international keyboard in X Window with Xmodmap and XKB

Friday, September 22, 2006

vim command line history...

If you're on a Red Hat box (or some other lowly being...) and call vi and :ver tells you you're in vim, but when you try and get your command line history with Up-Arrow and it just says /<Up> .. have a look at :ver again and you will probably see:

~
~
~
~
~
~
~
:ver
VIM - Vi IMproved 6.3 (2004 June 7, compiled Feb 7 2005 08:07:43)
Included patches: 1-21, 23-24, 26, 28-34, 36-37, 39-40, 42-43, 45-46
Compiled by <bugzilla@redhat.com>
Tiny version without GUI. Features included (+) or not (-):
-arabic -autocmd -balloon_eval -browse +builtin_terms -byte_offset -cindent
-clientserver -clipboard -cmdline_compl -cmdline_hist -cmdline_info -comments
-cryptv -cscope -dialog -diff -digraphs -dnd -ebcdic -emacs_tags -eval
-ex_extra -extra_search -farsi -file_in_path -find_in_path -folding -footer
+fork() -gettext -hangul_input +iconv -insert_expand -jumplist -keymap -langmap
-libcall -linebreak -lispindent -listcmds -localmap -menu -mksession
-modify_fname -mouse -mouse_dec -mouse_gpm -mouse_jsbterm -mouse_netterm
-mouse_xterm +multi_byte -multi_lang -netbeans_intg -osfiletype -path_extra
-perl -printer -python -quickfix -rightleft -ruby -scrollbind -signs
-smartindent -sniff -statusline -sun_workshop -syntax -tag_binary
-tag_old_static -tag_any_white -tcl +terminfo -termresponse -textobjects -title
-toolbar -user_commands -vertsplit -virtualedit -visual -viminfo -vreplace
+wildignore -wildmenu -windows +writebackup -X11 -xfontset -xim -xsmp
-xterm_clipboard -xterm_save
system vimrc file: "/etc/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
fall-back for $VIM: "/usr/share/vim"
Compilation: i386-redhat-linux-gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -g -pi
pe -march=i386 -mcpu=i686 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
Linking: i386-redhat-linux-gcc -L/usr/local/lib -o vim -ltermcap -lacl

If you read http://www.vim.org/htmldoc/cmdline.html#cmdline-history it says:

{not available when compiled without the |+cmdline_hist| feature}

The answer is to plant more trees.... (whoops, sorry Billy!)
Try "which vi" and if you're on Red Hat chances are you'll see:

user@host:~: which vi
/bin/vi
user@host:~: which vim
/usr/bin/vim
user@host:~: ll $(which vi) $(which vim)
-rwxr-xr-x 1 root root 473964 Feb 7 2005 /bin/vi
-rwxr-xr-x 1 root root 1966604 Feb 7 2005 /usr/bin/vim

do

alias vi='/usr/bin/vim'

And all your L337N355 will come flooding back to you!

Thursday, September 21, 2006

What's the IP of $HOSTNAME


perl -MSocket -e 'print inet_ntoa((gethostbyname '$HOSTNAME')[4]), $/;'

Dumping a webpage in text...

$ lwp-request -o text http://www.aotea.org/john/

This will probably need a few CPAN modules added to work, but the layout is nice and clean - it doesn't line up table cells.

$ elinks -no-numbering -no-references -dump http://www.aotea.org/john/

hostname in localhost line in /etc/hosts

DON'T DO IT!

the /etc/hosts file in the Slackware installer image still has this in it:


# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server. Just add the names, addresses
# and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine. It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1 localhost
# This next entry is technically wrong, but good enough to get TCP/IP apps
# to quit complaining that they can't verify the hostname on a loopback-only
# Linux box.
127.0.0.1 slackware.example.net slackware

# End of hosts.


Brain-dead Red Hat does this when you install


127.0.0.1 hostname localhost.localdomain localhost


Eeagh! WRONG!

Tuesday, September 05, 2006

Printing to PDF

Either or both of these:

PrimoPDF

CutePDF

I have found that the printer driver you chose makes a massive difference to the finished product, some are OK, and some are really crap.

The best driver I have found so far on XP is the latest built-in HP Postscript driver, (HP color LaserJet 9500 PostScript driver) which you can download from here

It's 11MB though, and you can get a 3.1MB one from here

I tried the ones from here or here but they don't want to let you print to the virtual local ports - either LP1 or COM1 or network printers - nothing else - I don't know how to seperate the renderer from the printing interface. :o(

The others I tried were not as good, particularly the "QMS ColorScript 1000 Level 1" which I found suggested here was truly pants!

The "Apple Color LaserWriter 12/600" which was recommended in the CutePDF FAQ was OK, but not great, the main body text of the first page I wanted to print came out in a rusty brown, not in black.

If you are making your PDFs from Word documents and want a PDF which has clickable links (like the index and web links) I'd recommend installing Open Office and exporting to PDF from OOWriter.

Useful applications

Dia rocks...
(I've tried WinFIG and it sucks)

GIMP for Windows & GTK+

Bits for screen...

Bits for screen

http://aperiodic.net/screen/

http://www.gnu.org/software/screen/

http://www.kuro5hin.org/story/2004/3/9/16838/14935




Cygwin:

screen for Cygwin

http://dellelce.com/code/screen/

http://www.cygwin.com/ml/cygwin/2005-05/msg00797.html




davekaufman.net::.screenrc
Heaviliy tweaked and full of goodies.

Was this the same as this one or a newer copy?:
http://pastebin.com/m152f025b
http://airto.hosted.ats.ucla.edu/wiki/index.php/Using_Screen


apple.com::.screenrc
More vanilla.

http://www.guckes.net/setup/screenrc

http://www.aperiodic.net/phil/configs/screenrc

http://nion.modprobe.de/setup/screenrc

http://home.insightbb.com/~bmsims1/Scripts/Screenrc.html
http://cafim.sssup.it/~giulio/other/gb.screenrc

TODO: Things you might like to do, things you might not want to do...