Skip to content

Instantly share code, notes, and snippets.

View tyler's full-sized avatar

Tyler McMullen tyler

View GitHub Profile
@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|
(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"
#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;
@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
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: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))
class PostsController
def show
...
respond_to do |format|
format.html
format.css do
render :string => post.css
end
end
end