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.2 | |
| Fork me. Solve me. |
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
| (5 + 4 + (2 - (3 - (6 + 4/5)))) / (3 * (6-2) * (2 - 7)) | |
| (+ 5 4 (2 - (3 - (6 + 4/5)))) / (3 * (6-2) * (2 - 7)) # prefix first set of addition | |
| (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))) / (3 * (6-2) * (2 - 7)) # prefix entire left side | |
| (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))) / (* 3 (- 6 2) (- 2 7)) # prefix right side | |
| (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7)) ) # prefix the rest |
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
| ( define ( sum-of-squares x y ) | |
| (+ (* x x) (* y y)) | |
| ) | |
| ( define ( exercise_answer x y z ) | |
| ( if ( > x y ) | |
| ( if ( > y z ) | |
| ( sum-of-squares x y ) | |
| ( sum-of-squares x z ) | |
| ) |
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
| (define (a-plus-abs-b a b) | |
| ((if (> b 0) + -) a b)) | |
| ( a-plus-abs-a-b 5 6 ) ; method invocation | |
| ((if (> 6 0) + -) 5 6) ; method with paramters filed in | |
| ((+) 5 6) ; evaluate the if statemnt | |
| (+ 5 6) | |
| 11 | |
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 Foo | |
| class Bar | |
| end | |
| end | |
| Foo::Bar.new | |
| Foo:: Bar.new |
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
| (import '(java.io File)) | |
| (defn file-list | |
| "returns a lists of files in a directory" | |
| ([dir] (.listFiles (File. dir) ))) | |
| (defn file-names [dir] | |
| (map #(.getName %) (file-list dir))) | |
| (defn ruby-files [dir] |
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
| (ns server.udp | |
| (:import (java.net InetAddress DatagramPacket DatagramSocket))) | |
| (def udp-server (ref nil)) | |
| (def port 3333) | |
| (defn localhost [] (. InetAddress getLocalHost)) | |
| (defn message [text] |
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
| # bwahahahahahaha | |
| op1 = Spec::Runner::OptionParser.parse("/spec/models/something.rb", STDERR, STDOUT) | |
| op2 = Spec::Runner::OptionParser.parse("/spec/models/something-else.rb", STDERR, STDOUT) | |
| Kernel.fork { Spec::Runner::CommandLine.run op1} ; Kernel.fork { Spec::Runner::CommandLine.run op2} |
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
| # getting more power out of Enumerable | |
| # this is to convert an RGB data structure, into RGBA | |
| require 'enumerator' | |
| 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 ) |
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
| (import | |
| '(java.awt Color Graphics Dimension) | |
| '(javax.swing JFrame JPanel)) | |
| (def width 640) | |
| (def height 480) | |
| (defn render [g] ) | |
| (def panel (doto (proxy [JPanel] [] |