Mittwoch, 7. November 2012

Rounding Integer in Javascript

There are a few options available when it comes to rounding a positive Integer value down in javascript.

  1. Math.floor()
  2. ~~
  3. >> 0


The third option is at least in Firefox a huge performance gain, you may check for yourself, have a look at this  JSPERF .

Dienstag, 6. November 2012

Resize Virtualbox Hard Drive

As I installed Virtualbox i created a harddisk with a dynamic size because I thought it would expand if it's full, well it didn't.

I found a usefull programm in the Virtualbox Forums which clones and resizes Virtualbox Harddisks.


after that you have to resize your partition in your VM.

go to http://gparted.sourceforge.net/download.php and download the GParted live CD.

boot from the GParted live CD and click GParted which will bring up a GUI which allows you to see your partitions.

now expand your swap partition to use up the free space and move it to the end of the partition, after that you can expand your root parition to use up the new space of your harddisk, et voila, reboot and you are done.


Montag, 1. Oktober 2012

node.js socket.io boilerplate

Yesterday i created a boilerplate for node.js, it uses the most common modules.
express.js - awesome http middleware which makes handling sessions and requests very easy
socket.io - most popular websockets implementation for node.js
jade - a template engine inspired by HAML
stylus - css template engine, same markup as jade and makes css writing less painfull, nearly fun ;)

Just clone the repo and get started.
git clone git://github.com/gocoffeecup/nodesocketioboilerplate.git

Additional information on the frameworks used can be found here:

Socket.io
express.js
jade
stylus

emulating whitespace in span elements

today a came across a very anoying problem, I'm currently working on a WYSIWYG editor, my approach is to wrap every single character in an <span></span> tag which works fine for every char except a whitespace.

at first i added &nbsp; but my markup is fairly complex and the editor allows you to float image elements, so non breaking spaces are not an option since the text won't float correctly arround wrapper elements which are floated.

adding only a whitespace in the span tag doesn't make the cursor jump on key input, and adding more spans in a row collapse to only one space.

i solved this by emulating a white space by adding a whitespace followed by a BOM character.
<span>*\ufeff</span>

where * is the whitespace itself.


this seems to work accross all browsers.

Sonntag, 30. September 2012

finaly, a blog!

I finaly decided to enter the blogosphere instead of writing my stuff into an old school .txt document which gets dusty on my harddrive. I will mostly post about technical stuff, programming with Javascript and provide some straight forward guides.