Archive for August, 2009

How to modify any web page with Firefox

Thursday, August 27th, 2009

An old trick to edit any web page you’re visiting with the Firefox browser. Just load the page and copy and paste the code in the browser toolbar:

javascript:document.body.contentEditable=’true’; document.designMode=’on’; void 0

We can then write on the text of the page to create a modified version, make a screenshot and ready. In addition to some practical uses can also be an inexhaustible source of fun changing webs headlines and convincingly.

5 ways to use Ajax with jQuery

Tuesday, August 25th, 2009

The people of Nettuts publishes an interesting article on using  jQuery with Ajax. Specifically the 5 ways that jQuery allows us to send asynchronous requests.

  • $.load()
  • $.get()
  • $.post()
  • $.getJSON()
  • $.getScript()

$. load ()

This is the feature I like most about jQuery already makes one of the most common tasks of developing with Ajax is as simple and straightforward as we shall see in this example:

$("#div_links").load("/Main_Page #jq-p-Getting-Started li");

This example brought to the documentation page on jQuery, it manages to launch a request to the URL /Main_Page (usa URL Rewrite) HTML response and take the #jq-p-Getting-Started li and inserted into #div_links
Just great, comfortable and fast.

$. get ()

This is the simple function with which we can launch the server via GET requests Ajax.

$.get("test.cgi", { name: "Venu", time: "7pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

By passing 3 options, 2 of which are options (rather conditional) you can request to launch the file (1) with parameters (2) and treat the response through a callback (3rd).

$. post ()

Like the above, this feature lets you send POST requests using Ajax.

$.post("test.php", { name: "Venu", time: "7pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

As easy as above.

$. getJSON ()

Although the above are able to specify the type of return, the best option is to use this method to obtain the response in JSON evaludada the callback function.

$.getJSON("test.js", { name: "Venu", time: "7pm" }, function(json){
  alert("JSON Data: " + json.users[3].name);
});

Taking into account the browser, the object will use native JSON or use a system based on eval().

$. getScript ()

Although technically not an Ajax request is a request to the server and therefore has a place in the post.

$.getScript("test.js", function(){
  alert("Script loaded and executed.");
});

With this method we can load a file asynchronously using JavaScript and the parameter (2) callback can execute Javascript code that is using the js file that we want to load (1).

FTP connection with JAVA

Tuesday, August 25th, 2009

Java again gives us another tool.

What is FTP?

FTP protocol that allows us to send or receive data from one point to another, be it a PC, server, or any other node that is connected to a network.

Usually when you have a web host these accounts have FTP congratulate sending files from our pc to the server that is hosting our site.

Investigating around I found a FTP client library very useful, I have tried it and going great. The library JvFTP Client provides interesting tasks, including:

  • Uploading / downloading files
  • Uploading directories recursively
  • Concurrent data transfer
  • Data transfer mode passive / active
  • Swing components to display directories
  • Components AWTpara display directories

This tool is available in jvftp and can be used in two ways, you run directly the jar, or do your own programming, including the libraries in your project.

If you want to program your own example here I leave a little guide on how you can do, let’s see …

… The first thing to do is incorporate the packages downloaded from jvftp in your project. Then you import the libraries to the class in which you make the connection:

import cz.dhl.io.*;
import cz.dhl.ftp.*;
import java.io.IOException;

Now we create the connection, the connection to prepare the data before creating access the FTP site. Let’s start with the server:

FtpConnect cn = FtpConnect.newConnect("ftp://ftp.domain.com");

ftp.domain.com value which is the server you are connecting. Each ftp account that include at least the server name, username and password. To log in using that account is something like this:

// Username
cn.setUserName("username");

// Password
cn.setPassWord("password");

Then it creates an object of type FTP, which is responsible for rendering all the information from our FTP site.

Ftp ftp1 = new Ftp();

Now the connection to the FTP site to begin processing the respective tasks

ftp1.connect(cn);

A practical example to test the connection would be to show the current directory with their files:

CoFile dir = new FtpFile(ftp1.pwd(), ftp1);

// Make a list of files that have the current directory
CoFile cfls[] = dir.listCoFiles();
if ( cfls != null )
        for (int n = 0; n < cfls.length; n++)
                    System.out.println( cfls[n].getName() + (cfls[n].isDirectory() ? "/" : ""));

Finally, there is only close the connection.

ftp1.disconnect();

Download jvftp

Happy Programming!!! ;-)

Everything you ever wanted to know about JSON

Monday, August 24th, 2009

JSON is short for JavaScript Object Notation and is a way of storing information in an organized and easily accessible.

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
};

At first glance you get a very clear and that helps your understanding. In this example we have defined a small JSON object called wcVenuThomas composed of a series of attributes. In this way, we can subsequently use to follow the following structure.

alert("Venu Thomas is " + wcVenuThomas.age );

Functions (not to carry information)

Thanks to the versatility of the variables in JavaScript it is possible to match one of these attributes to a function, creating a method of the object itself:

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
    "salute" : function(strString) {
    	alert("hello, " + strString + "! I'm Venu Thomas from " + this.hometown + ", How are you?");
    },
};

Now you can salute() :-D

 var usrName = "John James"
wcVenuThomas.salute(usrName);

As part of the JSON object, we can make use of the attributes from the same method by using this operator.

The functions do not make sense to use JSON as a conveyor of information, so we leave it alone as a curious object notation :-D

Arrays

Another option to the JSON is the ability to insert arrays as attributes and in turn define elements within JSON:

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
    "salute" : function(strString) {
    	alert("hello I'm Venu Thomas from " + this.hometown + ", How are you? " + strString + "?");
    },
    "projects":[
    	{
    		"name" : 	"Apple News and Analytics ",
    		"url"		 : 	"http://apple.wisecodes.com"
    	},
    	{
    		"name" :	"Life Style Blog",
    		"url"		 :  "http://telegraph.wisecodes.com"
    	}
    ]
};

