Archive for January, 2008

JavaScript in a browser is dead!

Sunday, January 27th, 2008

I am sure, if you tried to make a Java applet in last 3 years, you were told that:

Java in a browser is dead - Flash and Ajax killed it!

While graphical rendering of a Java applet is somewhere around Flash’s its computational speed is magnitudes higher than that of Flash.

So why is it dead then? Because applets sometimes make browser unresponsive, and occasionally crash it. But flash..

Flash never blocks or crashes the browser!

Well, but… Java is growing a Consumer JRE which supposedly will not block nor crash –and– as Flash is becoming more powerful it sometimes blocks too, and it even crashes my browser at special occasions. I think at the end when flash will perform even better than now and Java will have Consumer JRE both will be more or less in the same spot — they only came there from the two totally opposite directions.

What does all this have to do with JavaScript? Well, In this Web 2.0 that we all love JavaScript is used and pushed further and deeper, so even JavaScript started blocking and crashing. And this is not even rare. Certain web services crash my FireFox on exit 50% of times. So I repeat:

JavaScript in a browser is dead! It shot itself in the head.

Ocaml: mini SDL example v3

Thursday, January 24th, 2008

This is the 3rd iteration of OCaml SDLCaml game example that I make and learn OCaml at the same time. Changes are:

  • keyboard input as it should be (multiple keys at the same time, diagonal speed same as orthogonal)
  • ship shoots bullets (ctrl)
  • very dumb enemy space ships besides rocks
  • a scene record that holds all elements of the scene

Few codebits. Here we define the scene record and a function that creates an empty scene.

type scene = { ship: ship ; bullets : particle list ; rocks : particle list;  aliens : particle list; }
let empty_scene = { ship = {poss = (vec2 0 0); shoot_count = 0} ; bullets = [] ; rocks = [] ; aliens = [] }

This functions handle bullets. First updates each bullet and second one looks at a key-map and creates new bullets if needed.

let update_bullets r = { r with pos = r.pos +| r.vel }
let make_bullets bullets keys ship_pos =
	match keys.shoot with
		| 0 -> bullets;
		| _ -> { pos = ship_pos +| vec2 16 16 ; vel = vec2 12 0 ; size = 5 } :: bullets

If you are asking yourself what is +| - it is a vector operator (infix function). We defined it like this.

let ( +| ) a b = {x = a.x + b.x; y = a.y + b.y}

Click here to see the full source

Again thanks a lot to all who commented and suggested code improvements on #ocaml IRC channel. Especially asmanur suggested a lot of great improvements.

So you think your web-app is secure? #3

Wednesday, January 16th, 2008

At the first post on this topic I wrote a list of known vulnerabilities of a typical LAMP web-app. Plan is to investigate where exactly does each of them apply to the web-app I am making more secure and patch them.

virus: source wikipedia

In the process I realized that there is another perspective/question here that is also very important. One is to fix “all” the holes, but you also have to ask yourself.

“What am I really trying to prevent here?”

In our case. We need to prevent anyone getting to (identifying) personal information of the users. That is the most important thing and all others are magnitudes of less important. Every other data we hold, if it gets “stolen”, meh.. if they delete, change it, we have the backups. But the privacy of the users is sacred. Too bad I can’t say what exactly we did now in this regard.

The analogy is this. You have area of people infected with some virus X. You can put roadblocks, test and disinfect all outgoing people, spray their cars, forbid mail communication, put fences to prevent wild animals to spread it but sooner or later something will get through. Or you can focus on a virus and find a way to prevent itself from spreading.

You can try to prevent the problem to get “out” , or you can try to remove the problem in the first place

Well, nothing is as perfect as theory so we do both.

Ocaml: mini SDL example 2

Sunday, January 13th, 2008

Images residue in an array now, we passed them around individually before. This is how we load and free them.

let load_images () =
	[|
		load_image "data/background.bmp" ;
		load_image "data/ship.bmp" ;
		load_image "data/rock1.bmp" ;
	|]
;;

let free_surfaces images = Array.iter (function(img) -> free_surface img) images;;

game screenshot

Input is better handeled now. Ship moves while you hold the appropriate arrow key down. But it is not as it should be at the end. If you start pressing more than 1 keys at once it won’t work as expected.

Rocks have been added. They are records that residue in a list. Those two functions are used for drawing and calculating/making the new rock. The power that OCaml gives you with records shows here a little.

let draw_rocks screen images (r:particle) =
      let { pos = p } = r in apply_surface p images.(2) screen;;

let update_rocks (r:particle) =
      { r with pos = if r.pos.x > (-r.size) then r.pos +| r.vel else (vec2 650 r.pos.y) } ;;

