Built on Scriptaculous Autocompleter.local object, this class allows you to inject Google Suggest suggestions into any text field (input with type="text"). In the example, the input has an id of "searchBox" and the auto-populated dropdown div has an id of "searchBoxSuggestions"
GoogleSuggestAutocompleter = Class.create();
Object.extend(Object.extend(GoogleSuggestAutocompleter.prototype, Autocompleter.Local.prototype), {
cache: {},
getUpdatedChoices: function() {
var tok = this.getToken().toLowerCase();
if (this.cache[tok]) return this.sendRPCDone( null, tok, this.cache[tok] );
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://www.google.com/complete/search?hl=en&client=suggest&js=true&q=' + encodeURIComponent(tok);
document.body.appendChild(script);
},
sendRPCDone: function( meh, tok, list ) {
if (!list) return this.updateChoices( '<ul></ul>' );
if (!this.cache[tok]) this.cache[tok] = list;
var values = list.collect( function(v) {
return '<b>'+v.slice(0, tok.length)+'</b>'+v.slice(tok.length);
});
this.updateChoices( '<ul><li>' + values.join('</li><li>') + '</li><ul>' );
}
});
var frameElement, google = {};
Event.observe(window, 'load', function(event) {
google.ac = new GoogleSuggestAutocompleter( "searchBox", "searchBoxSuggestions", null, { minChars: 1 } );
}, 'false');
Simple PHP script to help you convert your files to either base64 or percent encoded strings. Presumably for use in Data URIs, or otherwise embedding image data directly in another file/format.
<?php
if ($_FILES && $_FILES['uploadfile']) {
header( "Content-type: text/plain; charset=UTF-8" );
$fp = fopen( $_FILES['uploadfile']['tmp_name'], 'rb' );
if ($_POST['base64']) {
while (!feof($fp)) echo(base64_encode(fread($fp, 45))."\n");
} else {
$buf = '';
while (!feof($fp)) {
$buf .= rawurlencode(fread($fp, 120));
while (strlen($buf)>=60) {
echo(substr($buf,0,60)."\n");
$buf = substr($buf,60);
}
}
if ($buf) echo($buf);
}
fclose($fp);
die();
}
?>
<html>
<head>
<title>Base64 File Encoder</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<p><label>File to convert: <input type="file" name="uploadfile" /></label>
<p><label>Check here to use base64 encoding: <input type="checkbox" name="base64" checked="checked" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
</body>
</html>
Code to embed a Google Calendar in any page. Replace "GOOGLE_EMAIL_ADDRESS" in the src attribute with the chosen user. Because this is an iframe, there's no need to fork over your password to the party doing the embedding.