Skip to content

Instantly share code, notes, and snippets.

View gar's full-sized avatar

Gar Morley gar

View GitHub Profile
@gar
gar / config.ru
Created January 22, 2012 10:17
Streaming example from Sinatra: Up and Running
# based on Heroku's documentation
require './streaming'
run Sinatra::Application
#include <stdio.h>
#include <string.h>
#define MAXLEN 256
void reverse(char *s, char *r);
main() {
char s[MAXLEN] = "hello reversed world!";
char r[MAXLEN];
def add(m, n)
total = m
for i in 1..n do
total += 1
end
total
end
def exp(m, n)
total = 1
@gar
gar / gist:647564
Created October 26, 2010 19:05
exercise1.8.rkt
; SICP Exercise 1.8
#lang racket
(define (cube-root x)
(define (square y) (* y y))
(define (good-enough? guess)
(< (abs (- (square guess) x)) 0.001))
(define (improve guess)
(/ (+ (square (/ guess x)) (* 2 guess))) 3)
; SICP Exercise 1.1
10 => 10
(+ 5 3 4) => 12
(- 9 1) => 8
(/ 6 2) => 3
(+ (* 2 4) (- 4 6)) => 6
(define a 3)
(define b (+ a 1))
(+ a b (* a b)) => 19
@gar
gar / antelopes.rb
Created October 6, 2010 17:18
Which antelope would score the most in Scrabble?
ANTELOPES = [:addax,:antelope,:antilopine,:ariel,:blackbuck,:blaubok,:bluebuck,:bloubok,:blesbok,:blesbuck,:bok,:bongo,:bontebok,:boschbok,:boshbok,:bosbok,:bubal,:bubale,:bubalis,:bubaline,:cabrie,:cabrit,:chamois,:chikara,:chinkara,:chiru,:dikdik,:duiker,:duyker,:duikerbok,:dzeren,:eland,:gazelle,:gemsbok,:gemsbuck,:gerenuk,:gnu,:goa,:gooral,:goral,:grysbok,:hartbees,:hartebeest,:hartbeest,:impala,:inyala,:nyala,:kaama,:klipspringer,:kob,:kongoni,:koodoo,:kudu,:lechwe,:madoqua,:marshbuck,:mhorr,:mohr,:nagor,:nilgai,:nilgau,:nilghai,:nilghau,:nylghai,:nylghau,:oribi,:ourebi,:oryx,:palebuck,:pallah,:prongbuck,:pronghorn,:puku,:pygarg,:reebok,:rhebok,:reedbuck,:reitbok,:saiga,:sasin,:sassaby,:tsessebe,:serow,:shamois,:sitatunga,:situtunga,:springbok,:springbuck,:steenbok,:steinbok,:steinbock,:stembok,:stembuck,:steenbuck,:thar,:topi,:tragelaph,:antelope,:antilopine,:ariel,:blackbuck,:blaubok,:bluebuck,:bloubok,:blesbok,:blesbuck,:bok,:bongo,:bontebok,:boschbok,:boshbok,:bosbok,:bubal,:bubale,:bubalis,:bubaline
class ReportCard
def initialize(print_strategy)
@print_strategy = print_strategy.new
@grades = Hash.new
end
def add_grade(subject, grade)
@grades[subject] = grade
end