From 61a74150f097e91a3e70e21193097eef7cae7186 Mon Sep 17 00:00:00 2001 From: arielherself Date: Mon, 25 Nov 2024 01:24:13 +0800 Subject: [PATCH] regular backup --- home-manager/home.nix | 163 +++++++++++++++++---------- nvim/lua/config.lua | 27 +++-- nvim/lua/snippets/ebcc-with-mult.lua | 51 +++++++++ nvim/lua/snippets/ebcc.lua | 51 +++++++++ nvim/lua/snippets/hash-vec.lua | 2 +- nvim/lua/snippets/init.lua | 39 +++++++ nvim/lua/snippets/manacher.lua | 31 +++++ nvim/lua/snippets/mcmf.lua | 9 +- nvim/lua/snippets/sparse-table.lua | 1 + 9 files changed, 297 insertions(+), 77 deletions(-) create mode 100644 nvim/lua/snippets/ebcc-with-mult.lua create mode 100644 nvim/lua/snippets/ebcc.lua create mode 100644 nvim/lua/snippets/manacher.lua diff --git a/home-manager/home.nix b/home-manager/home.nix index 300bb6d..94686b7 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -14,8 +14,8 @@ in { nixpkgs.config.allowUnfree = true; # Home Manager needs a bit of information about you and the paths it should # manage. - home.username = "user"; - home.homeDirectory = "/home/user"; + home.username = "nixos"; + home.homeDirectory = "/home/nixos"; xdg.enable = true; targets.genericLinux.enable = true; @@ -34,13 +34,17 @@ in { }; ".gitconfig" = { text = '' + [core] + sshCommand = ssh.exe [user] email = arielherself@duck.com name = arielherself [gpg "ssh"] - program = ${pkgs._1password-gui}/bin/op-ssh-sign + program = "/mnt/c/Users/user/AppData/Local/1Password/app/8/op-ssh-sign.exe" [safe] directory = /mnt/fdos_server/OS-24Fall-FDU + [credential] + helper = store ''; }; "Documents" = { @@ -50,6 +54,9 @@ in { }; xdg.configFile = { + "ptool/ptool.toml" = { + source = "${config.home.homeDirectory}/Dropbox/arch/ptool.toml"; + }; "nixpkgs/config.nix" = { source = ../nixpkgs-config.nix; }; @@ -83,6 +90,15 @@ in { source = ../nvim; recursive = true; }; + "nvim/ftplugin/java.lua" = { + text = '' + local config = { + cmd = {'${pkgs.jdt-language-server}/bin/jdtls'}, + root_dir = vim.fs.dirname(vim.fs.find({'gradlew', '.git', 'mvnw'}, { upward = true })[1]), + } + require('jdtls').start_or_attach(config) + ''; + }; "p10k/p10k.zsh" = { source = ../p10k.zsh; recursive = true; @@ -91,21 +107,21 @@ in { xdg.desktopEntries = { # Don't forget to change its permissions. - cider = { - name = "Cider"; - comment = "Apple Music Player"; - type = "Application"; - exec = "${pkgs.appimage-run}/bin/appimage-run ${config.home.homeDirectory}/Dropbox/arch/cider/Cider-linux-appimage-x64.AppImage"; - terminal = false; - categories = [ "AudioVideo" "Audio" ]; - }; - thorium = { - name = "Thorium (AppImage)"; - comment = "Access the Internet"; - type = "Application"; - exec = "${pkgs.appimage-run}/bin/appimage-run ${config.home.homeDirectory}/Dropbox/arch/thorium/Thorium.AppImage"; - terminal = false; - }; + # cider = { + # name = "Cider"; + # comment = "Apple Music Player"; + # type = "Application"; + # exec = "${pkgs.appimage-run}/bin/appimage-run ${config.home.homeDirectory}/Dropbox/arch/cider/Cider-linux-appimage-x64.AppImage"; + # terminal = false; + # categories = [ "AudioVideo" "Audio" ]; + # }; + # thorium = { + # name = "Thorium (AppImage)"; + # comment = "Access the Internet"; + # type = "Application"; + # exec = "${pkgs.appimage-run}/bin/appimage-run ${config.home.homeDirectory}/Dropbox/arch/thorium/Thorium.AppImage"; + # terminal = false; + # }; }; # This value determines the Home Manager release that your configuration is @@ -123,13 +139,14 @@ in { # Terminal # pkgs.contour # pkgs.tmux - pkgs.kitty - pkgs.alacritty + # pkgs.kitty + # pkgs.alacritty # Networking - pkgs.wireshark + # pkgs.wireshark # pkgs.clash-verge-rev mypkgs.aria2 + pkgs.qbittorrent-nox # Editor unstable.neovim @@ -145,8 +162,8 @@ in { pkgs.nodePackages.prettier unstable.markdown-oxide pkgs.helix - unstable.zed-editor - pkgs.xfce.mousepad + # unstable.zed-editor + # pkgs.xfce.mousepad # Tools pkgs.zip @@ -163,20 +180,20 @@ in { pkgs.mtr pkgs.htop pkgs.gdb - mypkgs.dropbox + # mypkgs.dropbox pkgs.brightnessctl pkgs.psmisc pkgs.xclip # Clipboard support - pkgs.vulkan-tools + # pkgs.vulkan-tools pkgs.lshw # Hardware info - unstable._1password - unstable._1password-gui + # unstable._1password + # unstable._1password-gui pkgs.nix-index pkgs.rclone pkgs.sshfs - pkgs.usbutils - pkgs.udiskie - pkgs.udisks + # pkgs.usbutils + # pkgs.udiskie + # pkgs.udisks # Pwn pkgs.nmap @@ -185,6 +202,7 @@ in { # Java pkgs.jdk22 + pkgs.jdt-language-server # Python (pkgs.python312.withPackages (ps: with ps; [ @@ -200,49 +218,50 @@ in { # pkgs.waybar-mpris # Desktop management - pkgs.xfce.thunar - pkgs.baobab + # pkgs.xfce.thunar + # pkgs.baobab pkgs.dua # CLI disk usage - pkgs.i3lock - pkgs.flameshot + # pkgs.i3lock + # pkgs.flameshot # Note & Documents - pkgs.obsidian - pkgs.xournalpp - pkgs.sioyek + # pkgs.obsidian + # pkgs.xournalpp + # pkgs.sioyek # Multimedia - pkgs.kdePackages.gwenview # Image viewer - pkgs.vlc + # pkgs.kdePackages.gwenview # Image viewer + # pkgs.vlc pkgs.playerctl pkgs.jellyfin-ffmpeg - pkgs.spotify - unstable.spotify-player + # pkgs.spotify + # unstable.spotify-player # Streaming - pkgs.obs-studio + # pkgs.obs-studio # Communication - pkgs.telegram-desktop - pkgs.discord + # pkgs.telegram-desktop + # pkgs.discord # Browser - pkgs.firefox-devedition - pkgs.chromium - mypkgs.thorium + # pkgs.firefox-devedition + # pkgs.chromium + # mypkgs.thorium # Misc pkgs.fastfetch pkgs.onefetch pkgs.lf # Terminal file manager + pkgs.lsof pkgs.smassh # Typing test pkgs.you-get # YouTube video downloader pkgs.asciinema # Record terminal sessions - pkgs.ulauncher # application launcher - pkgs.networkmanagerapplet # Network manager tray icon - pkgs.cbatticon # Battery tray icon - pkgs.pavucontrol # Volume control - pkgs.pasystray # Volume tray icon + # pkgs.ulauncher # application launcher + # pkgs.networkmanagerapplet # Network manager tray icon + # pkgs.cbatticon # Battery tray icon + # pkgs.pavucontrol # Volume control + # pkgs.pasystray # Volume tray icon pkgs.yaru-theme unstable.adwaita-icon-theme pkgs.adwaita-qt @@ -251,13 +270,13 @@ in { pkgs.asciiquarium # Interesting pkgs.starship # Prompt bar pkgs.patchelf - pkgs.screenkey + # pkgs.screenkey # My version of BerkeleyMono NF is incomplete. Should add some fallback fonts. - (pkgs.nerdfonts.override { fonts = [ - "JetBrainsMono" - "FiraCode" - ]; }) + # (pkgs.nerdfonts.override { fonts = [ + # "JetBrainsMono" + # "FiraCode" + # ]; }) # # You can also create simple shell scripts directly inside your # # configuration. For example, this adds a command 'my-hello' to your @@ -334,7 +353,7 @@ in { commit.gpgsign = true; gpg.format = "ssh"; # This may not apply. Also try `git config --global gpg.ssh.program "/home/user/.nix-profile/bin/op-ssh-sign"` - gpg."ssh".program = "${unstable._1password-gui}/bin/op-ssh-sign"; + # gpg."ssh".program = "${unstable._1password-gui}/bin/op-ssh-sign"; push.autoSetupRemote = true; core.editor = "nvim"; }; @@ -352,9 +371,13 @@ in { shell = "${pkgs.zsh}/bin/zsh"; extraConfig = '' # Fix font variants and undercurl but optional. - # set -ga terminal-overrides ",xterm-256color:Tc" + set -ga terminal-overrides ",xterm-256color:Tc" # set-option -sa terminal-features ',xterm-256color:RGB' - # set-option -g default-terminal "tmux-256color" + # Fix Windows Terminal + set-option -g default-terminal "tmux-256color" + set-option -sa terminal-overrides ",xterm-256color:RGB" + set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm' + set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m' # set-option -ga terminal-features ",xterm-256color:usstyle" # set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm' # set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m' @@ -373,7 +396,7 @@ in { }; programs.wezterm = { - enable = true; + enable = false; enableZshIntegration = true; extraConfig = '' local config = wezterm.config_builder() @@ -411,5 +434,23 @@ in { programs.home-manager = { enable = true; }; + + systemd.user.services.qbittorrent-nox = { + Unit = { + Description = "qBittorrent-nox service."; + # Wants = [ "network-online.target" ]; + # After = [ "local-fs.target" "network-online.target" "nss-lookup.target" "multi-user.target" ]; + }; + Install = { + WantedBy = [ "default.target" ]; + }; + Service = { + Type = "simple"; + PrivateTmp = "false"; + ExecStart = "${pkgs.qbittorrent-nox}/bin/qbittorrent-nox"; + TimeoutStopSec = 1800; + Restart = "always"; + }; + }; } diff --git a/nvim/lua/config.lua b/nvim/lua/config.lua index 6595e42..eab5132 100644 --- a/nvim/lua/config.lua +++ b/nvim/lua/config.lua @@ -1,5 +1,9 @@ vim.cmd("set encoding=utf-8") vim.cmd("set exrc") +vim.cmd("set undofile") +vim.cmd("set undodir=~/.vim/undofiles") +vim.cmd("set undolevels=10000") +vim.cmd("set undoreload=50000") vim.cmd("filetype off") vim.cmd("set pumblend=40") vim.cmd("set winblend=40") @@ -39,7 +43,7 @@ vim.diagnostic.config({ focusable = false, }, }) -vim.cmd([[au CursorHold * lua vim.diagnostic.open_float(0,{scope = "cursor"})]]) +-- vim.cmd([[au CursorHold * lua vim.diagnostic.open_float(0,{scope = "cursor"})]]) vim.g.mapleader = " "; vim.filetype.add({ extension = { @@ -151,12 +155,12 @@ local plugins = { { 'jdhao/better-escape.vim' -- `jk` without causing `j` to have delay }, - { - 'Pocco81/auto-save.nvim', - opts = { - enabled = true, - } - }, + -- { + -- 'Pocco81/auto-save.nvim', + -- opts = { + -- enabled = true, + -- } + -- }, { "windwp/nvim-autopairs", event = "InsertEnter", @@ -485,6 +489,7 @@ local plugins = { }, { 'NStefan002/screenkey.nvim' }, { 'kosayoda/nvim-lightbulb' }, + { 'mfussenegger/nvim-jdtls' }, -- Java LS } require("lazy").setup(plugins, {}) @@ -545,7 +550,7 @@ require('search').setup { }, } } -vim.keymap.set('n', 'o', 'lua require("search").open({ tab_name = "Smart Open" })') +vim.keymap.set('n', 'o', 'lua require("search").open({ tab_name = "Files" })') vim.keymap.set('n', 'f', 'lua require("search").open({ tab_name = "Symbols" })') vim.keymap.set('n', 'g', 'lua require("search").open({ tab_name = "Grep" })') @@ -654,7 +659,9 @@ lspconfig.clangd.setup { end, cmd = { "clangd", - -- "--header-insertion=never" + -- "--header-insertion=never", + "--clang-tidy", + "--clang-tidy-checks=*", } } lspconfig.pyright.setup { @@ -787,6 +794,8 @@ vim.keymap.set('n', 'x', require("mini.trailspace").trim, {noremap=true} vim.keymap.set('n', '', vim.notify.dismiss, {noremap=true}) vim.keymap.set({'n', 'v', 'x'}, 'Q', 'q', {noremap=true}) vim.keymap.set({'n', 'v', 'x'}, 'q', '', {noremap=true}) +vim.keymap.set('n', 'g ', [[/\v^\s+$$nohlsearch]], {noremap=true, silent=true}) +vim.keymap.set('n', 'gy', "`[v`]", {noremap=true}) vim.api.nvim_create_user_command('SearchInCurrentFile', function() vim.ui.input({ prompt = 'Grep ...'}, function(input) diff --git a/nvim/lua/snippets/ebcc-with-mult.lua b/nvim/lua/snippets/ebcc-with-mult.lua new file mode 100644 index 0000000..40b95c2 --- /dev/null +++ b/nvim/lua/snippets/ebcc-with-mult.lua @@ -0,0 +1,51 @@ +return [=[ +// INFO: This function treats vertex pairs that have multiple edges as eBCCs. +// +// Returns: (BCC count, indices of BCC of each vertex) +// +// BCC index starts from 1 +pair> ebcc_with_mult(const vector>& ch) { + int n = ch.size() - 1; + vector c(n + 1); + + vector low(n + 1), dfn(n + 1); + vector vis(n + 1); + vector stack; + + int time = 0; + int cnt = 0; + + auto dfs = [&] (auto dfs, int v, int prev_idx) -> void { + low[v] = dfn[v] = ++time; + stack.emplace_back(v); + vis[v] = 1; + for (auto&& [u, i] : ch[v]) { + if (i == prev_idx) continue; + if (not dfn[u]) { + dfs(dfs, u, i); + chmin(low[v], low[u]); + } else if (vis[u]) { + chmin(low[v], dfn[u]); + } + } + if (dfn[v] == low[v]) { + cnt += 1; + c[v] = cnt; + while (stack.back() != v) { + c[stack.back()] = cnt; + vis[stack.back()] = 0; + stack.pop_back(); + } + stack.pop_back(); + } + }; + + for (int i = 1; i <= n; ++i) { + if (not dfn[i]) { + dfs(dfs, i, -1); + } + } + return { cnt, c }; +} + +]=] diff --git a/nvim/lua/snippets/ebcc.lua b/nvim/lua/snippets/ebcc.lua new file mode 100644 index 0000000..5d5f5c3 --- /dev/null +++ b/nvim/lua/snippets/ebcc.lua @@ -0,0 +1,51 @@ +return [=[ +// WARN: Input should be a simple graph +// +// Returns: (BCC count, indices of BCC of each vertex) +// +// BCC index starts from 1 +pair> ebcc(const vector>& ch) { + int n = ch.size() - 1; + vector c(n + 1); + + vector low(n + 1), dfn(n + 1); + vector vis(n + 1); + vector stack; + + int time = 0; + int cnt = 0; + + auto dfs = [&] (auto dfs, int v, int pa) -> void { + low[v] = dfn[v] = ++time; + stack.emplace_back(v); + vis[v] = 1; + for (auto&& u : ch[v]) { + if (u == pa) continue; + if (not dfn[u]) { + dfs(dfs, u, v); + chmin(low[v], low[u]); + } else if (vis[u]) { + chmin(low[v], dfn[u]); + } + } + if (dfn[v] == low[v]) { + cnt += 1; + c[v] = cnt; + while (stack.back() != v) { + c[stack.back()] = cnt; + vis[stack.back()] = 0; + stack.pop_back(); + } + stack.pop_back(); + } + }; + + for (int i = 1; i <= n; ++i) { + if (not dfn[i]) { + dfs(dfs, i, 0); + } + } + return { cnt, c }; +} + +]=] diff --git a/nvim/lua/snippets/hash-vec.lua b/nvim/lua/snippets/hash-vec.lua index f761435..53417ee 100644 --- a/nvim/lua/snippets/hash-vec.lua +++ b/nvim/lua/snippets/hash-vec.lua @@ -74,7 +74,7 @@ struct range_hash { template range_hash(const T& vec) { hp.emplace_back(); - hash_vec hs(vec.size()); + hash_vec hs(vec.size() + 1); for (auto&& x : vec) { hs.push_back(x); hp.emplace_back(hs.hash()); diff --git a/nvim/lua/snippets/init.lua b/nvim/lua/snippets/init.lua index ba30509..cdf5e84 100644 --- a/nvim/lua/snippets/init.lua +++ b/nvim/lua/snippets/init.lua @@ -366,3 +366,42 @@ ls.add_snippets(nil, { } }) +local ebcc = require('snippets.ebcc') +ls.add_snippets(nil, { + cpp = { + snip({ + trig = 'ebcc', + namr = 'ebcc', + dscr = 'eBCC on simple undirected graph', + },{ + text(lines(ebcc)) + }) + } +}) + +local ebcc_with_mult = require('snippets.ebcc-with-mult') +ls.add_snippets(nil, { + cpp = { + snip({ + trig = 'ebcc_with_mult', + namr = 'ebcc_with_mult', + dscr = 'eBCC on common undirected graph (with multiple edges)', + },{ + text(lines(ebcc_with_mult)) + }) + } +}) + +local manacher = require('snippets.manacher') +ls.add_snippets(nil, { + cpp = { + snip({ + trig = 'manacher', + namr = 'manacher', + dscr = 'Manacher algorithm for counting palindrome substrings', + },{ + text(lines(manacher)) + }) + } +}) + diff --git a/nvim/lua/snippets/manacher.lua b/nvim/lua/snippets/manacher.lua new file mode 100644 index 0000000..30f10c1 --- /dev/null +++ b/nvim/lua/snippets/manacher.lua @@ -0,0 +1,31 @@ +return [=[ +template +vector manacher(const vector& s, const T& never) { + vector t = { never }; + for (auto&& c : s) { + t.emplace_back(c); + t.emplace_back(never); + } + int n = t.size(); + vector r(n); + for (int i = 0, j = 0; i < n; ++i) { + if (2 * j - i >= 0 && j + r[j] > i) { + r[i] = min(r[2 * j - i], j + r[j] - i); + } + while (i - r[i] >= 0 && i + r[i] < n && t[i - r[i]] == t[i + r[i]]) { + r[i] += 1; + } + if (i + r[i] > j + r[j]) { + j = i; + } + } + for (int i = 0; i < n; i += 2) { + r[i] = (r[i] - 1) / 2; + } + for (int i = 1; i < n; i += 2) { + r[i] /= 2; + } + return r; +} + +]=] diff --git a/nvim/lua/snippets/mcmf.lua b/nvim/lua/snippets/mcmf.lua index ec425e3..6387919 100644 --- a/nvim/lua/snippets/mcmf.lua +++ b/nvim/lua/snippets/mcmf.lua @@ -8,19 +8,15 @@ struct mcmf { int rev; int mark; }; - vector> edges; vector dis; vector vis; ll ret; - mcmf(int n) : edges(n + 1), dis(n + 1), vis(n + 1) {} - void add_edge(int from, int to, ll cap, ll cost, int mark = 0, int mark_rev = 0) { edges[from].push_back({ to, cap, 0, cost, int(edges[to].size()), mark }); edges[to].push_back({ from, 0, 0, -cost, int(edges[from].size() - 1), mark_rev }); } - bool sp(int s, int t) { dis.assign(edges.size(), INFLL); dis[s] = 0; @@ -39,7 +35,6 @@ struct mcmf { } return dis[t] != INFLL; } - ll dfs(int s, int t, ll cap) { if (vis[s]) { return 0; @@ -65,7 +60,6 @@ struct mcmf { } return res; } - // returns: (flow, cost) pll run(int s, int t) { ll res = 0; ret = 0; @@ -73,6 +67,9 @@ struct mcmf { vis.assign(edges.size(), 0); ll curr = dfs(s, t, LLONG_MAX); res += curr; + // BUG: this is a temporary fix of the infinite-looping issue observed + // when dealing with networks with negative weights. + if (curr == 0) break; } return { res, ret }; } diff --git a/nvim/lua/snippets/sparse-table.lua b/nvim/lua/snippets/sparse-table.lua index 1684f14..6e72439 100644 --- a/nvim/lua/snippets/sparse-table.lua +++ b/nvim/lua/snippets/sparse-table.lua @@ -2,6 +2,7 @@ return [[ template> struct sparse_table { _Op op; vector> st; + sparse_table() {} template sparse_table(ReverseIterator __first, ReverseIterator __last, _Op&& __operation) { op = __operation;