Skip to content

Instantly share code, notes, and snippets.

View BaseCase's full-sized avatar

Casey Brant BaseCase

  • Madison, WI
View GitHub Profile
@BaseCase
BaseCase / add_property.js
Last active August 29, 2015 13:57
Makes it super easy to convert `foo.bar` and `foo.bar = baz` into method calls instead of property lookups!
function add_property(prop_name, default_value) {
var getter = this['get_' + prop_name] || default_getter(prop_name);
var setter = this['set_' + prop_name] || default_setter(prop_name);
Object.defineProperty(this, prop_name, {
get: getter.bind(this),
set: setter.bind(this),
enumerable: true
});
@BaseCase
BaseCase / gist:b62f39a4889ba3ebc0ae
Last active August 29, 2015 14:05
using a counter instead of range() in a while loop
a = [7,12,9,14,15,18,12]
b = [9,14,8,3,15,17,15]
big = []
i = 0
length = len(a)
while i < length:
big.append(max(a[i], b[i]))
i += 1
@BaseCase
BaseCase / movie_time.py
Last active August 29, 2015 14:07
uses OMDB to grab running times for a list of movie titles
# Requires the 'requests' lib to be installed in your python path
# usage: `python movie_time.py "title 1" "title 2" "title 3" (etc.)`
# OR: `python movie_time.py -f filename` # file format should be newline separated list of titles
#
# output is a list of run times for each movie plus the total
# it will return 0 for the runtime of a movie it can't find
import sys
import requests

"Messy fridges are common, but their contents can be organized quickly and simply by standing things on end. I happen to love carrots, for example. If you open my fridge, you'll find carrots standing in the drink holders on the door."

"This is the routine I follow every day when I return from work. First, I unlock the door and announce to my house, “I’m home!” Picking up the pair of shoes I wore yesterday and left out in the entranceway, I say, “Thank you very much for your hard work,” and put them away in the shoe cupboard. Then I take off the shoes I wore today and place them neatly in the entranceway. Heading to the kitchen, I put the kettle on and go to my bedroom. There I lay my handbag gently on the soft sheepskin rug and take off my outdoor clothes. I put my jacket and dress on a hanger, say, “Good job!” and hang them temporarily from the closet doorknob. I put my tights in a laundry basket that fits into the bottom right corner of my closet, open a drawer, select the clothes I feel like wearing insid

;Exercise 1.1 - Given the Scheme code, what's the output?
10
;10
(+ 5 3 4)
;12
(- 9 1)
;8
;Exercise 1.2 -
(/ (+ 5 4
(- 2
(- 3
(+ 6
(/ 4 5)))))
(* 3
(- 6 2)
(- 2 7)))
;Exercise 1.3 - Define a procedure that takes three numbers
; and returns the sum of the squares of the two larger numbers.
(define (sum-of-squares a b)
(+ (* a a) (* b b)))
(define (foo a b c)
(cond ((and (>= a c) (>= b c)) (sum-of-squares a b))
((and (>= a b) (>= c b)) (sum-of-squares a c))
((and (>= b a) (>= c a)) (sum-of-squares b c))))
;first snippet
(define (+ a b)
(if (= a 0)
b
(inc (+ (dec a) b))))
;second snippet
(define (+ a b)
(if (= a 0)
b
;Exercise 1.4 - Describe the behavior of the following prodcedure:
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
;Exercise 1.5 - Applicative vs normal-order evaluation.
;given this code:
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
;what happens when we evaluate this?