Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar

Adrian Statescu thinkphp

View GitHub Profile
@thinkphp
thinkphp / gist:1448754
Created December 8, 2011 21:44
Binary Search Tree Implementation in PHP
<?php
/**
* by Adrian Statescu <adrian@thinkphp.ro>
* Twitter: @thinkphp
* G+ : http://gplus.to/thinkphp
* MIT Style License
*/
@thinkphp
thinkphp / gist:1862867
Created February 19, 2012 09:51
sin(x) in Python
'''
sin(x) = x-x^3/3!+x^5/5!-x^7/7!+..-
'''
import math
def fact(n):
if n==0:
return 1
else:
return n*fact(n-1)
@thinkphp
thinkphp / gist:1543590
Created December 31, 2011 10:07
Computes square root in Python SQRT
'''
Computes SQuare RooT in Python SQRT
s = (s+nr/s)1/2
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
'''
@thinkphp
thinkphp / gist:1450738
Created December 9, 2011 08:29
Binary Search Tree implementation in Python
'''
by Adrian Statescu <adrian@thinkphp.ro>
Twitter: @thinkphp
G+ : http://gplus.to/thinkphp
MIT Style License
'''
'''
Binary Search Tree
------------------
@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: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: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: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*/