Wednesday, 10 December 2008

Some language characteristic in Python

''' represent multi-line String.

Raw Strings. Strings start with a r or R. r"Newlines are indicated by \n". The special character in the String is not prefixed by a escape.

Unicode Strings. Strings start with u or U. u"This is a Unicode string.". Automatically converted into Unicode format.

String literal concatenation. If you place two string literals side by side, they are automatically concatenated by Python. For example, 'What\'s' 'your name?' is automatically converted in to "What's your name?".

Notice for different kind programmers:
Note for C/C++ Programmers
There is no separate char data type in Python. There is no real need for it and I am sure you
won't miss it.

Note for Perl/PHP Programmers
Remember that single-quoted strings and double-quoted strings are the same - they do not differin any way.

Note for Regular Expression Users


Indentation in python is used to define block. And don't use a mixture of tab and whitespace to indentation

Some significant features in Python

Interpreted
A program written in a compiled language like C or C++ is converted
from the source language i.e. C or C++ into a language that is spoken
by your computer (binary code i.e. 0s and 1s) using a compiler with
various flags and options. When you run the program, the linker/loader
software copies the program from hard disk to memory and starts running
it.
Python, on the other hand, does not need compilation to binary. You
just run the program directly from the source code. Internally, Python
converts the source code into an intermediate form called bytecodes and
then translates this into the native language of your computer and then
runs it. All this, actually, makes using Python much easier since you
don't have to worry about compiling the program, making sure that the
proper libraries are linked and loaded, etc, etc. This also makes your Python
programs much more portable, since you can just copy your Python
program onto another computer and it just works!

Extensible
If you need a critical piece of code to run very fast or want to have some
piece of algorithm not to be open, you can code that part of your program
in C or C++ and then use them from your Python program.

Embeddable
You can embed Python within your C/C++ programs to give 'scripting'
capabilities for your program's users.

Extensive Libraries
The Python Standard Library is huge indeed. It can help you do various
things involving regular expressions, documentation generation, unit
testing, threading, databases, web browsers, CGI, ftp, email, XML,
XML-RPC, HTML, WAV files, cryptography, GUI (graphical user interfaces),
Tk, and other system-dependent stuff. Remember, all this is
always available wherever Python is installed. This is called the 'Batteries
Included' philosophy of Python.
Besides, the standard library, there are various other high-quality libraries
such as wxPython [http://www.wxpython.org], Twisted
[http://www.twistedmatrix.com/products/twisted], Python Imaging Library
[http://www.pythonware.com/products/pil/index.htm] and many
more.

Tuesday, 9 December 2008

Beginning to Python

Python can run many platforms. Python is available for all major operating systems: Windows, Linux/Unix, OS/2, Mac, Amiga, among others.

Python can play well with others:

Python can integrate with COM, .NET, and CORBA objects.

For Java libraries, use Jython, an implementation of Python for the Java Virtual Machine.

For .NET, try IronPython , Microsoft's new implementation of Python for .NET, or Python for .NET.

Python is also supported for the Internet Communications Engine (ICE) and many other integration technologies.

If you find something that Python cannot do, or if you need the performance advantage of low-level code, you can write extension modules in C or C++, or wrap existing code with SWIG or Boost.Python. Wrapped modules appear to your program exactly like native Python code. That's language integration made easy. You can also go the opposite route and embed Python in your own application, providing your users with a language they'll enjoy using.


Python Success Stories


Monday, 8 December 2008

CUDA

CUDA is a technology that enable you to use the computing resource in GPU(Graphics processing Unit) to compute. This technology is given by NVIDIA.
The following is from wiki

CUDA (originally Compute Unified Device Architecture although this is no longer used) is a parallel computing architecture developed by NVIDIA. Simply put, CUDA is the compute engine in NVIDIA graphics processing units or GPUs, that is accessible to software developers through industry standard programming languages. Programmers use C for CUDA, compiled through a PathScale Open64 C compiler,[1] to code algorithms for execution on the GPU. CUDA is architected to support all computational interfaces, including C and new open standards like OpenCL and DX11 Compute. Third party wrappers are also available for Python, Fortran and Java.


The latest drivers all contain the necessary CUDA components. CUDA works with all NVIDIA GPUs from the G8X series onwards, including GeForce, Quadro and the Tesla line. NVIDIA states that programs developed for the GeForce 8 series will also work without modification on all future Nvidia video cards, due to binary compatibility. CUDA gives developers access to the native instruction set and memory of the parallel computational elements in CUDA GPUs. Using CUDA, the latest NVIDIA GPUs effectively become open architectures like CPUs (Central Processing Units). Unlike CPUs however, GPUs have a parallel "many-core" architecture, each core capable of running thousands of threads simultaneously - if an application is suited to this kind of an architecture, the GPU can offer large performance benefits.


In the computer gaming industry, in addition to graphics rendering, graphics cards are used in game physics calculations (physical effects like debris, smoke, fire, fluids), an example being PhysX and Bullet (software). CUDA has also been used to accelerate non-graphical applications in computational biology, cryptography and other fields by an order of magnitude or more.[2][3][4]


CUDA provides both a low level API and a higher level API. The initial CUDA SDK was made public 15th February 2007. NVIDIA has released versions of the CUDA API for Microsoft Windows, Linux and Mac OS X was added as a fully supported platform in version 2.0[5], which supersedes the beta released February 14, 2008.[6]


Advantages

CUDA has several advantages over traditional general purpose computation on GPUs (GPGPU) using graphics APIs.

  • It uses the standard C language, with some simple extensions.
  • Scattered reads – code can read to arbitrary addresses in memory.
  • Shared memory – CUDA exposes a fast shared memory region (16KB in size) that can be shared amongst threads. This can be used as a user-managed cache, enabling higher bandwidth than is possible using texture lookups.[7]
  • Faster downloads and readbacks to and from the GPU
  • Full support for integer and bitwise operations, including integer texture lookups.

Limitations

  • It uses a recursion-free subset of C language, plus some simple extensions. However, a single process must run spread across multiple disjoint memory spaces, unlike other C language runtime environments.
  • Texture rendering is not supported.
  • Recursive functions are not supported and must be converted to loops.
  • For double precision there are no deviations from the IEEE 754 standard. In single precision, Denormals and signalling NaNs are not supported; only two IEEE rounding modes are supported (chop and round-to-nearest even), and those are specified on a per-instruction basis rather than in a control word (whether this is a limitation is arguable); and the precision of division/square root is slightly lower than single precision.
  • The bus bandwidth and latency between the CPU and the GPU may be a bottleneck.
  • Threads should be run in groups of at least 32 for best performance, with total number of threads numbering in the thousands. Branches in the program code do not impact performance significantly, provided that each of 32 threads takes the same execution path; the SIMD execution model becomes a significant limitation for any inherently divergent task (e.g., traversing a ray tracing acceleration data structure).
  • CUDA-enabled GPUs are only available from NVIDIA (GeForce 8 series and above, Quadro and Tesla)[8]

Sunday, 7 December 2008

DataBinding in Flex

Flex let us use a very simple way to bind our data to the controls.
I will show just a very simple example first, more complicated examples will be add in future.
*Simple:
<mx:HBox> <mx:Text id="output" text="{input.text}"> </mx:Text> <mx:TextInput id="input"> </mx:TextInput> </mx:HBox>
The output text can updated instantly when you change the content in "input" TextInput control.

This is called inline data binding.Inline data binding represents the most limited use of ActionScript, because it can evaluate only one expression. For instance, the preceding example evaluates the expression input.text. You could use a more complex expression, such as the
following:
text="{'User input: ' + input.text}"

Test blog send from email

This is a blog send from email.

Ways to detect Flash version

1. Change the template file in the SDK Resource directory resides in Flex Builder.
There many items you can define, such as applicationName or backgroundColor.
2. Using SWFObject. For more reference, see here: http://
blog.deconcept.com/swfobject

Remote DataService in Flex

Flash Player is capable of making RPCs to many types of data services. For example,Flash Player can make requests to any web resource using HTTP, which means it canmake requests to many primitive data services such as a static or a dynamic XMLdocument, or the MapQuest example mentioned previously. That also means it canmake requests to web services. Moreover, the Flex class library simplifies requests to most data services.
In addition to the types of data services previously mentioned, Flex applications can also make calls to methods of classes on the server, using a technology called Flash Remoting. Flash Remoting uses the AMF binary messaging format, which is supported natively by Flash Player. AMF has all the benefits of SOAP, but since it is binary, the bandwidth overhead is greatly reduced. And since AMF is natively supported by Flash Player, no special coding is necessary to use Flash Remoting data services from the client tier. However, for a Flash Remoting data service to be available to the client tier, it must be made accessible via a piece of software that resides on the server, and can read and write AMF packets and delegate the requests to the correct services. Flex Data Services provides an implementation of Flash Remoting that integrates easily with components in the Flex framework. That means that if you use Flex Data Services, you can quickly configure applications to utilize Flash Remoting without writing ActionScript. However, you’re not locked into using Flex Data Services in order to use Flash Remoting. There are many Flash Remoting server products, including open source options such as OpenAMF (http://www.openamf.org) and AMFPHP (http://www.amfphp.org).

The interaction between flash and C++ component

I have tried to find a way to invoke C++ code in ActionScript directly, but just two ways available:
1. Using the ExternalInterface in flash and let it interact with browser directly. In this way, flash can invoke Javascript code directly and let its function been invoked from flash. Flash can just register the code it want to be invoked to the ExternalInterface.
2.Using Activex control. This way, C++ code can directly invoke the flash function through the ActiveX container. Check the demo given by actionscript_examples.

Some related concepts that I got clear today are as follows:
OCX
The file extension (and generic name) for OLE Custom control (the X must have been added because it looked cool to Microsoft Marketing types). OCX modules are independent program modules that can be accessed by other programs in a Windows environment. OCX controls replaced VBX controls written in Visual Basic. OCX, both as a marketing term and a technology, was replaced by ActiveX controls. ActiveX is backward compatible with OCX controls because ActiveX containers, such as Microsoft's Internet Explorer, can execute OCX components. OCX controls can be either 16-bit or 32-bit.

ActiveX
is Microsoft's specification for reusable software components. ActiveX is based on COM, the Component Object Model. The basic idea is to define exactly how software components interact and interoperate so developers can create components that work together using the definition. ActiveX components were originally called OLE Servers and ActiveX Servers and this renaming (actually for marketing rather than technical reasons) has created a lot of confusion about what they are. A lot of languages and applications support ActiveX in some way or another and Visual Basic supports it very strongly since it's one of the cornerstones of the Win32 environment.

Note: Dan Appleman, in his book on VB.NET, has this to say about ActiveX, "(Some) products come out of the marketing department. ... What was ActiveX? It was OLE2 -- with a new name."

Note 2: Although VB.NET is compatible with ActiveX components, they must be enclosed in "wrapper" code and they make VB.NET less efficient. In general, if you can move away from them with VB.NET, it's a good idea to do that.

OLE

OLE stands for Object Linking and Embedding. This is a technology that first came on the scene along with the first really successful version of Windows: Windows 3.1. (Which was released in April 1992. Yes, Virginia, they had computers that long ago.) The first trick that OLE made possible was the creation of what is called a "compound document" or a document that has content created by more than one application. For example, a Word document containing a genuine Excel spreadsheet (not a picture, but the actual thing). The data can be provided by either "linking" or "embedding" which accounts for the name. OLE has gradually been extended to servers and networks and has gained more and more capability.

COM
is Component Object Model. Although often associated with Microsoft, COM is an open standard that specifies how components work together and interoperate. Microsoft used COM as the basis for ActiveX and OLE. The use of the COM API ensures that a software object can be launched within your application using a wide variety of programming languages including Visual Basic. Components save a programmer from having to re-write code. A component can be large or small and can perform any kind of processing, but it must be re-usable and it must conform to set standards to for interoperability.
The infomation transferred between Flash and ActiveX is in XML Format

The interaction between flex application and DataService

Flash Player supports any text data, XML, a binary messaging format called
AMF, and persistent socket connections, allowing for real-time data pushed from the
server to the client.

Each data format Flex supports may or may not require special server resources. For
example, a Flex application can request XML data from a static resource or from a
dynamic resource such as a PHP page. AMF is a binary messaging format that Flash
Player understands natively, but for a server to interact with Flash Player via AMF, it
requires an AMF translator on the server, such as the remote object services that are
part of Flex Data Services.

Wednesday, 3 December 2008

Event metadata tag in Flex

This article gives an explanation of how metadata can be used in Flex:

Use the [Event] metadata tag to define the MXML property for an event and the data type of the event object that a component emits. You insert the [Event] metadata tag before the class definition in an ActionScript file, or in the block in an MXML file.

For more information on defining custom events, see Creating Custom Events.

The [Event] metadata tag has the following syntax:

[Event(name="eventName", type="package.eventType")]

The following table describes the properties of the [Event] metadata tag:

eventName: Specifies the name of the event, including its package name.
eventType: Specifies the class that defines the data type of the event object. The class name is either the base event class, Event, or a subclass of the Event class

The following example identifies the myClickEvent event as an event that the component can dispatch:

[Event(name="myClickEvent", type="flash.events.Event")]

If you do not identify an event in the class file with the [Event] metadata tag, the MXML compiler generates an error if you try to use the event name in MXML. Any component can register an event listener for the event in ActionScript by using the addEventListener() method, even if you omit the [Event] metadata tag.

The following example identifies the myClickEvent event as an event that an ActionScript component can dispatch:

[Event(name="myEnableEvent", type="flash.events.Event")]
public class MyComponent extends UIComponent
{
...
}

The following example shows the [Event] metadata tag in the tag in an MXML file:






[Event(name="myEnableEvent", type="flash.events.Event")]


....


Tuesday, 2 December 2008

The Facade Pattern

The façade pattern is a software engineering design pattern commonly used with Object-oriented programming.

A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:

  • make a software library easier to use and understand, since the facade has convenient methods for common tasks;
  • make code that uses the library more readable, for the same reason;
  • reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system;
  • wrap a poorly-designed collection of APIs with a single well-designed API (as per task needs).
An Adapter is used when the wrapper must respect a particular interface and must support a polymorphic behavior. On the other hand, a facade is used when one wants an easier or simpler interface to work with

Structure

Image:FacadeDesignPattern.png

Facade
The facade class interacts Packages 1, 2, and 3 with the rest of the application.
Clients
The objects using the Facade Pattern to access resources from the Packages.
Packages
Software library / API collection accessed through the Facade Class.

Examples

Java

This is an abstract example of how a client ("you") interacts with a façade (the "computer") to a complex system (internal computer parts, like CPU and HardDrive).

/* Complex parts */

class CPU {
public void freeze() { ... }
public void jump(long position) { ... }
public void execute() { ... }
}

class Memory {
public void load(long position, byte[] data) {
...
}
}

class HardDrive {
public byte[] read(long lba, int size) {
...
}
}

/* Façade */

class Computer {
public void startComputer() {
cpu.freeze();
memory.load(BOOT_ADDRESS, hardDrive.read(BOOT_SECTOR, SECTOR_SIZE));
cpu.jump(BOOT_ADDRESS);
cpu.execute();
}
}

/* Client */

class You {
public static void main(String[] args) {
Computer facade = new Computer();
facade.startComputer();
}
}