2012-01-06

Ghetto DNS

This is probably stupid, but…

I start my EC2 instance only when I need it but a while ago it was needed pretty often and figuring out the IP every time I wanted to SSH to the machine got annoying quickly.  Using the Dropbox Uploader bash script it was easy to set up a poor man's DNS since Amazon provides a way to figure out the public IP of an EC2 instance.

So by doing:
curl -s http://169.254.169.254/latest/meta-data/public-hostname
and using Dropbox Uploader one can put that result into a text file (say ec2-hostname.txt) in a Dropbox folder and use it in an SSH command as follows:
ssh -i your-amazon.pem username@`cat ~Dropbox/ec2-hostname.txt`
This solution had a certain gum and wire charm that I had to try it out but it only suffices for one man in his attic. If you want robust and scalable solution you'll need to use real DNS or Amazon's Elastic IP.

Labels:

2011-10-19

VirtualBox Common Lisp Environment for Google AI Ants Challenge

(see the end of this post for remarks I've gotten about the vbox image)

So, the next Google AI Challenge seems to be almost ready to get going, albeit six months later than I expected.

As blogged about earlier this year I have been worked on the Common Lisp starter bot for the challenge, an alternative starter bot with a proxybot, some YouTube videos and now a VirtualBox image with an Emacs+Slime environment ready to go.

Due to the long delay for this challenge to get started some of these projects aren't quite up to date anymore but they should still be quite usable and at least get you started or help you along.

The VirtualBox image is up to date as of writing this post and any comments on it would be welcomed. I will not make a new image (although someone else is free to do so) but if possible I will provide a patch on the AI Challenge forums.

On booting the image it will start up SBCL, Emacs and Slime (connected to SBCL) with some instructions in the scratch buffer.  Perhaps it is a good start for another Lisp-in-a-box project.

I am not sure how much time I will be able to spend on the current challenge due to also participating in the online Introduction to Artificial Intelligence and starting a three month sabbatical gig writing an iPad client for a startup November 1st.

Specific Remarks about the VirtualBox Image

14:23 < Xach> the remapping of [] and () confused me though.
Right, I've been computing like this for so many years that I totally forgot about this.  The parens have been swapped with the brackets otherwise Lisp programming becomes quite painful.  If you want to reset this check out keycodes 18, 19, 34 and 35 in ~/.xmodmaprc and reboot the image.

Now that I think of it, Control and Caps Lock are probably swapped as well.  That's done in the ~/.xmodmaprc as well.

Labels: , , , , ,

2011-09-25

Adding Text to PNGs

(I'm putting this out here since Google queries for this situation didn't turn up anything useful for me.)

Last night I had to add some text ± 5000 PNG files and I knew about Zach Beane's ZPNG package for reading PNGs but I didn't know of a package that would read them.

A quicklisp:system-apropos turned up png-read written by Ramarren which looked simple enough to use so I went with that. After initially failing to get ZPNG to use png-read's image-data slot I gave up and wrote a little loop to copy the values over to zpng:data-array. This was succesful after one or two tries:

(asdf :png-read)
(asdf :zpng)

;; http://imgur.com/qtriH.png
(defparameter png (png-read:read-png-file "qtriH.png"))
(defparameter zpng (make-instance 'zpng:png :color-type :truecolor
                                  :width (png-read:width png)
                                  :height (png-read:height png)))

(loop for y from 0 below (zpng:height zpng)
      do (loop for x from 0 below (zpng:width zpng)
               do (loop for rgb from 0 below 3
                        do (setf (aref (zpng:data-array zpng) y x rgb)
                                 (aref (png-read:image-data png) x y rgb)))))

(zpng:write-png zpng "tmp.png")

I'm sure Zach had a good reason to reverse the x and y in ZPNG but I can't deduce it.

So, reading and writing the files was working but now I realized ZPNG didn't have any functionality for generating text. (Why should it? It shouldn't.) I started thinking of Vecto since I had used that before and also recalled that it actually used ZPNG for saving PNGs. Now all I needed to do was getting the original image into Vecto so text could be written over it.

Going through Vecto's source showed me I could get at the ZPNG object through the (shadowed) *GRAPHICS-STATE* global. It wasn't exported from the Vecto package but since I was in hack mode anyway it didn't really matter. I used the (slightly adapted) code above, drew some text, did a VECTO:SAVE-PNG and got an empty image.

In Vecto's source I noticed the ZPNG object had four channels instead of the three I was using so I set the fourth channel (alpha) to opaque and got my input PNG back with the custom text generated by Vecto. Done!

(asdf :png-read)
(asdf :vecto)

(use-package :vecto)

;; http://imgur.com/qtriH.png
(defparameter png (png-read:read-png-file "qtriH.png"))
(defparameter zpng (make-instance 'zpng:png :color-type :truecolor
                                  :width (png-read:width png)
                                  :height (png-read:height png)))

(with-canvas (:width (zpng:width zpng) :height (zpng:height zpng))
  (loop for y from 0 below (zpng:height zpng)
        do (loop for x from 0 below (zpng:width zpng)
                 do (loop for rgb from 0 below 4
                          do (if (< rgb 3)
                                 (setf (aref (zpng:data-array (vecto::image vecto::*graphics-state*)) y x rgb)
                                       (aref (png-read:image-data png) x y rgb))
                                 (setf (aref (zpng:data-array (vecto::image vecto::*graphics-state*)) y x rgb)
                                       255)))))
  (set-font (get-font "font.ttf") 32)
  (draw-centered-string (floor (/ (zpng:width zpng) 2))
                        (- (zpng:height zpng) 80)
                        "Hello, World!")
  (save-png "tmp.png"))

Labels: , , , , ,

2011-07-31

What has happened to David O'Toole?

Update: he linked me to this restatement on #lisp: http://cryptome.org/0005/dod-lisp-sol.htm

Does anyone know what has happened to David O'Toole?  He hasn't been heard of since a last curious post to the lisp-games-dev mailing list: http://lists.common-lisp.net/pipermail/lisp-game-dev/2011-July/000158.html (read the whole thread)

His website, blog, twitter and github have all been either removed or cleared:

Labels: , ,

2011-07-23

Common Lisp Proxy Bot Videos for Google AI Ants Challenge

I have made two screencasts showing the setup and usage of the proxy bot for the upcoming Google AI Challenge. This was at the request of McLeopold.

For the Planet Wars challenge I've tried to explain the use case for a proxy bot on the forums. Please read that post if you have no idea what the proxy bot does, although I will try to sum it up now: the proxy bot allows one to develop your actual bot in the usual 'Lispy' way[1] while the game engine runs and kills the proxy bot.

Since it uses sockets for communication it ought to work for other languages than Common Lisp but this hasn't been tested.

[1] Running Lisp image and, for example, Emacs + Slime.





Labels: , ,