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
#include <event.h> | |
#include <evhttp.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <sys/time.h> | |
typedef struct { | |
const char * uri; | |
struct evhttp_request * ev_req; |
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
# Fibonacci numbers in logarithmic time | |
def even?(n) | |
n % 2 == 0 | |
end | |
def fib(n) | |
a = 1 | |
b = 0 |
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
def even?(n) | |
n % 2 == 0 | |
end | |
def fast_mult(b, n) | |
a = 0 | |
while n > 0 | |
if even?(n) | |
n /= 2 | |
b *= 2 |
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
def even?(n) | |
n % 2 == 0 | |
end | |
def fast_mult(b, n) | |
if n == 0 | |
0 | |
elsif even?(n) | |
fast_mult(b, n / 2) * 2 | |
else |
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
# Iterative O(log n) exponentiation | |
def fast_expt(b, n) | |
a = 1 | |
while n > 0 | |
if even?(n) | |
n /= 2 | |
b *= b | |
else | |
n -= 1 | |
a *= b |
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
# Returns an array representing a specific level of Pascal's triangle | |
def pascal1(n) | |
if n == 1 | |
[1] | |
else | |
nl = [0] + pascal1(n-1) + [0] | |
l = [] | |
(nl.size - 1).times do |i| | |
l << nl[i] + nl[i+1] | |
end |
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
def recursive(n) | |
if n < 3 | |
n | |
else | |
recursive(n - 1) + | |
2 * recursive(n - 2) + | |
3 * recursive(n - 3) | |
end | |
end |
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
def A(x,y) | |
if y == 0 | |
0 | |
elsif x == 0 | |
2 * y | |
elsif y == 1 | |
2 | |
else | |
A(x - 1, A(x, y - 1)) | |
end |
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
Search.prototype._findNthWord = function(node, n, current_count) { | |
if(current_count === undefined) | |
current_count = { i: 0 }; | |
var children = node.childNodes; | |
for(var i = 0; i < children.length; i++) { | |
var child = children[i]; | |
switch(child.nodeType) { | |
case 1: | |
var result = this._findNthTextNode(child, n, current_count); |
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
diff --git a/Makefile b/Makefile | |
index fe1e2b2..22546c1 100644 | |
--- a/Makefile | |
+++ b/Makefile | |
@@ -5,7 +5,7 @@ PHP_EXT_BUILD=$(REDIS_HOME)/php/build | |
libredis: src/batch.o src/connection.o src/ketama.o src/md5.o src/module.o src/parser.o src/buffer.o | |
mkdir -p lib | |
- gcc -shared -o"lib/libredis.so" ./src/batch.o ./src/buffer.o ./src/connection.o ./src/ketama.o ./src/md5.o ./src/module.o ./src/parser.o -lm -lrt | |
+ gcc -shared -o "lib/libredis.so" ./src/batch.o ./src/buffer.o ./src/connection.o ./src/ketama.o ./src/md5.o ./src/module.o ./src/parser.o -lm |