CoffeeScript 101

mars 3rd, 2013 / No Comments » / by istenes

Last week I had a little talk about CoffeeScript over at HiQ. It was short but meant as a basic introduction to the language and the tools to work with CoffeeScript. The talk was all in swedish and can be viewed here: https://docs.google.com/presentation/d/1u4HoCJJfo0Vyia2S-He91tNxVfy337_-QD-bp9XOTKA/edit?usp=sharing

I had a quick session showing of what CoffeeScript can do, including a simple task list manager (non GUI). The task list manager is made up by two classes. Task, which is the regular task instance containing a name and function for setting it to done or not done. TaskList which is the manager of tasks which can create and read all the tasks. Both files can be compiled into a js file using:

coffee -cj todo.js task.coffee tasklist.coffee

This is what the task.coffee file looks like this:

class Task
	constructor: (@name) ->
		@done = false
 
	getName: ->
		@name
 
	getDone: ->
		@done
 
	setDone: (@done) ->

And for the tasklist.coffee

class TaskList
	constructor: (tasks...) ->
		@tasks = []
		for task in tasks
			if task instanceof Task then @tasks.push task
 
	getTasks: ->
		@tasks
 
	addTask: (task) ->
		if task instanceof Task then @tasks.push task
 
	getAllDoneTasks: ->
		tasks = []
		for task in @tasks
			if task.getDone() is true then tasks.push task
		tasks
 
	getAllUnDoneTasks: ->
		tasks = []
		for task in @tasks
			if task.getDone() is false then tasks.push task
 
		tasks

Tags: , , , , , , ,

Highlighting node.js

februari 10th, 2012 / No Comments » / by istenes

Have you heard of node.js? Maybe you’ve seen it popping up on your twitter, google+ or facebook feed. I first heard about it from a friend who was using it in a new commercial project. When he told me about it I was might confused at first. Instinctively I thought that it was another js lib doing some cool stuff like jQuery or Prototype. But it’s not, really not at all. This might blow your mind but node.js is basically server-side javascript. Let me elaborate.

You could compare node.js to Ruby or Python, it runs your non-compiled scripts. It lives on your server (Linux, Windows, Mac) and is used for network stuff. For example you can easily create a tcp, udp or even a http server. It has an interactive shell where you can start your node files. A node file is written in javascript with an extended API for node.js functionality. It is basically a javascript vm based on googles V8 engine which is google chromes javascript engine. If you never heard about google v8 you should definitely check it out. This is how nodjs.org describes node.js:

”Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”

Sounds pretty sweet, but what does it all mean? Ryan Dahl does a pretty good job explaining it, check out the video below.

So what can I do with node.js? Well for one thing, one big thing, that I will use it for is as a game server. Currently I’m doing a HTML5 game with network support for more player. It will be more of a tech demo then a released game. To do it even faster I will use the awesome node plugin called nowjs, check out some examples of nowjs here. More info as it advances :^)

Tags: , , , , ,

Emotiv dev kit – Unboxing

januari 19th, 2012 / No Comments » / by istenes

Got my Emotiv dev kit! Here are some pics:


The box that contains the artifact to unlock your mind.


Behold! Every item in the box fits perfectly, easy to unpack an pack down.


The USB dongle for connecting to the EPOC headset.


16 Felt sensors in their hydrator pack. All these sensors need to be soaked and attached to the headset before each use. After use, they should be removed from the headset and put back into the hydrator pack.



Contact lens liquid, used for soaking the felt sensors. Had to use a lot the first time I used the headset. This is way better then using some sort of gel, doesn’t get sticky, messy and no smell.


USB cable, for charging the headset. You can’t use this as an alternative connection as far as I know.


And here is the headset itself! Had a bit of a hassle the first time putting it on, but just after some uses I can put it on with ease. It doesn’t feel weird wearing it, and my glasses is not in the way. But it’s really tedious installing and removing the felt sensors each time I want to use it.

Another post will come soon where I will show it in action. It will also feature me wearing this dorky thing :^)

