NodeJS cURL Tutorial

March 28, 2011 No comments yet

NodeJS is a powerful evented Javascript platform running on top of Google’s V8 javascript engine. Over the last year the popularity of NodeJS has increased greatly, as shown by the number of discussions on programming forums such as Hacker News, Reddit and Stackoverflow. Despite this NodeJS is still young and it falls short to Python and Ruby when it comes to the number and range of libraries and modules available.

The Problem

I wanted to convert one of my web scraping applications I made in PHP to NodeJS. The application interacts with SOCKS4 and SOCKS5 proxies using PHP’s cURL bindings. Unfortunately there are no cURL bindings (or SOCKS protocol wrappers) written for NodeJS. NodeJS does come with an HTTP client module that can issue web requests, however it doesn’t support SOCKS proxies.

The Solution

Although there are no specific NodeJS bindings for cURL, we can still issue cURL requests via the command line interface. NodeJS comes with the child_process module which easily allows us to start processes and read their output. Doing so is fairly straight forward. We just need to import the exec method from the child_process module and call it. The first parameter is the command…

Cloud9 IDE Review

October 25, 2010 1 comment

A couple of weeks ago, Ajax.org released a new IDE for Javascripters known as Cloud9. It’s an open source project built on Node.js. In case you don’t know, Node.js is an implementation of Server Side JavaScript (SSJS) and is now actively being used for SSJS development. Since Cloud9 IDE is built on top of Node.js, it has an integrated debugger for Node.JS applications. In this article we’ll be taking a look at various features of Cloud9 such as those mentioned above, but for now let’s begin with installation.

Installation

Installation is very simple provided you’re familiar with the terminal. There are three ways to install Cloud9:

1. If you’ve Git installed on your system then you can get the code repository directly from Github. Just enter the following command in your terminal:

git clone git://github.com/ajaxorg/cloud9.git

Installing Cloud9 via GitHub

After Git checkout, enter the following command to install all the submodules and run the IDE:

bin/cloud9.sh

Building Cloud9 IDE

The editor will open in your default browser after all the submodules have been installed.

Cloud9 IDE

You can also install Cloud9 via NPM

npm install cloud9

or by downloading the source code from Github.

Review

Cloud9′s UI is similar to Eclipse IDE, so Eclipse

Codemirror – javascript syntax highlighting

July 22, 2009 No comments yet

CodeMirror is an on the fly syntax highlighting engine, written in Javascript. Like CodePress (the syntax highlighter used in the latest version of wordpress for editing plugins), it can highlight many different languages (PHP, JS, HTML, CSS to name a few). This tutorial will show you how to implement CodeMirror on your site, there is a great article written by the author of this library here on how it works under the hood.

Installation

Download the latest version from the CodeMirror website. As of today, it is version 0.62. After you unzip it you will see 3 directories – js, css and contrib. contrib holds parsers that other people have written such as the lua, python and PHP. css holds the color schemes for syntax highlighting and js contains the necessary scripts for CodeMirror to run.

Basic Usage

If we have a textarea with an id of code that we wanted to turn into a CodeMirror editor with a MirrorFrame(more on this later) then we would use the code below. Note that we need to specify where the parserfiles and stylesheets for the particular type of syntax (in this case javascript) are located.

  var textarea = document.getElementById('code');

Dual form processing

April 14, 2009 No comments yet

Recently, a client of mine wanted a single web form, residing on the localhost to submit the form contents to a database in the localhost, and as well as to a web server simultaneously. Although this sounds like an unnecessary duplication of data, my client wanted some of the form data to be stored on the localhost for the intranet applications to use. Achieving this functionality would have been a piece of cake, if we were not handicapped by the unavailability of cross-domain AJAX. For those of us familiar with AJAX, we know that we cannot send an AJAX request to a remote server due to security reasons – atleast not in a reliable, hack-less way.

So, instead of looking for a pure AJAX solution, I decided to implement this functionality by using a combination of AJAX (for the localhost) and a traditional PHP POST request (for the web server). The trick here is to execute the AJAX call before the form is submitted – by catching the form submission event using JavaScript. Once the AJAX call is successful, we allow the default form submission to take place. In case there is an error with our AJAX call, we should…

No IE6 support on new W3C website?

March 27, 2009 No comments yet

W3.org is overhauling its website in order to make it more user-friendly and quiet people who used to wonder (including me) why the administrator body of web have such dull, flat, unorganized and old fashioned website?

The new website looks more attractive and organized. 10 minutes tour of new website can be found here. In contrast with the previous version, this new website uses rich content presentation, including JavaScript.

The website uses jQuery 1.3.2, a very known and popular JavaScript library, instead of pure JavaScript. This is very good news and a big leap towards streamlining the use of JavaScript frameworks, specially in case of jQuery. In addition of core jQuery framework, beta.w3.org also uses jQuery plugins (e.g.: http://malsup.com/jquery/cycle/), to enhance the user experience.

The biggest news of the day is w3.org beta website doesn’t render correctly in IE6. It’s supposed to be a strong argument for web developers in order to inspire and take initiative towards to stop exclusive coding to render their websites correctly in IE6.

See, Yes! Yes! – GO

December 9, 2008 2 comments

Modular CSS needs to be developed and all inherited properties needs to commented within CSS declaration so one don’t repeat same CSS again and selectors needs to named by some naming convention (e.g. prefixing every declaration by module).

Modules needs to be devised in such way so it remain plug and play if plugged in different application.

Philosophy of Object Oriented Programming and Software Design

November 1, 2008 5 comments

Now, I am no expert in OOP or software design, but here’s a philosophy which might help you make the most of what you know about OOP and software design.

jQuery AJAX Tutorial Pt2

May 13, 2008 No comments yet

Heres Part 2 of the jQuery AJAX login tutorial. If you haven’t already, i suggest you read part 1 located here.

We are going to start writing the PHP code to process the form. This is fairly basic stuff, using $_POST to get the values from the form, then checking them against pre-assigned values, if they match, then echo approved, if they don’t then echo denied.


So at the end of this stage, you will have an HTML form set up and this PHP file. You can enter the username Panzer and the password of query7 into the form and it will return Logged in.

Next tutorial, the fun part, the AJAX!

AJAX Series Coming Soon!

May 9, 2008 No comments yet

Hey guys, just thought i’d post a little interim post (as such). Im in the process of making a 4 part tutorial series on using jQuery’s AJAX. Its a “case study” where i/we will make a basic login form with a PHP backend and then use jQuery to make the login seemless. Eg. you put your username/password in the form and click the login button the page doesn’t reload but it will tell you whether its the correct user/pass , in which case a cookie is set, or if its bad info.

It might take a little while to finish up so i might not be posting much over the next week (sorry) but it will be worth it in the end.