This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 || |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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);}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Let's build the following contructor for YQL | |
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Jsonp(url,callback){this.url=url;this.callback=callback;}Jsonp.prototype.fetch=function(){var id=new Date().getTime(),fn="callback_"+id,url=this.url.replace("=?","=Jsonp."+fn),that=this,s=document.createElement("script");s.type="text/javascript";Jsonp[fn]=this.evalJSON(this.callback,that);s.src=url;document.getElementsByTagName("head")[0].appendChild(s);this.s=s;this.fn=fn;};Jsonp.prototype.evalJSON=function(callback,that){return function(data){var validjson=false;if(typeof data=="string"){try{validjson=JSON.parse(data);}catch(e){}}else{if(typeof data=="object"){validjson=data;}else{validjson=JSON.parse(JSON.stringify(data));console.log("response data was not a JSON string");}}if(validjson){callback(validjson);delete Jsonp[that.fn];document.getElementsByTagName("head")[0].removeChild(that.s);}else{console.log("JSONP call returned invalid JSON or empty JSON");}};}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Jsonp(url, callback) { | |
this.url = url; | |
this.callback = callback | |
} | |
Jsonp.prototype.fetch = function() { | |
var id = new Date().getTime(), | |
fn = "callback_" + id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tpl = "<li><a href='http://twitter.com/{from_user}'>{from_user}</a> {text}<span>{created_at}</span></li>", | |
urltwitter = 'http://search.twitter.com/search.json?q=mootools&rpp=5&callback=?'; | |
new Jsonp(urltwitter, function(data){ | |
var result = data.results, | |
out = '<ul>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var urltwitter = 'http://search.twitter.com/search.json?q=mootools&rpp=5&callback=?' | |
jsonp.fetch(urltwitter, function(data){ | |
var result = data.results, | |
out = '<ul>' | |
for(var i in result) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonp={counter:0,fetch:function(url,callback){var fn="jsoncallback_"+this.counter++;window[fn]=this.evalJsonp(callback);url=url.replace("=?","="+fn);var s=document.createElement("script");s.type="text/javascript";s.src=url;document.getElementsByTagName("head")[0].appendChild(s);},evalJsonp:function(callback){return function(data){var validjson=false;if(typeof data=="string"){try{validjson=JSON.parse(data);}catch(e){}}else{if(typeof data=="object"){validjson=data;}else{validjson=JSON.parse(JSON.stringify(data));console.log("response data was not a JSON string");}}if(validjson){callback(validjson);}else{console.log("JSONP call returned invalid JSON or empty JSON");}};}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonp = { | |
counter: 0, | |
fetch: function(url, callback) { | |
var fn = "jsoncallback_" + this.counter++; | |
window[fn] = this.evalJsonp(callback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* @thinkphp | |
* | |
* Approximate the function sin with series Taylor! | |
* cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + ....(-1)^n*x^(2n)/(2n)!; | |
* | |
*/ | |
function fact($n) { |