Cheers!

Tags: , , ,

Emotiv Dev kit ordered!

januari 9th, 2012 / No Comments » / by istenes

I recently ordered a dev kit from Emotiv and just found out that it will be here this Friday!

So what is this Emotiv stuff?
Emotiv is the company behind the EPOC neuroheadset, a wireless headset that reads neuro-signals basically. I won’t get into what a neuron is but if you want to read more about that sort of stuff check out the wikipedia article. It can read two types of major neuroscience branches (as they are called on the wiki) Cognitive and Affective. To make this easy we could say that the cognitive part is your conscious thoughts and intent while the affective part is your emotions. It can also read your face expression and has a gyro.

So what can you do with it?
A lot! Imagine using this headset in games, where you use your thoughts as input. Some people has connected it to their homes to switch on and off lights by just thinking about it. Another guy built it to control his wheelchair by using facial expressions. I can’t wait to get started, I noticed this project 2 years ago but I don’t think they shipped internationally by that time.

it currently only supports Windows but both OSX and Linux support (yay!) is in beta stage. So right now the dev kit contains a few dll files that you can access with C\C++, C#, Java (with jni), mathlab (I think) and other languages where you can communicate with win dlls. I’ve that there is a Unity plugin for this as well. The dev kit also contains a few applications such as a control panel for the EPOC headset.

Is this the future for gaming and human to device interaction? I don’t know, but I will blog about my experience of it when it gets here. Currently my only concern is that it has some latency, making action based games hard to create. Check out the videos below to see more of this awesome product!

Read more about Emotiv and EPOC here: http://emotiv.com/



Tags: , , , , , , ,

Classic Ubunut in 11.10

oktober 21st, 2011 / No Comments » / by istenes

This one goes to the stickies. Simple get the gnome-panel package and you should be fine.

sudo apt-get install gnome-panel

Now go to the login screen settings and change the default session to Ubunut Classic.

Done.

Tags: , , , , , ,

Raspberry Pi – Yum Yum!

oktober 20th, 2011 / 2 Comments » / by istenes


I’ve hear rumors that this little baby will be released November\December this year! I will most definitively get me one of those for experimenting, especially for gaming, see the sprite and graphics tech demo below.

UPDATE: I got a tweet from Raspberry Pi yesterday saying that they are still on track for releasing it this year.

So if you never head of Raspberry Pi (not many have) here is a quick summary.

It’s a single board computer, unlike it’s ”competitor” Pico-itx which is only a motherboard. So this means that all the ports, memory, cpu, gpu etc. is already mounted on the board. It will be bundled with Debian but any other OS compatible with an ARM processor should work (Android?). So what’s so awesome about it? In my opinion these three aspects are more then enough to buy one:

- It’s cheap, they got two models, one budget\lite version for $25 and one more featured version for $35. The later one has more RAM, Ethernet and one more USB port.

- Power,the low-end model only consumes around 1W on full load and has external PSU like laptops. This makes it smaller and more portable. The high-end requires more power, but still unconfirmed of how much more. And you can also run it on 4 AA batteries!

- The GPU and HDMI. Yeah, you heard me. On board HDMI. And it’s powerful too. It can render a full HD 1080p movie directly to a television or monitor and demos has been shown where it runs Quake 3 at 1080p(!). Check the sprite demo below, and make sure to visit http://www.raspberrypi.org/

Take a byte! ;)

Tags: , , , , , , , ,

Set JAVA_HOME and JDK_HOME in Ubuntu 11

oktober 19th, 2011 / No Comments » / by istenes

Setting up the environment variables JAVA_HOME and JDK_HOME is easy, just type this into the terminal:

export JAVA_HOME=/usr/lib/jvm/<platform_name>
export JDK_HOME=/usr/lib/jvm/<platform_name>

Note: No trailing slash and point to the root of the platform, not /bin. And no ”quot” chars.

This works great until you reboot or re-login. You may know that you can add these two lines to .bash_properties located in your home folder. But you won’t find that file in Ubuntu, instead add these two lines in the bottom of .bashrc.

