Instantly share code, notes, and snippets.

View gist:2327342
var tpl = "<li><a href='http://twitter.com/{from_user}'>{from_user}</a> {text}<span>{created_at}</span></li>";
var url = 'http://search.twitter.com/search.json';
JSONP.get(url, {q: 'mootools', rpp: 10}, function(data){
var result = data.results,
out = '<ul>'
View gist:2327336
var JSONP=(function(){var counter=0,query,key,head,context=this;function jsonp(url,params,callback){query="?";params=params||{};for(var key in params){if(params.hasOwnProperty(key)){query+=encodeURIComponent(key)+"="+encodeURIComponent(params[key])+"&";}}var fnHandler="JSONP_"+(new Date().getTime())+"_"+(++counter);context[fnHandler]=function(data){callback(data);try{delete context[fnHandler];}catch(e){}context[fnHandler]=null;};url=url+query+"callback="+fnHandler;loadScript(url);}function loadScript(url){var s=document.createElement("script");s.src=url,s.async=true,done=false;s.onload=s.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){done=true;s.onload=s.onreadystatechange=null;if(s&&s.parentNode){s.parentNode.removeChild(s);}}};if(!head){head=document.getElementsByTagName("head")[0];}head.appendChild(s);}return{get:jsonp};})();
View gist:2327334
var JSONP = (function(){
/*private members*/
var counter = 0,
query,
key,
head,
context = this;
/*private method that becomes public method through return object*/
View gist:2326585
(function(){
var url = 'use "http://thinkphp.ro/apps/lastfm/YQL-open-data-table/recentlastfm.xml" as lastfm; select * from lastfm where username=#{username} and api_key=@api'
new Request.YQL(url, {
onSuccess: function(data){
$('result').set('html', data.query.results.result)
}},
{'username': 'olivboy','api': '2993c6e15c91a2890c2f11fa95673067'}
).send();
})(document.id);
View gist:2326582
Request.YQL = new Class({
Extends: Request.JSONP,
_endpoint: 'http://query.yahooapis.com/v1/public/yql',
_formats: ['json','xml'],
initialize: function(query, options, vars) {
View gist:2261855
var url = 'use "http://thinkphp.ro/apps/lastfm/YQL-open-data-table/recentlastfm.xml" as lastfm; select * from lastfm where username=#{username} and api_key=@{api}'
$(function(){
$.yql(url,
{username: 'asd', api: '2993c6e15c91a2890c2f11fa95673067'},
function(data){
document.getElementById('result').innerHTML = data.query.results.result
View gist:2261843
(function($){
$.extend({
_prepareParams: function(query, params) {
$.each(params,function(key){
var name = "#{"+ key +"}",
View gist:2162772
var yqlcache=function(){var cacheid,cb,cancache=(("localStorage" in window)&&(window.localStorage!==null));function get(transaction){if(!transaction.id||!transaction.callback||!transaction.yql||!transaction.cacheage){return}var current,data;cb=transaction.callback;cacheid=transaction.id;if(!cancache){loadYQL(transaction.yql)}if(cancache){current=JSON.parse(localStorage.getItem(cacheid));if(current!==null){if((new Date().getTime()-current.time)<transaction.cacheage){cb({type:"cached",data:current.data})}else{loadYQL(transaction.yql)}}else{loadYQL(transaction.yql)}}}function loadYQL(yql){var old=document.getElementById("yqloadscript");if(old){old.parentNode.removeChild(old)}var YQL="http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent(yql)+"&diagnostics=false&format=json&callback=yqlcache.cache";var s=document.createElement("script");s.setAttribute("type","text/javascript");s.id="yqloadscript";s.setAttribute("src",YQL);document.getElementsByTagName("head")[0].appendChild(s)}function cache(data){if(da
View gist:2162763
var yqlcache = function() {
/* Globals for JSON callback, check for cache support */
var cacheid, cb,
cancache = (("localStorage" in window) && (window["localStorage"] !== null));
/* get the data - expects a transaction object */
function get(transaction) {
if(!transaction.id ||
View gist:2162717
function YQLQuery(query,callback,format,diagnostics){this.query=query;this.format=format||"json";this.diagnostics=diagnostics||false;this.callback=callback||function(){};}YQLQuery.prototype.fetch=function(){if(!this.query||!this.callback){console.log("Fetch error: missing parameters!");return;}var scriptEl=document.createElement("script"),endpoint="http://query.yahooapis.com/v1/public/yql?q=",env="&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys",encodedURL=encodeURIComponent(this.query),format=this.format,id="yql"+(+new Date()),that=this,src=endpoint+encodedURL+"&format="+format+"&callback=YQLQuery."+id+"&diagnostics="+this.diagnostics+env;YQLQuery[id]=function(data){if(window.console){console.log(data);}that.callback(data);delete YQLQuery[id];document.body.removeChild(scriptEl);};scriptEl.src=src;document.body.appendChild(scriptEl);};