Skip to content

Instantly share code, notes, and snippets.

View redsquirrel's full-sized avatar
🐿️

Dave Hoover redsquirrel

🐿️
  • Flexa, Inc.
  • Evanston, IL
  • 13:28 (UTC -05:00)
  • X @davehoover
View GitHub Profile
##
# HACKER: Dave Hoover
#
# AUTHORS: Geoffrey Grosenbach http://nubyonrails.com
# Also http://p.ramaze.net/1887
#
# RUN:
# script/console
# paste the following and make sure an exception is thrown
;; SICP 1.5
;; Given:
;;
;; (define (p) (p))
;;
;; (define (test x y)
;; (if (= x 0)
;; 0
;; y))
;; What happens when Alyssa uses new-if is that all of new-if's
;; "arguments" are evaluated and then given to new-if, as opposed
;; to the special form of "if" where the "else" clause is only
;; evaluated if the predicate is false. Since there is a
;; recursive call in the "else" clause, the call never returns.
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
;; The good-enough? test used in computing square roots will not be
;; very effective for finding the square roots of very small numbers. Explain.
;;
;; good-enough? is not effective for small numbers because the square
;; of a small number minus the number quickly becomes less than 0.001.
(sqrt 0.00001)
(define (cbrt-iter guess x)
(if (good-enough? guess x)
guess
(cbrt-iter (improve guess x)
x)))
(define (improve guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))
(define (good-enough? guess x)
require "hpricot" # need hpricot and open-uri
require "open-uri"
require "date"
current_date = Date.civil(2007, 6, 16)
while (current_date != Date.today)
puts "#{ current_date }:#{ fetch_number_of_assaults(current_date) }"
current_date = current_date.next
end
require "hpricot" # need hpricot and open-uri
require "open-uri"
require "date"
current_date = Date.civil(2007, 6, 16)
while (current_date != Date.today)
puts [current_date, fetch_number_of_assaults(current_date)].join(":")
current_date = current_date.next
end
require 'httparty'
require 'json'
class Campfire
include HTTParty
base_uri 'https://YOUR_DOMAIN.campfirenow.com'
basic_auth 'YOUR_API_KEY', 'X' # yes, that is a literal X string. it's needed to satisfy basic_auth(), but campfire ignores it.
headers 'Content-Type' => 'application/json'
def self.speak(message)
#!/usr/bin/env ruby
# Print the vaportrail of a ruby file in a git repo, i.e.,
# the complexity level at each commit.
#
# Requires: >= bash ?.?
# >= git 1.7.1
# >= ruby 1.9.2
# >= flog 2.5.0
#
@redsquirrel
redsquirrel / _trending.html.erb
Created August 7, 2012 18:20 — forked from tjarmain/_trending.html.erb
Trying to set up rendering of partials within tabs using AJAX