Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Archive for Marzec, 2011

NodeJS cURL Tutorial

NodeJS cURL Tutorial

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 we want to execute and the second is a callback function that accepts error, stdout, stderr.

The Code

var util = require('util');
var exec = require('child_process').exec;

var command = 'curl -sL -w "%{http_code} %{time_total}\\n" "http://query7.com" -o /dev/null'

child = exec(command, function(error, stdout, stderr){

	console.log('stdout: ' + stdout);
	console.log('stderr: ' + stderr);

	if(error !== null)
	{
		console.log('exec error: ' + error);
	}

});

This returns the HTTP code and time it took for the request to be issued:

stdout: 200 0.710

Conclusion

Although NodeJS is still young and bindings haven’t been made for alot of C libraries, the code above shows how you can still interact with the functionality they provide. That being said, the number of NodeJS modules is growing weekly. Be sure to keep an eye on the module wiki and npm registry for a list of modules.

Source: http://query7.com/nodejs-curl-tutorial

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

This Week in Web: PyCon, Django 1.3, Symfony2

This Week in Web: PyCon, Django 1.3, Symfony2

Symfony2 API Browser, Cheatsheet

The official API browser for Symfony2 can now be accessed at api.symfony.com/2.0. There you can browse look through all namespaces, classes and methods in Symfony2 (documented by PHPdoc comments). The folks at elao.org have released a cheatsheet for using Doctrine2 with Symfony2. The cheatsheet contains field information, configuration parameters and examples of relations (ManyToMany, ManyToOne etc.). Download the cheatsheet here (available in many formats).

MEPP – Mac Nginx Percona PHP

MEPP ​​is a set of applications to provide a local web development environment independent of OS X, installs in minutes. MEPP ​​is a similar alternative to LAMP, WAMP or MAMP for OSX

MEPP use nginx as web server and Percona as database server. MEPP ​​is free software and has no relation with any company in charge of the applications you use, in which case each has its own license.

PyCon 2011 Videos Released

Most of the talks given at the recent PyCon were recorded and have now been uploaded onto BlipTV. Below are some of the most popular talks:

Django 1.3 Released

Django 1.3’s focus has mostly been on resolving smaller, long-standing feature requests, but that hasn’t prevented a few fairly significant new features from landing, including:

A framework for writing class-based views.
Built-in support for using Python’s logging facilities.
Contrib support for easy handling of static files.
Django’s testing framework now supports (and ships with a copy of) the unittest2 library.

There’s plenty more, of course; see the coverage of new features below for a full rundown and details.

Wherever possible, of course, new features are introduced in a backwards-compatible manner per our API stability policy policy. As a result of this policy, Django 1.3 begins the deprecation process for some features.

Some changes, unfortunately, are genuinely backwards-incompatible; in most cases these are due to security issues or bugs which simply couldn’t be fixed any other way. Django 1.3 includes a few of these, and descriptions of them – along with the (minor) modifications you’ll need to make to handle them – are documented in the list of backwards-incompatible changes below.

Django 1.3 Cheatsheet

Jacob Kaplan-Moss, co-creator and lead developer of Django, has published a Django 1.3 cheatsheet. The cheatsheet covers parameters, names and defaults for forms, models, template tags, settings, signals and querysets as well as reference material for ModelAdmin and Datetime formatting. This is a great resource for those trying to learn the Django framework but are having a hard time remembering specific names.

Source: http://query7.com/this-week-in-web-pycon-django-1-3-symfony2

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Zend Developer Zone: Using the Plurk API with PHP

Zend Developer Zone: Using the Plurk API with PHP

On the Zend Developer Zone there’s a recent post looking at using the Plurk API in a PHP application (by Vikram Vaswani). Plurk is a micro-blogging service similar to Twitter.

While it’s quite easy to connect a PHP application to Twitter (I’ve discussed it in detail in this Devzone article), there exist a number of other free micro-blogging sites that also expose open APIs. In this article, I’ll introduce you to Plurk, which includes a JSON-based service API and also comes with a PHP library to simplify integration with Web applications.

He includes sample code showing how to connect to their API (with the help of the php-plurk-api) and work with the results. He shows how to search the service, get the latest “plurks”, find the entries for a given user and create a simple form for uploading comments to your own Plurk account.

Source: http://www.phpdeveloper.org/news/16118

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Kore Nordmann’s Blog: Generating XML schemas from XML data

Kore Nordmann’s Blog: Generating XML schemas from XML data

In a new post to his blog Kore Nordmann talks about a tool he’s developed that will “learn” XML schemas based on a document it’s given. The tool, the XML-schema-learner, makes it as simple as a one-line command to generate the DTD file and transform it into a schema.

