tung's blog

Where in the world is me?

tung's picture

Another 1 hour upgrade for Drupal. More voodoo rain dances required, but this time, the core Update Status checker module doesn't work: enabling it causes all admin pages to blank out.

It's just as well, because I've done most of my updating elsewhere.

@tungtn is where I post interesting articles that I find on Hacker News, and the occasional thought.

I talk with people on Google Buzz. If you've got Gmail, check it out, and feel free to follow.

I think that's about it.

Read more »

JavaScript: Does removing comments from a function make it faster?

tung's picture

A few days ago putting comments in a function slow them down. I decided to put this to the test: I couldn't believe it unless I saw it.

The method I used was a statistical hypothesis test. I'm not here to teach maths (I wouldn't be very good at it anyway), but the process involves gathering raw data, setting up hypotheses about what distribution those data fit, and calculating how likely the data fit that distribution.

Read more »

Max-heap in Go

tung's picture

I was helping somebody on a forum a few days ago with a C++ max-heap implementation. I thought it might be fun to try it out in Go.

package main
 
import (
    "container/vector";
    "flag";
    "rand";
    "time";
)
 
var num = flag.Int("n", 10, "number of elements to heap sort")
 
func main() {
    flag.Parse();
    rand.Seed(time.Nanoseconds());
    v := vector.NewIntVector(*num);
    for i := 1; i <= *num; i++ {
        v.Set(i - 1, rand.Int() % 100)
    }
    heapSort(v);
    printHeap(v, 0, 0);
}
 
func left(i int) int {
    return i * 2 + 1
}
 
func right(i int) int {
    return i * 2 + 2
}
 
func parent(i int) int {
    return (i - 1) / 2
}
 
// Swap vec[i] with its parent if its larger. Stop at the top.
func maxHeapify(vec *vector.IntVector, i int) {
    if i <= 0 {
        return
    }
    p := parent(i);
    if vec.At(p) < vec.At(i) {
        temp := vec.At(p);
        vec.Set(p, vec.At(i));
        vec.Set(i, temp);
        maxHeapify(vec, p);
    }
}
 
// Given a list of numbers in any order, max heap sort it.
func heapSort(vec *vector.IntVector) {
    for i := 0; i < vec.Len(); i++ {
        maxHeapify(vec, i)
    }
}
 
func printHeap(vec *vector.IntVector, i int, nest int) {
    if i >= vec.Len() {
        return
    }
    for n := 0; n < nest; n++ {
        print("    ")
    }
    print(vec.At(i));
    print("\n");
    printHeap(vec, left(i), nest + 1);
    printHeap(vec, right(i), nest + 1);
}
Read more »

goblog: A proof-of-concept blog in Go

tung's picture

As if I wasn't bored enough, I've written a proof-of-concept blog using Go, that new language out of Google. I blogged about this language before, but I wanted to give it a real test drive, so I came up with this.

goblog on github

Pointers ahoy

The first thing I noticed when I got started was pointer trouble on my part. Go still has pointers like in C, but some of the syntax smooths over the differences.

Read more »

Impressions of Go: From the guy who learned it in 2 days

tung's picture

Go is that new-fangled language out of Google, and though I won't describe it (been done much better by somebody else), I will give a few opinions from the point of view of somebody who's written some code in it.

C-like syntax

It looks like C. Braces, parens and semi-colons all make yet another cameo in a programming language.

Read more »

Dirty Coding Tricks

tung's picture

Caught this on Hacker News:

Gamasutra - Dirty Coding Tricks

Hacker News discussion

Nine real-world stories of the horrible hacks that games programmers had to use in order to meet their deadlines. Here's one from the comments on the page by Ken Demarest:

Back on Wing Commander 1 we were getting an exception from our EMM386 memory manager when we exited the game. We'd clear the screen and a single line would print out, something like "EMM386 Memory manager error. Blah blah blah." We had to ship ASAP. So I hex edited the error in the memory manager itself to read "Thank you for playing Wing Commander."
Read more »

Status: Tea and other thoughts

tung's picture

I haven't written here often, because it's stunningly difficult to write something worth reading; only more so when your thoughts are fleeting and your Internet access is sparse. However, just to affirm that I'm still alive and kicking, I'd like to share some stuff I've been up to and thinking about.

First is my new project: Tea. Tea is a simple 2D game development library for Ruby. It's made for the sort of grass-roots development that was popular with QBASIC back in its era. Tea is designed with simplicity in mind: 0 is better than 1, and 1 is better than 2, but at the same time, it won't avoid a valuable, convenient feature just because it can be built from other features. Graphics, input, sound and text are the pillars of Tea.

Tea is making slow but steady progress. Events have been blasted right through. Sound and text are waiting on graphics, and speaking of graphics, that has been a royal pain to deal with so far. Why? In the words of Joel Spolsky:

All non-trivial abstractions, to some degree, are leaky.

To demonstrate, I'll describe what I'm dealing with in the graphics subsystem of Tea. Tea is built largely on Ruby/SDL, which, surprise surprise, provides a Ruby-like flavouring to SDL.

Read more »

RINGO! MOGIRE! BEAM!

tung's picture

I cast my eyes upon the landscape, and saw a third season. I despaired.

Bare-bones embedding Ruby 1.9 in C++

tung's picture

So I never have waste time trying to figure this out again, here's how to embed the current Ruby 1.9 into a basic C++ program.

1. Install Ruby 1.9

I'm running Arch Linux, so I can install the ruby1.9 package from AUR.

yaourt -S ruby1.9
Read more »

Compiler censorship? In my Drupal?

tung's picture

I don't know what the hell is going on, but if I enter "g plus plus" (no quotes, no spaces, plus replaced with plus sign), followed by a space followed by anything, my own blog gives me a 403 permission denied error!

I'd lodge a bug report, but to whom? Drupal, which has a million layers which may or may not be responsible for this? The GeSHi plugin for Drupal? GeSHi itself? The old, outdated PHP 4 installation? I don't have the will to debug yet more web crap, so I'll just post "around" it, if that's even possible.

Incidentally, that's why I haven't posted in a while: this error in a long blog post fooled me into thinking I couldn't post to my own blog. I'll post something I've kept on the back-burner right away.

Read more »
Syndicate content