Posts Tagged javascript

fun with nodejs and rabbitmq

The long awaited server side javascript revolutions is alive and well!

Here is a quickstart for funning around with nodejs and rabbitmq

The copy-pasta is from my retro machine at the house running ubuntu 10 (Maverick), but there’s little ubuntu specific stuff…

install nodejs

 % git clone https://github.com/joyent/node.git
 % cd node
 % sudo apt-get install g++ libssl-dev
 % ./configure && make && sudo make install
 % echo 'console.log( "go node!" )'  | node

install npm

As per the website, you can run the install script from curl.

Oddly enuff, to avoid running it as root, buddy suggests making your user own all of /usr/local.

Instead, I thought I’d add an npm user and setuid the npm stuff:

 % sudo adduser --gid 0 npm
 % sudo chmod g+w /usr/local/lib 
 % sudo chmod g+w /usr/local/share/man 
 % sudo chmod g+w /usr/local/bin 
 % sudo chmod g+w /usr/local/man/man1
 % sudo su npm
 % cd /tmp
 % git clone https://github.com/isaacs/npm.git
 % cd npm
 % ./configure
 % make && make install 
I tried setting 4755 on /usr/local/lib/node_modules/npm/bin/npm.js, but it complains when I tried to install some stuff..

Just have to use the npm user to install node-amqp:

 % sudo su npm -c "npm install -g amqp"
 % cd 
 % ln -s /usr/local/lib/node_modules

install rabbitmq

The out of the box rabbit for ubu10 was ancient bullshit!

The rabbitmq guys have some tips… basically:

 % echo deb http://www.rabbitmq.com/debian/ testing main | sudo tee -a /etc/apt/sources.list
 % wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
 % sudo apt-key add rabbitmq-signing-key-public.asc
 % sudo apt-get update
 % sudo apt-get install rabbitmq-server

It gets cranked up at install and there is a handy init script:

 % sudo /etc/init.d/rabbitmq-server status

a simple demo

So… this code runs fine on my mac, but is weirdly busted on my olde ubuntu box:

clear ; ./amqp-dee-dum.js
connected
ready
got the exchange
[hilarity ensues: try it out!]

I had to create new exchange named ‘tmp’, it wouldn’t let me use ‘amq.direct’ for some reason…

Anyhooo…

I think the code is pretty ez to follow if sorta copy-pasta heavy.

I hope to do a refactored version at some point…

what happened with the old rabbit

connected
ouch: Oversized frame 1342243080
cya!
FATAL ERROR: v8::Object::SetIndexedPropertiesToExternalArrayData() length exceeds max acceptable value

Using the non-crusty version everything worked fine.

Comments (2)

one application, two applications platforms

I wanted to try out a side-by-side of Haxe generating Javascript+Canvas versus Flash when I came across OctalJam’s post.

This method is really clean:

I modified my demo to add:

#if js
    neash.Lib.Init( "Container", 214, 50 );
    neash.Lib.Run();
#end

and a similar wrapper around “flash.Lib.current.loaderInfo.parameters.scale”

The side-by-side shows they look identical:

Haxe let’s you write the same application and deploy it via flash or HTML 5. How cool is that?

Leave a Comment

generation permutations of a set of sets

From time to time, the idea of creating all the permutations from a set of sets or array of arrays comes up. Here is a nice simple iterative implementation. The core is createPermutations. The inputs are comma separate lists of strings.

The Javascript is commented, but I think it will make more sense once you have played with it a little bit: http://brianin3d.googlepages.com/permute.html

Leave a Comment

Have Browser – Will Travel

These days I’m mostly a Java guy, but for a number of years now, I’ve been convinced the future of development is the browser.

Yup, I put my money on Javascript.

But… I also put a little bit of cash down on SWF. Once I found I could develop for it under Linux thanks to mtasc and later Haxe.

IMO, here are the rules:

  1. you have to be able to develop for it under Linux
  2. it has to run in the browser
  3. it has to be completely free (as in beer, as in cash)

Some people won’t like these rules and will want to write in ActiveX or some other proprietary crap, sorry, you can’t exclude developers. Every developer you turn away (Qualcomm, I am talking about your crappy BREW), is going to try and destroy you. Oh, maybe not directly, but we will seek out a platform where we can produce software, and that platform will kick their platform right square in the sitting down parts.

Other people will say that you will alway have to have a server for your clients. P2P shows that is just wrong. It was a better network model back in the day, until scaling squashed it and now bittorrent shows how it will scale. The right answer to where you persist your data is everywhere.

What about mobile devices? They will run HTML 5.0 browsers. They may also run flash. I don’t know why they won’t run Java. I really don’t. “My applet? Why hast thou forsaken me?”

What about OpenGL and DirectX? Too easy: canvas.getContext(“3d”);

But IE doesn’t support the canvas element you say! That is why IE must be destroyed. Safari, I’m putting you on notice. I don’t like hearing you not supporting Firefox API’s.

Cross-browser scripting needs to end now.

Today.

Refuse to support anything but Firefox.

Don’t think

  1. it is an accident you can’t write BREW applications for you Verizon phone
  2. Microsoft isn’t the reason the canvas tag isn’t used everywhere
  3. Apple doesn’t want to be Microsoft
  4. IBM loves Linux

Do think:

  1. major technology companies are doing everything they can to keep developers in check
  2. we will overcome
  3. OSS all the time
  4. you sell software, not code

Javascript or Haxe? The good news is we don’t really have to choose.

😀

---------------------
IE must be destroyed.

Comments (1)