This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FromHashable | |
def initialize hash | |
@hash = hash | |
set_ivars | |
set_methods | |
set_as_hash | |
end | |
private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT main_genres.* | |
FROM main_genres | |
JOIN movie_genres ON movie_genres.genre_id = main_genres.genre_id | |
JOIN netflix_instant_movies ON netflix_instant_movies.id = movie_genres.netflix_instant_movie_id | |
JOIN rotten_tomatoes ON rotten_tomatoes.netflix_instant_movie_id = netflix_instant_movies.id | |
JOIN netflix_instant_movie_imports ON netflix_instant_movie_imports.netflix_instant_movie_id = netflix_instant_movies.id | |
JOIN netflix_instant_imports ON netflix_instant_imports.id = netflix_instant_movie_imports.netflix_instant_import_id | |
WHERE netflix_instant_imports.id = | |
(SELECT id | |
FROM netflix_instant_imports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Curryable | |
def def_function &block | |
@function = block | |
end | |
def call arg | |
unless @function | |
raise StandardError, 'must define a function with def_function' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
countChange :: Integer -> [Integer] -> Integer | |
countChange amount denominations | |
| null denominations || amount < 0 = 0 | |
| amount == 0 = 1 | |
| otherwise = countChange amount (tail denominations) + countChange (amount - head denominations) denominations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SICP 1.11 | |
-- | |
-- A function f is defined by the rule that f(n) = n if n < 3 and | |
-- f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n >= 3. Write a | |
-- procedure computes f by means of a recursive process. | |
-- | |
f :: Integer -> Integer | |
f n | |
| n < 3 = n | |
| otherwise = f (n - 1) + 2 * f (n - 2) + 3 * f (n - 3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SICP 1.12 | |
-- | |
-- The following pattern of numbers is called Pascal's triangle. | |
-- | |
-- 1 | |
-- 1 1 | |
-- 1 2 1 | |
-- 1 3 3 1 | |
-- 1 4 6 4 1 | |
-- ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Evented; | |
Evented = { | |
on: function(event, callback) { | |
var _base; | |
(_base = this.callbacks)[event] || (_base[event] = []); | |
return this.callbacks[event].push(callback); | |
}, | |
trigger: function(event) { | |
var args, callbacks; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ... | |
-- ... | |
-- [Assume your language doesn't have a multiplication function or | |
-- table. Given `double` and `half` functions,] design a | |
-- multiplication procedure that uses a logarithmic number of steps. | |
double :: Integer -> Integer | |
double x = x + x | |
halve :: Integer -> Integer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- [Design an *iterative* process for multiplying to integers that] uses a | |
-- logarithmic number of steps. | |
double :: Integer -> Integer | |
double x = x + x | |
halve :: Integer -> Integer | |
halve x = x `div` 2 | |
multiply :: Integer -> Integer -> Integer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
/usr/local/Cellar/bison/3.0.4/bin/bison lispcalc.y && gcc -lm -o lispcalc lispcalc.tab.c |