🥇 Winner project of the AlgoExpert SWE Project Contest 🥇
8 | 9 | ## Overview 10 | 11 | Stop drawing recursion trees by hand. Watch the [demo video](https://youtu.be/1f-KeeN8AHs) or check out the [live project](https://recursion.now.sh). 12 | 13 | ### Folders structure 14 | 15 | - `web`: react user interface. 16 | - `lambda`: serverless lambda function to execute user-defined code remotely. 17 | 18 | ## Local development 19 | 20 | ### Web 21 | 22 | In the `web` directory, run: 23 | 24 | ```bash 25 | # to install all dependencies 26 | $ npm install 27 | 28 | # to run the app on http://localhost:3003 29 | $ npm run start 30 | ``` 31 | 32 | ### Lambda 33 | 34 | You can use the Amazon Runtime Interface Emulator (RIE), already contained in the docker image, to test the Lambda function. 35 | 36 | In the `lambda` directory, run: 37 | 38 | ```bash 39 | # build your local image 40 | $ docker build --tag rtv . 41 | 42 | # create and run a container using AWS RIE as executable to emulate a server for your lambda function 43 | $ docker run --rm -p 8080:8080 rtv 44 | 45 | # make a http request to your function, passing event with the -d in body field (escaped json), see examples in requests.http file 46 | $ curl -XPOST "http://localhost:8080/2015-03-31/functions/function/invocations" -d '{"body":"{}"}' 47 | ``` 48 | 49 | ## Deploy to production 50 | 51 | ### Lambda 52 | 53 | In `terraform` folder: 54 | 55 | - create terraform.tfvars file 56 | - run `terraform init` 57 | - run `terraform validate` 58 | - run `terraform plan` 59 | - run `terraform apply` 60 | 61 | ### Web 62 | 63 | Ships `web` on Vercel, setup environment variables. 64 | 65 | ## Acknowledgements 66 | 67 | Thanks to [Drawing Presentable Trees](https://llimllib.github.io/pymag-trees/#foot5) and [Improving Walker's Algorithm to Run in Linear Time](http://dirk.jivas.de/papers/buchheim02improving.pdf) articles I implemented Reingold-Tilford's algorithm to position each node of the tree on a 2D plane in an aesthetically pleasing way. 68 | 69 | ## Compatibility 70 | 71 | For a better experience, I recommend using a chromium-based browser like Chrome or Edge. 72 | 73 | ## Contact me 74 | 75 | - [Twitter](https://twitter.com/brnpapa) 76 | 77 | -------------------------------------------------------------------------------- /web/src/components/function-form/code-editor/index.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | import React, { useCallback, useContext } from 'react' 3 | import Editor from 'react-simple-code-editor' 4 | import type { PrismTheme } from 'prism-react-renderer' 5 | import { Highlight, themes } from 'prism-react-renderer' 6 | 7 | import { ThemeContext } from 'styled-components' 8 | import { Language } from '../../../types' 9 | import * as s from './styles' 10 | import { LanguageHandler } from '../../../logic/language-handler' 11 | import { ThemeName } from '../../../styles/themes' 12 | 13 | const prismTheme: Record