Sunday, December 20, 2009

In the name of offering a more consistent service, all the articles under scriptdiaries.blogspot.com are now moving back to the main site codediaries.blogspot.com. This is to make it easier to maintain as I don't have the time to administer too many sites. While most articles have moved over. Some will take a little longer as I will edit them and make them better before I add them to code diaries.

Summary
This is lesson 3 of 4. In this lesson we will use Yahoo's image search API to display images in a circle. We will then use Yahoo's "context" API to extract relevant keywords. This widget makes two seperate calles to the Yahoo API. This is done by loading itself into an "iframe" and then using the "parent" object like parent.callAFunction() to deliver the results. Back to the Lesson Index.

Summary
This is lesson 2 of 4. For this example we will use Google's RSS feed API to decode rss feeds and display them on a site. This widget will display weather taken from Yahoo's weather RSS feed and local news taken from two selected newspaper RSS feeds. View this Widget !!!

Explanation
First let us have a quick look at the code. First let's have a look at the weather.js file.

Summary
This is lesson 1 of 4. It is the simplest form of widget possible. For this widget we will create some simple javascript that will randomly display an image and a quote. The images and quotes will be held in two arrays. The javascript Math.random function will be used to select an image. View this Widget !!!

Explanation
First let us have a quick look at the code. This is the simplest example so the code is very straigntforward.

1. /* scriptdiaries.blogspot.com
2. Righteous Ninja aka Ping Ching.
3. Free to use and modify.*/
4. 5. var SXY_cutegirls = new Array("http://codediaries.com/widgets/cutelnka/wid_cutelnka_anarkalli.jpg",
6. "http://codediaries.com/widgets/cutelnka/wid_cutelnka_nadeeka.jpg",
7. "http://codediaries.com/widgets/cutelnka/wid_cutelnka_derana.jpg");
8. 9. var SXY_cutequotes = new Array(
10. "Sex without love is an empty experience, but as empty experiences go, it's one of the best.",
11. "Sex is not the answer. Sex is the question. Yes is the answer.",
12. "Sex without love is an empty experience, but as empty experiences go, it's one of the best.",
13. "The sex was so good that even the neighbors had a cigarette.",
14. "The difference between pornography and erotica is lighting.",
15. "Sex is like a bridge game; if you don't have a good partner, you better have a good hand."
16. );
17. 18. function SXY_DoSexyWidget(){
19. document.getElementById('cutelankapanel').innerHTML=
20. "<center>"+
21. "<img src=\""+SXY_cutegirls[Math.round((SXY_cutegirls.length-1)*Math.random())]+"\"/>"+
22. "<br/>"+
23. SXY_cutequotes[Math.round((SXY_cutequotes.length-1)*Math.random())]+
24. "</center>";
25. }

Learn more about this Widget
Super sexy widget that displays a random hot girl with a sexy and funny quote. Refresh page for a different quote and image. This can be easily changed to include any images and any number of quotes. Pure javascript only.

Wednesday, November 4, 2009

Sri Lanka Weather

Sri Lanka News

Learn more about this widget
A RSS feed widget that displays the news and weather in Sri Lanka. This uses Google's feed API, Yahoo's weather RSS feed and the feeds from two Sri Lankan Newspapers. This widget can be easily adapted to display news and weather from any country or a combination of countries.

Sunday, November 1, 2009

Learn more about this widget
A twiter widget that displays what has been on Paris Hilton's mind for the past week. This widget can be easily adapted to display any celebrity or entity on Twittter. Pure Javascript only. Using Twitter and Yahoo APIs.

Wednesday, October 21, 2009

There are heaps and heaps of free APIs on the web that you can use to mash up and create a widget. Most of the giants such as yahoo, google, twitter, digg etc have APIs that allow you to leverage off their search and social networking engines. Here we will list only the big names, but there are thousands of equally if not better services offered by smaller players for free.

Wednesday, October 14, 2009

If you would like to simply icrease the font size in the widget content without installing other widgets or embedding fancy javascript, you can edit the size in the template. Go to the Dashboard, click on Layout and select Edit HTML. Now look for the text below.

1. .widget-content {
2. margin-top: 0.5em;
3. }

Hide line numbers

You can modify this to increase the size, font, color etc of the widget content like so.

Tuesday, October 13, 2009

If you want to remove the Blogger bar at the top because it's clashing with your site. Many people seem to think this is illegal, that is up to you to decide. Go to the Dashboard. Click on Layout and then click "Edit HTML". Now stick this bit of code somewhere.

#navbar-iframe {
display: none;
}

Easiest is just before the "body {" and after the variable definitions. So your template should have this bit of code in it like below.

Wednesday, September 30, 2009

This is a simple AJAX tutorial using php, javascript and XMLHttpRequest. AJAX is the fundamental lynchpin of web 2 services and underpins almost every widget today. This is the simplest example that demonstrates AJAX.

This example consists of two files. ajaxexample.html contains all the javascript and getresult.php is the php backend that returns an xml result. Create or copy these two files into the same directory on a webserver (such as apache) that supports php.

Now type http://127.0.0.1/WEB/AJAXExample/ajaxexample.html in a browser, type your name in the textbox and click on the link.

lines 4-19 Creates an XMLHttpRequest object

lines 22-28 DoAjaxCall get's called when you click on the link. This creates an XMLHttpRequest object sets MyAjaxCallback as the callback function and adds the url to call.

lines 30-46 Once getresult.php is called the MyAjaxCallback function is called with the reuslt. You can then 'decode' the XMLHttpRequest object by traversing the sctructure and extracting the information.

Tuesday, September 22, 2009

This is a simple php Database example illustrating the basics such as creating an SQL query, fetching and updating a database. For this example we will be using a MySQL Database. However, this will work with any database. This example will use commands such as mysql_connect, mysql_fetch_object, mysql_query etc.

This is a simple php 5, DOM/XML example illustrating the basics such as creating tags, name/vaule pairs and text nodes using createElement, appendChild , setAttribute etc. The XML is displayed on the console, but could just as well be the response to an XMLHttpRequest.

Wednesday, September 16, 2009

Once you know how to read from and write to a file, connect to a database and insert and retrieve records, use regular expressions and open a socket to a server and read and write data, you have covered 80% of what is really required to write most applications in perl.

The aim of this tutorial is to show how to read and write a socket in Perl. We will open a socket to a website, write the request headers, read the response and write the response to the console. You do not need any prior HTTP 1.x knowledge.