Mike Hommey: Sudoku perverts
You might remember the Sudoku solver in XSLT. Now let me introduce you another range of perverts with solvers in SQL and regular expressions.
I also very much like ‘%ed’ within ipython using the following snippet in my ~/.ipython/ipythonrc:
editor 1 editor /usr/bin/vim.pythonNotice: Don’t wonder about the prompt style of the following ipython-screenshot, I customized it a little bit (see python-webpage in the grml-wiki again to get an idea).
So running the last line containing ‘%ed 1′ will execute /usr/bin/vim.python providing the code from the first command line of ipython and I can use all the magic of Vim for editing the code. When exiting the editor I have the code within ipython. Rocking. Compilers can be then just be defined withcan_translate(Src, Tgt, [L]) :- t_diagram(Src, Tgt, _, L). can_translate(Src, Tgt, [H T]) :- t_diagram(Src, Via, _, H), can_translate(Via, Tgt, T).
and querying the translation pipeline is done witht_diagram(source, target, implemented in, name).
(Modifying it so that it works with cycles isn’t very tricky, either.)?- can_translate(source, target, Result)
#!/bin/bash
set -e
set -C
set -u
JOBNAME=“update-wiki-firewall-config”
DWPAGE=“php4 /usr/share/dokuwiki/bin/dwpage.php”
TMPBASE=“/tmp”
SSHID=“$HOME/.ssh/$USER-passphraseless-$(hostname)”
REMOTEHOST=“remote.fqdn.example”
REMOTEJOB=“pull-netfilter-init-config-tar”
SHAREDIR=“$HOME/share/$JOBNAME”
WIKINAMESPACE=“pointer:to:namespace”
start=’/*BEGIN generated firewall rules */’
end=’/*END generated firewall rules */’
insert=’/*INSERT generated firewall rules */’
umask 077
if ! TMPDIR=“$(mktemp -d $TMPBASE/fwconfig.XXXXXXXXXX)”; then
echo >&2 “ERR: cannot create temp dir in $TMPBASE”
exit 1
fi
cd $TMPDIR
mkdir remote
ssh -i $SSHID root@$REMOTEHOST $REMOTEJOB \
tar --extract --gzip --file - --directory remote
mkdir workdir
touch workdir/rulelistfile
echo “$start” >> workdir/rulelistfile
for fwfile in $(find $TMPDIR/remote/rules/up -type f sort); do
MTIME=“$(stat --format=”%y“ $fwfile)”
PROSEEXPLANATION="$( $fwfile sed -n '/^#::#/ s/^#::#[[:space:]]*//;p;q; ')"
if [ -z "$PROSEEXPLANATION" ]; then
PROSEEXPLANATION="netfilter-init internal code"
fi
rm -f workdir/newwikipage
$SHAREDIR/wikipagetemplate \
sed \
-e "s PLHfilenamePLH $(basename $fwfile) " \
-e "s PLHproseexplanationPLH $PROSEEXPLANATION " \
-e "s PLHmtimePLH $MTIME " \
-e "/PLHcontentsPLH/r$fwfile" \
-e "s/PLHcontentsPLH//" \
> workdir/newwikipage
WIKIPAGENAME=“$WIKINAMESPACE:regeln:$(basename $fwfile .rul)”
$DWPAGE checkout $WIKIPAGENAME workdir/wikipage
if ! cmp --quiet workdir/wikipage workdir/newwikipage; then
cp workdir/newwikipage workdir/wikipage
$DWPAGE -m “new contents imported from $fwfile” commit workdir/wikipage $WIKIPAGENAME
fi
echo “ * [[$WIKIPAGENAME $(basename $fwfile)]] - $PROSEEXPLANATION” >> workdir/rulelistfile
done
echo “$end” >> workdir/rulelistfile
$DWPAGE checkout $WIKINAMESPACE workdir/contentspage.txt
workdir/contentspage.txt \
sed -e "\ ^$ start//\\*/\\* \$ ,\ ^$ end//\\*/\\* \$ d; " \
sed -e "\ ^$ insert//\\*/\\* \$ rworkdir/rulelistfile" \
> workdir/newcontentspage.txt
if ! cmp --quiet workdir/contentspage.txt workdir/newcontentspage.txt; then
cp workdir/newcontentspage.txt workdir/contentspage.txt
$DWPAGE -m “new contents page” commit workdir/contentspage.txt $WIKINAMESPACE
fi
cd /
rm -rf “$TMPDIR”
Yes, this needs some more documentation and generalization. But it’s just a proof of concept that needs some
polishing before being put into real life use.
Here are the two template files for wiki page and contents page:
====== Firewallregeln PLHfilenamePLH ======
Last changed on target system: PLHmtimePLH
PLHproseexplanationPLH
<code>
PLHcontentsPLH
</code>
===== Dump of firewall rules =====
/*INSERT generated firewall rules */
/*BEGIN generated firewall rules */
/*END generated firewall rules */
The index page template relys on the HiddenComment dokuwiki plugin to be installed, or the placeholders show up in the
rendered wiki page. The code uses the first comment line marked with #::# to generate a short explanation of the file
being pulled into the wiki. dwpage.php is a fully-fledged command line interface to dokuwiki, committed new pages are
fulled versioned as if entered through the wiki web front end. This way, the documentation in the wiki is guaranteed to
be current and to fit the configuration found on the live system - it is directly pulled from the live system.
Yes, rendering of the code is currently suboptimal. Working on it.
ran out of input data System haltedReason: everything OK, except for the filesystem used on your usb device. So instead of fat16 you use for example fat32. Fix: use the appropriate filesystem (fat16 for usb pens usually).
Invalid operating systemPossible reason: the partition layout is not ok. Very probably there’s no primary partition or none has the flag ‘bootable’ set. (Read on for further details.)
No operating system found.Possible reason: you forgot to set the boot-flag on the partition. Or you did not install an operating system at all.
FATAL ERROR: Bad primary partition 0: Partition ends in the final partial cylinderReason: the partition layout is not ok. Either use fdisk (requires detailed knowledge about partition setup!) or better: use a fronted of libparted, like gparted. gparted does an excellent job at setting up an appropriate partition layout for booting from USB (read on for details about the correct setup). As long as cfdisk has problems with the layout - it will exit on errors - your usb pen very probably does not have a valid partition setup for booting. Please notice that fdisk very often uses defaults which are not OK, whereas gparted uses the appropriate heads, sectors/track and cylinders settings. So if you really want to use fdisk for setting up the appropriate partition layout you might have to enter the ‘extra functionality (experts only)’ menu of fdisk.
kernel-panic: unable to mount root-fs...Yes? Then the root= argument in your kernel commandline (specified in the bootloader, usually lilo, grub or isolinux/syslinux) is pointing to the wrong device. Solution: adjust the root=-option in your bootmanager’s configuration. Tip: use root=UUID instead of root=/dev/[hs]d…
# fdisk -l -u /dev/sda Disk /dev/sda: 1039 MB, 1039663104 bytes 255 heads, 63 sectors/track, 126 cylinders, total 2030592 sectors Units = sectors of 1 * 512 = 512 bytes Device Boot Start End Blocks Id System /dev/sda1 * 63 2024189 1012063+ 6 FAT16 # fdisk -l /dev/sda Disk /dev/sda: 1039 MB, 1039663104 bytes 255 heads, 63 sectors/track, 126 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 126 1012063+ 6 FAT16 # sfdisk -d /dev/sda # partition table of /dev/sda unit: sectors /dev/sda1 : start= 63, size= 2024127, Id= 6, bootable /dev/sda2 : start= 0, size= 0, Id= 0 /dev/sda3 : start= 0, size= 0, Id= 0 /dev/sda4 : start= 0, size= 0, Id= 0Tip: if you have a working stick, store your partition layout using ’sfdisk -d /dev/sda > sfdisk.sda’ for later restore (via ’sfdisk /dev/sda < sfdisk.sda’). This is also very useful for cloning a working setup to other devices (though you might have to adjust cylinder/units later on). And of course you can use it as backup if you ran [sc]fdisk-commands on the wrong device.
deb http://debian.hansode.org/ ./and the package name is libplagger-perl. However, it has no "assets", the essential components for Plagger, so you need to get them from the svn repo.
svn co http://svn.bulknews.net/repos/plagger/trunk/plagger/assets/The following is the example of YAML:
global:
timezone: Asia/Tokyo
assets_path: /home/knok/plagger/assets
plugins:
- module: Subscription::Config
config:
feed:
- http://internal.host/~knok/index.rdf
- module: Bundle::Planet
config:
title: Planet Office
dir: /home/knok/planet
url: http://internal.host/planet/
theme: sixapart-std
duration: 30 days
description: The internal RSS aggregation.
Usually, Windows will not be able to boot, unless you copy, move or restore NTFS to the same partition which starts at the same sector on the same type of disk having the same BIOS legacy cylinder setting as the original partition and disk had.
Next.