Here’s another quick tip. If you have an integer value stored as a string and want to convert it to an “int” type, this tip is for you. You might want to use this if you’ve read an integer from a text file and therefore it was read in as a string value, but now you want to do a numeric comparison. Anyways, on to the tip. The following code converts a the string “25” to integer format. Continue reading
Here’s a quick tip for those of you interested in using MongoDB from a node.js application. Here we provide an example of how to perform a “find” to retrieve documents from a MongoDB collection. For those of you used to the SQL world, this would be equivalent to a SELECT. The following code snippet retrieves all documents in the “users” collection which have a field “age” with a value greater than 30… or in simple terms, retrieve all users who are older than 30.
Unit testing and unit testing frameworks are an important part of any significant development project. For our needs, the unit testing framework that turned out to be the best option was nodeunit. However, maybe because we are running on Windows (not linux), it took a little bit to figure out a nice clean way to run the unit tests.
In the end, we wrote our own node.js script to run the unit tests and we thought it might be nice to share that with others to save some time.
Recently I had an issue connecting to an Active Directory LDAP server from within PHP using the standard ldap_connect and ldap_bind functions. The problem is, the code I was using was working without problems on a Linux based webserver, so I knew it wasn’t a problem with the PHP code itself or the parameters I was passing. So… I did some reading and found many people experiencing similar problems, but not all of them for the the same reason as me. I’m going to summarize in this article the three main problems I came across so that hopefully one of the solutions solves your particular problem.
PHP began as a language which was not designed around object oriented principles, but lately you’d be hard pressed to find a PHP application that does not utilize classes, objects, and other object oriented design concepts. Now that PHP is big into the OO world, you might be wondering how you can implement some common object oriented design patterns like a “singleton” in PHP.
In this article, I’ll go through how to create a singleton class and also briefly describe when you might want to use a singleton design pattern in your application.
When creating a webservice using Restify, you may want to be able to handle data POSTed to your API. Have a look at our article about creating a RESTful webservice in node.js for the basics on setting up the server and routing the requests. In that article you see that you use the following code to route a POST request to your handler function.
OK, so now all POST requests will be sent to the my_post_handler function. The problem is that the data being POSTed to the server needs to be properly parsed so that it can be easily handled by your script. This is where the Restify plugin bodyParser comes into play. The plugin can be used easily by simply adding the following line of code before your post handler. So setting up your routes would look something like this. Continue reading