dracoblue.net

Enhanced API Browser for node.JS

Today I created a little (~450loc) extension for the official node.JS api page. It's a client side Live-Search: filters over content and navigation as you type.

Feel free to try it out at http://dracoblue.net/showcase/enhanced-node-api/.

This is made 100% javascript (with jquery) and does not change the api.html at all.

Source is available at enhanced-node-api@github.

Comments appriciated!

In javascript, jquery, node.js, open source by DracoBlue @ 24 Apr 2010 | 62 Words

bash tip: for each line in a file

When you want execute an action on a set of files (all, which contain testfile), this technique is pretty straight forward:

for line in `find . | grep "testfile"`
do
    rm "$line"
done

But this actually does not work, if the file name contains spaces!

In this cases the "while read"-construct is failsafe:

find . | grep "testfile" | while read line
do
    rm "$line"
done

In bash by DracoBlue @ 05 Apr 2010 | 76 Words

What's faster: JSON.parse+stringify or extend/mixin?

Today I ran into the case, that I just wanted to clone a plain javascript object (no functions at all, just values). I was wondering whether it would be faster to use the native JSON.stringify+parse (which would include generating a very big string, just to throw it away):

copy = JSON.stringify(JSON.parse(entry));

or to use the javascript functions

process.mixin/extend and perform a deep copy:

copy = extend(true, {}, entry)

Here are the results:

 JSON-String: 19886421 characters
  8691ms 3x JSON.parse(JSON.stringify(object))
  5839ms 3x extend(true, {}, object)

JSON-String: 29959 characters
  10305ms 3000x JSON.parse(JSON.stringify(object))
  7445ms 3000x extend(true, {}, object)

JSON-String: 249 characters
  214ms 3000x JSON.parse(JSON.stringify(object))
  94ms 3000x extend(true, {}, object)

JSON-String: 39 characters
  118ms 3000x JSON.parse(JSON.stringify(object))
  32ms 3000x extend(true, {}, object)

The script is the following:

http://gist.github.com/354628 and the Test PC was a i7-920 Quadcore with HT and 8GB DDR3 RAM.

In my test setup it was 2x faster to use a function like extend.

In javascript, node.js by DracoBlue @ 03 Apr 2010 | 170 Words

process.mixin deprecated in nodejs

When you are using process.mixin within nodejs 0.1.33, you'll get the following message:

deprecation warning: process.mixin will
be removed from node-core future releases

That this function is not in process anymore, is correct. It has nothing to do with processes. That said, you may think if you really need process.mixin at all. This function is available to create a (deep) copy of an entire object and it's properties.

In my case, I wanted to keep the ability to extend a prototype of an object with an aspect like "Logging".

Thatswhy I called the function

extend and borrowed the implementation from jquery (also licensed under the terms of MIT).

Where to get this "extend"-function from? Option 1: Copy the process.mixin from nodejs 0.1.30 Option 2: Take extend from jquery and modify it so it fits nodejs Option 3: Copy the nodejs version of jquerys extend from my util.js :)

Now I can easily do:

extend(true, Controller.prototype, Logging.prototype)

and every new Controller will have the Logging features, too!

By the way, there's always the possibility to do

JSON.parse(JSON.stringify(obj))

if the object does not contain any functions or those are not important to you.

In javascript, jquery, node.js by DracoBlue @ 03 Apr 2010 | 210 Words

Moving GTAT Database Server

Hello,

Now I'll move the database server to a new host. GTAT.org may not be available until 23:00.

  • Draco

In gta:tournament by DracoBlue @ 29 Mar 2010 | 21 Words

Page 18 - Page 19 - Page 20

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About