Hoorah Node.js!

Several months ago, I had a look at Node.js, just for fun.  I was getting more into JavaScript and thought it looked neat.  I didn’t do a lot with it, but I did go through a tutorial to build a web server that did math equations.  Nothing fancy.

Flash forward to today.

I’m working on an Andoird project where I need to download some JSON from a client’s server.  They asked for my IP earlier in the week so they could set me up with access.  Sadly, my busy life these days meant I couldn’t get to the project until Saturday, when lo and behold, I don’t have access to the server.  And it won’t be up until Monday, which makes the data download/parsing work I planned on doing a little harder.

Well, then I decided I would just put up the data on my web server, but then it’s coming as HTML (unless I mess around with it) which isn’t quite as realisitc.  Then I remembered Node.js, so I went back to it, fiddled about 10 minutes, and voila!  I had a web server that would distribute my JSON, and also show that it is receiving the proper query.  Plus, I got to mess around with Node, which is just a fun thing to do when you’re working on the weekend. :)

Here’s the code I wrote, which shows how easy it is to do quick server-y kind of stuff with Node.  It could have been done faster even if it was more fresh in my mind.

var sys = require('sys'),
	http = require('http'),
	url = require('url'),
	querystring = require('querystring');

var serverIP = "192.168.1.100";
var port = 3001;

http.createServer(function(req,res){
	res.writeHead(200, {'Content-Type':'application/json'});

	var q = querystring.parse( url.parse( req.url ).query );
        // write the query to the console.
	sys.puts( JSON.stringify( q ) );
	var s = {};
	if( q.t && q.t != "nw" ) {
	   s = { t : "now",
	        p : [ ..customer stuff.. ],
                c : [ ..more customer stuff.. ]
           };
	}

	res.end( JSON.stringify( s ) );
}).listen(port, serverIP);

sys.puts("Server running at http://" + serverIP + ":" + port + "/");

The Joy of Learning

I am a generalist by nature. I like to know at least a little about everything, and preferably a lot about most things. When it comes to software development, it means I’ve used a whole bunch of languages and frameworks and keep working on learning new ones when I can. Well these days, in addition to the Android and BB projects, I have some time to learn more stuff as well.  Some things I have to relearn since a consequence of using lots of different languages is that you tend to forget details in the lesser used languages.  For no reason whatsoever, here is a list of some things I’ve decided to work on.

Android

Mainly because of the Mindr project and the fact that I wanted to get into mobile app development (one goes with the other), I’ve been doing some Android development.  It’s Java based, so not that hard to get into other than having to learn the framework and application lifecycle.  Not difficult, just new.  I like the openness and ease of development and publication which makes it really nice for developers.  It’s given me a lot of ideas for other projects, once I get the time.  Of course, I should probably get a newer Android phone to play with as well.  And as I work on them, I’ll post here since that was the main intent of the blog.

HTML, CSS, Javascript

These kind of all go together.  When I was starting the BB port of the Mindr project, I looked at doing BB native or Webworks.  Since BB10 native development is significantly different from pre-BB10 native development, Webworks won.  At least code could be shared between the two versions even if they can’t be identical.  I’ve actually done web development in the past, but that was a long time ago and it has evolved significantly.  I really like it now and there are just so many things that can be done with it.  Plus, with Webworks or PhoneGap, I can still target mobile devices and make mobile apps with it if I want, which I may.  Some of those Android projects may well end up being PhoneGap.

PHP

Originally, I wanted to learn Ruby on Rails, but I didn’t have the time to get into the relatively steep learning curve required for Rails.  I’ve done PHP in the past, and figure if I’m going to have any kind of server/web app, I need something.  The nice thing is that PHP has a ton of frameworks out there.  A couple I’ve started looking at (but not learning yet) are CakePHP and Yii.  Leaning towards Yii right now as it seems to be more flexible and newer (although the creator worked on another PHP framework so it isn’t really completely new).  PHP is also supported by more hosts than Rails so may be a little easier to use in the real world.

ASP.Net

I’ve done a lot of .Net client development.  I’ve even designed an ASP.Net site and directed the actions of developers on the project, but not a lot of actual development.  If I ever decide to do a real job again, this is one option, so I’ll be at least reading up on it.  .Net development is more expensive to get into (vs free) so that is a bit of an issue.  Historically, it’s also been more verbose and less efficient than other solutions, but it’s still used quite a bit.

You may notice the lack of iDevices on here.  Mainly that is because I do not have any iDevices or a Mac.  It is probably something I will look at at some point, but I’m cheap and don’t want to buy a Mac.  From what I’ve heard, Apple also makes it a little more difficult to develop on than the others.  Plus, Android now has a greater market share, so may as well start there.

JavaScript Async <> Multi-threaded

Upon reacquainting myself with JavaScript, I learned to love the asynchronous nature built into JavaScript. It’s just there, with no real work to do on my part.  Want something to happen later?  setTimeout.  *poof* it’s done when you want.  Want something to happen continuously?  setInterval.  *poof* that’s done too.

Now the danger of this is that Asynchronous feels like you just sent something to the background  to happen later on another thread and won’t interfere with anything you want to do.  That is not the case.  At least within the browser anyway.
Continue reading

HTML5 WebSQL Database Joy

First, some history. I’ve been working on a Blackberry app for Mindr Mobile using WebWorks. Given how drastically BB is changing with BB10, I figured it was easier to use WebWorks in both legacy BB and BB10, rather than completely different development on each. So I got to dust off the HTML and Javascript skills.

Part of the app I’m building requires having a local database. OK, require might be the wrong word as it could be done with HTML local storage, but a database is easier, and more in line with the Android version of the app.  Conveniently, both Android and HTML5 WebSQL use SqlLite as the backend database as well, so I don’t even have to worry about differences in syntax (although I already use several db’s, so not a big deal), and should be able to port everything across easily.

Continue reading

Hello World!

Isn’t that how everything is supposed to be started?

This is going to be the home of my personal software development blog. I’ve been a developer for years, but now I’m doing some stuff on my own. I’ll be using this blog to log my experiences in the various technologies and what not.

I work with a startup doing primarily Android and BB webworks development, but I’ll probably play with some web dev at some point. Just not sure which of the specific web technologies yet. I also do a very little bit of consulting in primarily .Net, so that may show up as well. Who knows? That’s part of the adventure!