about summary refs log tree commit diff
path: root/users/tazjin/dt
diff options
context:
space:
mode:
Diffstat (limited to 'users/tazjin/dt')
-rw-r--r--users/tazjin/dt/CMakeLists.txt16
-rw-r--r--users/tazjin/dt/README.md11
-rw-r--r--users/tazjin/dt/default.nix15
-rw-r--r--users/tazjin/dt/dt.cc79
4 files changed, 121 insertions, 0 deletions
diff --git a/users/tazjin/dt/CMakeLists.txt b/users/tazjin/dt/CMakeLists.txt
new file mode 100644
index 000000000000..85b659fea862
--- /dev/null
+++ b/users/tazjin/dt/CMakeLists.txt
@@ -0,0 +1,16 @@
+# -*- mode: cmake; -*-
+cmake_minimum_required(VERSION 3.16)
+project(dt)
+add_executable(dt dt.cc)
+find_package(absl REQUIRED)
+
+target_link_libraries(dt
+  absl::flags
+  absl::flags_parse
+  absl::hash
+  absl::time
+  absl::strings
+  farmhash
+)
+
+install(TARGETS dt DESTINATION bin)
diff --git a/users/tazjin/dt/README.md b/users/tazjin/dt/README.md
new file mode 100644
index 000000000000..ee43d5606409
--- /dev/null
+++ b/users/tazjin/dt/README.md
@@ -0,0 +1,11 @@
+dt
+==
+
+It's got a purpose.
+
+## Usage:
+
+```
+nix-build -E '(import (builtins.fetchGit "https://git.tazj.in/") {}).fun.dt'
+./result/bin/dt --one ... --two ...
+```
diff --git a/users/tazjin/dt/default.nix b/users/tazjin/dt/default.nix
new file mode 100644
index 000000000000..ae9388d187be
--- /dev/null
+++ b/users/tazjin/dt/default.nix
@@ -0,0 +1,15 @@
+{ depot, pkgs, ... }:
+
+let
+  stdenv = with pkgs; overrideCC clangStdenv clang_10;
+  abseil_cpp = pkgs.abseil_cpp;
+in stdenv.mkDerivation {
+  name = "dt";
+  src = ./.;
+  nativeBuildInputs = [ pkgs.cmake ];
+  buildInputs = with pkgs; [
+    abseil_cpp
+    farmhash
+  ];
+  meta.ci = false;
+}
diff --git a/users/tazjin/dt/dt.cc b/users/tazjin/dt/dt.cc
new file mode 100644
index 000000000000..5c4c3da76853
--- /dev/null
+++ b/users/tazjin/dt/dt.cc
@@ -0,0 +1,79 @@
+#include <iostream>
+#include <vector>
+
+#include "absl/flags/flag.h"
+#include "absl/flags/parse.h"
+#include "absl/hash/hash.h"
+#include "absl/strings/str_cat.h"
+#include "absl/time/clock.h"
+#include "absl/time/time.h"
+#include "absl/types/optional.h"
+#include "farmhash.h"
+
+ABSL_FLAG(std::vector<std::string>, words, {}, "words to use");
+
+struct Result {
+  std::string a;
+  int ec;
+  absl::optional<std::string> p;
+};
+
+std::string which(const std::vector<std::string>& words) {
+  uint64_t fp;
+  std::string word;
+
+  for (const auto& w : words) {
+    auto nfp = util::Fingerprint64(w);
+    if (nfp > fp) {
+      fp = nfp;
+      word = w;
+    }
+  }
+
+  return word;
+}
+
+Result decide(const std::vector<std::string>& words) {
+  auto input = absl::FormatTime("%Y%m%d", absl::Now(), absl::UTCTimeZone());
+  for (const auto& w : words) {
+    input += w;
+  }
+
+  auto base = util::Fingerprint64(input);
+  Result result = { "nope" };
+
+  if (base % 10 == 0) {
+    result.a = "ca";
+  } else if (base % 8 == 0) {
+    result.a = "c1";
+    result.p = which(words);
+  } else if (base % 6 == 0) {
+    result.a = "skip";
+  } else if (base % 3 == 0) {
+    result.a = "e1";
+    result.ec = base % 10;
+    result.p = which(words);
+  } else if (base % 2 == 0) {
+    result.a = "ea";
+    result.ec = base % 10;
+  }
+
+  return result;
+}
+
+int main(int argc, char *argv[]) {
+  absl::ParseCommandLine(argc, argv);
+
+  auto words = absl::GetFlag(FLAGS_words);
+  if (words.size() < 2) {
+    std::cerr << "needs at least two!" << std::endl;
+    return 1;
+  }
+
+  auto result = decide(words);
+  std::cout << result.a
+            << (result.p.has_value() ? absl::StrCat(" ", "(", result.p.value(), ")")
+                                     : "")
+            << (result.ec > 0 ? absl::StrCat(": ", result.ec) : "")
+            << std::endl;
+}