Skip to content

Instantly share code, notes, and snippets.

View tyler's full-sized avatar

Tyler McMullen tyler

View GitHub Profile
class PostsController
def show
...
respond_to do |format|
format.html
format.css do
render :string => post.css
end
end
end
@tyler
tyler / gist:54295
Created January 29, 2009 01:02 — forked from kpumuk/gist:54141
# Usage:
# >> User.random
# => #<User login: ...
class ActiveRecord::Base
def self.random
cc = count
begin
find(rand(cc))
user system total real
Hash Insert: 0.050000 0.000000 0.050000 ( 0.050243)
Trie Insert: 1.810000 0.010000 1.820000 ( 1.829849)
user system total real
Hash Search: 8.240000 0.030000 8.270000 ( 8.318251)
Trie Search: 5.990000 0.020000 6.010000 ( 6.055828)
@tyler
tyler / gist:139902
Created July 3, 2009 04:25
Really basic major mode for Potion
; Potion Mode
(defconst potion-indent-offset 2 "Offset for indentation.")
; Stolen from Ioke Mode
(defconst potion-operator-symbols
'("?" "..." "=>" "++" "--" "*" "/" "%" "+" "-" "<<" ">>" ">" "<" "<=" ">=" "<=>" "==" "!=" "=~" "!~" "&" "^" "|" "&&" "||" ".." "=" "+=" "-=" "*=" "/=" "%=" "&=" "^=" "|=" "<<=" ">>=" "<-" "<->" "->")
"Potion mode operator symbols")
(defgroup potion-font-lock-faces nil
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <time.h>
typedef struct _Node {
int key;
(defconst css2-tags
'("a" "abbr" "acronym" "address" "applet" "area" "b"
"base" "basefont" "bdo" "big" "blockquote" "body" "br"
"button" "caption" "center" "cite" "code" "col"
"colgroup" "dd" "del" "dfn" "dir" "div" "dl" "dt" "em"
"fieldset" "font" "form" "frame" "frameset" "h1" "h2"
"h3" "h4" "h5" "h6" "head" "hr" "html" "i" "iframe"
"img" "input" "ins" "isindex" "kbd" "label" "legend"
"li" "link" "map" "menu" "meta" "noframes" "noscript"
"object" "ol" "optgroup" "option" "p" "param" "pre" "q"
@tyler
tyler / gist:341783
Created March 23, 2010 22:54
Binomial Distribution
def factorial(n)
(2..n).inject(1) { |o,k| o * k }
end
def binomial_coefficient(n,k)
factorial(n) / (factorial(n - k) * factorial(k))
end
def binomial_distribution(p,n)
(1..n).inject(0) do |total,k|
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
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);
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