This file contains 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
# Method should do just one thing at a time | |
# How can we flag methods that are doing more than one thing? | |
# Words like and & or should never be in a method. These words indicate that | |
# the method is doing more than one thing. | |
# bad | |
def bake_and_eat(cookies) | |
cookies.bake | |
cookies.eat |
This file contains 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
students = YogaStudent.find(:all, :limit => 10) | |
# will return an array with 10 random yoga student records | |
ashtanga_students = students.select { |student| student[:xml].match(/ashtanga/) } | |
# will look only at the xml keys to match ashtanga in the values. |
This file contains 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(column_name) from table_name order by column_name ASC; |
This file contains 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
; The big change in logic happens at 5. You can use nested if statements to solve the kata up to 5. | |
; After that, its best to define the roman numerals and their numbers in pairs, and pull from that. | |
(def pairs [[10 "X"][9 "IX"][5 "V"] [4 "IV"] [1 "I"]]) | |
(defn roman [n] | |
(loop [n n | |
result "" | |
pairs pairs] | |
(if (< n 1) |
This file contains 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
(mapcat [1 2 3] [4 5 6]) | |
=> Gives an error. Mapcat wants a function and a coll, not two colls. | |
(maptcat str [4 5 6]) | |
=> Gives (\4 \5 \6). It applies the function its given to the coll its given. Then it concats the result. | |
(concat [4 5 6]) gives [4 5 6]. So really, mapcat is a great shortcut for accomplishing two things at once. |
This file contains 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
(concat [1 2 3] 4) | |
=> gives an error. Remember, concat wants to squish together 2 differnt collections of data. | |
(conj [1 2 3] 4) | |
=> gives [1 2 3 4]. Sucessfully adds an item to a collection. Added it to the end because the coll is a vector. | |
(concat [1 2 3] [4]) |
This file contains 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
private class CarBuilder { | |
private int year; | |
private String make; | |
public CarBuilder setYear(int year) { | |
this.year = year; | |
return this; | |
} | |
public CarBuilder setMake(String make) { |
This file contains 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
{"assignments":[{"slug":"robot-name","track":"clojure","files":{"robot.clj":"(ns robot)\r\n\r\n(def num-letters 26)\r\n\r\n(def name-seed\r\n (atom [0 0]))\r\n\r\n(defn- inc-name-seed\r\n []\r\n (swap! name-seed\r\n (fn [[letter number]]\r\n (if (\u003e= number 999)\r\n [(inc letter) 0]\r\n [letter (inc number)]))))\r\n\r\n(defn- letter-at\r\n [n]\r\n (char (+ n (int \\A))))\r\n\r\n(defn- generate-name\r\n []\r\n (let [[letter number] @name-seed\r\n result (str (letter-at (quot number num-letters))\r\n (letter-at (mod number num-letters))\r\n (format \"%03d\" number))]\r\n (inc-name-seed)\r\n result))\r\n\r\n(defn robot\r\n []\r\n (atom (generate-name)))\r\n\r\n(defn robot-name\r\n [robot]\r\n @robot)\r\n\r\n(defn reset-name\r\n [robot]\r\n (reset! robot (generate-name)))\r"}},{"slug":"scrabble-score","track":"go","files":{"scrabble_score.go":"package scrabble_score\n\nimport \"unicode\"\n\nvar scores = m |
This file contains 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
public class FileRouter implements iResponse { | |
// omitted code | |
@Override | |
public byte[] buildResponseBody(Map<String, String> request) throws IOException { | |
String fileOneString = request.get("DIRECTORY") + request.get("URI"); | |
Path file = Paths.get(fileOneString); | |
byte[] body = Files.readAllBytes(filePath); | |
return body; | |
} |
This file contains 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
GET /logs HTTP/1.1 | |
Authorization: Basic YWRtaW46aHVudGVyMg== | |
Connection: close | |
Host: localhost:5000 | |
The request: {Type=GET} |