Now log out and in again and try to type this in the terminal:

echo $JAVA_HOME

If you see: /usr/lib/jvm/java-6-sun for example, then your done! Recheck the .bashrc file in your home folder if you only see blank space.

You can do this for all the custom environment variables you want to add to your Ubuntu account.

Tags: , , , , , , ,

Retrieve deleted files from a Subversion repository

oktober 18th, 2011 / No Comments » / by istenes

Easy as pie with a GUI (like tortoise or rapidSVN), but sometimes you don’t want a GUI (for numerous reasons). I struggled with this for a while and found a solution. My biggest issue was to find the actual revision --limit was my savior. It may not be the best but worked great for my purpose.

To locate the revision where the file was deleted, use svn log --verbose --limit 15

I add --verbose to see the files and not just the comments and revision numbers and --limit 15 to only get the 15 latest revisions (our HEAD is at 9780). Now locate the revision where the file was deleted, marked with a big D.

Then run svn up -r revision_number filename_or_folder

That’s it! Hope it worked!

Tags: , , ,

New Category, Stickies!

oktober 18th, 2011 / No Comments » / by istenes

When I’m coding, or actually whatever I’m doing at work, I tend to forget common things. By things, I mean commands, code library names, processes, code snippets, environments, softwares etc. I used to have a notepad with this common stuff in case I forgot them. But now I’ve lost that notepad… Can’t find it… But I learn on my mistakes! I’m going to use a digital notepad from now on for safe keeping. I was planning to use google docs, but then I realized, why keep this common stuff to my self? Why not share it for other people having the same problem?

So, that’s why I created this category called Stickies on my blog, for post that I might need later on, for safe keeping or just a memo. Feel free to comment on my ”Stickies” if you have a better way of solving the problem.

Enjoy!

Tags: , ,

Basic Arrays and ArrayLists in Java

augusti 4th, 2011 / No Comments » / by istenes

A common thing I’ve noticed is that people that begin to code java (or any other language supporting ArrayLists) can not see the differences and uses ArrayLists before traditional Arrays. So here is a quick description of both and when to use them.

Array

An array has fixed length which is set when it is created (using the new keyword), it cannot grow dynamically. It can be 2-dimensional, 3-dimensional or more. Don’t really know if there is a max matrix, guess not, but only as long as your computer has ram for it. Arrays are quick and always start with index 0, a common beginner mistake is to set the array length counting 0 as a value, see below.

byte[] myArray = new byte[1];
byte[0] = 1;
byte[1] = 2; //Won't work as the length of the array is only set to 1!

Arrays are good to use when you know the maximum length after code compilation. An example related to game development is Tile Maps, when loading the map data you should already know how big your level is. This is true for most tile maps. Another example could be if you want to enter player High-Score data into an array before converting it to JSON or XML to a webservice such as: score, name, email, time and ip; total length of 5.

ArrayList

ArrayLists are very similar to regular Arrays, you store stuff in them. But instead of having a fixed length ArrayLists grow each time you add another element. Unlike Arrays, ArrayLists are filled with data through the method add() and you get the data by using the method get(int index). But under the hood of an ArrayList lies an Array. So each time you call the add() method you clone your current Array in the ArrayList into a new Array with the new fixed length of n+1, where n is the current length, and then the new data is added. This can slow down performance of course, but it’s a cool feature if you need dynamic arrays. I use a custom built version of ArrayLists in my game for handling all the objects.

Here is a performance tip: when creating your ArrayList you can set the built-in Arrays fixed length using ensureCapacity(int minCapacity). This way the ArrayList does not clone the current Array when you call the add() method until it reaches the minCapacity.

http://download.oracle.com/javase/1.5.0/docs/api/java/util/ArrayList.html [ArrayList JavaDoc]

So that’s it! Please feel free to comment, email or tweet me if you find errors or other tips that can improve the post.

Happy Codin’!

Tags: , , , , , ,