This Week in Web – jQuery Forms, JS Microframeworks, Resig & Dahl Q+A

May 6th, 2011 / By admin / No comments

jQuery IdealForms

jQIdealForms is a forms framework for jQuery that assists developers in building attractive forms with minimal Javascript code. Forms are defined in standard HTML so if the user has Javascript disabled, the form still displays. After calling the .idealForms() method on your form, jQIdealForms automatically styles and enhances all inputs. All styling is done with CSS, no images are used. jQIdealForms supports IE7+ and other modern browsers.

MicroJS.com

Microjs.com helps you discover the most compact-but-powerful microframeworks, and makes it easy for you to pick one that’ll work for you.

Micro-frameworks are definitely the pocketknives of the JavaScript library world: short, sweet, to the point. And at 5k and under, micro-frameworks are very very portable. A micro-framework does one thing and one thing only — and does it well. No cruft, no featuritis, no feature creep, no excess anywhere.

jQuery 1.6 Released

The jQuery team have released version 1.6 of the jQuery Javascript library. This release includes an increase in performance for the .attr(), .val() and .data() methods, changes to the way jQuery manages HTML element attribute data, numerous big fixes and the addition of relative movements in the .css() method. Links to the new…

PHP Twig Template Wrapper

May 2nd, 2011 / By admin / No comments

Requirements

Template Class

The use of the Settings class is self explanatory. Just replaces the instances of Settings with your own configuration system (or just strings). All Twig settings are documented here.

class Template
{

	public $context = array();

	private $template;

	public function __construct($template)
	{		

		$loader = new Twig_Loader_Filesystem(Settings::get('template_directories'));

		$twig = new Twig_Environment($loader, array(

			'cache' => Settings::get('template_cache_directory'),
			'debug' => Settings::get('debug'),

				)

		);

		$this->template = $twig->loadTemplate($template);

	}

	public function setContext(array $context = array())
	{
		$this->context = array_merge($context, $this->context);

	}

	public function render()
	{
		return $this->template->render($this->context);
	}	

	public function __toString()
	{
		return $this->render();
	}

	public function __set($key, $val)
	{
		$this->context[$key] = $val;
	}

	public function __get($key)
	{
		return $this->context[$key];
	}

}

Simple Example

hello.html

Hey there <strong>{{ name }}</strong> welcome to the website.

Code in controller

$t = new Template('hello.html');
$t->name = 'Frank';
echo $t->render();

Output:

Hey there <strong>Frank</strong> welcome to the website.

Example with Inheritance

base.html

<h3>Welcome to the website<h3>
{% block content %}{% endblock %}

hello.html

{% extends 'base.html' %}
{% block content %}
Hey there <strong>{{ name }}</strong> welcome to the website.
{% endblock %}

Code in controller

$t = new Template('hello.html');
$t->name = 'Joe';
echo $t->render();

Output:

This Week in Web – JS Videos, Mozilla, Titanium Docs, ExtSJS, django-rules

April 29th, 2011 / By admin / No comments

Day of JS

On 27th January 2011 a conference was held at Google HQ which covered the state of Javascript both on the web and mobile platform. Six talks between 40 and 60 minutes in length were given by Javascript community leaders such as Ben Galbraith, Dion Almar, Yehuda Katz and Kevin Whinnery. MJG (the sponsor of the conference) recorded those talks and has uploaded them in high quality video format. If you have an interest in jQuery Mobile, Titanium Mobile, SproutCore, Sencha Touch or Javascript on the web in general, I highly recommend you watch these videos.

Mozilla’s JS Plans for 2011

David Mandelin, a developer at Mozilla, has written a blog post titled Mozilla Javascript 2011. In it he discusses the features and enhancements planned this year for Mozilla’s Javascript engine. These include a new debugging API (which will allow for remote debugging), performance enhancements to the garbage collector, type inference for TraceMonkey and a new JIT compiler called IonMonkey. Mandelin does a really good job at explaining each of these enhancements in simple terms (without the lingo). I personally learned alot by reading it.

TiDocs.com

ExtJS 4.0 Released

Sencha have released version 4…

Learning Python Qt Programming with PyQt & PySide