In this way we can travel an arrays are:

var projects = wcVenuThomas.projects, html = '';
for (var x = 0 ; x < projects.length ; x++) {
html += '<li><a href="' + projects[x].url + '">' + projects[x].name + '</a></li>';
}

JSON object chaining

Another way of grouping elements is to use JSON JSON objects embedded within other objects JSON:

var wcVenuThomas = {
    "age" : "28",
    "hometown" : "Cochin, Kerala, India",
    "gender" : "male"
    "salute" : function(strString) {
    	alert("hello I'm Venu Thomas from " + this.hometown + ", How are you? " + strString + "?");
    },
    "projects":{
    	"applenews": {
    		"url"		 : 	"http://apple.wisecodes.com"
},
  	  "lifestyleblog": {
    		"url"		 :  "http://telegraph.wisecodes.com"
}
    }
};

As we can see, really the only thing we have done is to insert an object into a JSON attribute father, so we can access it as follows:

var URL = wcVenuThomas.projects.applenews.url;

Practical uses

As data storage system, is ideal for transporting from one page to another, even a website to another. A very simple and is used to obtain data from Flickr using jQuery to get data.

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
        function(data){
          $.each(data.items, function(i,item){
            $("<img/>").attr("src", item.media.m).appendTo("#images");
            if ( i == 3 ) return false;
          });
        });

In this example, taken from the documentation of jQuery, as we launched a call for the latest images sent to Flickr that have been scheduled with the tag “Cat”. The result will be evaluated and processed to the end to reach us within data, a variable that can go as if we were talking about a variable.

Native JSON

One of the problems encountered with JSON is the assessment of code, since it must be transformed into a variable to use, and this requires the use of eval() which makes the process time is increased considerably .

// Eval
var myObject = eval('(' + myJSONtext + ')');

// Native JSON
var myObject = JSON.parse(myJSONtext);

// Mix
var myObject = (JSON)?JSON.parse(myJSONtext): eval('(' + myJSONtext + ')');

Fortunately, modern browsers (IE8, FF3.5, WebKit, ….) Features are implemented to forget eval() and improve the process time.

Preloaders.net: Loading of images in 3D

Saturday, August 22nd, 2009

Preloaders.net shows me, a site style ajaxload.info that allows us to generate images of “Loading” for our applications, but this can generate images with animations in 3D.

Adminer: Web frontend to MySQL, in a single file

Friday, August 21st, 2009

adminer_210809

This is a tool that will be useful to developers who need to make urgent changes in some server MySQL. Admin is a Web frontend to the popular database, which requires only a 170 Kb file to run. Just upload it to your site and use it.

Supports all functions that can be found in phpMyAdmin, for example: create database, list the contents of the tables and change their parameters, adding and removing tables and columns, perform all kinds of indexes and stored procedures to execute commands on line or from a file, export as CSV or SQL display or kill processes, among others.

Works with MySQL 4.1, 5.0 and 5.1 running on PHP 4.3 or 5 sessions enabled. It is available in eleven languages, including Spanish, and is absolutely free. Ideal for out of trouble or do not download packages installations.

