# Top 3 tips for migrating a server to a virtual machine

I recently migrated a server to a virtual machine, and while it was mostly a smooth process, I did encounter a couple of problems.

• Ensure that any licensing services will run on the new virtual hardware. Our accounting system’s license server wouldn’t run until it was set up with new licenses.
• Check date and time are correct on the new host and guest vm.
• Make sure the server is set to use a static IP addresses before migrating.

# Anacron run-parts: /etc/cron.daily/amavisd-new exited with return code 1

I’ve been getting messages like the ones below from cron my debian box for some time now. I finally got sick of seeing them and I tracked down the error.

/etc/cron.daily/amavisd-new: Please run this cronjob as user amavis run-parts: /etc/cron.daily/amavisd-new exited with return code 1 

At some point the debian package moved the cron config file from /etc/cron.daily/amavisd-new to /etc/cron.d/amavisd-new but for some reason when upgrading, it does not remove the old config file, leaving you with an erroneous file.

All you need to do is delete /etc/cron.daily/amavisd-new and the messages should go away.

# How to make a bootable usb stick in Windows 7 of a debian iso

Every so often I need to make a bootable USB stick in Windows 7 (64 bit) of a debian installer iso. For some reason my googleing usually does not reveal a simple solution for this.

I asked on #debian on the OFTC network and got various suggestions. The first suggestions were to use win32 compiled variants of dd or rawwrite. The problem is that there seems to be multiple versions of these tools out there and the ones I tried all seemed to have issues of one sort or another, mostly to do with dd complaining that it would not run on 64 bit Windows. My other issue is that they are command line based. Not that I mind using the command line but it does feel fiddly when all you want to do is get on with writing the image to the USB stick so you can install Debian.

Next I came up with unetbootin. This looks promising and seems to work but it does some very strange rewriting of the boot menus you get on the resulting USB stick. I was confused by the menus when I first saw it and I’m sure novice users would have no idea what to do.

Finally dvs on #debian suggested win32diskimager. This is exactly what I wanted. A point and click solution.

screenshot of win32diskimager

Select the DVD image you want. If the file’s extension is .iso you’ll need to change the filter from *.img;*.IMG to *.* in order to see the file. Then select the Device you want to write to. Hit Write and go and have a cup of tea while it writes the ISO to the USB stick.

There are quite a few programatic CAD, OpenSCAD alternatives out there. I am collecting a list of them and providing links to them here. The requirements to be included in this list are:

• Free and libre.
• They are a programming language as opposed to a GUI.

OpenSCAD: The most well known programmatic CAD program. Probably the original open source one that I am aware of.

RapCAD: Rapid prototyping CAD IDE for RepRap and RepStrap 3D printing machines.

OpenJSCAD: OpenSCAD + JavaScript = OpenJSCAD, edit locally or remote online, preview in browser direct via WebGL.

FABFabbers bills itself as “a new site for the 3d printing community”. It provides in browser OpenSCAD compilation and linking to github projects.

Update 2: gzmask pointed out SchemeCad, a programmable 3D CAD tool that supports wireframe models and features animation. Users can program Scheme Cad by writing extensions in Scheme (a dialect of LISP). It’s available for Windows and Linux.