April 25th, 2011 / By admin / No comments

Introduction

Qt is a cross platform application framework that is made up of not only a GUI widget toolkit, but also classes for working with OpenGL, SQL databases, threading, network protocols (HTTP, FTP, UDP, TCP) and much more. Currently Python has two separate bindings for the Qt framework: Pyside and PyQt. In this post we look at Pyside and PyQt and the resources that exist for learning them.

Pyside or PyQt?

Both Pyside and PyQt have full Python bindings for Qt 4.7 and are available for Mac, Windows and Linux. The main difference between the two is how they are licensed. PyQt is developed by River Bank Computing and is available under the GPL or a commercial license. This means that if your application is open source you can use the free GPL version, but if your application is closed source you need to buy the commercial license (350 GBP). Pyside is licensed under the LGPL so it can be used in both open and closed source applications with no cost. In addition to the standard Desktop bindings, Pyside is also available for the Maemo and MeeGo mobile platforms.

Because Pyside is a relatively young project the majority…

This Week in Web – Git Cheatsheet, PHP Profiling, Netbeans, Dojo Layouts

April 22nd, 2011 / By admin / No comments

Git Cheatsheet

Basic Profiling Techniques for PHP Applications

Eric Hogue has written an article outlining the different profiling techniques a developer can use to test their PHP applications. He starts off by introducing Apache Siege which gives response time and request/sec figures. He then goes on to talk about XDebug, which is used to find bottlenecks in a development environment, and XHProf, which is appropriate to use in a production environment. He explains how to install and configure all 3, as well as view output from XDebug and XHProf in KCacheGrind and XHGui. If you haven’t done any application profiling in PHP before I recommend you read this article as it is a good introduction.

Netbeans 7.0 Released

The Netbeans Project has released version 7.0 of their IDE. Some of the big new features 7.0 introduces are:

  • HTML5 support
  • JDK7 support
  • PHP application refactoring
  • Java GUI designer, GridBag
  • Git 1.7 support

A detailed list of the changes since Netbeans 6 are available here.

Dojo Application Layouts with Dijit

Sam Foster of the Dojo Project has written a tutorial showing how to layout Dojo application using dijit.layout. Layouts are vital in any Dojo…

Tutorial Django Dojo DataGrid

April 18th, 2011 / By admin / No comments

Dojo is an open source Javascript toolkit. It provides an easy way to access and modify the DOM as well as a rich user interface widget library. One of the most powerful widgets in the Dojo toolkit is DataGrid. It provides an easy way to represent what is essentially a cross between a spreadsheet and a table. In a recent Django project I needed to output the contents of a model into the DataGrid. Thanks to django-dojoserializer this is very easy.

Setup

We need the Python package django-dojoserializer. This can be installed by downloading the source and running

python setup.py install

or with setuptools using

easy_install django-dojoserializer

or with pip using

pip install django-dojoserializer

Then add django-dojoserializer to the INSTALLED_APPS tuple in settings.py.

Dojo will need to be linked correctly in the Django template. We need to require the dojox.grid.DataGrid and dojo.data.ItemFileReadStore classes.

<script src="/static/libs/dojo/dojo.js" djConfig="parseOnLoad: true">%lt;/script>
<script type="text/javascript">
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.data.ItemFileReadStore');
</script>

Django Model

PROXY_TYPE_CHOICES = (

	('SOCKS4', 'SOCKS4'),
	('SOCKS5', 'SOCKS5'),
	('HTTP', 'HTTP'),

)

class Proxy(models.Model):
	ip = models.CharField(max_length=50)
	type = models.CharField(max_length=6, choices=PROXY_TYPE_CHOICES)
	alive = models.BooleanField(default=False)
	added = models.DateTimeField(auto_now=False, auto_now_add=True)
	last_checked = models.DateTimeField(auto_now=True, auto_now_add=False)

	def __unicode__(self):
		return self.ip

Django View

The view needs…

This Week In Web – LiveJS, SunlightJS, Python, MySQL INSERT

April 15th, 2011 / By admin / No comments

LiveJS

