Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
codecrafters-bot authored Apr 10, 2024
0 parents commit 7e5a1e9
Show file tree
Hide file tree
Showing 50 changed files with 1,469 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/post-diffs-in-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Post diffs

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
post_diffs:
uses: codecrafters-io/course-sdk/.github/workflows/post-diffs-in-pr.yml@main
with:
sdkRef: main
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test

on:
pull_request:
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test_course_definition:
uses: codecrafters-io/course-sdk/.github/workflows/test-course-definition.yml@main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
course-definition-tester
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 CodeCrafters

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# build-your-own-<fill_in_course_slug>

Content for the "<fill_in_course_name>" challenge

## Setup

This challenge is developed using https://github.com/codecrafters-io/course-sdk. Read the README there for information
on how to contribute language support & submit solutions.
1 change: 1 addition & 0 deletions compiled_starters/go/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
33 changes: 33 additions & 0 deletions compiled_starters/go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/<fill_in_course_slug>.png)

This is a starting point for Go solutions to the
["Build Your Own <fill_in_course_name>" Challenge](https://app.codecrafters.io/courses/<fill_in_course_slug>/overview).

_Add a description of your course here_

**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 `<fill_in_executable_name>` implementation is in
`cmd/mygrep/main.go`. Study and uncomment the relevant code, and push your
changes to pass the first stage:

```sh
git add .
git commit -m "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 `go (1.19)` installed locally
1. Run `./<fill_in_script_name>.sh` to run your program, which is implemented in
`cmd/mygrep/main.go`.
1. Commit your changes and run `git push origin master` to submit your solution
to CodeCrafters. Test output will be streamed to your terminal.
54 changes: 54 additions & 0 deletions compiled_starters/go/cmd/mygrep/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
// Uncomment this to pass the first stage
// "bytes"
"fmt"
"io"
"os"
"unicode/utf8"
)

// Usage: echo <input_text> | your_grep.sh -E <pattern>
func main() {
if len(os.Args) < 3 || os.Args[1] != "-E" {
fmt.Fprintf(os.Stderr, "usage: mygrep -E <pattern>\n")
os.Exit(2) // 1 means no lines were selected, >1 means error
}

pattern := os.Args[2]

line, err := io.ReadAll(os.Stdin) // assume we're only dealing with a single line
if err != nil {
fmt.Fprintf(os.Stderr, "error: read input text: %v\n", err)
os.Exit(2)
}

ok, err := matchLine(line, pattern)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(2)
}

if !ok {
os.Exit(1)
}

// default exit code is 0 which means success
}

func matchLine(line []byte, pattern string) (bool, error) {
if utf8.RuneCountInString(pattern) != 1 {
return false, fmt.Errorf("unsupported pattern: %q", pattern)
}

var ok bool

// You can use print statements as follows for debugging, they'll be visible when running tests.
fmt.Println("Logs from your program will appear here!")

// Uncomment this to pass the first stage
// ok = bytes.ContainsAny(line, pattern)

return ok, nil
}
11 changes: 11 additions & 0 deletions compiled_starters/go/codecrafters.yml
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: false

# Use this to change the Go version used to run your code
# on Codecrafters.
#
# Available versions: go-1.19
language_pack: go-1.19
11 changes: 11 additions & 0 deletions compiled_starters/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// DON'T EDIT THIS!
//
// Codecrafters relies on this file being intact to run tests successfully. Any changes
// here will not reflect when CodeCrafters tests your code, and might even cause build
// failures.
//
// DON'T EDIT THIS!

module github.com/codecrafters-io/grep-starter-go

go 1.16
Empty file added compiled_starters/go/go.sum
Empty file.
15 changes: 15 additions & 0 deletions compiled_starters/go/your_grep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# DON'T EDIT THIS!
#
# CodeCrafters uses this file to test your code. Don't make any changes here!
#
# DON'T EDIT THIS!
set -e

tmpFile=$(mktemp)

( cd $(dirname "$0") &&
go build -o "$tmpFile" ./cmd/mygrep )

exec "$tmpFile" "$@"
1 change: 1 addition & 0 deletions compiled_starters/python/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
153 changes: 153 additions & 0 deletions compiled_starters/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
21 changes: 21 additions & 0 deletions compiled_starters/python/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
#
# DON'T EDIT THIS!
#
# CodeCrafters uses this file to test your code. Don't make any changes here!
#
# DON'T EDIT THIS!

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pyparsing = "~=3.0"
lark = "~=1.1"

[dev-packages]

[requires]
python_version = "3"
Loading

0 comments on commit 7e5a1e9

Please sign in to comment.