You can get the “XML schema learner” from my Github account: https://github.com/kore/XML-Schema-learner. Just clone it, and you can run the tests, or use the learn command to infer XML schemas from XML data.

He includes an example XML definition and the resulting DTD that the tool generates from it, defining each of the elements and attributes each can have. The tool can then take this DTD file and generate an XSD file, creating complex and simple types that match the original data.

Source: http://www.phpdeveloper.org/news/16117

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

JSClasses.org Blog: Lately in JavaScript podcast – Episode 5 (PHP.js)

JSClasses.org Blog: Lately in JavaScript podcast – Episode 5 (PHP.js)

In the latest episode of the Lately in Javascript podcast, Manuel Lemos and Michael Kimsal interview Brett Zamir about PHP.js, a project that tries to bring PHP methods to the Javascript environment.

PHP.js is a JavaScript library that provides the same functions as the PHP language in JavaScript. Manuel Lemos and Michael Kimsal interview Brett Zamir, one of the main developers of the PHP.JS project, to tell us more about it on episode 5 of the Lately in JavaScript podcast. On this episode they also discuss the JavaScript related improvements of the latest releases of Internet Explorer 9, Firefox 4, Chrome 10 and Opera 11.

There’s an in-page player if you’d like to listen immediately or you can download the mp3 and subscribe to the feed to get this latest episode delivered locally.

Source: http://www.phpdeveloper.org/news/16116

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Stuart Herbert’s Blog: Series: Beyond Frameworks

Stuart Herbert’s Blog: Series: Beyond Frameworks

Based on his Beyond Frameworks session presented at this year’s PHP UK Conference 2011, Stuart Herbert is in the process of creating a series of posts based about its contents:

[In my session] I explained how a component-based architecture can help answer some of the important (i.e. expensive!) questions you might face when creating long-lived apps that rely on a PHP framework. In this series of blog posts, I’m going to look at how to go about creating and working with components.

As of the time of this post, there’s three different sections – “Getting Started”, “The Tools We Use” and “Working with PHP Components” – and lots of posts to match. The large part of the series has been focused in the components area with articles about planning, unit tests and making PEAR-compatible packages.

Source: http://www.phpdeveloper.org/news/16115

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Sameer Borate’s Blog: Data filtering and validation using Inspekt

Sameer Borate’s Blog: Data filtering and validation using Inspekt

Sameer Borate has a recent post to his blog looking at an important part of any application – filtering input from the user and output before its used. In his examples he uses a library called Inspekt (from Ed Finkler) to make the job a lot easier.

Most web security glitches are caused by insufficient input filtering and validation. Despite a large number of validation libraries being available, input sanitization is usually bypassed due to sheer laziness or the idea that your site is somehow immune from bad input data. Inspekt is one such library that has a small footprint and is very easy to integrate into your application.

He goes through the installation (a require_once) and a few examples of how to “cage” incoming data from a sample form with two hidden fields. He shows how to use the library to access the filtered versions of the values and how to run some tests on the data (like checks for alphanumeric, valid hostname, between two values, valid phone number, etc). He also briefly mentions “super cages” that can be used over and over.

Source: http://www.phpdeveloper.org/news/16114

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Voices of the ElePHPant: Interview with Vid Luther

Voices of the ElePHPant: Interview with Vid Luther

The Voices of the ElePHPant podcast has posted their latest episode – an interview with Vid Luther,

Cal’s “three questions” of choice this time center around Vid’s community experience:

  • How did you get involved in the PHP community?
  • What’s the biggest benefit you or your company/employer gets from participating in the PHP community?
  • What’s the easiest way to get involved in the PHP community?

As always, you can listen to this latest episode via the in-page player, by downloading the episode or by subscribing to their feed.

Source: http://www.phpdeveloper.org/news/16113

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Community News: Latest PECL Releases for 03.29.2011

Community News: Latest PECL Releases for 03.29.2011Latest PECL Releases:

Source: http://www.phpdeveloper.org/news/16112

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Eran Galperin’s Blog: Database Optimization Techniques You Can Actually Use

Eran Galperin’s Blog: Database Optimization Techniques You Can Actually Use

Eran Galperin has posted a few helpful tips (ones you can “actually use”) for optimizing your database and how your application uses it.

I understand the need for simplicity because of the wide audience of Smashing Magazine, but I’d wish they’d give something more than the absolute basics you could find in almost any other site out there [in their recent tutorial]. I also didn’t like some of the methods mentioned there for profiling (or the code itself), so I here is my starter guide to optimizing database performance.

Tips included in his post center around a different set of questions:

  • When should you optimize the database?
  • Think about profiling first, optimizing last
  • How EXPLAIN can find the big problems
  • When caching should be used

Some code is included, but only briefly since his point is more about the server than the client (script) side of things.

Source: http://www.phpdeveloper.org/news/16111

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>