Update 3: CScheme is the integration of geometric kernels in a functional language.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 ;export the model (define (print-brep shape filename) (BRepTools_Write shape filename))   ;translate an object (define (translate obj x y z) (let ((vec (make-object gp_Vec% x y z)) (trsf (make-object gp_Trsf%))) (begin (send trsf SetTranslation vec) (send (make-object BRepBuilderAPI_Transform% obj trsf #t) Shape))))   ;make a structure from two given object (define (structure obj1 obj2) (let ((compound (make-object TopoDS_Compound%)) (builder (make-object BRep_Builder%))) (begin (send builder MakeCompound compound) (send builder Add compound obj1) (send builder Add compound obj2) compound)))   ;make a structure from a list of object (define (composite lis) (if (list? lis) (cond ((= (length lis) 0) (error "empty list")) ((= (length lis) 1) (car lis)) (else (make-compound (car lis) (composite (cdr lis))))) (error "Not a list")))   ;build a torus (define (torus radius circle) (make-object BRepPrimApi_MakeTorus% radius circle))   ;build a sphere (define (sphere radius) (make-object BRepPrimApi_MakeSphere% radius))   ;calculate the torus dimension (define (radius z) (sqrt (- 1 (* z z))))   ;make all torus objects (define (torus-on-sphere the-list) (composite (map (lambda (z) (translate (torus (radius z) 0.05) 0.0 0.0 z)) the-list)))   Final export operation ;export the model (print-brep (structure (sphere 0.3) (torus-on-sphere (list -0.93 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 +0.93))) "./torus.brep")

and PLaSM: a functional language for computing with geometry.

1 2 3 4 5 6 7 8 DEF points1 = <<0,0,0>,<0,3,4>,<0,6,3>,<0,10,0>>; DEF points2 = <<3,0,2>,<2,2.5,5>,<3,6,5>,<4,8,2>>; DEF points3 = <<6,0,2>,<8,3,5>,<7,6,4.5>,<6,10,2.5>>; DEF points4 = <<10,0,0>,<11,3,4>,<11,6,3>,<10,9,0>>; DEF dom = intervals:1:12;   MAP:(beziersurface:< points1 , points2 , points3 , points4 >): (dom * dom);

Thanks to Kristoffer Josefsson for those two.

Update 4: Parametric Parts allows consumers to create and print 3D parts through our web-based platform. Anyone can make an idea come to life, even without technical expertise or prior 3D experience. It apparently uses  CadQuery for its backend.

CadQuery is an intuitive, easy-to-use python based language for building parametric 3D CAD models. CadQuery is for 3D CAD what jQuery is for javascript. Imagine selecting Faces of a 3d object the same way you select DOM objects with JQuery! Thanks to Monique for pointing them out.

Let me know if I’ve left any off the list?

# Emacs: yank a line multiple times from the kill ring

Today I needed to copy a line multiple times in emacs. I needed 8 copies, but how to do that in emacs short of pressing C-y to yank 8 times? My initial guess was to try C-u 8 C-y but that yanks the 8th item from the kill ring.

Fuco on #emacs supplied the awesome answer:

F3 C-y C-8 F4

So what does that do? F3starts recording a macro, C-yyanks the line, then within the macro itself you can add a numeric argument of 8 using C-8. End recording of the macro with F4. Emacs then runs the macro 8 times. Recall that pressing F4 after ending recording of the macro runs the macro.

# Setting alternate hreflang in WordPress

UPDATE 2013-05-03:

After writing this I found out my approach was incorrect. I have since removed the code as it was not useful.

Dan’s team was kind enough to point me to Virgin Australia‘s site. If you inspect the source and search for hreflang, you’ll see how it should be done.

/UPDATE

After seeing the excellent talk by Dan Petrovic at the Melbourne WordCamp, I went to find out more about the <link rel=”alternate” hreflang=”en-AU” href=”http://somesite.com.au/” />. He has an article describing it. Essentially if you have multiple sites that have similar content (but not exactly the same) then you can instruct google that the sites serve different regions by using the rel=alternate hreflang=”en=gb” options for the link tag.

A common scenario that you might find this useful would be in online stores where there is a different store for each country.

eg. for site somesite.com.au you want a <link> tag like this:

and for somesite.com you might want a tag like this:

and you want to remove the rel=”canonical” option too.

I couldn’t find a plugin that would implement this in WordPress so I wrote one and put it up on github. Yoast does not have an option for this as far as I can tell.

At some point I might put it up on wordpress.org too if it seems like there is interest in it.

# There will be Emacs Chocolate at the #Emacs Meetup Melbourne

I decided to make something special for the inaugural Australian emacs meetup.

If you want some, come to the Melbourne emacs meetup.

Sofia’s Camberwell.
Camberwell 3124
Victoria, Australia

Friday April 26, 2013 6:00 PM

# Launching cygwin emacs from native win32 programs

My business’s accounting program, which I’ll call Canopus, has issues. One of which is that it assumes wordpad.exe will be in c:\windows. As far as I know, Microsoft moved wordpad.exe’s default location away from c:\windows about 20 years ago. Canopus live in hope that it will be there so installing Canopus always requires one to copy wordpad.exe to c:\windows

The other problem with Canopus is that it does not fork when launching wordpad.exe, so you can’t continue using it until you close wordpad. This is stupid as most likely you need the information in wordpad to do further work in Canopus.

So a long time ago I came up with a solution. With the help of a friend (well, he wrote it for me in Delphi) I developed a small program called wordpad.exe which reads a config.ini file to configure which editor to open. It makes a copy of the file in $1 and launches whatever editor you specify in the config.ini with $1 as its parameter.

This worked well and everyone was happy until I decided to use cygwin emacs instead of the native win32 compiled emacs.

The problem is that cygwin emacs expects paths to be of the unix flavour (/home/jason/whatever) rather than the dos flavour (c:\users\jason\whatever). And so the rabbit hole needed and extension.

I didn’t want to have to modify my wordpad.exe program as that would require me to get the lazarus (open source delphi replacement) toolchain working again, so I decided to write a shell script wrapper to do it.

launchemacs.sh:

#!/bin/bash /usr/local/bin/emacsclient.exe -n $(cygpath "$1")

[Config]
Exe=c:\cygwin\bin\run.exe
option=/usr/bin/bash.exe "/cygdrive/c/Users/jason/launchemacs.sh"

You can see that wordpad.exe launches the cygwin run.exe which calls the launchemacs.sh file with the first parameter.

# Project Euler No. 2 in Emacs elisp

My second Project Euler solution.

Project Euler No. 2

This was a little tougher to solve than No. 1. I decided to use recursion to solve it, and as I haven’t had to write anything that used recursion since I was at Uni, it took me a while go remember how to do it. Also, it was an elisp learning exercise.

Things I learnt:

1. successive statements inside an if statement need to be inside a progn.
2. passing in the evens variable was the way to solve this without needing a static variable. Thanks to spacebat for that one. Apparently that is the functional programming way of doing things.
;; Project Euler no 2. Calculate the sum of all even terms in the
;; fibonacci sequence of numbers that do not exceed 4,000,000

(defun fibonacci (x y)
"calculate the next number in the fibonacci sequenece"
(+ x y))

(defun fibonacci-sum  (fib1 fib2 target &optional evens)
"find the next fibonacci number bigger than target, given fib1 and fib2"
(unless evens
(setq evens 0))
(let ((fib3 (fibonacci fib1 fib2 ))
)
(if (<=  fib3 target)
(progn (if (zerop (mod fib3 2))
(setq evens (+ fib3 evens)))
(message (format "fib3 is: %d, evens: %d" fib3 evens))
(setq fib3  (fibonacci-sum fib2 fib3 target evens)))
(format "fib3: %d > %d target, evens = %d" fib3 target evens)
)
)
)

(fibonacci-sum 0 1 4000000)


# Install perl modules automatically using lib::xi

So you’ve downloaded a really cool perl script but it has 200 module dependencies? You could just install them one by one with cpanm or, you could use lib::xi. It automatically installs modules your perl script uses.

 # to install missing libaries automatically
\$ perl -Mlib::xi script.pl