From 5bb17e9fcf87a976c69dab9e6a73a42745b3d4ce Mon Sep 17 00:00:00 2001 From: j-james Date: Wed, 30 Nov 2022 19:01:41 -0800 Subject: Move scripts to a util folder --- 2022/get | 16 ---------------- 2022/main.nim | 16 ---------------- 2022/main.rs | 8 -------- 2022/one | 7 ------- 2022/run | 5 ----- 2022/two | 7 ------- 2022/vars | 4 ---- 2022/watch | 7 ------- util/get | 17 +++++++++++++++++ util/main.nim | 16 ++++++++++++++++ util/main.rs | 8 ++++++++ util/one | 7 +++++++ util/run | 5 +++++ util/two | 7 +++++++ util/watch | 7 +++++++ 15 files changed, 67 insertions(+), 70 deletions(-) delete mode 100755 2022/get delete mode 100644 2022/main.nim delete mode 100644 2022/main.rs delete mode 100755 2022/one delete mode 100755 2022/run delete mode 100755 2022/two delete mode 100755 2022/vars delete mode 100755 2022/watch create mode 100755 util/get create mode 100644 util/main.nim create mode 100644 util/main.rs create mode 100755 util/one create mode 100755 util/run create mode 100755 util/two create mode 100755 util/watch diff --git a/2022/get b/2022/get deleted file mode 100755 index b1eff41..0000000 --- a/2022/get +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -source "vars" -INPUT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/input" - -mkdir "nim/day${DAY}" -cp "main.nim" "nim/day${DAY}/main.nim" -curl $INPUT_URL --cookie "session=${TOKEN}" > "nim/day${DAY}/input.txt" - -cargo new "rust/day${DAY}" -cp "main.rs" "rust/day${DAY}/src/main.rs" -cp "nim/day${DAY}/input.txt" "rust/day${DAY}/src/input.txt" - -subl -a "nim/day${DAY}/input.txt" -subl -a "nim/day${DAY}/main.nim" -# chromium "https://adventofcode.com/${YEAR}/day/$((10#${DAY}))" diff --git a/2022/main.nim b/2022/main.nim deleted file mode 100644 index 15ba6b9..0000000 --- a/2022/main.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Day ???: ??? -import std/[os, strutils, sequtils, sugar] -# import std/[algorithm, math, hashes, tables, sets] -# import std/[strformat, strscans, enumerate] - -# useful functions and things to remember: -# - readFile, splitLines, split(""), strip({''}) -# - map(func), filter(func), all(func), any(func) -# - foldl(func, init), string.repeat(count), zip(a, b) -# for i, chr in "string": assert "string"[i] == chr -# assert @[0, 1, 2, 3] == collect(for i in 0..3: i) - -let input = paramStr(1).readFile().strip().split("\n") - -for line in input: - discard diff --git a/2022/main.rs b/2022/main.rs deleted file mode 100644 index 2cad662..0000000 --- a/2022/main.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::env; -use std::fs; - -fn main() { - let args = env::args().nth(1).expect(""); - let input = fs::read_to_string(args).expect(""); - println!("{}", input); -} diff --git a/2022/one b/2022/one deleted file mode 100755 index 6b7db35..0000000 --- a/2022/one +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -source "vars" -LEVEL="1" -SUBMIT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/answer" - -curl $SUBMIT_URL --cookie "session=${TOKEN}" --data "level=${LEVEL}&answer=$1" | rg -C 1 "main" diff --git a/2022/run b/2022/run deleted file mode 100755 index 45f80aa..0000000 --- a/2022/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -source "vars" - -nim c --warnings:off --hints:off -r "nim/day${DAY}/main.nim" "nim/day${DAY}/input.txt" diff --git a/2022/two b/2022/two deleted file mode 100755 index 8dd0080..0000000 --- a/2022/two +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -source "vars" -LEVEL="2" -SUBMIT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/answer" - -curl $SUBMIT_URL --cookie "session=${TOKEN}" --data "level=${LEVEL}&answer=$1" | rg -C 1 "main" diff --git a/2022/vars b/2022/vars deleted file mode 100755 index 31e8b53..0000000 --- a/2022/vars +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -DAY="01" -YEAR="2022" diff --git a/2022/watch b/2022/watch deleted file mode 100755 index 3792b58..0000000 --- a/2022/watch +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -source "vars" - -while inotifywait --quiet --event modify "~/watched_file" -do ./run -done diff --git a/util/get b/util/get new file mode 100755 index 0000000..423dfca --- /dev/null +++ b/util/get @@ -0,0 +1,17 @@ +#!/bin/bash + +source "vars" +INPUT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/input" + +mkdir "nim/day${DAY}" +mkdir "nim/day${DAY}/src" +cp "main.nim" "nim/day${DAY}/src/main.nim" +curl $INPUT_URL --cookie "session=${TOKEN}" > "nim/day${DAY}/input.txt" + +cargo new "rust/day${DAY}" +cp "main.rs" "rust/day${DAY}/src/main.rs" +cp "nim/day${DAY}/input.txt" "rust/day${DAY}/input.txt" + +subl -a "nim/day${DAY}/input.txt" +subl -a "nim/day${DAY}/src/main.nim" +# chromium "https://adventofcode.com/${YEAR}/day/$((10#${DAY}))" diff --git a/util/main.nim b/util/main.nim new file mode 100644 index 0000000..15ba6b9 --- /dev/null +++ b/util/main.nim @@ -0,0 +1,16 @@ +# Day ???: ??? +import std/[os, strutils, sequtils, sugar] +# import std/[algorithm, math, hashes, tables, sets] +# import std/[strformat, strscans, enumerate] + +# useful functions and things to remember: +# - readFile, splitLines, split(""), strip({''}) +# - map(func), filter(func), all(func), any(func) +# - foldl(func, init), string.repeat(count), zip(a, b) +# for i, chr in "string": assert "string"[i] == chr +# assert @[0, 1, 2, 3] == collect(for i in 0..3: i) + +let input = paramStr(1).readFile().strip().split("\n") + +for line in input: + discard diff --git a/util/main.rs b/util/main.rs new file mode 100644 index 0000000..2cad662 --- /dev/null +++ b/util/main.rs @@ -0,0 +1,8 @@ +use std::env; +use std::fs; + +fn main() { + let args = env::args().nth(1).expect(""); + let input = fs::read_to_string(args).expect(""); + println!("{}", input); +} diff --git a/util/one b/util/one new file mode 100755 index 0000000..6b7db35 --- /dev/null +++ b/util/one @@ -0,0 +1,7 @@ +#!/bin/bash + +source "vars" +LEVEL="1" +SUBMIT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/answer" + +curl $SUBMIT_URL --cookie "session=${TOKEN}" --data "level=${LEVEL}&answer=$1" | rg -C 1 "main" diff --git a/util/run b/util/run new file mode 100755 index 0000000..3d068e1 --- /dev/null +++ b/util/run @@ -0,0 +1,5 @@ +#!/bin/bash + +source "vars" + +nim c --warnings:off --hints:off -r "nim/day${DAY}/src/main.nim" "nim/day${DAY}/input.txt" diff --git a/util/two b/util/two new file mode 100755 index 0000000..8dd0080 --- /dev/null +++ b/util/two @@ -0,0 +1,7 @@ +#!/bin/bash + +source "vars" +LEVEL="2" +SUBMIT_URL="https://adventofcode.com/${YEAR}/day/$((10#${DAY}))/answer" + +curl $SUBMIT_URL --cookie "session=${TOKEN}" --data "level=${LEVEL}&answer=$1" | rg -C 1 "main" diff --git a/util/watch b/util/watch new file mode 100755 index 0000000..9c79c6e --- /dev/null +++ b/util/watch @@ -0,0 +1,7 @@ +#!/bin/bash + +source "vars" + +while inotifywait --quiet --event modify "nim/day${DAY}/src/main.nim" +do ./run +done -- cgit v1.2.3-70-g09d2