From 7f666ec61c4ed316567d7cc811f2fc01f24698ee Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Wed, 14 Dec 2022 11:18:18 +0000 Subject: [PATCH 01/16] add aliveuuid --- .gitignore | 1 + Cargo.lock | 78 ++++++++++++++++++++++++++- Cargo.toml | 8 +++ src/bin/aliveuuid.rs | 8 +++ src/bin/timestamp_epoch_to_rfc3339.rs | 18 ++++++- 5 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 src/bin/aliveuuid.rs diff --git a/.gitignore b/.gitignore index bde1e65..ce6ffd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ ./target/ result-bin +target/ diff --git a/Cargo.lock b/Cargo.lock index b41de2b..581c49a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,6 +110,17 @@ dependencies = [ "syn", ] +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + [[package]] name = "html-escape" version = "0.2.12" @@ -207,6 +218,12 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.47" @@ -225,6 +242,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "scratch" version = "1.0.2" @@ -258,7 +305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", - "wasi", + "wasi 0.10.0+wasi-snapshot-preview1", "winapi", ] @@ -271,6 +318,7 @@ dependencies = [ "ipnet", "unescape", "urlencoding", + "uuid", ] [[package]] @@ -303,12 +351,40 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" +[[package]] +name = "uuid" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +dependencies = [ + "getrandom", + "rand", + "uuid-macro-internal", +] + +[[package]] +name = "uuid-macro-internal" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73bc89f2894593e665241e0052c3791999e6787b7c4831daa0a5c2e637e276d8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.83" diff --git a/Cargo.toml b/Cargo.toml index 42873e3..fcda571 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,11 @@ html-escape = "0.2.11" unescape = "0.1.0" ipnet = "2.5.0" chrono = "0.4" + +[dependencies.uuid] +version = "1.2.2" +features = [ + "v4", # Lets you generate random UUIDs + "fast-rng", # Use a faster (but still sufficiently random) RNG + "macro-diagnostics", # Enable better diagnostics for compile-time UUIDs +] diff --git a/src/bin/aliveuuid.rs b/src/bin/aliveuuid.rs new file mode 100644 index 0000000..688e351 --- /dev/null +++ b/src/bin/aliveuuid.rs @@ -0,0 +1,8 @@ +use uuid::Uuid; + +fn main() { + println!( + "{}", + Uuid::new_v4().to_string().replace("-", "").to_lowercase() + ) +} diff --git a/src/bin/timestamp_epoch_to_rfc3339.rs b/src/bin/timestamp_epoch_to_rfc3339.rs index 9ab2b8a..ff4258b 100644 --- a/src/bin/timestamp_epoch_to_rfc3339.rs +++ b/src/bin/timestamp_epoch_to_rfc3339.rs @@ -4,8 +4,22 @@ use chrono::{DateTime, TimeZone, Utc}; fn process>(strings: I) { for string in strings { - let epoch: i64 = string.parse().unwrap(); - let dt: DateTime = Utc.timestamp_opt(epoch, 0).unwrap(); + let secs: i64; + let nsecs: u32; + match string.len() { + 10 => { + secs = string.parse().expect("error parsing seconds"); + nsecs = 0; + } + 13 => { + secs = string[0..10].parse().expect("error parsing seconds"); + nsecs = string[11..].parse().expect("error parseing nanoseconds"); + } + _ => { + panic!("unsupported epoch length") + } + } + let dt: DateTime = Utc.timestamp_opt(secs, nsecs).unwrap(); println!("{}", dt.format("%FT%H:%M:%SZ")); } } From e2681fb894bdae6e68a6ff4c498ac45d128fae1f Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Mon, 6 Mar 2023 12:31:15 +0000 Subject: [PATCH 02/16] rfc3339 to crontab --- Cargo.lock | 100 ++++++++++++------------ src/bin/timestamp_rfc3339_to_crontab.rs | 17 ++++ 2 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 src/bin/timestamp_rfc3339_to_crontab.rs diff --git a/Cargo.lock b/Cargo.lock index 581c49a..5fe56f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,15 +19,15 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "cc" -version = "1.0.77" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" @@ -68,9 +68,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cxx" -version = "1.0.83" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf" +checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" dependencies = [ "cc", "cxxbridge-flags", @@ -80,9 +80,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.83" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39" +checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" dependencies = [ "cc", "codespan-reporting", @@ -95,15 +95,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.83" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12" +checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" [[package]] name = "cxxbridge-macro" -version = "1.0.83" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6" +checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" dependencies = [ "proc-macro2", "quote", @@ -123,9 +123,9 @@ dependencies = [ [[package]] name = "html-escape" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15315cfa9503e9aa85a477138eff76a1b203a430703548052c330b69d8d8c205" +checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" dependencies = [ "utf8-width", ] @@ -156,30 +156,30 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.6.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec947b7a4ce12e3b87e353abae7ce124d025b6c7d6c5aea5cc0bcf92e9510ded" +checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.138" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "link-cplusplus" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" dependencies = [ "cc", ] @@ -214,9 +214,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "ppv-lite86" @@ -226,18 +226,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -274,15 +274,15 @@ dependencies = [ [[package]] name = "scratch" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" [[package]] name = "syn" -version = "1.0.105" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -291,9 +291,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -329,9 +329,9 @@ checksum = "ccb97dac3243214f8d8507998906ca3e2e0b900bf9bf4870477f125b82e68f6e" [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-width" @@ -353,9 +353,9 @@ checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" [[package]] name = "uuid" -version = "1.2.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ "getrandom", "rand", @@ -364,9 +364,9 @@ dependencies = [ [[package]] name = "uuid-macro-internal" -version = "1.2.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73bc89f2894593e665241e0052c3791999e6787b7c4831daa0a5c2e637e276d8" +checksum = "c1b300a878652a387d2a0de915bdae8f1a548f0c6d45e072fe2688794b656cc9" dependencies = [ "proc-macro2", "quote", @@ -387,9 +387,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -397,9 +397,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", @@ -412,9 +412,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -422,9 +422,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", @@ -435,9 +435,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "winapi" diff --git a/src/bin/timestamp_rfc3339_to_crontab.rs b/src/bin/timestamp_rfc3339_to_crontab.rs new file mode 100644 index 0000000..61d5346 --- /dev/null +++ b/src/bin/timestamp_rfc3339_to_crontab.rs @@ -0,0 +1,17 @@ +use std::io::{self, BufRead}; + +use chrono::{DateTime, FixedOffset}; + +fn process>(strings: I) { + for string in strings { + let dt: DateTime = DateTime::parse_from_rfc3339(&string).unwrap(); + println!("{}", dt.format("%M %H %d %m *")); + } +} + +fn main() { + match std::env::args().len() { + 1 => process(io::stdin().lock().lines().map(|ln| ln.unwrap())), + _ => process(std::env::args().skip(1)), + }; +} From 8486e2a120b51c5109e84fecd45ec03a8ceb6cef Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Mon, 6 Mar 2023 12:41:08 +0000 Subject: [PATCH 03/16] rename --- src/bin/{aliveuuid.rs => alive_uuid.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/bin/{aliveuuid.rs => alive_uuid.rs} (100%) diff --git a/src/bin/aliveuuid.rs b/src/bin/alive_uuid.rs similarity index 100% rename from src/bin/aliveuuid.rs rename to src/bin/alive_uuid.rs From 63e8c0744bf0a594a171f73af5464e2369bb301a Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Mon, 6 Mar 2023 12:43:31 +0000 Subject: [PATCH 04/16] normal uuid --- src/bin/uuid.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/bin/uuid.rs diff --git a/src/bin/uuid.rs b/src/bin/uuid.rs new file mode 100644 index 0000000..635080e --- /dev/null +++ b/src/bin/uuid.rs @@ -0,0 +1,8 @@ +use uuid::Uuid; + +fn main() { + println!( + "{}", + Uuid::new_v4().to_string() + ) +} From 2801cf5a1fa5c5a764a0d1cc77ed05572374fba8 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Mon, 6 Mar 2023 12:52:02 +0000 Subject: [PATCH 05/16] iter --- src/bin/cidr_expand.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bin/cidr_expand.rs b/src/bin/cidr_expand.rs index a0f829c..f781d98 100644 --- a/src/bin/cidr_expand.rs +++ b/src/bin/cidr_expand.rs @@ -9,9 +9,7 @@ fn process>(strings: I) { for string in strings { let net = IpNet::from_str(&string).expect("input was not a valid IPv4/IPv6 CIDR"); let subnets = net.subnets(net.max_prefix_len()).unwrap(); - for (_, subnet) in subnets.enumerate() { - println!("{}", subnet.addr()) - } + subnets.into_iter().for_each(|f| println!("{}", f.addr())); } } From 83f4852cc68273fa2483be419ba032270f17b47a Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Mon, 6 Mar 2023 12:54:17 +0000 Subject: [PATCH 06/16] update workflow --- .github/workflows/rust-clippy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust-clippy.yml b/.github/workflows/rust-clippy.yml index 8097814..b7c96a0 100644 --- a/.github/workflows/rust-clippy.yml +++ b/.github/workflows/rust-clippy.yml @@ -48,7 +48,7 @@ jobs: continue-on-error: true - name: Upload analysis results to GitHub - uses: github/codeql-action/upload-sarif@v1 + uses: github/codeql-action/upload-sarif@v2 with: sarif_file: rust-clippy-results.sarif wait-for-processing: true From ef201458a72b2ca380b01148597f570e9a22e249 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Mon, 6 Mar 2023 12:55:34 +0000 Subject: [PATCH 07/16] update workflow --- .github/workflows/rust-clippy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust-clippy.yml b/.github/workflows/rust-clippy.yml index b7c96a0..858e5f5 100644 --- a/.github/workflows/rust-clippy.yml +++ b/.github/workflows/rust-clippy.yml @@ -27,10 +27,10 @@ jobs: security-events: write steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install Rust toolchain - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1 + uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable From d4928e2f56b7e5ed8f02c094f9ca5c3b607ac265 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Tue, 4 Apr 2023 19:11:21 +0100 Subject: [PATCH 08/16] misc --- src/bin/html_encode.rs | 1 - src/bin/timestamp_epoch_to_rfc3339.rs | 2 +- src/bin/timestamp_rfc3339_to_epoch.rs | 2 +- src/bin/timestamp_rfc3339_to_epoch_ms.rs | 17 +++++++++++++++++ src/bin/unicode_unescape.rs | 1 - src/bin/uuid.rs | 5 +---- 6 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/bin/timestamp_rfc3339_to_epoch_ms.rs diff --git a/src/bin/html_encode.rs b/src/bin/html_encode.rs index 8b92cbc..7b99ab1 100644 --- a/src/bin/html_encode.rs +++ b/src/bin/html_encode.rs @@ -15,4 +15,3 @@ fn main() { _ => process(std::env::args().skip(1)), }; } - diff --git a/src/bin/timestamp_epoch_to_rfc3339.rs b/src/bin/timestamp_epoch_to_rfc3339.rs index ff4258b..980df8b 100644 --- a/src/bin/timestamp_epoch_to_rfc3339.rs +++ b/src/bin/timestamp_epoch_to_rfc3339.rs @@ -20,7 +20,7 @@ fn process>(strings: I) { } } let dt: DateTime = Utc.timestamp_opt(secs, nsecs).unwrap(); - println!("{}", dt.format("%FT%H:%M:%SZ")); + println!("{}", dt.to_rfc3339()) } } diff --git a/src/bin/timestamp_rfc3339_to_epoch.rs b/src/bin/timestamp_rfc3339_to_epoch.rs index d355e2d..c299b49 100644 --- a/src/bin/timestamp_rfc3339_to_epoch.rs +++ b/src/bin/timestamp_rfc3339_to_epoch.rs @@ -5,7 +5,7 @@ use chrono::{DateTime, FixedOffset}; fn process>(strings: I) { for string in strings { let dt: DateTime = DateTime::parse_from_rfc3339(&string).unwrap(); - println!("{}", dt.format("%s")); + println!("{}", dt.timestamp()); } } diff --git a/src/bin/timestamp_rfc3339_to_epoch_ms.rs b/src/bin/timestamp_rfc3339_to_epoch_ms.rs new file mode 100644 index 0000000..f3248ff --- /dev/null +++ b/src/bin/timestamp_rfc3339_to_epoch_ms.rs @@ -0,0 +1,17 @@ +use std::io::{self, BufRead}; + +use chrono::{DateTime, FixedOffset}; + +fn process>(strings: I) { + for string in strings { + let dt: DateTime = DateTime::parse_from_rfc3339(&string).unwrap(); + println!("{}", dt.timestamp_millis()); + } +} + +fn main() { + match std::env::args().len() { + 1 => process(io::stdin().lock().lines().map(|ln| ln.unwrap())), + _ => process(std::env::args().skip(1)), + }; +} diff --git a/src/bin/unicode_unescape.rs b/src/bin/unicode_unescape.rs index bed0ac1..6449a4a 100644 --- a/src/bin/unicode_unescape.rs +++ b/src/bin/unicode_unescape.rs @@ -16,4 +16,3 @@ fn main() { _ => process(std::env::args().skip(1)), }; } - diff --git a/src/bin/uuid.rs b/src/bin/uuid.rs index 635080e..a2a7eb5 100644 --- a/src/bin/uuid.rs +++ b/src/bin/uuid.rs @@ -1,8 +1,5 @@ use uuid::Uuid; fn main() { - println!( - "{}", - Uuid::new_v4().to_string() - ) + println!("{}", Uuid::new_v4().to_string()) } From db8a6a5157215f659d067ae4995e689c9d5d85fe Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Tue, 4 Apr 2023 19:21:39 +0100 Subject: [PATCH 09/16] make clippy happy --- src/bin/alive_uuid.rs | 2 +- src/bin/html_decode.rs | 4 ++-- src/bin/html_encode.rs | 4 ++-- src/bin/uuid.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin/alive_uuid.rs b/src/bin/alive_uuid.rs index 688e351..ee1fee4 100644 --- a/src/bin/alive_uuid.rs +++ b/src/bin/alive_uuid.rs @@ -3,6 +3,6 @@ use uuid::Uuid; fn main() { println!( "{}", - Uuid::new_v4().to_string().replace("-", "").to_lowercase() + Uuid::new_v4().to_string().replace('-', "").to_lowercase() ) } diff --git a/src/bin/html_decode.rs b/src/bin/html_decode.rs index 9c88b9f..1d87e4e 100644 --- a/src/bin/html_decode.rs +++ b/src/bin/html_decode.rs @@ -1,10 +1,10 @@ use std::io::{self, BufRead}; -use html_escape; +use html_escape::decode_html_entities; fn process>(strings: I) { for string in strings { - let output = html_escape::decode_html_entities(string.as_str()); + let output = decode_html_entities(string.as_str()); println!("{}", output); } } diff --git a/src/bin/html_encode.rs b/src/bin/html_encode.rs index 7b99ab1..9b728bf 100644 --- a/src/bin/html_encode.rs +++ b/src/bin/html_encode.rs @@ -1,10 +1,10 @@ use std::io::{self, BufRead}; -use html_escape; +use html_escape::encode_text; fn process>(strings: I) { for string in strings { - let output = html_escape::encode_text(string.as_str()); + let output = encode_text(string.as_str()); println!("{}", output); } } diff --git a/src/bin/uuid.rs b/src/bin/uuid.rs index a2a7eb5..8db5fcc 100644 --- a/src/bin/uuid.rs +++ b/src/bin/uuid.rs @@ -1,5 +1,5 @@ use uuid::Uuid; fn main() { - println!("{}", Uuid::new_v4().to_string()) + println!("{}", Uuid::new_v4()) } From a72246844806a6d8f7707283f9fdac909cabfc45 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Thu, 10 Aug 2023 16:40:11 +0100 Subject: [PATCH 10/16] join strings --- Cargo.lock | 145 ++++++++++++++++++++++++++++++---------- src/bin/join_strings.rs | 10 +++ 2 files changed, 121 insertions(+), 34 deletions(-) create mode 100644 src/bin/join_strings.rs diff --git a/Cargo.lock b/Cargo.lock index 5fe56f8..7b1585f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,9 +37,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.23" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" dependencies = [ "iana-time-zone", "js-sys", @@ -62,15 +62,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cxx" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -80,9 +80,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -90,31 +90,31 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.15", ] [[package]] name = "cxxbridge-flags" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.15", ] [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ "cfg-if", "libc", @@ -132,16 +132,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows", ] [[package]] @@ -156,9 +156,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" [[package]] name = "js-sys" @@ -171,9 +171,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "link-cplusplus" @@ -226,18 +226,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -289,6 +289,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termcolor" version = "1.2.0" @@ -353,9 +364,9 @@ checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" [[package]] name = "uuid" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" +checksum = "5b55a3fef2a1e3b3a00ce878640918820d3c51081576ac657d23af9fc7928fdb" dependencies = [ "getrandom", "rand", @@ -364,13 +375,13 @@ dependencies = [ [[package]] name = "uuid-macro-internal" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b300a878652a387d2a0de915bdae8f1a548f0c6d45e072fe2688794b656cc9" +checksum = "20e8a505384e9309dc842520c6c9348f4b141dee06aaa845522727b1b99ca235" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.15", ] [[package]] @@ -406,7 +417,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -428,7 +439,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -469,3 +480,69 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/src/bin/join_strings.rs b/src/bin/join_strings.rs new file mode 100644 index 0000000..b3f4858 --- /dev/null +++ b/src/bin/join_strings.rs @@ -0,0 +1,10 @@ + + +fn process>(strings: I) { + let res = strings.into_iter().collect::>().join(", "); + println!("{}", res) +} + +fn main() { + process(std::env::args().skip(1)) +} \ No newline at end of file From 765e5604d41fc54ea84c9f67757988029cf837a9 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Fri, 11 Aug 2023 12:05:04 +0100 Subject: [PATCH 11/16] improve --- src/bin/join_strings.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bin/join_strings.rs b/src/bin/join_strings.rs index b3f4858..6aadd08 100644 --- a/src/bin/join_strings.rs +++ b/src/bin/join_strings.rs @@ -1,10 +1,14 @@ - +use std::io::{self, BufRead}; fn process>(strings: I) { - let res = strings.into_iter().collect::>().join(", "); - println!("{}", res) + println!( + "{}", + strings.into_iter().collect::>().join(", ") + ) } - fn main() { - process(std::env::args().skip(1)) -} \ No newline at end of file + match std::env::args().len() { + 1 => process(io::stdin().lock().lines().map(|ln| ln.unwrap())), + _ => process(std::env::args().skip(1)), + }; +} From edd39177986bbecfb7c1030168b343c4342a7c4d Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Fri, 6 Oct 2023 10:56:43 +0100 Subject: [PATCH 12/16] tidy --- Cargo.lock | 191 +++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/bin/join_strings.rs | 32 +++++-- 3 files changed, 213 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b1585f..2de5f0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,12 +11,67 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "bumpalo" version = "3.12.0" @@ -50,6 +105,47 @@ dependencies = [ "winapi", ] +[[package]] +name = "clap" +version = "4.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -60,6 +156,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -110,6 +212,27 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "errno" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "getrandom" version = "0.2.9" @@ -121,6 +244,18 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + [[package]] name = "html-escape" version = "0.2.13" @@ -160,6 +295,17 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + [[package]] name = "js-sys" version = "0.3.61" @@ -171,9 +317,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.141" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "link-cplusplus" @@ -184,6 +330,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" + [[package]] name = "log" version = "0.4.17" @@ -272,12 +424,31 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rustix" +version = "0.38.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "scratch" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.109" @@ -325,6 +496,7 @@ name = "toolkit" version = "0.1.0" dependencies = [ "chrono", + "clap", "html-escape", "ipnet", "unescape", @@ -362,6 +534,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.3.1" @@ -490,6 +668,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index fcda571..035397b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ html-escape = "0.2.11" unescape = "0.1.0" ipnet = "2.5.0" chrono = "0.4" +clap = { version = "4.3.21", features = ["derive"] } [dependencies.uuid] version = "1.2.2" diff --git a/src/bin/join_strings.rs b/src/bin/join_strings.rs index 6aadd08..60e4aaf 100644 --- a/src/bin/join_strings.rs +++ b/src/bin/join_strings.rs @@ -1,14 +1,28 @@ +use clap::Parser; use std::io::{self, BufRead}; -fn process>(strings: I) { - println!( - "{}", - strings.into_iter().collect::>().join(", ") - ) +#[derive(Parser, Debug)] +#[command(author,version,about,long_about=None)] +struct Args { + #[arg(short, long, default_value_t=String::from(","))] + separator: String, + + strings: Option>, } + fn main() { - match std::env::args().len() { - 1 => process(io::stdin().lock().lines().map(|ln| ln.unwrap())), - _ => process(std::env::args().skip(1)), - }; + let args = Args::parse(); + let sep = &format!("{} ", args.separator); + match args.strings { + Some(ss) => println!("{}", ss.join(&sep)), + None => println!( + "{}", + io::stdin() + .lock() + .lines() + .map(|ln| ln.unwrap()) + .collect::>() + .join(&sep) + ), + } } From 2689bae2aeaf3d3fbe205dc65c0745127d8107fb Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Tue, 23 Jul 2024 00:03:58 +0100 Subject: [PATCH 13/16] add unixnow --- src/bin/unixnow.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/bin/unixnow.rs diff --git a/src/bin/unixnow.rs b/src/bin/unixnow.rs new file mode 100644 index 0000000..ed7ed87 --- /dev/null +++ b/src/bin/unixnow.rs @@ -0,0 +1,34 @@ +use std::env; +use std::time::{SystemTime, UNIX_EPOCH}; + +fn main() { + let args: Vec = env::args().collect(); + + let mut millis: bool = false; + + if args.contains(&String::from("-h")) { + println!(" +prints unix time now + +Flags: + -m: prints time in milliseconds + -h: prints this message + "); + return + } + + if args.contains(&String::from("-m")) { + millis = true; + } + + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("unixmillis"); + + let mut unix = now.as_secs() as u128; + + if millis { + unix = now.as_millis(); + } + println!("{}", unix) +} From e9cca0290f207b14eb8e4b8ec0e61816551bb175 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Wed, 23 Apr 2025 15:45:36 +0100 Subject: [PATCH 14/16] add rand_string --- Cargo.lock | 82 ++++++++++++++++++++++++++++-------------- Cargo.toml | 1 + src/bin/rand_string.rs | 26 ++++++++++++++ 3 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 src/bin/rand_string.rs diff --git a/Cargo.lock b/Cargo.lock index 119e43c..1027689 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "android-tzdata" @@ -80,9 +80,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "cc" -version = "1.0.98" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" [[package]] name = "cfg-if" @@ -156,6 +156,15 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -205,6 +214,15 @@ dependencies = [ "cc", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -234,9 +252,9 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "num-traits" @@ -261,9 +279,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -307,6 +325,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "random-string" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f70fd13c3024ae3f17381bb5c4d409c6dc9ea6895c08fa2147aba305bea3c4af" +dependencies = [ + "fastrand", +] + [[package]] name = "strsim" version = "0.11.1" @@ -315,9 +342,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.64" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -332,6 +359,7 @@ dependencies = [ "clap", "html-escape", "ipnet", + "random-string", "unescape", "urlencoding", "uuid", @@ -469,9 +497,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -485,48 +513,48 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 035397b..98cea34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ unescape = "0.1.0" ipnet = "2.5.0" chrono = "0.4" clap = { version = "4.3.21", features = ["derive"] } +random-string = "1.1.0" [dependencies.uuid] version = "1.2.2" diff --git a/src/bin/rand_string.rs b/src/bin/rand_string.rs new file mode 100644 index 0000000..170a6fe --- /dev/null +++ b/src/bin/rand_string.rs @@ -0,0 +1,26 @@ +use clap::{Arg, Command}; +use random_string::{charsets, generate}; + +fn main() { + let matches = Command::new("rand_string") + .arg( + Arg::new("length") + .short('l') + .long("length") + .default_value("16"), + ) + .arg( + Arg::new("charset") + .short('c') + .long("charset") + .default_value(charsets::ALPHANUMERIC), + ) + .get_matches(); + + let length_string: &String = matches.get_one("length").expect("a default value"); + let charset: &String = matches.get_one("charset").expect("a default value"); + + let length: usize = length_string.parse().expect("a valid usize"); + + println!("{}", generate(length.to_owned(), charset.to_owned())) +} From 6a9fa51f5eb9eb8a7a7141fc7cd8465cc2744ee4 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Wed, 23 Apr 2025 15:51:35 +0100 Subject: [PATCH 15/16] remove alive_uuid --- src/bin/alive_uuid.rs | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/bin/alive_uuid.rs diff --git a/src/bin/alive_uuid.rs b/src/bin/alive_uuid.rs deleted file mode 100644 index ee1fee4..0000000 --- a/src/bin/alive_uuid.rs +++ /dev/null @@ -1,8 +0,0 @@ -use uuid::Uuid; - -fn main() { - println!( - "{}", - Uuid::new_v4().to_string().replace('-', "").to_lowercase() - ) -} From d22a450b7acadeb7ceead49c7814bc7fa2820a99 Mon Sep 17 00:00:00 2001 From: Sam Barrett Date: Wed, 23 Apr 2025 16:09:04 +0100 Subject: [PATCH 16/16] add base64 flag --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/bin/rand_string.rs | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 01dbec1..b313883 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,6 +73,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "2.9.0" @@ -388,6 +394,7 @@ dependencies = [ name = "toolkit" version = "0.1.0" dependencies = [ + "base64", "chrono", "clap", "html-escape", diff --git a/Cargo.toml b/Cargo.toml index 98cea34..23d05c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ ipnet = "2.5.0" chrono = "0.4" clap = { version = "4.3.21", features = ["derive"] } random-string = "1.1.0" +base64 = "0.22.1" [dependencies.uuid] version = "1.2.2" diff --git a/src/bin/rand_string.rs b/src/bin/rand_string.rs index 170a6fe..3ee944b 100644 --- a/src/bin/rand_string.rs +++ b/src/bin/rand_string.rs @@ -1,3 +1,4 @@ +use base64::{prelude::BASE64_STANDARD, Engine}; use clap::{Arg, Command}; use random_string::{charsets, generate}; @@ -15,12 +16,26 @@ fn main() { .long("charset") .default_value(charsets::ALPHANUMERIC), ) + .arg( + Arg::new("base64") + .required(false) + .num_args(0) + .short('b') + .help("encodes string into base64") + .long("base64"), + ) .get_matches(); let length_string: &String = matches.get_one("length").expect("a default value"); let charset: &String = matches.get_one("charset").expect("a default value"); + let b64: &bool = matches.get_one("base64").unwrap(); let length: usize = length_string.parse().expect("a valid usize"); - println!("{}", generate(length.to_owned(), charset.to_owned())) + let mut s = generate(length.to_owned(), charset.to_owned()); + + if *b64 { + s = BASE64_STANDARD.encode(s); + } + println!("{}", s) }