dracoblue.net

How to use postgres with nodeJS

With NodeJS (built on V8) it's pretty simple to access libraries written in C/C++.

Since NodeJS is 100% non-blocking I/O you'll need to tell your libraries to do the same. Even though libmysql is not yet capable of doing that, you may use postgres for this.

Ryan's node_postgres is a binary binding.

Compiling is easy as usual:

$ node-waf configure build
This may not work if a bug in node-waf is still present. So you get the error: Version mismatch: waf 1.5.9 <> wafadmin 1.5.10. To fix that edit /usr/local/bin/node-waf and change 1.5.9 to 1.5.10.

If you receive the error: The program pk_config could not be found, you'll need to install postgres dev libraries package first. On debian/ubuntu you do that the following way:

$ sudo apt-get install libpq-dev

It may fail to build then with the message: "Build failed", "cxx binding.cc -> binding_1.o". I am currently running into the same issue and will post an update as soon as I got this fixed.

There is also an pure Javascript implementation of the Postgres API available at

postgres-js.

In javascript, node.js by DracoBlue @ 23 Dec 2009 | 195 Words

Installing jsl (JavascriptLint) on Linux

I tried to figure out how to compile and run jsl. As I just needed the binary, here is how I finally got it working in a pretty nice way:

First of all download latest JavaScript Lint.

Extract all files in that folder and go right into the src folder.

Run:

$ make -f Makefile.ref

If all dependencies are there, you'll have a folder LinuxALLDBG.OBJ created. Go right into that and there is a file called "jsl". Copy that file to your bin folder (~/bin, /usr/local/bin, /usr/bin, /usr/sbin ... wherever you appriciate).

Now you are capable of running:

$ jsl -process file.js

whereever you want!

In javascript by DracoBlue @ 23 Dec 2009 | 116 Words

Spezielle XML Zeichen in Javascript Enkodieren/Dekodieren

Wenn man in Javascript die

HtmlSpecialChars in ungefährlichen Text und wieder zurück konvertieren möchte, hat man meist die zugänglichen Funktionen auf den Dom-Elementen (in mootools sind das .get('html') und .get('text')).

Wenn man aber einfach simple Strings html enkodieren/dekodieren will, benutze ich die folgenden Funktionen:

var xml_special_to_escaped_one_map = {
    '&': '&',
    '"': '"',
    '&lt;': '&lt;',
    '>': '&gt;'
};

var escaped_one_to_xml_special_map = {
    '&': '&',
    '"': '"',
    '&lt;': '&lt;',
    '&gt;': '>'
};

function encodeXml(string) {
    return string.replace(/([\&"&lt;>])/g, function(str, item) {
        return xml_special_to_escaped_one_map[item];
    });
};

function decodeXml(string) {
    return string.replace(/("|&lt;|&gt;|&)/g,
        function(str, item) {
            return escaped_one_to_xml_special_map[item];
    });
}

In javascript, mootools by DracoBlue @ 23 Dec 2009 | 101 Words

Encode/Decode special xml characters in Javascript

When you want to convert htmlspecialchars in javascript to not so dangerous text and decode those html entities back again, you may have some convenient methods on a dom entity (like mootools .get('html') and .get('text')).

If you want to do that simple work on simple strings, I use the following functions:

var xml_special_to_escaped_one_map = {
    '&': '&amp;',
    '"': '&quot;',
    '<': '&lt;',
    '>': '&gt;'
};

var escaped_one_to_xml_special_map = {
    '&amp;': '&',
    '&quot;': '"',
    '&lt;': '<',
    '&gt;': '>'
};

function encodeXml(string) {
    return string.replace(/([\&"<>])/g, function(str, item) {
        return xml_special_to_escaped_one_map[item];
    });
};

function decodeXml(string) {
    return string.replace(/(&quot;|&lt;|&gt;|&amp;)/g,
        function(str, item) {
            return escaped_one_to_xml_special_map[item];
    });
}

In javascript, mootools by DracoBlue @ 23 Dec 2009 | 200 Words

amx/amxfile.c, fails in fputs_cell:

When trying to run my pawn script on a new linux server, I received the following error:

samp03svr: amx/amxfile.c:222: fputs_cell:
Assertion `fp!=((void *)0)' failed.

This was actually caused by a missing

scriptfiles directory (or the directory was not writeable).

So take care in your scripts if an fopen really gives you a vaild file pointer and handle the situation if it does not!

In pawn by DracoBlue @ 31 Oct 2009 | 70 Words

Page 20 - Page 21 - Page 22

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