Skip to content

Instantly share code, notes, and snippets.

require 'webrick'
require 'webrick/httpproxy'
require 'fileutils'
require 'md5'
###
# FakeWebRecorder is an HTTP Proxy that records sessions as calls to FakeWeb.
# The code that FakeWebRecorder generates should be suitable for testing
# interaction with a particular website.
#
@ryanbriones
ryanbriones / gist:269803
Created January 5, 2010 22:27 — forked from madmimi/gist:269783
post to Campfire via new API
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)
# getting more power out of Enumerable
# this is to convert an RGB data structure, into RGBA
RGB_WIDTH = 3
raw_data = [1,1,1,2,2,2,3,3,3,4,4,4]
# returns an enumerable object with the raw data split up into chunks of 3
pixels = raw_data.enum_slice( RGB_WIDTH )
@ryanbriones
ryanbriones / gist:193298
Created September 25, 2009 04:17 — forked from jimweirich/gist:189270
SICP Exercise 1.8
;; SICP 1.8
;; Fork me. Solve me.
(define (cube x) (* x x x))
(define (improve y x)
(/ (+ (/ x (* y y)) (* 2 y)) 3))
(define (good-enough? guess x)
(< (abs (- (cube guess) x)) 0.001))
@ryanbriones
ryanbriones / gist:193291
Created September 25, 2009 04:02 — forked from jimweirich/gist:189259
SICP Exercise 1.6
;; SICP 1.6
;; Fork me. Solve me.
;; if is a special form that only evaluates the arguments after the predicate has been evaluated.
;; since new-if evaluates it's arguments immediately, the program is sent into an infinite loop
;; evaluating sqrt-iter with an improved guess
@ryanbriones
ryanbriones / gist:193282
Created September 25, 2009 03:49 — forked from jimweirich/gist:189248
SICP Exercise 1.5
;; SICP 1.5
;; Given:
;;
;; (define (p) (p))
;;
;; (define (test x y)
;; (if (= x 0)
;; 0
;; y))
@ryanbriones
ryanbriones / gist:193272
Created September 25, 2009 03:25 — forked from redsquirrel/gist:189193
SICP Exercise 1.4
;; SICP 1.4
;; Fork me. Solve me.
;; ====
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
(a-plus-abs-b 1 2)
;; ((if (> 2 0) + -) 1 2)
;; (+ 1 2)
@ryanbriones
ryanbriones / gist:193268
Created September 25, 2009 03:19 — forked from redsquirrel/gist:189192
SICP Exercise 1.3
SICP 1.3
Fork me. Solve me.
====
(define (square x) (* x x))
(define (sum-of-squares a b) (+ (square a) (square b)))
(define (sum-two-largest-squares a b c)
(cond ((and (< a b) (< a c))
@ryanbriones
ryanbriones / gist:193262
Created September 25, 2009 03:06 — forked from redsquirrel/gist:189191
SICP Exercise 1.2
SICP 1.2
Fork me. Solve me.
====
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3 (- 6 2) (- 2 7)))
;; => -37/150
@ryanbriones
ryanbriones / gist:193257
Created September 25, 2009 02:51 — forked from redsquirrel/gist:189190
SICP Exercise 1.1
SICP 1.1
Fork me. Solve me.
====
;; I wasn't completely clear on the point of this exercise
;; so I tried doing them in my head before running them in the repl
10 ;; => 10
(+ 5 3 4) ;; => 12
(- 9 1) ;; => 8