JsBehaviour 1.0 released
This is a tiny library I have been using to create inline dynamic effects at docsforit without inline javascript. Since it is not spludo (serverside javascript mvc framework) specific and works as long as mootools is available, I release it for the public today.
How does it work?
The idea behind JsBehaviour is pretty simple. Put a class (jsb_) on all elements which should be enriched/enhanced by javascript. Additionally put a class jsb_keyword on the element to define which behaviour should be applied to the element.
Each behaviour can register on such keyword by using this
method. As soon as the dom is loaded
is executed. You might even overwrite your Request.HTML method to do the same.
Hope you enjoy to work and tweak this little piece of MIT-licensed software.
Download @ DracoBlue.net and js-behaviour@dracoblue.
Demo + Spludo-Integration at "Editing the sections" on docsforit (double click on the content, this is all done by using JsBehaviour!!).
Hot reload for node.js servers on code change
If you are working with node.JS, you may experience the need to restart the node server as soon as a file has changed.
There are plenty approaches for this field. One is, to parse for all require statements in the code and watch those files then.
I took a different approach, which could be described by this linux command:
It searches for all .js files in the folder and restarts the server, as soon as one of those changed. Very easy, but yet powerful.
To use it, just copy: run_dev_server.js into your server directory.
This script expects your server script to be called run_server.js. If you want to change it, just change the line.
Instead of running your server with
you now start it with:
That's it!
This feature is of course part of the spludo framework's 1.0-dev version. In spludo, you can use
instead of
to achieve a hot reload on each .js change.
Update 2010/08/27: Wilkerlucio created a version for hot reloading coffee-scripts.
Connecting to a VirtualBox Guest Machine
Today I was setting up some test machines running a minimal debian installation.
Since it's not that handy to work always in the virtualbox window, I tried to connect to them by using ssh.
In the debian machine I typed:
2
$ apt-get install openssh-server
And tried to connect to the machine. It did not work.
I found plenty instructions how to fix ports and stuff with host-only-networks, but figured out, this is not what I was searching for!
The reason was, that virtualbox's default network mode is NAT.
I changed it to "network bridge". After that a restart of the machine did the trick, my router gave a proper IP to the guest debian.
Hello World Benchmarks for Nodejs Web Frameworks
Since I am releasing spludo pretty soon, I wanted to check out how performance is against other web frameworks for node.js.
To keep it fair (and little expressive) I just took the hello world application from each framework and benchmarked those with apache benchmark.
Concurrency Level: 256
Results:
2
3
4
5
expressjs: 3998.17 [#/sec]
(fab): 6588.95 [#/sec]
picard: 4648.41 [#/sec]
spludo 6780.38 [#/sec]
Concurrency Level: 1
Results:
2
3
4
5
6
expressjs: 2744.79 [#/sec]
(fab): 4271.43 [#/sec]
picard: 4755.03 [#/sec]
spludo: 3866.12 [#/sec]
The source code for all sample applications may be found at the public gist post.
The Test PC was a i7-920 Quadcore with HT and 8GB DDR3 RAM and a single node.js instance running.
Why <!-- beats <![CDATA[ for inline javascript
I guess everyone knows, that using:
2
3
myMagicFunction("This & That");
</script>
is pretty bad practice. The issue is, that the & should be escaped and read as & instead.
If you are reading this code with an Ajax-Request and it contains for instance unescaped & character, it will fail to load the xml properly and also fail executing the embedded javascript.
The workaround I see pretty often is the following (even suggested by w3schools):
2
3
4
5
<![CDATA[
myMagicFunction("This & That");
]]>
</script>
a better way is of course:
2
3
4
5
// <![CDATA[
myMagicFunction("This & That");
// ]]>
</script>
because it does not break any backwards compatibility to browsers, who do not get the cdata tag when in non xml mode.
This solution has one big problem: This claims the inner content to be included at this point and be escaped automaticly. And this valid html will be made visible to search engines.
Since I don't want anyone to count this comments as content for my website I am using the following solution for ages:
2
3
4
5
// <!--
myMagicFunction("This & That");
// -->
</script>
It works like a charm. If you are still using any of the previous solutions, please consider this solution as a replacement.
DJson 1.6.2 released
Today I have an important little bugfix release for djson available.
The issue was, that reading a value after an invalid set, breaks the reading. Thus, if you did a djInt on a value, which does not exist, any later dj call does not work. Thanks to Raphinity for reporting the issue.
Zamaroht reported a strange issue, when setting a value between two append-operations. This was due to a problem with the caching algorithm and has been resolved! Thanks Zamaroht for the report!
Another problem occurred, when you tried to write a string containing " (quotation marks). Those are escaped now properly, too.
These issue are of course fixed with the latest version djson 1.6.2 download.


