Raspberry Pi - Node JS

Raspberry Pi - Node JS

So i finally got my pi! I went to micro direct at the weekend, turns out they have lots in stock!! so I cancelled my order with RS components as it was delayed until probably next year Now i have raspian up and running, i need a project!! I'm tempted to try out raspbmc, but i think my first project to try out will be using my pi as a server. First I need to setup SSH and FTP, this shouldn't be too difficult, then i can install Node JS. Its quite difficult looking for tutorials on this kinda stuff as its all relatively new, but I think i'll be following this link http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=18775 which seems fairly straight forward! ...but what to do next? I have been trying out some of the features of jQuery mobile, so maybe I'll try some kind of client server type app? This link should call straight into my pi, running node js

Long overdue update - Functional programming in scala

Long overdue update - Functional programming in scala

Its been a while since i managed to get the time post on my blog, I've been really busy with work and home life,
I've recently enrolled in an online course. Functional programming in Scala.
I haven't really touched upon much function programming (except for javascript and a bit of F#). I like it! And i can see its uses! It feels a bit weird entering back into the java world, firing up eclipse etc. I guess i have just become  reliant on the friendly features of Visual Studio.

Anyway, here are the answers to the assignment I just submitted for the Functional Programming in Scala!

Pascals Triangle
  1.   def pascal(c: Int, r: Int): Int =
  2.     if (c == 0 || r == c) 1
  3.     else (pascal(c - 1, r - 1) + pascal(c, r - 1));
Parentheses Balancing
  1. def balance(chars: List[Char]): Boolean = {
  2.     def countParenthese(index: Int, list: List[Char]): Boolean = {
  3.       if (index == 0 && list.isEmpty) true
  4.       else if (index < 0 || list.isEmpty) false
  5.       else if (list.head == '(') countParenthese(index + 1, list.tail)
  6.       else if (list.head == ')') countParenthese(index - 1, list.tail)
  7.       else countParenthese(index, list.tail)
  8.     }
  9.     countParenthese(0, chars)
  10.   }
Change Counting
  1.  def countChange(money: Int, coins: List[Int]): Int =
  2.     if (money == 0) 1
  3.     else if (money < 0 || coins.isEmpty) 0
  4.     else countChange(money, coins.tail) + countChange(money - coins.head, coins)
  5. }

No Sleep!!!

No Sleep!!!

So i did not manage to get much sleep last night, work up around 3, and couldn't go back to sleep so started coding! I started having a look at PhoneGap again. Its something i have tried out in the past, but never really grasped what i would use it for. I think now i could try out a few Html5 games, since i enjoyed working on the game for the JS13k competition!

So far i have setup the Cordova solution, and have implemented a simple FPS on the canvas.
I cant believe how simple it is use, I also deployed to my HTC Sensation and Xperia X10 and performance seemed resonable.

Its not very good on my laptop, but then again what did I expect on a lowish spec laptop!

I guess i have to see how far i can push the app, its always more complicated working on supporting multiple devices!!

General Update

General Update

Finally my submission is up on the JS13kGames site, its good to see it up finally!

The games by other people seem pretty cool too, I've never created a HTML5 game, nor entered any sort of competition to create some software, so its been real hard to judge what level is expected etc. I suppose the 13k limit is pretty cool, as it makes you think more about what you are coding, and its more about what you can fit in rather than making it look nice!

In other news, my google rank seems like its getting up there, I annoys me that everytime i google my name it comes up with some horse photography or some rock and roll geezer. Its about time i got on top!

I've also decided to give up on the bouncing ball game thing, I'll just leave my AgentXIII game in the JS13k competition as the bouncing ball game isn't really going anywhere; and now i have coded the logic, i'm getting real bored adding new platforms/walls/hazards! I enjoyed coding gravity etc, it's something I don't get to do everyday

Who knows, maybe one day I'll pick it back up!

Bouncing Ball Example

Bouncing Ball Example

So after seeing a few other examples of peoples entries for js13k competition, i realised i need to step it up a notch! I'm new to the whole html5 canvas, and game development in general, (I'm an App / Web developer, not a game developer!) so i started a new game.

I dont know where i am going with this, but here is POC so far, its like a bouncing ball type thing. So far I have almost nailed Newtons law (still a bit laggy!) in its most basic form and the concept of trajectory. Hopefully an idea will happen as I keep implementing things.

Heres the POC so far:
Bouncing Ball Example

  • I've now updated this to include inverted gravity logic, and also platform collision detection logic. I just need something to create with it now!! I still cant work out why it runs so slow in firefox!! In chrome, its fine

js13k game submission and general javascript rant

js13k game submission and general javascript rant

So i finally to round to finishing my 13k game, its not too fancy, just simple, but I like simple games :)

