Skip to content

Commit 57179e6

Browse files
authored
Merge pull request #153 from codecrafters-io/andy/add-scala
Add Scala support
2 parents 19c1da5 + ec5226d commit 57179e6

File tree

33 files changed

+488
-0
lines changed

33 files changed

+488
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
# The option is needed for Java 17+ to allow native memory access operations.
12+
SBT_OPTS="--enable-native-access=ALL-UNNAMED" sbt assembly
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 "$(dirname "$0")/target/scala-3.7.4/http-server.jar" "$@"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

compiled_starters/scala/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# macOS
2+
.DS_Store
3+
4+
# sbt specific
5+
dist/*
6+
debug/
7+
target/
8+
lib_managed/
9+
src_managed/
10+
project/boot/
11+
project/plugins/project/
12+
project/local-plugins.sbt
13+
.history
14+
.ensime
15+
.ensime_cache/
16+
.sbt-scripted/
17+
local.sbt
18+
19+
# Bloop
20+
.bsp
21+
22+
# VS Code
23+
.vscode/
24+
25+
# Metals
26+
.bloop/
27+
.metals/
28+
metals.sbt

compiled_starters/scala/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/http-server.png)
2+
3+
This is a starting point for Scala 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
20+
`src/main/scala/codecrafters_http_server/App.scala`. Study and uncomment the
21+
relevant code, and push your changes to pass the first stage:
22+
23+
```sh
24+
git commit -am "pass 1st stage" # any msg
25+
git push origin master
26+
```
27+
28+
Time to move on to the next stage!
29+
30+
# Stage 2 & beyond
31+
32+
Note: This section is for stages 2 and beyond.
33+
34+
1. Ensure you have `sbt (1.11.7)` installed locally
35+
1. Run `./your_program.sh` to run your program, which is implemented in
36+
`src/main/scala/codecrafters_http_server/App.scala`.
37+
1. Commit your changes and run `git push origin master` to submit your solution
38+
to CodeCrafters. Test output will be streamed to your terminal.

compiled_starters/scala/build.sbt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ThisBuild / scalaVersion := "3.7.4"
2+
ThisBuild / version := "0.1.0-SNAPSHOT"
3+
ThisBuild / organization := "com.codecrafters"
4+
ThisBuild / organizationName := "CodeCrafters"
5+
6+
assembly / assemblyJarName := "http-server.jar"
7+
8+
lazy val root = (project in file("."))
9+
.settings(
10+
name := "codecrafter-http-server",
11+
// List your dependencies here
12+
libraryDependencies ++= Seq(
13+
)
14+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 Scala version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: scala-3.7
11+
buildpack: scala-3.7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.11.7
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package codecrafters_http_server
2+
3+
import java.io.IOException
4+
import java.net.ServerSocket
5+
6+
object Main extends App {
7+
// You can use print statements as follows for debugging, they'll be visible when running tests.
8+
System.err.println("Logs from your program will appear here!")
9+
10+
// TODO: Uncomment the code below to pass the first stage
11+
//
12+
// try {
13+
// val serverSocket = new ServerSocket(4221)
14+
//
15+
// // Since the tester restarts your program quite often, setting SO_REUSEADDR
16+
// // ensures that we don't run into 'Address already in use' errors
17+
// serverSocket.setReuseAddress(true)
18+
//
19+
// serverSocket.accept() // Wait for connection from client.
20+
// println("accepted new connection")
21+
// } catch {
22+
// case e: IOException =>
23+
// println(s"IOException: ${e.getMessage}")
24+
// }
25+
}

0 commit comments

Comments
 (0)