Developer42

2011-06-28

A Request / Random Thoughts

As with many of my posts, this is basically an unedited brain dump – apologies. Hopefully this will encourage some interesting comments / discussion though. . .

A Standard for Developer APIs
Facebook, Twitter, Worpress (and I’m sure Google+ will) offer APIs to developers allowing them to pull data out of their applications and manipulate it as they like. Most of these services offer similar functions; authentication, get the last x posts, pull back a grid of contacts, etc. All do this in their own way.
What would be great is some unification – either a library over the top of the existing APIs to pull them all in line, or for some set of social standards to be formed in the same way Netscape, IE, Mozilla and more came up with ECMAScript as a way to allow javascript to become portable. What I’m hoping for is something like this:

//this is entirely made up code - not (yet) some awesome new Google thing 
var application = GetApplication('Google+'); //creates a new object with an "application interface" for Google+
if (application.authenticate('Developer42','DemoCodePassword') //authenticate a user against the web app
{
    var identity = application.me(); //pull back an object which represents me
    var allFriends = me.ListContacts(); //by default pull back all contacts
    var colleagues = me.ListContacts('colleagues'); //or filter by group
    var posts = identity.GetPosts(20); //get my last 20 posts
    var friendsPosts = allFriends.GetPosts(100); //Get the last 100 posts by my friends/contacts
}

A Service for Services
This is probably what the guys who came up with UDDI were thinking:

If two companies offer a service to give out exchange rate information, and both use the same standard, when I want to get back exchange rate info why can’t I just post a request to the web saying “give me the exchange rate from USD to GBP” and have it chuck back .67 without all the hassle of searching for a suitable service.

There’s a whole bunch of data which we often need, but have to trawl the web for. Search engines began to make this better, WolframAlpha got a bit closer, but no one’s yet cracked it. What I’d like is a single web site containing a catalogue of services and their schemas. I pick a service, write code to its schema, then use the service url to pull back this data. From my point of view I’m just pulling data from http://www.UsefulServices.com/ExchangeRates, but in the background that could be talking to any (approved) provider. I guess the reason this doesn’t yet exist is the issue around monetisation; but surely there’s a way. . . ?
Below’s my wish list of services:

- Exchange Rates
- Share Prices
- National Holidays
- Daylight Savings Dates
- Post Code / Geo (long & lat) Conversion
- Credit Checks
- Product Prices
- Companies House Info

2011-03-28

Button to spell check a web-page in Google Chrome

Filed under: Google, Technology — Developer42 @ 20:32

A question recently popped up on the Chromium discussion forum asking if there was a way to get Chrome to apply its spell check to a whole website, as opposed to just a text box. Though I don’t know of one, I thought of a little javascript workaround. Copying and pasting the code below into your address bar will copy the text content of the website into a textarea causing Chrome to automatically spell check the contents. Not ideal, but nice for anyone who enjoys scripts.

javascript:var ta=document.createElement('textarea'); var s=document.createAttribute('style'); s.nodeValue='width:100%;height:100em;'; ta.setAttributeNode(s); ta.appendChild(document.createTextNode(document.body.innerText)); document.body.appendChild(ta); ta.focus(); for(var i=1;i<=ta.value.length;i++)ta.setSelectionRange(i,i);

Useful resource: Getting & setting the caret (text cursor) position
Original Question: Q. Button to spell check a web-page

2009-11-23

Google Wave Robot :: Standard Commands

Filed under: Google, Technology, Wave — Tags: , , , , , , , , , , — Developer42 @ 19:57

Currently each programmer writing a bot for Google Wave is able to write whatever they want, sometimes providing support, but using their own, custom syntax. Having a set of commands which all (or many) bots implement would make the user experience far better, as users would then be able to easily find out how to use the bot, or where to find additional help.
e.g.
botName@appspot.com /? //see /help
botName@appspot.com /help //brings up a list of commands available
botName@appspot.com /about //displays a summary of what this robot does
botName@appspot.com /devsite //provides a link to the developer’s site
botName@appspot.com /mode private //the bot’s responses are only shown to the person who invited it
botName@appspot.com /mode public //everyone in the wave sees the bot’s responses

I’ve also made a summary of this post available on the Google Wave Bots site. Please can you post any responses to that site, as this will allow all communications to be kept in the same place.

2009-11-04

Ideas for Wave Robots

Filed under: Google, Ideas, Technology, Wave — Tags: , , , , , , , , , , , — Developer42 @ 21:32

One of the hardest things about developing a wave robot is coming up with an original idea. My smiley bot [smiley_wave@appspot.com] was just for me to play with wave & get used to uploading apps to App Engine / get back into java coding and using eclipse. Now that that’s done, it’s time to think of something useful; an application that people will actually want to use. The point of this post is partly a brainstorming session for myself, and partly to put these ideas out there to anyone stuck for ideas, who think they can code one of these, and finally, to encourage others to submit ideas.

Webby – The Web Service Robot
A robot which when added, detects any URLs pointing to web services, generates a form based on the parameters, then submits this data via SOAP, and puts the return value into a new blip.

Squely – A Database Query Bot
A robot which can run SQL statements against given connection strings. At present, this will only be possible if the database is publicly accessible, or if you have a wave server installed on the same network as your database.

QIFry – Interesting
This robot would monitor waves for key words, then on detection, pop in an interesting fact about that word (e.g. if it spots the word Banana, it says “did you know that bananas are herbs, and these shrubs can walk?”). It also monitors for boring words, and replaces them with more eloquent ones.

Pretty – Pretty Print
Detects common languages / markup & changes the layout to make it more readable.

Recipe
Finds recipes based on ingredients or dish names in the wave.

FindMe
Uses the GEO features of HTML 5 to locate where each wave user is and lets wavers know where their nearest wavers are. This could also take info about their interests to help match people up to folks whose hobbies they share.

2009-11-03

My First Wave Robot :: smiley-wave@appspot.com

Filed under: Google, Technology, Wave — Tags: , , , , , , , — Developer42 @ 00:34

smiley-wave@appspot.com first demo

appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
	<application>smiley-wave</application>
	<version>1</version>
</appengine-web-app>

web.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
	<servlet>
		<servlet-name>Smiley</servlet-name>
		<servlet-class>inverso.google.wave.robot.smiley.SmileyServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>Smiley</servlet-name>
		<url-pattern>/_wave/robot/jsonrpc</url-pattern>
	</servlet-mapping>
</web-app>

capabilities.xml

<?xml version="1.0" encoding="utf-8"?>
<w:robot xmlns:w="http://wave.google.com/extensions/robots/1.0">
  <w:capabilities>
    <w:capability name="blip_submitted" content="true" />
    <w:capability name="wavelet_self_added" content="true" />
  </w:capabilities>
  <w:version>1&lt/w:version>
</w:robot>

SmileyServlet.java

package inverso.google.wave.robot.smiley;
import com.google.wave.api.*;
import java.util.*;
		
//FIX FOR ISSUE 354 is used where the robot suffers from the bug mentioned in the below links
//http://code.google.com/p/google-wave-resources/issues/detail?id=373
//http://code.google.com/p/google-wave-resources/issues/detail?id=354
		
public class SmileyServlet extends AbstractRobotServlet {
		
       /**
	 * Robot's version id & usage info
	 */
	private static final long serialVersionUID = 1L;
	private static final long serialSubVersionUID = 2L; //this is to help me prove that my latest changes 
                                                            //have been uploaded correctly
	private static final String serialVersionID = "Version #" + new Long(serialVersionUID).toString() + "." + 
                                                      new Long(serialSubVersionUID).toString();
	private static final String helpInfo = "\nThis robot is my learning tool for wave development, " +
                                               "so may occasionally break!  Apologies if you're one of " +
                                               "the people for whom it doesn't work!";
	private static HashMap dictionary = null;
		
	/*
	 * Creates the images & registers them against their invoking smileys 
	 * */	
	static {
		final int width = 24;
		final int height = 24;
		//http://commons.wikimedia.org/wiki/Smiley
		dictionary = new HashMap();
		dictionary.put(":)",new Image("http://upload.wikimedia.org/wikipedia/commons/7/79/Face-smile.svg",width,height,":)"));
		dictionary.put(":(",new Image("http://upload.wikimedia.org/wikipedia/commons/0/06/Face-sad.svg",width,height,":("));
		dictionary.put(";)",new Image("http://upload.wikimedia.org/wikipedia/commons/5/57/Face-wink.svg",width,height,";)"));
		dictionary.put(":D",new Image("http://upload.wikimedia.org/wikipedia/commons/1/15/Face-smile-big.svg",width,height,":D"));
	}
	
   /**
     * Handles changes to the wave 
     **/
	@Override 
	public void processEvents(RobotMessageBundle bundle) {		
		
		if (bundle.wasSelfAdded()) {
			final Blip blip = bundle.getWavelet().appendBlip();
			blip.getDocument().delete(); //FIX FOR ISSUE 354
			final TextView textView = blip.getDocument();
			textView.append( serialVersionID );
			textView.append( helpInfo );
		}
		
		for (Event e: bundle.getEvents()) {
			if ((e.getType() == EventType.BLIP_SUBMITTED) || (e.getType() == EventType.WAVELET_SELF_ADDED)) {
				final Blip blip = e.getBlip();
				smile(blip.getDocument());
			}
		}
	    
	}
	
	private void smile(TextView textView){
		final String text = textView.getText();
		Iterator<Map.Entry> i = dictionary.entrySet().iterator();
		while(i.hasNext()){
			Map.Entry pic = i.next();
			String key = pic.getKey();
			int pos = -1;
			while((pos = text.indexOf(key,++pos))>-1){
				textView.delete(new Range(pos, pos + key.length()));
				textView.insertElement(pos,pic.getValue());
			}
		}	
	}
		
}

2009-10-28

Blog at WordPress.com.

%d bloggers like this: