‘Compact’ bash prompt

July 30th, 2007

Especially when working with cakephp, the following line in your .bash_profile script might come in handy:

HOSTCOLOR="31m"
PS1="\u@\[\e[${HOSTCOLOR}\]\h\[\e[0m\]:\w\n\[\e[33m\]\!\[\e[0m\] \$ "

It will print out the current working directory on the first line and the actual bash prompt on the second line. Making it less likely that your command will wrap lines after the first few typed characters.
It changes the command prompt from:

command line long

….into:

command line 'short'

The login prompt now shows the following info:

  • username
  • hostname in red (in my bash script, it will print red for one group of servers and blue for other servers)
  • current working directory
  • command history number, ie: use !520 to execute the previous command

Extracting layers from a XCF (gimp) file

July 21st, 2007

This is a script that extracts the layers of a XCF file to individual PNG files. It uses xcftools (debian/ubuntu package):

#!/bin/bash

xcffile=$1

layers=`xcfinfo $xcffile  | awk '{ print $NF }'`

destdir=`dirname $xcffile`/layers
mkdir $destdir

for layer in $layers
do
        echo saving $layer to $destdir/$layer.png
        xcf2png -o $destdir/$layer.png $xcffile $layer
done

exit 0

Convert ^M to newline character in text files

July 9th, 2007

Summary:
In vi use the following:

:%s/^M/\n/g

or, when just removing ^M characters:

:%s/^M//g

NOTE: Be sure to create the ^M by typing ctrl+V followed by ctrl+M.

CakePHP radio button example

January 26th, 2007

cakephp radio buttons.png
Thanks Ronnie, for the example! It looks like this useful hint won’t appear in the cakephp documentation any time soon. I think is’t “nerdnoteworthy”:

echo $html->radio(
	'User/admin',
	array(
		'no' => 'No',
		'yes' => 'Yes'),
	null,
	array('value' => 'no')
);

Open Source Mac Apps

December 30th, 2006

Just names and links:
Adium X, Chicken of the VNC, Colloquy, Cyberduck, Chmox, Fink, Firefox, macam, Smultron, Tomato Torrent, Virtuedesktop

Until it’s posssible to mount ssh filesystems…

December 30th, 2006

Forget about cyberduck, the real thing is made possible by Amit Singh!! Two visitors dropped comments about about the release of this project. I’ve updated the post that I made back in September.


Until then… I will use cyberduck!!!
Cyberduck is an FTP / SFTP client that let’s you browse filesystems on systems you have ssh access to. It not only lets you upload and download files, it also file edit support. After connecting to a server, select a file and right click it. Select ‘Edit with > Smultron’.
Cyberduck monitors the file that you just opened in Smultron. If you save it, it will be automatically uploaded to the server, just like you where editing a local file.

And, of course, both Cyberduck and Smultron are Free and Open Souce ;-)
Neat!!

Wireless setup

December 26th, 2006

For some reason, I couldn’t get my wireless card (Linksys WMP54G pci) working under Ubuntu 6.10. Another attempt today. First without encryption: Hey! it works!. Then WEP ‘encryption’: no luck. WPA: on my access point (asus wl530g) it’s called WPA-PSK with TKIP encryption. OS X calls it “WPA personal”. Under Linux, adapting the /etc/networking/interfaces file was sufficient:

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

iface ra0 inet dhcp
pre-up iwconfig ra0 essid default
pre-up iwconfig ra0 mode managed
pre-up iwconfig ra0 channel 1
pre-up iwpriv ra0 set AuthMode=WPAPSK
pre-up iwpriv ra0 set EncrypType=TKIP
pre-up iwpriv ra0 set WPAPSK="mysecretpassphrase"

auto ra0

So, no additional drivers / modules, just choosing the right encryption was the trick to get this card working. This was one of the posts that where very helpful.

www.hiddenspiral.net/node/23

December 18th, 2006

This is a comment that I would have posted on this blog entry, if the author was willing to receive it without me signing up. It’s about retrieving the keys and values of an enum field in CakePHP:

This version returns the original mysql key values and returns false if the enum is not found:

function generateEnumArray($enum)
{
  if (!is_string($enum)) {
    return false;
  }

  foreach($this->_tableInfo->value as $field)
  {
    // found matching field, check for type enum and field name
    if(substr($field['type'], 0 ,4) == 'enum' && $field['name'] == $enum)
    {
      $enum_array = array();
      foreach(split("','", substr($field['type'], 6, -2)) as $key => $value)
      {
        $enum_array[$key]=$value;
      }
      return $enum_array;
    }
  }

  // enum not found
  return false;
}

Batch conversion of images

December 15th, 2006

For batch image conversion, file renaming, etc, I usually use these kind of one-liners:

$ for i in `ls *.bmp` ; do echo convert $i ${i%.*}.png ;done
convert screendump_01.bmp screendump_01.png
convert screendump_02.bmp screendump_02.png
convert screendump_03.bmp screendump_03.png

When you’re satisfied with the result, have it executed by the shell:

$ for i in `ls *.bmp` ; do echo convert $i ${i%.*}.png ;done | sh

Scripting the Unscriptable

October 11th, 2006

I’ve been looking for different ways to send keystrokes, mouse movements and clicks to GUI applications. Under Windows, this is straight forward with AutoIt. The BASIC-like language allows you to read files, start applications, send keystrokes move the mouse etc. A nice feature is to wait for certain dialogs, for example:

; wait for tightvnc window
WinWaitActive("New TightVNC Connection")
; send hostname and port number
Send($hostname & ":" & $displaynumber)

This makes sure that the keystrokes actually end up in the right window. Mouse coordinates can be specified relative to the application window. Using these features allows you to write ‘reasonably’ robust code. But don’t expect your AutoIt script to run flawlessly on other PC’s. There are a lot of dependencies, like dialogs that look different in another version. Internationalization might cause the window title to read “Nieuwe TightVNC Verbinding” (Dutch) and the above code snippet will fail. Even user preferences like font sizes, window themes and screen resolution might result in unexpected behavior.

Anyway, it’s just fun to figure out which sequences to send to an application and let it process a batch of documents!
Ok, this works pretty nice under windows. But what about my favorite platform?
Read the rest of this entry »