-
Notifications
You must be signed in to change notification settings - Fork 32
Add Clojure code #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Clojure code #127
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
433be48
Add Clojure code
bolivier 627af25
Add Clojure to course-definition
bolivier f4c4fd5
Update Clojure code
bolivier 28dac43
Remove clojure debug
bolivier 3ee9efa
Remove debug config value
bolivier 5a8ff97
Skip over writing to stderr instead of stdout
bolivier 014fff4
Add changes from template
bolivier 46c63a4
Sort list alphabetically
bolivier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/sh | ||
| # | ||
| # This script is used to compile your program on CodeCrafters | ||
| # | ||
| # This runs before .codecrafters/run.sh | ||
| # | ||
| # Learn more: https://codecrafters.io/program-interface | ||
|
|
||
| set -e # Exit on failure | ||
|
|
||
| clj -T:build |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/sh | ||
| # | ||
| # This script is used to run your program on CodeCrafters | ||
| # | ||
| # This runs after .codecrafters/compile.sh | ||
| # | ||
| # Learn more: https://codecrafters.io/program-interface | ||
|
|
||
| set -e # Exit on failure | ||
|
|
||
| exec java -jar /tmp/codecrafters-build-http-server-clojure/target.jar "$@" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * text=auto |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| pom.xml | ||
| pom.xml.asc | ||
| *.jar | ||
| *.class | ||
| /lib/ | ||
| /classes/ | ||
| /target/ | ||
| /checkouts/ | ||
| .lein-deps-sum | ||
| .lein-repl-history | ||
| .lein-plugins/ | ||
| .lein-failures | ||
| .nrepl-port | ||
| .cpcache/ | ||
| deps/ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|  | ||
|
|
||
| This is a starting point for Clojure solutions to the | ||
| ["Build Your Own HTTP server" Challenge](https://app.codecrafters.io/courses/http-server/overview). | ||
|
|
||
| [HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) is the | ||
| protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server | ||
| that is capable of serving multiple clients. | ||
|
|
||
| Along the way you'll learn about TCP servers, | ||
| [HTTP request syntax](https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html), | ||
| and more. | ||
|
|
||
| **Note**: If you're viewing this repo on GitHub, head over to | ||
| [codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
|
||
| # Passing the first stage | ||
|
|
||
| The entry point for your HTTP server implementation is in | ||
| `src/http_server/core.clj`. Study and uncomment the relevant code, and push your | ||
| changes to pass the first stage: | ||
|
|
||
| ```sh | ||
| git commit -am "pass 1st stage" # any msg | ||
| git push origin master | ||
| ``` | ||
|
|
||
| Time to move on to the next stage! | ||
|
|
||
| # Stage 2 & beyond | ||
|
|
||
| Note: This section is for stages 2 and beyond. | ||
|
|
||
| 1. Ensure you have `clj` installed locally | ||
| 1. Run `./your_program.sh` to run your program, which is implemented in | ||
| `src/http_server/core.clj`. | ||
| 1. Commit your changes and run `git push origin master` to submit your solution | ||
| to CodeCrafters. Test output will be streamed to your terminal. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| (ns build | ||
| (:gen-class) | ||
| (:require [clojure.tools.build.api :as b])) | ||
|
|
||
| (def lib 'io.codecrafters.http-server) | ||
| (def class-dir "/tmp/codecrafters-build-http-server-clojure/classes") | ||
| (def basis (b/create-basis {:project "deps.edn"})) | ||
| (def uber-file "/tmp/codecrafters-build-http-server-clojure/target.jar") | ||
|
|
||
| (defn clean [_] | ||
| (b/delete {:path "/tmp/codecrafters-build-http-server-clojure"})) | ||
|
|
||
| (defn uber [_] | ||
| (clean nil) | ||
| (b/copy-dir {:src-dirs ["src"] :target-dir class-dir}) | ||
| (b/compile-clj {:basis basis | ||
| :ns-compile '[http-server.core] | ||
| :class-dir class-dir}) | ||
| (b/uber {:class-dir class-dir | ||
| :uber-file uber-file | ||
| :basis basis | ||
| :main 'http-server.core})) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Set this to true if you want debug logs. | ||
| # | ||
| # These can be VERY verbose, so we suggest turning them off | ||
| # unless you really need them. | ||
| debug: true | ||
|
|
||
| # Use this to change the Clojure version used to run your code | ||
| # on Codecrafters. | ||
| # | ||
| # Available versions: clojure-1.12.0 | ||
| language_pack: clojure-1.12.0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| :paths ["src"] | ||
|
|
||
| :deps { | ||
| org.clojure/clojure {:mvn/version "1.12.0"} | ||
| org.clojure/tools.cli {:mvn/version "1.1.230"} | ||
| } | ||
|
|
||
| :aliases { | ||
| :build { | ||
| :extra-deps {io.github.clojure/tools.build {:mvn/version "0.10.9"}} | ||
| :exec-fn build/uber | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| (ns http-server.core | ||
| (:require | ||
| [clojure.java.io :as io]) | ||
| (:import | ||
| [java.net ServerSocket]) | ||
| (:gen-class)) | ||
|
|
||
| (def port 4221) | ||
|
|
||
| (defn serve [] | ||
| (let [server-sock (ServerSocket. port)] | ||
| (.setReuseAddress server-sock true) | ||
| (.accept server-sock) | ||
| (println "accepted new connection"))) | ||
|
|
||
| (defn -main [& args] | ||
| ;; You can use print statements as follows for debugging, they'll be visible when running tests. | ||
| (binding [*out* *err*] | ||
| (println "Logs from your program will appear here!")) | ||
|
|
||
| ;; Uncomment this block to pass the first stage | ||
| ;;(serve) | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/bin/sh | ||
| # | ||
| # Use this script to run your program LOCALLY. | ||
| # | ||
| # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. | ||
| # | ||
| # Learn more: https://codecrafters.io/program-interface | ||
|
|
||
| set -e # Exit early if any commands fail | ||
|
|
||
| # Copied from .codecrafters/compile.sh | ||
| # | ||
| # - Edit this to change how your program compiles locally | ||
| # - Edit .codecrafters/compile.sh to change how your program compiles remotely | ||
| ( | ||
| cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory | ||
| clj -T:build | ||
| ) | ||
|
|
||
| # Copied from .codecrafters/run.sh | ||
| # | ||
| # - Edit this to change how your program runs locally | ||
| # - Edit .codecrafters/run.sh to change how your program runs remotely | ||
| exec java -jar /tmp/codecrafters-build-http-server-clojure/target.jar "$@" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # syntax=docker/dockerfile:1.7-labs | ||
| FROM clojure:tools-deps-bookworm | ||
|
|
||
| # Ensures the container is re-built if dependency files change | ||
| ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="deps.edn" | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses | ||
| COPY --exclude=.git --exclude=README.md . /app | ||
|
|
||
| # Install language-specific dependencies | ||
| RUN .codecrafters/compile.sh |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/sh | ||
| # | ||
| # This script is used to compile your program on CodeCrafters | ||
| # | ||
| # This runs before .codecrafters/run.sh | ||
| # | ||
| # Learn more: https://codecrafters.io/program-interface | ||
|
|
||
| set -e # Exit on failure | ||
|
|
||
| clj -T:build |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/sh | ||
| # | ||
| # This script is used to run your program on CodeCrafters | ||
| # | ||
| # This runs after .codecrafters/compile.sh | ||
| # | ||
| # Learn more: https://codecrafters.io/program-interface | ||
|
|
||
| set -e # Exit on failure | ||
|
|
||
| exec java -jar /tmp/codecrafters-build-http-server-clojure/target.jar "$@" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * text=auto |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| pom.xml | ||
| pom.xml.asc | ||
| *.jar | ||
| *.class | ||
| /lib/ | ||
| /classes/ | ||
| /target/ | ||
| /checkouts/ | ||
| .lein-deps-sum | ||
| .lein-repl-history | ||
| .lein-plugins/ | ||
| .lein-failures | ||
| .nrepl-port | ||
| .cpcache/ | ||
| deps/ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|  | ||
|
|
||
| This is a starting point for Clojure solutions to the | ||
| ["Build Your Own HTTP server" Challenge](https://app.codecrafters.io/courses/http-server/overview). | ||
|
|
||
| [HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) is the | ||
| protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server | ||
| that is capable of serving multiple clients. | ||
|
|
||
| Along the way you'll learn about TCP servers, | ||
| [HTTP request syntax](https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html), | ||
| and more. | ||
|
|
||
| **Note**: If you're viewing this repo on GitHub, head over to | ||
| [codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
|
||
| # Passing the first stage | ||
|
|
||
| The entry point for your HTTP server implementation is in | ||
| `src/http_server/core.clj`. Study and uncomment the relevant code, and push your | ||
| changes to pass the first stage: | ||
|
|
||
| ```sh | ||
| git commit -am "pass 1st stage" # any msg | ||
| git push origin master | ||
| ``` | ||
|
|
||
| Time to move on to the next stage! | ||
|
|
||
| # Stage 2 & beyond | ||
|
|
||
| Note: This section is for stages 2 and beyond. | ||
|
|
||
| 1. Ensure you have `clj` installed locally | ||
| 1. Run `./your_program.sh` to run your program, which is implemented in | ||
| `src/http_server/core.clj`. | ||
| 1. Commit your changes and run `git push origin master` to submit your solution | ||
| to CodeCrafters. Test output will be streamed to your terminal. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| (ns build | ||
| (:gen-class) | ||
| (:require [clojure.tools.build.api :as b])) | ||
|
|
||
| (def lib 'io.codecrafters.http-server) | ||
| (def class-dir "/tmp/codecrafters-build-http-server-clojure/classes") | ||
| (def basis (b/create-basis {:project "deps.edn"})) | ||
| (def uber-file "/tmp/codecrafters-build-http-server-clojure/target.jar") | ||
|
|
||
| (defn clean [_] | ||
| (b/delete {:path "/tmp/codecrafters-build-http-server-clojure"})) | ||
|
|
||
| (defn uber [_] | ||
| (clean nil) | ||
| (b/copy-dir {:src-dirs ["src"] :target-dir class-dir}) | ||
| (b/compile-clj {:basis basis | ||
| :ns-compile '[http-server.core] | ||
| :class-dir class-dir}) | ||
| (b/uber {:class-dir class-dir | ||
| :uber-file uber-file | ||
| :basis basis | ||
| :main 'http-server.core})) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Set this to true if you want debug logs. | ||
| # | ||
| # These can be VERY verbose, so we suggest turning them off | ||
| # unless you really need them. | ||
| debug: true | ||
|
|
||
| # Use this to change the Clojure version used to run your code | ||
| # on Codecrafters. | ||
| # | ||
| # Available versions: clojure-1.12.0 | ||
| language_pack: clojure-1.12.0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| :paths ["src"] | ||
|
|
||
| :deps { | ||
| org.clojure/clojure {:mvn/version "1.12.0"} | ||
| org.clojure/tools.cli {:mvn/version "1.1.230"} | ||
| } | ||
|
|
||
| :aliases { | ||
| :build { | ||
| :extra-deps {io.github.clojure/tools.build {:mvn/version "0.10.9"}} | ||
| :exec-fn build/uber | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| (ns http-server.core | ||
| (:require | ||
| [clojure.java.io :as io]) | ||
| (:import | ||
| [java.net ServerSocket]) | ||
| (:gen-class)) | ||
|
|
||
| (def port 4221) | ||
|
|
||
| (defn serve [] | ||
| (let [server-sock (ServerSocket. port)] | ||
| (.setReuseAddress server-sock true) | ||
| (.accept server-sock) | ||
| (println "accepted new connection"))) | ||
|
|
||
| (defn -main [& args] | ||
| (println "Logs from your program will appear here!")) | ||
|
|
||
| (serve) | ||
| ) | ||
bolivier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/bin/sh | ||
| # | ||
| # Use this script to run your program LOCALLY. | ||
| # | ||
| # Note: Changing this script WILL NOT affect how CodeCrafters runs your program. | ||
| # | ||
| # Learn more: https://codecrafters.io/program-interface | ||
|
|
||
| set -e # Exit early if any commands fail | ||
|
|
||
| # Copied from .codecrafters/compile.sh | ||
| # | ||
| # - Edit this to change how your program compiles locally | ||
| # - Edit .codecrafters/compile.sh to change how your program compiles remotely | ||
| ( | ||
| cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory | ||
| clj -T:build | ||
| ) | ||
|
|
||
| # Copied from .codecrafters/run.sh | ||
| # | ||
| # - Edit this to change how your program runs locally | ||
| # - Edit .codecrafters/run.sh to change how your program runs remotely | ||
| exec java -jar /tmp/codecrafters-build-http-server-clojure/target.jar "$@" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.