File tree 30 files changed +544
-0
lines changed
compiled_starters/clojure
starter_templates/clojure
30 files changed +544
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # This script is used to compile your program on CodeCrafters
4
+ #
5
+ # This runs before .codecrafters/run.sh
6
+ #
7
+ # Learn more: https://codecrafters.io/program-interface
8
+
9
+ set -e # Exit on failure
10
+
11
+ clj -T:build uber
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # This script is used to run your program on CodeCrafters
4
+ #
5
+ # This runs after .codecrafters/compile.sh
6
+ #
7
+ # Learn more: https://codecrafters.io/program-interface
8
+
9
+ set -e # Exit on failure
10
+
11
+ exec java -jar /tmp/codecrafters-build-http-server-clojure/codecrafters-http-server-clojure-standalone.jar " $@ "
Original file line number Diff line number Diff line change
1
+ * text =auto
Original file line number Diff line number Diff line change
1
+ * .jar
2
+ target /
3
+ .idea /
4
+ .clj-kondo /
5
+ .lsp /
6
+ .nrepl-port
7
+ * .class
8
+ /lib /
9
+ /classes /
10
+ .cpcache /
Original file line number Diff line number Diff line change
1
+ ![ progress-banner] ( https://codecrafters.io/landing/images/default_progress_banners/http-server.png )
2
+
3
+ This is a starting point for Clojure solutions to the
4
+ [ "Build Your Own HTTP server" Challenge] ( https://app.codecrafters.io/courses/http-server/overview ) .
5
+
6
+ [ HTTP] ( https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol ) is the
7
+ protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server
8
+ that is capable of serving multiple clients.
9
+
10
+ Along the way you'll learn about TCP servers,
11
+ [ HTTP request syntax] ( https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html ) ,
12
+ and more.
13
+
14
+ ** Note** : If you're viewing this repo on GitHub, head over to
15
+ [ codecrafters.io] ( https://codecrafters.io ) to try the challenge.
16
+
17
+ # Passing the first stage
18
+
19
+ The entry point for your HTTP server implementation is in ` src/main.clj ` . Study
20
+ and uncomment the relevant code, and push your changes to pass the first stage:
21
+
22
+ ``` sh
23
+ git commit -am " pass 1st stage" # any msg
24
+ git push origin master
25
+ ```
26
+
27
+ Time to move on to the next stage!
28
+
29
+ # Stage 2 & beyond
30
+
31
+ Note: This section is for stages 2 and beyond.
32
+
33
+ 1 . Ensure you have ` clj (1.12.0) ` installed locally
34
+ 1 . Run ` ./your_program.sh ` to run your program, which is implemented in
35
+ ` src/main.clj ` .
36
+ 1 . Commit your changes and run ` git push origin master ` to submit your solution
37
+ to CodeCrafters. Test output will be streamed to your terminal.
Original file line number Diff line number Diff line change
1
+ (ns build
2
+ (:require [clojure.tools.build.api :as b]
3
+ [clojure.edn :as edn]))
4
+
5
+ (def project (-> (edn/read-string (slurp " deps.edn" ))
6
+ :aliases :neil :project ))
7
+ (def lib (or (:name project) 'my/lib1))
8
+
9
+ (def version (or (:version project)
10
+ " 0.0.1" ))
11
+ (def class-dir " target/classes" )
12
+ (def basis (b/create-basis {:project " deps.edn" }))
13
+ (def uber-file " /tmp/codecrafters-build-http-server-clojure/codecrafters-http-server-clojure-standalone.jar" )
14
+ (def jar-file " /tmp/codecrafters-build-http-server-clojure/codecrafters-http-server-clojure.jar" )
15
+
16
+ (defn clean [_]
17
+ (b/delete {:path " target" }))
18
+
19
+ (defn jar [_]
20
+ (b/write-pom {:class-dir class-dir
21
+ :lib lib
22
+ :version version
23
+ :basis basis
24
+ :src-dirs [" src" ]})
25
+ (b/copy-dir {:src-dirs [" src" " resources" ]
26
+ :target-dir class-dir})
27
+ (b/jar {:class-dir class-dir
28
+ :jar-file jar-file}))
29
+
30
+ (defn install [_]
31
+ (jar {})
32
+ (b/install {:basis basis
33
+ :lib lib
34
+ :version version
35
+ :jar-file jar-file
36
+ :class-dir class-dir}))
37
+
38
+ (defn uber [_]
39
+ (clean nil )
40
+ (b/copy-dir {:src-dirs [" src" " resources" ]
41
+ :target-dir class-dir})
42
+ (b/compile-clj {:basis basis
43
+ :src-dirs [" src" ]
44
+ :class-dir class-dir})
45
+ (b/uber {:class-dir class-dir
46
+ :uber-file uber-file
47
+ :basis basis
48
+ :main 'main}))
49
+
50
+ (defn deploy [opts]
51
+ (jar opts)
52
+ ((requiring-resolve 'deps-deploy.deps-deploy/deploy)
53
+ (merge {:installer :remote
54
+ :artifact jar-file
55
+ :pom-file (b/pom-path {:lib lib :class-dir class-dir})}
56
+ opts))
57
+ opts )
58
+
Original file line number Diff line number Diff line change
1
+ # Set this to true if you want debug logs.
2
+ #
3
+ # These can be VERY verbose, so we suggest turning them off
4
+ # unless you really need them.
5
+ debug : false
6
+
7
+ # Use this to change the Clojure version used to run your code
8
+ # on Codecrafters.
9
+ #
10
+ # Available versions: clojure-1.12
11
+ language_pack : clojure-1.12
Original file line number Diff line number Diff line change
1
+ {:paths [" src" ]
2
+ :deps {}
3
+ :aliases {:build {:deps {io.github.clojure/tools.build {:git/tag " v0.10.7"
4
+ :git/sha " 573711e" }
5
+ slipset/deps-deploy {:mvn/version " 0.2.2" }}
6
+ :ns-default build}}}
Original file line number Diff line number Diff line change
1
+ (ns main
2
+ (:gen-class ))
3
+
4
+ (defn -main [& args]
5
+ ; ; You can use print statements as follows for debugging, they'll be visible when running tests.
6
+ (println " Logs from your program will appear here!" )
7
+ ; ; Uncomment this block to pass the first stage
8
+ ; ; (try
9
+ ; ; (let [server-socket (java.net.ServerSocket. 4221)]
10
+ ; ; (doto server-socket
11
+ ; ; (.setReuseAddress true)
12
+ ; ; (.accept))
13
+ ; ; (println "accepted new connection"))
14
+ ; ; (catch java.io.IOException e
15
+ ; ; (println (str "IOException: " (.getMessage e)))))
16
+ )
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # Use this script to run your program LOCALLY.
4
+ #
5
+ # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6
+ #
7
+ # Learn more: https://codecrafters.io/program-interface
8
+
9
+ set -e # Exit early if any commands fail
10
+
11
+ # Copied from .codecrafters/compile.sh
12
+ #
13
+ # - Edit this to change how your program compiles locally
14
+ # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15
+ (
16
+ cd " $( dirname " $0 " ) " # Ensure compile steps are run within the repository directory
17
+ clj -T:build uber
18
+ )
19
+
20
+ # Copied from .codecrafters/run.sh
21
+ #
22
+ # - Edit this to change how your program runs locally
23
+ # - Edit .codecrafters/run.sh to change how your program runs remotely
24
+ exec java -jar /tmp/codecrafters-build-http-server-clojure/codecrafters-http-server-clojure-standalone.jar " $@ "
Original file line number Diff line number Diff line change
1
+ # syntax=docker/dockerfile:1.7-labs
2
+ FROM clojure:tools-deps-1.12.0.1501-bookworm
3
+
4
+ ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="deps.edn"
5
+
6
+ WORKDIR /app
7
+ # COPY deps.edn ./
8
+
9
+ # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10
+ COPY --exclude=.git --exclude=README.md . /app
11
+
12
+ # Install language-specific dependencies
13
+ RUN .codecrafters/compile.sh
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # This script is used to compile your program on CodeCrafters
4
+ #
5
+ # This runs before .codecrafters/run.sh
6
+ #
7
+ # Learn more: https://codecrafters.io/program-interface
8
+
9
+ set -e # Exit on failure
10
+
11
+ clj -T:build uber
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # This script is used to run your program on CodeCrafters
4
+ #
5
+ # This runs after .codecrafters/compile.sh
6
+ #
7
+ # Learn more: https://codecrafters.io/program-interface
8
+
9
+ set -e # Exit on failure
10
+
11
+ exec java -jar /tmp/codecrafters-build-http-server-clojure/codecrafters-http-server-clojure-standalone.jar " $@ "
Original file line number Diff line number Diff line change
1
+ * text =auto
Original file line number Diff line number Diff line change
1
+ * .jar
2
+ target /
3
+ .idea /
4
+ .clj-kondo /
5
+ .lsp /
6
+ .nrepl-port
7
+ * .class
8
+ /lib /
9
+ /classes /
10
+ .cpcache /
Original file line number Diff line number Diff line change
1
+ ![ progress-banner] ( https://codecrafters.io/landing/images/default_progress_banners/http-server.png )
2
+
3
+ This is a starting point for Clojure solutions to the
4
+ [ "Build Your Own HTTP server" Challenge] ( https://app.codecrafters.io/courses/http-server/overview ) .
5
+
6
+ [ HTTP] ( https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol ) is the
7
+ protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server
8
+ that is capable of serving multiple clients.
9
+
10
+ Along the way you'll learn about TCP servers,
11
+ [ HTTP request syntax] ( https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html ) ,
12
+ and more.
13
+
14
+ ** Note** : If you're viewing this repo on GitHub, head over to
15
+ [ codecrafters.io] ( https://codecrafters.io ) to try the challenge.
16
+
17
+ # Passing the first stage
18
+
19
+ The entry point for your HTTP server implementation is in ` src/main.clj ` . Study
20
+ and uncomment the relevant code, and push your changes to pass the first stage:
21
+
22
+ ``` sh
23
+ git commit -am " pass 1st stage" # any msg
24
+ git push origin master
25
+ ```
26
+
27
+ Time to move on to the next stage!
28
+
29
+ # Stage 2 & beyond
30
+
31
+ Note: This section is for stages 2 and beyond.
32
+
33
+ 1 . Ensure you have ` clj (1.12.0) ` installed locally
34
+ 1 . Run ` ./your_program.sh ` to run your program, which is implemented in
35
+ ` src/main.clj ` .
36
+ 1 . Commit your changes and run ` git push origin master ` to submit your solution
37
+ to CodeCrafters. Test output will be streamed to your terminal.
Original file line number Diff line number Diff line change
1
+ (ns build
2
+ (:require [clojure.tools.build.api :as b]
3
+ [clojure.edn :as edn]))
4
+
5
+ (def project (-> (edn/read-string (slurp " deps.edn" ))
6
+ :aliases :neil :project ))
7
+ (def lib (or (:name project) 'my/lib1))
8
+
9
+ (def version (or (:version project)
10
+ " 0.0.1" ))
11
+ (def class-dir " target/classes" )
12
+ (def basis (b/create-basis {:project " deps.edn" }))
13
+ (def uber-file " /tmp/codecrafters-build-http-server-clojure/codecrafters-http-server-clojure-standalone.jar" )
14
+ (def jar-file " /tmp/codecrafters-build-http-server-clojure/codecrafters-http-server-clojure.jar" )
15
+
16
+ (defn clean [_]
17
+ (b/delete {:path " target" }))
18
+
19
+ (defn jar [_]
20
+ (b/write-pom {:class-dir class-dir
21
+ :lib lib
22
+ :version version
23
+ :basis basis
24
+ :src-dirs [" src" ]})
25
+ (b/copy-dir {:src-dirs [" src" " resources" ]
26
+ :target-dir class-dir})
27
+ (b/jar {:class-dir class-dir
28
+ :jar-file jar-file}))
29
+
30
+ (defn install [_]
31
+ (jar {})
32
+ (b/install {:basis basis
33
+ :lib lib
34
+ :version version
35
+ :jar-file jar-file
36
+ :class-dir class-dir}))
37
+
38
+ (defn uber [_]
39
+ (clean nil )
40
+ (b/copy-dir {:src-dirs [" src" " resources" ]
41
+ :target-dir class-dir})
42
+ (b/compile-clj {:basis basis
43
+ :src-dirs [" src" ]
44
+ :class-dir class-dir})
45
+ (b/uber {:class-dir class-dir
46
+ :uber-file uber-file
47
+ :basis basis
48
+ :main 'main}))
49
+
50
+ (defn deploy [opts]
51
+ (jar opts)
52
+ ((requiring-resolve 'deps-deploy.deps-deploy/deploy)
53
+ (merge {:installer :remote
54
+ :artifact jar-file
55
+ :pom-file (b/pom-path {:lib lib :class-dir class-dir})}
56
+ opts))
57
+ opts )
58
+
Original file line number Diff line number Diff line change
1
+ # Set this to true if you want debug logs.
2
+ #
3
+ # These can be VERY verbose, so we suggest turning them off
4
+ # unless you really need them.
5
+ debug : false
6
+
7
+ # Use this to change the Clojure version used to run your code
8
+ # on Codecrafters.
9
+ #
10
+ # Available versions: clojure-1.12
11
+ language_pack : clojure-1.12
Original file line number Diff line number Diff line change
1
+ {:paths [" src" ]
2
+ :deps {}
3
+ :aliases {:build {:deps {io.github.clojure/tools.build {:git/tag " v0.10.7"
4
+ :git/sha " 573711e" }
5
+ slipset/deps-deploy {:mvn/version " 0.2.2" }}
6
+ :ns-default build}}}
Original file line number Diff line number Diff line change
1
+ (ns main
2
+ (:gen-class ))
3
+
4
+ (defn -main [& args]
5
+ (try
6
+ (let [server-socket (java.net.ServerSocket. 4221 )]
7
+ (doto server-socket
8
+ (.setReuseAddress true )
9
+ (.accept ))
10
+ (println " accepted new connection" ))
11
+ (catch java.io.IOException e
12
+ (println (str " IOException: " (.getMessage e)))))
13
+ )
You can’t perform that action at this time.
0 commit comments