LiveJS is a Javascript library that is designed to speed up development times. It actively monitors the CSS and Javascript files that are in the used in the current page and automatically reloads them whenever a change is made. This saves you from having to refresh the web browser every time you make a change to a stylesheet or script. Check out the demo.

SunlightJS

SunlightJS is an intelligent syntax highlighter for web pages. It supports Internet Explorer 6+ in addition to all Gecko and Webkit powered web browsers. It supports most popular languages out of the box (PHP, Python, Java, Javascript etc..) and has a simple API interface that allows you to create your language bindings. Full documentation and tutorial on how to use SunlightJS is available here.

Advanced Programming Language

Matt Might, Assistant Professor of CS at University of Utah, has written a blog post titled Advanced Programming Languages. Might opens with:

If you’re looking for a job in industry, my reply is to learn whatever is hot right now: C++, Java and C#–and probably Python, Ruby, PHP and Perl too.

If, on the other hand, you’re interested in enlightenment, academic research

Why You Should Be Using a PHP Framework

April 11th, 2011 / By admin / 7 comments

All frameworks discussed in this post are full stack web frameworks coded in PHP such as Code Igniter, Symfony, Kohana, Yii and CakePHP. Some (but definitely not all) of the points below may apply to micro frameworks such as FatFreeFramework, Limonade, Glue and Slim.

When should I use a framework?

Frameworks should be used when constructing web applications. Any application that involves a database, forms, sessions, cookies or a remote service (such as Twitter or Facebook) will benefit from being powered by a framework. There is no need to use a framework for a website that has only one or two pages, nor for command line utility scripts.

What features do frameworks provide?

  • Database abstraction. Frameworks can abstract away SQL-vendor specific features. This allows you to change your SQL database without needing to rewrite any code. For example, switch from MySQL to Postgres or MSSQL. Some frameworks can also handle database relations automatically, which saves you having to write JOIN queries.
  • Cache abstraction. Rather than using backend specific caching functions (such as apc_add and apc_fetch), you use a generic caching class which has support for multiple backends such as Memcache, APC and XCache.
  • Form management. Symfony2 and CakePHP allow

This Week in Web – App Engine, Titanium Studio, Useful PHP Snippets

April 8th, 2011 / By admin / No comments

App Engine 1.4.3 Released

Python API Changes
Prospective Search API: The experimental Prospective Search API allows Python runtime users to detect and take action on datastore entities that match certain criteria when they are written. For the experimental release, users will be allowed 10,000 subscriptions with the Prospective Search API. Pricing will be announced once the feature is fully launched.

Testbed Unit Test Framework: The Testbed suite for Python provides an easy interface for using App Engine API stubs in integration tests similar to the previously existing Java Testing Framework. You can create tests for your application that do not rely on calling App Engine production services, which speeds up the time your tests take to complete, and eliminates dependencies for your test on external services.

Files API: The new Files API in Python and Java allow you to programatically read and write data using Blobstore. This API can be used to generate reports, export data, or do anything that your heart desires that requires large, binary objects.

full announcement

Titanium Studio Preview

Appcelerator have announced a preview release of Titanium Studio, an IDE built on top of Aptana (Eclipse) for Titanium Mobile development. It includes…

Using Celery with Django

April 4th, 2011 / By admin / No comments

Introduction

In a recent Django project I needed to issue some HTTP requests to a website, save the results and then display the information to the user. I could have issued those HTTP requests in a Django view, however the requests could take up to 10 seconds to return, and I didn’t want the page hanging that long for the user. I ended up using Celery, an asynchronous task queue written in Python, to execute the requests.

Installation

Celery
Celery is in pypi so installation is simple.

easy_install celery
pip install celery

Or download the source code, extract it and

python setup.py install

Django + Celery
In a high traffic production environment Celery should be paired with the RabbitMQ backend. However for my low traffic application I went with the django-kombu backend. django-kombu uses the Django database as a message store and requires very little configuration compared to other backends. We also need the djcelery package.

easy_install django-kombu
easy_install django-celery

Configuration

Before we can start using Celery we need configure our Django project. In settings.py make sure you add djkombu and djcelery to the INSTALLED_APPS tuple. Also make sure your database is configured and working.

Also add…