It really surprised me that I have spent many an evening working on random ideas for android games etc. (I've probably worked on over 50) and never finished one [ Except my POC Triple Triad Card List ], yet with this 13k game I managed to complete in a couple of nights! Maybe I should start playing around with html5 and javascript more, its just soooooo easy to get everything up and running, and i find debugging the code much nicer using firebug than using eclipse (for android)

And I guess knowing more and more about javascript can only be a bonus, as it seems like that's the way we are headed! Javascript is not a language i have ever officially studied, i just picked it up as I went along because i needed more functionality than html only supplied.

Classic example: today i realised that from a function, you can get all arguments passed in, but in array form by using the arguments object. I never knew this until today! Its scary how something simple like that can catch you out if you don't know a language inside out. I guess it also shows that someone can use complicated frameworks, test suites (jasmine etc.) yet not know something relatively basic. I guess you never really need to know something until you need to use it to solve a problem!!

...Guess it's time i got the textbooks out!!

Importance of good javascript convention

I've been writing my js13k submission whenever i have had chance over the last few days, and it's made me think more about the way i write javascript.

I haven't has much experience in my working life with javascript, i've dabbled here and there (moreso in my current role). I've read multiple design patterns that can be implemented using javascript, but i still tend to write javascript in an oop style, asd i just find it easier to follow. I always think separation of concern is the most important thing to start of with; I find that if you don't start separating things out at the earliest stages, the code you write becomes more and more unmanageable as you write it.

The way i like to write javascript - using IOC where possible: This is what i call a View Controller pattern, it separates the view code (if using jQuery etc.) and the controller. It makes testing of the code very easy, you only really need to assert that methods were called on the controller, then test the view separately.

I have tried to apply this pattern to my js13k game, but since I haven't had much experience with game code (I spend 99% of my time writing business logic etc.) it kind of follows, but not really strictly. Plus normally I would write test driven, thats probably where the game went wrong!!
1:  function View(){  
2:    return {  
3:      getSomeValue: function(){  
4:        return $("idOfElement").val();  
5:      },  
6:      setSomeValue: function(value){  
7:        $("idOfElement").val(value);  
8:      }  
9:    };  
10:  }  
11:  function Controller(view){  
12:    Controller.prototype = this;  
13:    Controller.prototype.view = view;  
14:  }  
15:  Controller.prototype.Initialise = function(){  
16:    //constructor code  
17:    var controller = Controller.prototype;  
18:    controller.SomeValueChanged();  
19:  }  
20:  Controller.prototype.SomeValueChanged = function(){  
21:    var view = Controller.prototype.view;  
22:    view.setSomeValue("value");  
23:  }  
24:  domReady(function(){  
25:    var view = new View();  
26:    var controller = new Controller(view);  
27:    controller.Initialise();  
28:  });  

JS 13k Html Game

This should be fun... there's a competition running at the moment (ending 13th Sept) to create a full javascript / Html5 game that is under 13k in size (minified)

Since i haven't had much exposure to Html5 canvas etc. it will be a good chance to try a few things out!
I'm thinking of having some sort of strategy game. At the moment i'm just getting the Game Runner logic in place, its already proving to be not too easy, without using 3rd party code!

Here is what I have done so far: Its coming in at about 7kb Zipped. I think i should be able to make the 13k limit, I just need to learn how to draw images using lines and rects, that should save me some kb, so far i have one 100x100px png image (weighing in at 2.6kb, if i add any more its going to eat up all my code space!!)
I really like the space effect, its basically 520 random generated points on a 2d plane, I iterate through each point but also iterate a for(int i=0; i < 5; i++) then modulus the index of the point. I move each point 2 px to the left. This creates the illusion of layers of stars each layer moving at a different speed. Its pretty cool, i haven't done anything like it before!!
I just noticed the images dont load, oh well ill upload a working copy once i do some more on the game
Update - an updated version of the game so far: 20/08/2012 Not too far from completion!
Agent XIII Game

ATV2 Webserver - Lighttpd

So I've been pondering for something to do all morning on my day off work, and i came across this pretty cool article, http://www.macminivault.com/atv-webserver/

Basically it is possible to install lighttpd on the ATV2.
...Now I've already jailbroken my shiny little black box to install XBMC, so this should be a nice little project that i can run in the background that will keep running costs cheap and means i wont have to buy some web hosting. Lets just hope my ISP starts to be more reliable!

It looks like you only need to run a few commands over SSH
 - SSH in and change the root password<br />  
 - Use apt-cache and apt-get to find and install lighttpd<br />  
 - Use SFTP to upload a /etc/lighttpd.conf config file for lighttpd<br />  
 - Within /usr/sbin/ run lighttpd-angel -f /etc/lighttpd.conf to start lighttpd<br />  
 - Write a plist file in /Library/LaunchDaemons to launch lighttpd on boot  
  Hopefully i should be able to serve some content to my blog straight from my ATV!

Online Reputation

So I've been reading a lot recently about "Online Reputation" and how important it is going to be in the future, Apparently its common now for employers to do a "Google Search" and have a look at what you have achieved in online communities. I think this is a positive, I mean I do like to go onto sites like StackOverflow and help people out with programming related problems, its just the negatives... What's to stop someone posting something bad about you online? I mean everyone has a past and we all have the odd photo on Facebook we don't want potential employers to see! The thought is a little bit scary!!