Link via Admin

Code in C# to create a backup of a database in SQL server and restore it

Wednesday, August 19th, 2009

Here they left a code in C # very useful when making your applications with databases in SQL server can support the database and restore it.

Support code for a button:

private void btnBackUp_Click(object sender, EventArgs e)
{
    bool bBackUpStatus = true;

    Cursor.Current = Cursors.WaitCursor; 

     if (Directory.Exists(@"c:\SQLBackup"))
        {
            if (File.Exists(@"c:\SQLBackup\wcBackUp1.bak"))
            {
                if (MessageBox.Show(@"Do you want to replace it?", "Back", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    File.Delete(@"c:\SQLBackup\wcBackUp1.bak");
                }
                else
                    bBackUpStatus = false;
            }
        }
        else
            Directory.CreateDirectory(@"c:\SQLBackup");

        if (bFileStatus)
        {
            //Connect to DB
            SqlConnection connect;
            string con = "Data Source = localhost; Initial Catalog=dbWiseCodes ;Integrated Security = True;";
            connect = new SqlConnection(con);
            connect.Open();
            //----------------------------------------------------------------------------------------------------

            //Execute SQL---------------
            SqlCommand command;
            command = new SqlCommand(@"backup database dbWiseCodes to disk ='c:\SQLBackup\wcBackUp1.bak' with init,stats=10", connect);
            command.ExecuteNonQuery();
            //-------------------------------------------------------------------------------------------------------------------------------

            connect.Close();

            MessageBox.Show("The support of the database was successfully performed", "Back", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
}

Code for a button to restore:


private void btnRestore_Click(object sender, EventArgs e)
{

    Cursor.Current = Cursors.WaitCursor;

    try
    {
        if (File.Exists(@"c:\SQLBackup\wcBackUp1.bak"))
        {
            if (MessageBox.Show("Are you sure you restore?", "Back", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //Connect SQL-----------
                SqlConnection connect;
                string con = "Data Source = localhost; Initial Catalog=master ;Integrated Security = True;";
                connect = new SqlConnection(con);
                connect.Open();
                //-----------------------------------------------------------------------------------------

                //Excute SQL----------------
                SqlCommand command;
          command = new SqlCommand("use master", connect);
            command.ExecuteNonQuery();
                command = new SqlCommand(@"restore database dbWiseCodes01 from disk = 'c:\SQLBackup\wcBackUp1.bak'", connect);
                command.ExecuteNonQuery();
                //--------------------------------------------------------------------------------------------------------
                connect.Close();

                MessageBox.Show("Has been restored database", "Restoration", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        else
            MessageBox.Show(@"Do not make any endorsement above (or is not in the correct path)", "Restoration", MessageBoxButtons.OK, MessageBoxIcon.Information);

    }
    catch (Exception exp)
    {
        MessageBox.Show(exp.Message);
    }

}

Print PDF with JPedal

Sunday, August 16th, 2009

Researching a bit about the handling of a PDF document I found a library called JPedal for manipulating PDF documents from Java.
Like other libraries I’ve seen among other iText and iReport, which are very comprehensive and allow you to do many tasks, including printing. Disadvantage that the latter is that you need to have installed Acrobat Reader and for many users this is not possible.
But even with JPedal lets you see the Acrobat Reader tools within the Java application, providing a task pane for the PDF to manipulate.

With PrinterJob.lookupPrintServices can get the services available and print them PrinterJob a concrete one.

PrintService[] psService = PrinterJob.lookupPrintServices();
PrinterJob pjPrintJob = PrinterJob.getPrinterJob();
pjPrintJob.setPrintService(psService[0]);

// Assigns the size of the paper to A4.

Paper paper = new Paper();
paper.setSize(595, 842);
paper.setImageableArea(0, 0, 595, 842);
PageFormat pf = pjPrintJob.defaultPage();
pf.setPaper(paper);

Loads the PDF to be printed. The file is called wc_PDF.pdf printed and given format.

PdfDecoder pdfD = null;
pdfD = new PdfDecoder(true);
pdfD.openPdfFile("wc_PDF.pdf");
pdfD.setPageFormat(pf);

It sends the file to print

printJob.setPageable(pdfD);
printJob.print();

And to finalize the document is closed.

pdf.closePdfFile();

Download JPedal..

The example would then complete as follows:

import java.awt.print.Paper;
import java.awt.print.PrinterJob;
import java.awt.print.PageFormat;
import javax.print.PrintService;
import org.jpedal.PdfDecoder;

public final void wc_PrintPDF() {
    PdfDecoder pdfD = null;
    try {
        PrintService[] psService = PrinterJob.lookupPrintServices();
        PrinterJob pjPrintJob = PrinterJob.getPrinterJob();
        pjPrintJob.setPrintService(psService[0]);

        Paper paper = new Paper();
        paper.setSize(595, 842);
        paper.setImageableArea(0, 0, 595, 842);
        PageFormat pf = pjPrintJob.defaultPage();
        pf.setPaper(paper);

        pdfD = new PdfDecoder(true);
        pdfD.openPdfFile("wc_PDF.pdf");
        pdfD.setPageFormat(pf);

        pjPrintJob.setPageable(pdfD);
        pjPrintJob.print();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        pdfD.closePdfFile();
    }
}

Mono project brings .NET platform to the iPhone

Friday, August 14th, 2009


Video: MonoTouch iPhone Hello World [05:14 min]

Apple made several conditions to develop applications on its iPhone platform, one of them is unable to use any type of virtual machine execution engine or script as a basis for applications, only native code. This condition leaves no contests or sweepstakes to developers with extensive experience in Java and. NET, reducing the universe of developers who have knowledge in Objective-C, without being able to reuse their skills in other languages are more widespread.

But did not have the cunning of the Mono Project, the implementation of the open source platform. NET. A feature of Mono that is relevant in this context is the ability to compile code-compatible. NET code in native, he is called AOT (Ahead of Time). The idea is very similar to what GNU Compiler for Java (GCJ), part of GNU Compiler Collection (GCC) and is making the source code and compile it instead of a virtual machine to compile the code Machine-specific, if iPhone is ARM code.

With AOT, laid the groundwork that makes sense to create MonoTouch, framework that has everything necessary for developers to create applications in C # and. NET for the iPhone.

MonoTouch access to all the potential of the iPhone’s APIs as well as the code and libraries that have been created around Mono. This will allow those with skills in C # and. NET can now start to use them in this exciting platform.

The HTML5 dialog tag

Friday, August 14th, 2009

The HTML5 tag <dialog/> designed to make a conversation, a chat or other interaction among two or more partners, provide a semantic value to your code.

<dialog>
<dt>Robin</dt>
<dd>Hello Venu</dd>
<dt>Venu</dt>
<dd>Hello Robin, How are you?</dd>
<dt>Robin</dt>
<dd>I'm fine Venu, What is your plan for today??</dd>
<dt>Venu</dt>
<dd>We will go Dream Hotel??</dd>
<dt>Robin</dt>
<dd>Thats great!!</dd>
</dialog>

live_previewView Demo

As we can see in the above code, mark the text as a <dialog/> subsequently sectioned in <dt /> and <dd /> to specify names and phrases associated with that person. We also use the <time /> tag to indicate when the conversation.

Twiter in HTML5

<dialog>
<dt><a href="http://twitter.com/VenuThomas">@VenuThomas</a>, <time datetime="2009-08-14T10:14:54">25 minutes ago</time></dt>
<dd>Any body coming with me to Dream Hotel?</dd>
<dt><a href="http://twitter.com/cijupeter">@cijupeter</a>, <time datetime="2009-08-14T10:16:45">23 minutes ago</time></dt>
<dd><a href="http://twitter.com/VenuThomas">@VenuThomas</a> Hey, of course i'm coming :-)  </dd>
<dt><a href="http://twitter.com/VenuThomas">@VenuThomas</a>, <time datetime="2009-08-14T10:20:01">19 minutes ago</time></dt>
<dd><a href="http://twitter.com/cijupeter">@cijupeter</a> you are welcome. :-) </dd>
<dt><a href="http://twitter.com/cijupeter">@cijupeter</a>, <time datetime="2009-08-14T10:15:02">14 minutes ago</time></dt>
<dd><a href="http://twitter.com/VenuThomas">@VenuThomas</a> Hey, What about <a href="http://twitter.com/CerinPathrose">@CerinPathrose</a> ??</dd>
<dt><a href="http://twitter.com/VenuThomas">@VenuThomas</a>, <time datetime="2009-08-14T10:10:06">9 minutes ago</time></dt>
<dd><a href="http://twitter.com/cijupeter">@cijupeter</a> I've told him!</dd>
</dialog>

live_previewView Demo

Happy Programming!!! ;)