Skip to content

Instantly share code, notes, and snippets.

View mattknox's full-sized avatar

matt knox mattknox

View GitHub Profile
Gem::Specification.new do |s|
s.name = %q{goaloc}
s.version = "0.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["matt knox"]
s.date = %q{2009-01-09}
s.default_executable = %q{goaloc}
s.description = %q{Generate On A Lot of Crack speeds and extends the early sketching phase of RESTFUL MVC app development}
s.email = %q{matthewknox@gmail.com}
1: C
2: PHP
3: JavaScript
4: C++
5: Java
6: Ruby
7: Emacs Lisp
8: Python
9: Perl
10: C Sharp
- simple
- public over private
- personal vanity
- internet is global
- permalinks
- one important item per page
- don't break the browser
- don't wanker in technology
- a medium is not a grande
- break convention for your users
module CouchRest
class Logger
def initialize(app, db=nil)
@app = app
@db = db
end
def call(env)
log['started_at'] = Time.now
# inject our logger into CouchRest HTTP abstraction layer
module HttpAbstraction
def self.get(uri, headers=nil)
start_query = Time.now
log = {:method => :get, :uri => uri, :headers => headers}
response = super(uri, headers=nil)
end_query = Time.now
log[:duration] = (end_query - start_query)
CouchRest::Logger.record(log)
function step_std_dev(val) {
n += 1
delta = val - mean
mean = mean + delta/n
M2 = M2 + delta*(val - mean) # This expression uses the new value of mean
if (n > 1) {
variance_n = M2/n
variance = M2/(n - 1)
}
}
module MathFunctions
include InlineTest
def factorial(n)
(1..n).inject(1) { |acc, x| acc * x}
end
unit_test do
assert factorial(6) == 720
assert factorial(5) == 120
@mattknox
mattknox / init.el
Created September 15, 2010 19:13 — forked from aaroncampos/init.el
;; Helpful macro function
(defun my-macro-query (arg)
"Prompt for input using minibuffer during kbd macro execution.
With prefix argument, allows you to select what prompt string to use.
If the input is non-empty, it is inserted at point."
(interactive "P")
(let* ((query (lambda () (kbd-macro-query t)))
(prompt (if arg (read-from-minibuffer "PROMPT: ") "Input: "))
(input (unwind-protect
(progn
@mattknox
mattknox / gist:703954
Created November 17, 2010 19:56
hamming numbers in haskell, common lisp and scheme
main = print (take 1000 hamming)
hamming = 1 : map (2*) hamming ~~ map (3*) hamming ~~ map (5*) hamming
where
xxs@(x:xs) ~~ yys@(y:ys) -- To merge two streams:
| x==y = (x : xs~~ys) -- if the heads are common, take that
| x<y = (x : xs~~yys) -- otherwise, take the smaller one
| x>y = (y : xxs~~ys) -- and proceed to merge the rest
(defun n-hammings (twos threes fives tail n out)
(if (= n 0)
ls .rvm/gems/ree-1.8.7-2010.02/gems/ | perl -ne 's/(.*)-[.\d]+/$1/; print' | sort | uniq >~/gems
...change to a different ruby...
cat ~/gems | xargs gem install