Tag Archives: World Wide Web

Diving into Node.js – Introduction & Installation

Why I Need Something Like Node.js?

First of all the use of some software is needed not because of itself, but because of the need of some specific functionality. In my case this was the need of real time news feed. Of course there is a way to make this without Node.js, as I’ll describe later in this post, but there are several disadvantages. However to begin from somewhere, let me explain what is Node.js.

Introducing Node.js

Perhaps the best way do describe what is Node.js is from its about page.

Node’s goal is to provide an easy way to build scalable network programs. In the “hello world” web server example above, many client connections can be handled concurrently. Node tells the operating system (through epoll, kqueue, /dev/poll, or select) that it should be notified when a new connection is made, and then it goes to sleep. If someone new connects, then it executes the callback. Each connection is only a small heap allocation.

In general Node is a program using the Google Chrome’s V8 JavaScript engine, which in turn is a program that can parse and execute code written in JavaScript. V8 is a very very interesting project itself. First of all from Google have developed this engine especially for one of his products – their browser Chrome. It pretends to be and by no means is one of the masterpieces of Google. It is fast and reliable engine, written in C++ and JavaScript, as Wikipedia’s page says. Actually this code is open source and can be embedded in whatever application written in C++. Thus you can have in your application a JavaScript engine. Continue reading Diving into Node.js – Introduction & Installation

2xjQuery: Select a Selector

Selectors in jQuery

jQuery JavaScript Library

If you’re familiar with jQuery you should already know what are selectors and how they work. However we’re used to get some DOM element with a specific selector, but actually sometimes you cannot select directly what you need. This is especially true when mixing more than one JavaScript libraries. In my case OpenLayers generated a vector layer and jQuery was supposed to change the vectors fill-color property.


With the simple $(‘path’) I easily got all vectors in the current document, but the problem was that I took them as text. Thus it came to me to use nested jQuery – $($(‘selector’));

To describe what actually happened in my case, let me show you a breve example.


Here’s a short HTML markup:

<div><span>text text</span></div>

With jQuery I can select both the DIV and SPAN with the simple $(‘div’) and $(‘span’), but just for the example lets assume I’ve only the inner text of the DIV tag:


That was the case in the OpenLayers/jQuery problem. Now I can easily use another jQuery selector:


This will return the same as $(‘span’) – a jQuery object.

Automatically Upload Images with PHP Directly from the URI

It is a simple task to upload images on the server with PHP using a simple web form. Than everything’s in the $_FILES array and after submitting the form the file’s on the server. By simply move_uploaded_file you can change its location on the server to the desired folder.

However is there a way to “upload” files without using a web form, but only by telling the PHP script where to find the image. First and most important the image should be web visible and accessible by HTTP.

The solution is quite easy – you can grab the file using file_get_contents, and than put it on the desired server folder with file_put_contents. Here’s some source:

$image = file_get_contents('http://www.example.com/image.jpg');
file_put_contents('/var/www/my.jpg', $image);

Extending the Case

You can go even further by downloading any kind of files with the same approach. What will be the case for an mp4 video is shown in the next example:

$video = file_get_contents('http://www.example.com/video.mp4');
file_put_contents('/var/www/my.mp4', $video);


This can be quite useful when trying to automate an remote upload process. In this case when somebody uploads an image on his site, you can duplicate this file on your server! However don’t forget the copyrights!

Can Twitter Replace the RSS Feed Readers


I’m sure this is not the first time you’ve been asked this question. However there’s nobody today that doesn’t wonder the answer. For me – yes, twitter can replace the RSS feed readers, and NO – feed readers are awsome!


First of all why do I use a feed reader? I’m simply seeing what’s in it and barely read the article from the reader, but rather I jump to the site, and what’s happening often in twitter is the same scenario, I just see what’s in the tweet and if it seems to be interesting to me I jump to the link (if there’s a link). The good thing is that the tweets are limited and I’m focused. That’s why twitter is my favorite social site. I can follow all of the interesting people I know from their blogs. So perhaps twitter is becoming more useful than the feed readers.


In other hand in twitter you’ve to stay all the day long to get all the tweets you need. The timeline is quickly changing and sometimes you get lots of “junk”. While in the feed reader you’ve all the “important” posts as an incoming mail. You cannot miss anything! That’s why I cannot forget the feed readers they are doing a great job!

Fetching Rows With Zend_Db fetch()

Fetching the Entire Row Set


What is really handy in Zend Framework is that you can fetch the entire row set with the fetchAll() method. It comes with some parameters that you can use for limiting the result or ordering, but in general you can use it without specifying parameters. Let say this is the model:

class User extends Zend_Db_Table
	public function listAll()
		$query = "SELECT * FROM user";
		// exec query
		$rs = $this->getAdapter()->query($query);
		return $rs->fetchAll();

You can simply return the row set with the fetchAll() method as described in the example, but what if you have to loop through the rows and to modify somehow the values?

Fetching a Row

By simply change the code like so:

class User extends Zend_Db_Table
	public function listAll()
		$query = "SELECT * FROM user";
		// exec query
		$rs = $this->getAdapter()->query($query);
		// fetch
		$list = array();
		while ($row = $rs->fetch()) {
			// removing the password column value
			$row['password'] = '';
		    $list[] = $row;
		return $list;

you can modify the rows and you’ll have the same result.