That +|is an operator we defined. It represents the addition of two vectors. Vectors and this operator are defined in 3 lines of code.

type vec2 = { x: int; y: int };;
let vec2 x y = {x=x; y=y};;

let ( +| ) a b = {x = a.x + b.x; y = a.y + b.y}

Click to look at the source code.

I warn you however. I am learning OCaml as I type this and this is the first time I use SDL also. If you notice any mistakes or stupidities let me know. I am still proud (and surprised) that there is no mutable or global stuff in the code. Basically one chat on the IRC hinted me how I should think in FP at all, much better than anything I read before, and it worked so far. I intend to post that IRC chat here soon.

Thanks to bluestorm on #ocaml IRC for proposing few improvements to the code. It has been updated.

OMG, OMG REBOL 3 is here!?

Wednesday, January 9th, 2008

You know. There are some things, that are very cool and are about to happen… someday. And you just wait and wait. Slowly a feeling creeps over that it is just never going to happen…

Well, BUT IT DID TODAY!

REBOL 3 - PUBLIC Alpha was released in its standard <1MB size. I downloaded it, it works, examples look great!

A quick scan through the new wiki docs showed that Rebol 3 somewhat changed it’s focus and philosophy to better in the two very important fields. It seems it’s more open in many ways than before, and more practical (competitive to other languages in doing stuff, not just as a language but as a toolkit).

To name just few features

  • Open implementation of interfaces and subsystems
  • Async networking
  • Multi-threaded
  • New graphical subsystem.

I think they use AntiGrain software renderer now which already proved itself with sore real big-time casual games (Wik and the fable of souls). I can’t wait to have time to play with R3 and feel some REBOLUTION!

—-

Btw. I accidentally came to a slick comparison of Ruby & Rebol. It very quickly shows what REBOL is and isn’t. Think of it as comparison of a more or less “normal” progy. language with REBOL :)

funny quote:

Ruby is a blend of ideas from other programming languages, with some new bits thrown in (no offense meant to Matz; Ruby is what I might be using if not for REBOL). REBOL is different; really different; and we don’t know how to exploit it fully yet.

Compiling Ocaml, SDL and OpenGL on Windows (mini tutorial)

Monday, January 7th, 2008

One of two ways to get OpenGL into Ocaml is by using GLCaml binding. It is up to date and alive. GLCaml also includes so called compact drop-in binding for SDL SDLCaml. I am not much of a low level guy so I had real trouble figuring out how to compile the thing on windows and almost gave up. But the author replied to my mail and gave me few crucial hints which made it all work.

NeHe tutorial number 9 in GLCaml

Here is what to do:

  1. Download and install Ocaml for windows (the MingW version)
  2. Install MingW. Install at least the C package, but NOT make.
  3. Install MSys (also from MingW site) which also installs its own make.
  4. Install the SDL library for mingw. Unzip and copy it to appropriate folders in mingw or make sure mingw can find it.
  5. Unzip glcaml.zip somewhere, and go to that location with MSys shell. When you are there run make in MSys.
  6. All examples should compile (the binding has many SDL and OpenGL) examples.

Thanks to Elliot for making the binding and replying to my mail. I hope I will dig Ocaml and make something concrete with it and this binding. Here is some more info and screens GLCaml and SDLCaml.

Enjoy the camel ride!

F.R.O.N. dec 07 was released

Sunday, January 6th, 2008

Oh, I saw on the forum that new F.R.O.N. is released. If you understand Slovene language you can read it here.

If you have no idea what F.R.O.N. is go here.

p. languages: Haxe is quite elegant

Saturday, January 5th, 2008

I had one evening of time for programming these holidays and I decided to make progress at QUBIDRAW. On my to-do list was to remake QUBI PAIRS game in flash. Now it is very shakily implemented in html+js.

I hadn’t programmed in haxe for more than a month, my mind was clear. I wrote code and it just worked. Code flew together without including the reasoning side of my brain. At the end I looked at it and everything was very neat, clean and minimal. After all the code written in haxe I only now see that Haxe is a very cool language !

I also implemented few paradigms here and there that I learned from FP (functional programming) recently. Immutable data and anonymous functions.

Just some nothing-special snippet of code from Qubidraw Pairs:

var col:Int = 0;
var row:Int = 0;
var getXFromCol = function(i){ return 40 + i * 100; };

for (id in picIds3)
{
	pics.push(new PairItem(app, id, getXFromCol(col), 60 + row * 80));
	col ++;
	if (getXFromCol(col) > 350) { row ++; col = 0; }
}

This code creates PairItem objects (the pictures you have to find pairs) and calculates/puts them into right position. N items per row, until the certain width is filled and then it goes to the next row. A WIP version can be played here.