diff --git a/solutions/javascript/02-rg2/code/.codecrafters/compile.sh b/solutions/javascript/02-rg2/code/.codecrafters/compile.sh new file mode 100755 index 00000000..e13a8a7a --- /dev/null +++ b/solutions/javascript/02-rg2/code/.codecrafters/compile.sh @@ -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 + +# (This file is empty since JavaScript programs don't use a compile step) diff --git a/solutions/javascript/02-rg2/code/.codecrafters/run.sh b/solutions/javascript/02-rg2/code/.codecrafters/run.sh new file mode 100755 index 00000000..66bbd824 --- /dev/null +++ b/solutions/javascript/02-rg2/code/.codecrafters/run.sh @@ -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 node app/main.js "$@" diff --git a/solutions/javascript/02-rg2/code/.gitattributes b/solutions/javascript/02-rg2/code/.gitattributes new file mode 100644 index 00000000..176a458f --- /dev/null +++ b/solutions/javascript/02-rg2/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/javascript/02-rg2/code/.gitignore b/solutions/javascript/02-rg2/code/.gitignore new file mode 100644 index 00000000..c2658d7d --- /dev/null +++ b/solutions/javascript/02-rg2/code/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/solutions/javascript/02-rg2/code/README.md b/solutions/javascript/02-rg2/code/README.md new file mode 100644 index 00000000..f850a7b5 --- /dev/null +++ b/solutions/javascript/02-rg2/code/README.md @@ -0,0 +1,33 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/redis.png) + +This is a starting point for JavaScript solutions to the +["Build Your Own Redis" Challenge](https://codecrafters.io/challenges/redis). + +In this challenge, you'll build a toy Redis clone that's capable of handling +basic commands like `PING`, `SET` and `GET`. Along the way we'll learn about +event loops, the Redis protocol 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 Redis implementation is in `app/main.js`. 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 +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `node (21)` installed locally +1. Run `./your_program.sh` to run your Redis server, which is implemented in + `app/main.js`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/solutions/javascript/02-rg2/code/app/main.js b/solutions/javascript/02-rg2/code/app/main.js new file mode 100644 index 00000000..24cee2dc --- /dev/null +++ b/solutions/javascript/02-rg2/code/app/main.js @@ -0,0 +1,8 @@ +const net = require("net"); + +const server = net.createServer((connection) => { + // Handle connection + connection.write(`+PONG\r\n`); +}); + +server.listen(6379, "127.0.0.1"); diff --git a/solutions/javascript/02-rg2/code/codecrafters.yml b/solutions/javascript/02-rg2/code/codecrafters.yml new file mode 100644 index 00000000..e61c476c --- /dev/null +++ b/solutions/javascript/02-rg2/code/codecrafters.yml @@ -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: false + +# Use this to change the JavaScript version used to run your code +# on Codecrafters. +# +# Available versions: nodejs-21 +language_pack: nodejs-21 diff --git a/solutions/javascript/02-rg2/code/package-lock.json b/solutions/javascript/02-rg2/code/package-lock.json new file mode 100644 index 00000000..6dcd28c9 --- /dev/null +++ b/solutions/javascript/02-rg2/code/package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "@codecrafters/redis", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@codecrafters/redis", + "version": "1.0.0" + } + } +} diff --git a/solutions/javascript/02-rg2/code/package.json b/solutions/javascript/02-rg2/code/package.json new file mode 100644 index 00000000..6c6a61ba --- /dev/null +++ b/solutions/javascript/02-rg2/code/package.json @@ -0,0 +1,5 @@ +{ + "name": "@codecrafters/redis", + "version": "1.0.0", + "dependencies": {} +} diff --git a/solutions/javascript/02-rg2/code/your_program.sh b/solutions/javascript/02-rg2/code/your_program.sh new file mode 100755 index 00000000..8b264dae --- /dev/null +++ b/solutions/javascript/02-rg2/code/your_program.sh @@ -0,0 +1,15 @@ +#!/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/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec node app/main.js "$@" diff --git a/solutions/javascript/02-rg2/diff/app/main.js.diff b/solutions/javascript/02-rg2/diff/app/main.js.diff new file mode 100644 index 00000000..0241ef8e --- /dev/null +++ b/solutions/javascript/02-rg2/diff/app/main.js.diff @@ -0,0 +1,9 @@ +@@ -1,7 +1,8 @@ + const net = require("net"); + + const server = net.createServer((connection) => { + // Handle connection ++ connection.write(`+PONG\r\n`); + }); + + server.listen(6379, "127.0.0.1"); diff --git a/solutions/javascript/02-rg2/explanation.md b/solutions/javascript/02-rg2/explanation.md new file mode 100644 index 00000000..11620436 --- /dev/null +++ b/solutions/javascript/02-rg2/explanation.md @@ -0,0 +1,20 @@ +The entry point for your Redis implementation is in `app/main.js`. + +Study and uncomment the relevant code: + +```javascript +// Uncomment this block to pass the first stage +const server = net.createServer((connection) => { + // Handle connection +}); + +server.listen(6379, "127.0.0.1"); +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/solutions/typescript/02-rg2/code/.codecrafters/compile.sh b/solutions/typescript/02-rg2/code/.codecrafters/compile.sh new file mode 100755 index 00000000..d8b7a95f --- /dev/null +++ b/solutions/typescript/02-rg2/code/.codecrafters/compile.sh @@ -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 + +# (This file is empty since TypeScript programs don't use a compile step) diff --git a/solutions/typescript/02-rg2/code/.codecrafters/run.sh b/solutions/typescript/02-rg2/code/.codecrafters/run.sh new file mode 100755 index 00000000..f41df1fe --- /dev/null +++ b/solutions/typescript/02-rg2/code/.codecrafters/run.sh @@ -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 bun run $(dirname $0)/app/main.ts "$@" diff --git a/solutions/typescript/02-rg2/code/.gitattributes b/solutions/typescript/02-rg2/code/.gitattributes new file mode 100644 index 00000000..176a458f --- /dev/null +++ b/solutions/typescript/02-rg2/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/typescript/02-rg2/code/.gitignore b/solutions/typescript/02-rg2/code/.gitignore new file mode 100644 index 00000000..c2658d7d --- /dev/null +++ b/solutions/typescript/02-rg2/code/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/solutions/typescript/02-rg2/code/README.md b/solutions/typescript/02-rg2/code/README.md new file mode 100644 index 00000000..5b785454 --- /dev/null +++ b/solutions/typescript/02-rg2/code/README.md @@ -0,0 +1,33 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/redis.png) + +This is a starting point for TypeScript solutions to the +["Build Your Own Redis" Challenge](https://codecrafters.io/challenges/redis). + +In this challenge, you'll build a toy Redis clone that's capable of handling +basic commands like `PING`, `SET` and `GET`. Along the way we'll learn about +event loops, the Redis protocol 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 Redis implementation is in `app/main.ts`. 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 +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `bun (1.1)` installed locally +1. Run `./your_program.sh` to run your Redis server, which is implemented in + `app/main.ts`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/solutions/typescript/02-rg2/code/app/main.ts b/solutions/typescript/02-rg2/code/app/main.ts new file mode 100644 index 00000000..a6b3738e --- /dev/null +++ b/solutions/typescript/02-rg2/code/app/main.ts @@ -0,0 +1,8 @@ +import * as net from "net"; + +const server: net.Server = net.createServer((connection: net.Socket) => { + // Handle connection + connection.write(`+PONG\r\n`); +}); + +server.listen(6379, "127.0.0.1"); diff --git a/solutions/typescript/02-rg2/code/bun.lockb b/solutions/typescript/02-rg2/code/bun.lockb new file mode 100755 index 00000000..968db942 Binary files /dev/null and b/solutions/typescript/02-rg2/code/bun.lockb differ diff --git a/solutions/typescript/02-rg2/code/codecrafters.yml b/solutions/typescript/02-rg2/code/codecrafters.yml new file mode 100644 index 00000000..a263216b --- /dev/null +++ b/solutions/typescript/02-rg2/code/codecrafters.yml @@ -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: false + +# Use this to change the TypeScript version used to run your code +# on Codecrafters. +# +# Available versions: bun-1.1 +language_pack: bun-1.1 diff --git a/solutions/typescript/02-rg2/code/package.json b/solutions/typescript/02-rg2/code/package.json new file mode 100644 index 00000000..96d878be --- /dev/null +++ b/solutions/typescript/02-rg2/code/package.json @@ -0,0 +1,11 @@ +{ + "name": "@codecrafters/redis", + "description": "Build your own Redis challenge, from CodeCrafters", + "type": "module", + "scripts": { + "dev": "bun run app/main.ts" + }, + "devDependencies": { + "@types/bun": "latest" + } +} diff --git a/solutions/typescript/02-rg2/code/tsconfig.json b/solutions/typescript/02-rg2/code/tsconfig.json new file mode 100644 index 00000000..238655f2 --- /dev/null +++ b/solutions/typescript/02-rg2/code/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/solutions/typescript/02-rg2/code/your_program.sh b/solutions/typescript/02-rg2/code/your_program.sh new file mode 100755 index 00000000..fcc2fd5f --- /dev/null +++ b/solutions/typescript/02-rg2/code/your_program.sh @@ -0,0 +1,15 @@ +#!/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/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +exec bun run $(dirname $0)/app/main.ts "$@" diff --git a/solutions/typescript/02-rg2/diff/app/main.ts.diff b/solutions/typescript/02-rg2/diff/app/main.ts.diff new file mode 100644 index 00000000..bd293f1b --- /dev/null +++ b/solutions/typescript/02-rg2/diff/app/main.ts.diff @@ -0,0 +1,9 @@ +@@ -1,7 +1,8 @@ + import * as net from "net"; + + const server: net.Server = net.createServer((connection: net.Socket) => { + // Handle connection ++ connection.write(`+PONG\r\n`); + }); + + server.listen(6379, "127.0.0.1"); diff --git a/solutions/typescript/02-rg2/explanation.md b/solutions/typescript/02-rg2/explanation.md new file mode 100644 index 00000000..56d7ec0a --- /dev/null +++ b/solutions/typescript/02-rg2/explanation.md @@ -0,0 +1,20 @@ +The entry point for your Redis implementation is in `app/main.ts`. + +Study and uncomment the relevant code: + +```typescript +// Uncomment this block to pass the first stage +const server: net.Server = net.createServer((connection: net.Socket) => { + // Handle connection +}); + +server.listen(6379, "127.0.0.1"); +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +```