Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar
💭
If I have seen further it is only by standing on the shoulders of giants. NEWTON

Adrian Statescu thinkphp

💭
If I have seen further it is only by standing on the shoulders of giants. NEWTON
View GitHub Profile
@thinkphp
thinkphp / gist:1476358
Created December 14, 2011 12:12
Array.prototype.reverse 3 methods
Array.prototype.reverse1 = function() {
var stack = [],
n = this.length
for(var i=n-1;i>=0;i--) {
stack.push(this[i])
}
return stack
}
Array.prototype.reverse2 = function() {
var i = 0,
@thinkphp
thinkphp / gist:1476390
Created December 14, 2011 12:27
Reverse the order of the items in the array in Python
'''
Reverse the order of the items in the array.
@thinkphp
MIT Style License
'''
arr = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
def reverse(arr):
m = len(arr) / 2
n = len(arr) - 1
for i in range(m):
@thinkphp
thinkphp / gist:1501320
Created December 20, 2011 11:48
math.pi
'''
Calculate the value of PI using Infinite Series
Twitter: @thinkphp
Website: http://thinkphp.ro
G+ : http://gplus.to/thinkphp
MIT Style License
4*(1- 1/3 + 1/5 - 1/7 + 1/9 +...)
'''
import math
@thinkphp
thinkphp / gist:1528363
Created December 28, 2011 15:32
e in Python
'''
Computes the value of e(2.718281827...) using infinite series
Twitter: @thinkphp
Website: http://thinkphp.ro
G+ : http://gplus.to/thinkphp
MIT Style License
1 + 1/1! + 1/2! + 1/3! + ...
2 + 1/2! + 1/3!+ ...
'''
@thinkphp
thinkphp / gist:1529713
Created December 28, 2011 21:00
Ln in Python
'''
x
f(x) = e - a
if f(0)*f(a) < 0 then exists the solution (0,a]
'''
import math
import sys
def loge(n,li,ls):
if math.fabs(li-ls) <= 0.000001:
@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:1544807
Created December 31, 2011 18:10
Sieve of Eratosthenes in Python
'''
Sieve of Eratosthenes in Python
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
'''
import sys
@thinkphp
thinkphp / gist:1544812
Created December 31, 2011 18:11
Primes
'''
Primes
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
'''
import math
import sys
@thinkphp
thinkphp / gist:1641985
Created January 19, 2012 19:29
Insertion Sort in JavaScript
/*
Insertion Sort in JavaScript
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
*/
function insertionSort(arr) {
var n = arr.length-1,
@thinkphp
thinkphp / gist:1642090
Created January 19, 2012 19:38
Insertion Sort in PHP
/**
Insertion Sort in PHP
Twitter : http://twitter.com/thinkphp
Website : http://thinkphp.ro
Google Plus : http://gplus.to/thinkphp
MIT Style License
*/
function insertionSort($arr){
$n = count($arr);