chore: initial commit
This commit is contained in:
commit
1d8c4546a6
29 changed files with 313 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/_/
|
9
.vscode/extensions.json
vendored
Normal file
9
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"esbenp.prettier-vscode",
|
||||
"ms-python.black-formatter",
|
||||
"ms-vscode.cpptools",
|
||||
"13xforever.language-x86-64-assembly",
|
||||
"skellock.just"
|
||||
]
|
||||
}
|
35
.vscode/settings.json
vendored
Normal file
35
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"editor.formatOnPaste": true,
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnType": true,
|
||||
|
||||
"cSpell.words": ["developomp", "fstat", "nums", "rustup", "substr", "yasm"],
|
||||
"dotnet.preferCSharpExtension": true,
|
||||
|
||||
"[python]": {
|
||||
"editor.defaultFormatter": "ms-python.black-formatter"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[jsonc]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[markdown]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[c]": {
|
||||
"editor.defaultFormatter": "ms-vscode.cpptools"
|
||||
},
|
||||
"files.associations": {
|
||||
"*.ejs": "html",
|
||||
"ostream": "cpp",
|
||||
"format": "cpp"
|
||||
}
|
||||
}
|
39
README.md
Normal file
39
README.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Playground
|
||||
|
||||
This is [developomp](https://github.com/developomp)'s vscode-based coding playground.
|
||||
|
||||
The playground is used to...
|
||||
|
||||
- quickly test and benchmark snippets of code
|
||||
- solve algorithm problems
|
||||
|
||||
## Setting up
|
||||
|
||||
Setup the following:
|
||||
|
||||
- shell (only if you're a Windows user. Get [Git bash](https://git-scm.com/downloads) / [GitHub Desktop](https://desktop.github.com) / [Cygwin](https://cygwin.com/install.html) / ... )
|
||||
- [just](https://github.com/casey/just)
|
||||
- [hyperfine](https://github.com/sharkdp/hyperfine)
|
||||
- [python](https://python.org)
|
||||
- [node](https://nodejs.org)
|
||||
- [rust](https://rust-lang.org) (recommend using [rustup](https://github.com/rust-lang/rustup))
|
||||
- [go](https://go.dev)
|
||||
- [clang](https://clang.llvm.org)
|
||||
- [GCC](https://gcc.gnu.org)
|
||||
- [yasm](https://yasm.tortall.net)
|
||||
|
||||
You can check other dev tools I use and more over [here](https://github.com/developomp/pompup).
|
||||
|
||||
## Usage
|
||||
|
||||
Simply call just recipes using the `just` command runner CLI.
|
||||
|
||||
Examples:
|
||||
|
||||
```bash
|
||||
just run-go # automatically build go code before running it and pass arguments from input.txt
|
||||
```
|
||||
|
||||
```bash
|
||||
just bench-asm # automatically build and benchmark program from x86_64 assembly using yasm and hyperfine
|
||||
```
|
20
asm/.asm
Normal file
20
asm/.asm
Normal file
|
@ -0,0 +1,20 @@
|
|||
; export _start label and make entry point to the programing
|
||||
global _start
|
||||
|
||||
section .text
|
||||
_start:
|
||||
; write(1, message, length)
|
||||
mov rax, 1 ; system call for write
|
||||
mov rdi, 1 ; making file handle stdout
|
||||
mov rsi, message ; passing adress of string to output
|
||||
mov rdx, length ; number of bytes
|
||||
syscall ; invoking os to write
|
||||
|
||||
; exit(0)
|
||||
mov rax, 60 ; sys call for exit
|
||||
xor rdi, rdi ; exit code 0
|
||||
syscall ; invoke os to exit
|
||||
|
||||
section .data
|
||||
message: db "Hello, asm!", 0xa ; const char* message = "Hello, asm!" oxa is "\n"
|
||||
length: equ $-message ; int length = len(message);
|
2
asm/.gitignore
vendored
Normal file
2
asm/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
a
|
||||
.o
|
11
asm/asm.justfile
Normal file
11
asm/asm.justfile
Normal file
|
@ -0,0 +1,11 @@
|
|||
# https://www.devdungeon.com/content/hello-world-nasm-assembler
|
||||
|
||||
@build-asm:
|
||||
yasm -f elf64 asm/.asm -o asm/.o
|
||||
ld asm/.o -o asm/a
|
||||
|
||||
@run-asm: build-asm
|
||||
./asm/a < ./input.txt
|
||||
|
||||
@bench-asm: build-asm
|
||||
hyperfine './asm/a < ./input.txt'
|
6
c/.c
Normal file
6
c/.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hello C++!\n");
|
||||
}
|
1
c/.gitignore
vendored
Normal file
1
c/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
a
|
8
c/c.justfile
Normal file
8
c/c.justfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
@build-c:
|
||||
clang ./c/.c -o ./c/a
|
||||
|
||||
@run-c: build-c
|
||||
./c/a < ./input.txt
|
||||
|
||||
@bench-c: build-c
|
||||
hyperfine './c/a < ./input.txt'
|
1
cpp/.gitignore
vendored
Normal file
1
cpp/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
a
|
12
cpp/a.cpp
Normal file
12
cpp/a.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <iostream>
|
||||
|
||||
#pragma GCC optimize("O3")
|
||||
#pragma GCC optimize("Ofast")
|
||||
#pragma GCC optimization("unroll-loops")
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "Hello, C++!\n";
|
||||
}
|
8
cpp/cpp.justfile
Normal file
8
cpp/cpp.justfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
@build-cpp:
|
||||
g++ ./cpp/a.cpp -o ./cpp/a
|
||||
|
||||
@run-cpp: build-cpp
|
||||
./cpp/a < ./input.txt
|
||||
|
||||
@bench-cpp: build-cpp
|
||||
hyperfine './cpp/a < ./input.txt'
|
1
go/.gitignore
vendored
Normal file
1
go/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
a
|
8
go/go.justfile
Normal file
8
go/go.justfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
@build-go:
|
||||
cd go && go build -o a
|
||||
|
||||
@run-go: build-go
|
||||
./go/a < ./input.txt
|
||||
|
||||
@bench-go: build-go
|
||||
hyperfine './go/a < ./input.txt'
|
3
go/go.mod
Normal file
3
go/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module github.com/developomp/playground
|
||||
|
||||
go 1.22
|
32
go/main.go
Normal file
32
go/main.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// prepare stuff for faster IO
|
||||
var reader = bufio.NewReader(os.Stdin)
|
||||
var writer = bufio.NewWriter(os.Stdout)
|
||||
|
||||
func main() {
|
||||
defer writer.Flush() // manually flush stdout
|
||||
|
||||
// read stdin
|
||||
b, _, _ := reader.ReadLine()
|
||||
|
||||
// parse string
|
||||
s := string(b)
|
||||
sum := 0
|
||||
for _, s := range strings.Fields(s) {
|
||||
num, _ := strconv.Atoi(s)
|
||||
sum += num
|
||||
}
|
||||
|
||||
// print sum of nums
|
||||
writer.WriteString(strings.ReplaceAll(s, " ", " + ") + " = " + strconv.Itoa(sum) + "\n")
|
||||
// or
|
||||
// fmt.Fprintf(writer, "%s = %d\n", strings.ReplaceAll(s, " ", " + "), sum)
|
||||
}
|
1
input.txt
Normal file
1
input.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1 2 3
|
16
js/.js
Normal file
16
js/.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
// prepare stuff for faster IO
|
||||
const fs = require("fs")
|
||||
|
||||
// read stdin
|
||||
const s = fs.readFileSync(process.stdin.fd).toString()
|
||||
|
||||
// parse string
|
||||
const nums = s.split(" ").map(Number)
|
||||
|
||||
// print sum of nums
|
||||
process.stdout.write(
|
||||
s.replaceAll(" ", " + ") +
|
||||
" = " +
|
||||
nums.reduce((acc, curr) => acc + curr, 0) +
|
||||
"\n"
|
||||
)
|
3
js/.prettierrc
Normal file
3
js/.prettierrc
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"semi": false
|
||||
}
|
5
js/js.justfile
Normal file
5
js/js.justfile
Normal file
|
@ -0,0 +1,5 @@
|
|||
@run-js:
|
||||
node ./js/.js < ./input.txt
|
||||
|
||||
@bench-js:
|
||||
hyperfine 'node ./js/.js < ./input.txt'
|
10
justfile
Normal file
10
justfile
Normal file
|
@ -0,0 +1,10 @@
|
|||
import 'asm/asm.justfile'
|
||||
import 'c/c.justfile'
|
||||
import 'cpp/cpp.justfile'
|
||||
import 'go/go.justfile'
|
||||
import 'js/js.justfile'
|
||||
import 'py/py.justfile'
|
||||
import 'rust/rust.justfile'
|
||||
|
||||
@default:
|
||||
just --list --unsorted
|
0
py/.gitignore
vendored
Normal file
0
py/.gitignore
vendored
Normal file
16
py/.py
Normal file
16
py/.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
# prepare stuff for faster IO
|
||||
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
|
||||
print = sys.stdout.write
|
||||
|
||||
# read line
|
||||
s = input().decode("utf-8")
|
||||
|
||||
# parse string
|
||||
nums = map(int, s.split(" "))
|
||||
|
||||
# print sum of nums
|
||||
print(s.replace(" ", " + ") + " = " + str(sum(nums)) + "\n")
|
5
py/py.justfile
Normal file
5
py/py.justfile
Normal file
|
@ -0,0 +1,5 @@
|
|||
@run-py:
|
||||
python py/.py < ./input.txt
|
||||
|
||||
@bench-py:
|
||||
hyperfine 'python py/.py < ./input.txt'
|
20
rust/.gitignore
vendored
Normal file
20
rust/.gitignore
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/rust
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
|
||||
|
||||
### Rust ###
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/rust
|
6
rust/Cargo.toml
Normal file
6
rust/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "playground"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
2
rust/rust.justfile
Normal file
2
rust/rust.justfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
@run-rust:
|
||||
cd rust && cargo run --quiet < ../input.txt
|
32
rust/src/main.rs
Normal file
32
rust/src/main.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader, BufWriter, Write},
|
||||
os::unix::io::FromRawFd,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
// prepare stuff for faster IO
|
||||
let mut s = String::new();
|
||||
let stdin = unsafe { File::from_raw_fd(0) };
|
||||
let stdout = unsafe { File::from_raw_fd(1) };
|
||||
let mut reader = BufReader::new(stdin);
|
||||
let mut writer = BufWriter::new(stdout);
|
||||
|
||||
// read line
|
||||
reader.read_line(&mut s).expect("Failed to read from stdin");
|
||||
|
||||
// parse string
|
||||
let nums: Vec<usize> = s
|
||||
.split(" ")
|
||||
.map(|substr| substr.parse().expect("Failed to convert &str to usize"))
|
||||
.collect();
|
||||
|
||||
// print sum of nums
|
||||
writer
|
||||
.write_fmt(format_args!(
|
||||
"{} = {}\n",
|
||||
s.replace(" ", " + "),
|
||||
nums.iter().sum::<usize>()
|
||||
))
|
||||
.expect("Failed to write to stdout");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue