Skip to content

Instantly share code, notes, and snippets.

View tyler's full-sized avatar

Tyler McMullen tyler

View GitHub Profile
def recursive(n)
if n < 3
n
else
recursive(n - 1) +
2 * recursive(n - 2) +
3 * recursive(n - 3)
end
end
# 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
# 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
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
def even?(n)
n % 2 == 0
end
def fast_mult(b, n)
a = 0
while n > 0
if even?(n)
n /= 2
b *= 2
# Fibonacci numbers in logarithmic time
def even?(n)
n % 2 == 0
end
def fib(n)
a = 1
b = 0
#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;
class Scanner
class << self
attr_accessor :p, :marker, :line, :line_marker, :data, :output
end
%%{
machine scanner;
variable p self.p;
variable data self.data;
--- src/http/modules/ngx_http_image_filter_module_old.c 2010-09-01 17:02:17.000000000 -0700
+++ src/http/modules/ngx_http_image_filter_module.c 2010-09-01 17:06:17.000000000 -0700
@@ -16,6 +16,7 @@
#define NGX_HTTP_IMAGE_SIZE 2
#define NGX_HTTP_IMAGE_RESIZE 3
#define NGX_HTTP_IMAGE_CROP 4
+#define NGX_HTTP_IMAGE_BOX 5
#define NGX_HTTP_IMAGE_START 0
@tyler
tyler / llvm-lisp.py
Created December 24, 2010 09:45
a basic lisp using llvm-py
from llvm import *
from llvm.core import *
m = Module.new('lisp')
main = m.add_function(Type.function(Type.int(), []), "main")
main_block = main.append_basic_block('entry')
b = Builder.new(main_block)
class ReferenceNotFound(Exception):
pass