2011-06-24

Python 3.2 binaries released in StaticPython for Linux

This blog post is to announce that StaticPython, a binary distribution of Python, has just released Python 3.2 binaries for Linux. (Previously StaticPython contained only Python 2.7 binaries.) Download links for the binaries:

  • python3.2: almost all built-in Python modules, C extensions (including sqlite3) and greenlet
  • stackless3.2: ditto, but with Stackless Python
  • stacklessxl3.2: ditto, and also OpenSSL (with the _ssl and _hashlib modules)

The Python 3.2 binaries of StaticPython can be useful on Linux and FreeBSD systems where Python 3.2 distribution packages are not available, and recompiling from source would be too inconvenient. They can also be used to demo the features of Python 3 for users with a little time and patience, and without a commitment to install it.

2011-06-05

PTetriS/HTML: A minimalistic, but correct Tetris-clone in HTML + JavaScript

This blog post is to announce PTetriS/HTML, a minimalistic, but correct Tetris-clone in HTML + JavaScript. Play PTetriS/HTML here, with a JavaScript-enabled browser.

PTetris/HTML was born to celebrate the coming 10-year anniversary of PTetris, the same Tetris-clone implemented as a Java applet and application. Play PTetriS here, with a Java-enabled browser.

Please note that the PTetriS games are not feature rich (e.g. they don't count the score and they don't show the next brick, and they don't have multiple levels). This is intentional, so they can work as a reference implementation of a correct Tetris game. By correct I mean that the board size is correct, bricks rotate in the correct direction, and the rotation pixel pattern of the bricks is correct (e.g. they don't jump up or down when changing the rotation phase). These properties are copied from the old game FUXOFT's Tetris2 (architecture: ZX Spectrum). There are many Tetris-clones available nowadays which are incorrect.

2011-06-04

How to download a https:// page in Ruby 1.8

This blog post shows an example low-level implementation of downloading a https:// page in Ruby 1.8. The reason why is this blog post was born is that the documentation of the openssl and socket Ruby modules didn't contain a working end-to-end example.

#! /usr/bin/ruby1.8
require 'socket'
require 'openssl'
# Returns a HTTP response header + body.
def download_https(host, port, suburl)
  s = TCPSocket.new('www.gmail.com', 443)
  begin
    ss = OpenSSL::SSL::SSLSocket.new(s)
    begin
      ss.connect
      ss << "GET #{suburl} HTTP/1.0\r\nHost: #{host}:#{port}\r\n\r\n"
      ss.flush
      ss.read
    ensure
      ss.close
    end
  ensure
    s.close
  end
end
p download_https('www.gmail.com', 443, '/')

Please note that this doesn't check the authenticity of the server, i.e. it will happily and silently accept self-signed certificates.