Friday, February 18, 2011

Chrome WebGL a no go, methinks

So, Chrome has WebGL on by default ... if you have hardware OpenGL 2.0 support, so far as I can tell. Well, I suppose modern Direct3D support on Windows would also suffice, given their ANGLE compatibility library.

One of the Linux computers I use regularly has no such support, so WebGL content doesn't render at all. Said computer is a little over two years old, so I suspect I'm not the only one with problems.

Saying "Sorry, the web doesn't work on your fairly modern computer" isn't good enough.

Until WebGL just works on everyday computers and handhelds across Chrome and Firefox and Safari (and Opera?), it's a no go for me.

Anyway, if I'm misunderstanding the state of Chrome WebGL support, let me know, but for now it's just vaporware in my book.

Wednesday, February 9, 2011

Web server in CoffeeScript and Node

So, here's a first stab at a web server using CoffeeScript and Node:

# Imports.
{createServer} = require 'http'
{parse: parseUrl} = require 'url'
{readFile} = require 'fs'
{resolve} = require 'path'

# Setup.
base = "#{resolve('.')}/"
log = console.log

# Server definition.
server = createServer (request, response) ->
reqPath = parseUrl(request.url).pathname
filePath = ".#{reqPath}"
status = 500
respond = (content) ->
response.writeHead status,
'Content-Length': content.length
'Content-Type': 'text/html'
response.end content
log "#{request.method} #{reqPath} #{status}"
# Verify the path is local to the base!!!
# TODO Better startsWith
if resolve(filePath).indexOf base
# TODO status = forbidden?
respond("")
return
# Handle the request.
if request.method is 'GET'
readFile filePath, (err, data) ->
if err
if err.errno is 2
status = 404
data = ""
else
status = 200
respond(data)
else
respond("")

# Start the server.
port = 8080
server.listen port, ->
log "Running on #{port} from #{base} ..."

Not so bad. Probably could be cleaned up. I get tangled in CoffeeScript sometimes, but usually it's straightforward.

I don't drink coffee, but this is nice little scripting all right.

Wednesday, February 2, 2011

Python import angst

I've said it before, and I'll say it again, Python importing stinks. Either you corrupt your module namespace, or you put imports in all your individual functions. Both are horrible options.