Monday, September 30, 2013

bash script to backup compiled applescripts

#! /bin/bash

IFS=$(echo -en "\n\b")
for i in *.scpt
do
    osadecompile "$i" > "${i%.scpt}.applescript"
done
Here are some short scripts I use:
---- Clean Desktop.applescript
on run
    do shell script "chflags hidden ~/Desktop/*"
end run

---- Clutter Desktop.applescript
on run
    do shell script "chflags nohidden ~/Desktop/*"
end run

---- Eject and Sleep.applescript
tell application "Finder" to eject (every disk whose ejectable is true)
tell application "Finder" to sleep

---- Skip Forward 30 Seconds.applescript
tell application "iTunes" to set player position to (player position + 30)

Thursday, September 26, 2013

Java regular expression: anchored versus unanchored greedy quantifier

Here's a simple Java program

$ cat Test.java
class Test
{
    public static void main (String args[])
    {
        System.out.println ("this".replaceAll (".*", "that"));
        System.out.println ("this".replaceAll ("^.*$", "that"));
    }
}

When compiled and run, it produces

$ javac Test.java
$ java Test
thatthat
that

What's up with that first replacement? Why is the "that" doubled? Beats me...

$ java -version
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-456-11M4508)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-456, mixed mode)

Thursday, September 5, 2013

check_mk on OpenBSD

First, grab the most recent source, and extract and install it.
wget http://mathias-kettner.de/download/check_mk-1.2.2p2.tar.gz
gunzip check_mk-1.2.2p2.tar.gz
tar xf check_mk-1.2.2p2.tar
cd check_mk-1.2.2p2
gunzip agents.tar.gz
tar xf agents.tar
sudo cp check_mk_agent.openbsd /usr/local/bin/check_mk_agent
sudo chmod 755 /usr/local/bin/check_mk_agent
Then add the check_mk service to /etc/services.
$ rcsdiff /etc/services
===================================================================
RCS file: /etc/services,v
retrieving revision 1.1
diff -r1.1 /etc/services
1c1
< #     $OpenBSD: services,v 1.1 2013/09/03 18:52:00 beaty Exp beaty $
---
> #     $OpenBSD: services,v 1.1 2013/09/03 18:52:00 beaty Exp $
296a297,298
>
> check_mk      6556/tcp
Add the service to /etc/inetd.conf and restart inetd
$ rcsdiff /etc/inetd.conf
===================================================================
RCS file: /etc/inetd.conf,v
retrieving revision 1.1
diff -r1.1 /etc/inetd.conf
1c1
< #     $OpenBSD: inetd.conf,v 1.1 2013/09/03 18:49:57 beaty Exp beaty $
---
> #     $OpenBSD: inetd.conf,v 1.1 2013/09/03 18:49:57 beaty Exp $
50a51,52
> check_mk      stream  tcp     nowait  root    /usr/local/bin/check_mk_agent
> check_mk      stream  tcp6    nowait  root    /usr/local/bin/check_mk_agent

$ sudo kill -HUP `cat /var/run/inetd.pid `
Open up the port in pf (and probably allow pings from the nagios host).
$ sudo rcsdiff -r1.1 /etc/pf.conf
===================================================================
RCS file: /etc/pf.conf,v
retrieving revision 1.1
diff -r1.1 /etc/pf.conf
1c1
< #     $OpenBSD: pf.conf,v 1.1 2013/09/03 18:54:56 beaty Exp $
---
> #     $OpenBSD: pf.conf,v 1.2 2013/09/03 21:57:17 beaty Exp $
38c38,39
<
---
> pass in proto tcp from 128.117.64.51 to any port 6556
> pass in proto icmp from 128.117.64.51 to any icmp-type echoreq

$ sudo pfctl -f /etc/pf.conf