Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar

Adrian Statescu thinkphp

View GitHub Profile
@aaronjwood
aaronjwood / swap.go
Created November 2, 2016 03:42
Comparing variable swap with XOR and with temporary variable.
package main
func Swap(a, b int) int {
a = a ^ b
b = b ^ a
a = a ^ b
return a
}
@thinkphp
thinkphp / gist:2327342
Created April 7, 2012 10:37
JSONP Light Usage
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>'
@thinkphp
thinkphp / gist:2327336
Created April 7, 2012 10:37
JSONP Light minified
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};})();
@thinkphp
thinkphp / gist:2327334
Created April 7, 2012 10:36
JSONP Light
var JSONP = (function(){
/*private members*/
var counter = 0,
query,
key,
head,
context = this;
/*private method that becomes public method through return object*/
@thinkphp
thinkphp / gist:2326585
Created April 7, 2012 08:55
MooTools-YQL usage
(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);
@thinkphp
thinkphp / gist:2326582
Created April 7, 2012 08:54
MooTools-YQL Plugin
Request.YQL = new Class({
Extends: Request.JSONP,
_endpoint: 'http://query.yahooapis.com/v1/public/yql',
_formats: ['json','xml'],
initialize: function(query, options, vars) {
@thinkphp
thinkphp / gist:2261855
Created March 31, 2012 10:41
jQuery-yql usage
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
@thinkphp
thinkphp / gist:2261843
Created March 31, 2012 10:40
jQuery-yql plugin
(function($){
$.extend({
_prepareParams: function(query, params) {
$.each(params,function(key){
var name = "#{"+ key +"}",
@thinkphp
thinkphp / gist:2162772
Created March 22, 2012 19:42
YQLCache minified
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
@thinkphp
thinkphp / gist:2162763
Created March 22, 2012 19:41
YQLCache
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 ||