diff options
| author | Paul Buetow <paul@buetow.org> | 2025-10-02 11:31:38 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-10-02 11:31:38 +0300 |
| commit | ff9f3a641fec256e1f4b01fcd95590451f656f0a (patch) | |
| tree | 04f4b0d8d370006bd2cc22e35c4ce76f7ba134d6 /gemfeed/examples/conf/dotfiles/scripts | |
| parent | c0f9ecf5e0b075db8e54ef1235ec80878e418398 (diff) | |
Update content for html
Diffstat (limited to 'gemfeed/examples/conf/dotfiles/scripts')
12 files changed, 0 insertions, 411 deletions
diff --git a/gemfeed/examples/conf/dotfiles/scripts/README.md b/gemfeed/examples/conf/dotfiles/scripts/README.md deleted file mode 100644 index ecbc8ec0..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Scripts installed to my ~/scripts - -Mostly quick-n-dirty ones! diff --git a/gemfeed/examples/conf/dotfiles/scripts/ai b/gemfeed/examples/conf/dotfiles/scripts/ai deleted file mode 100755 index abcf4909..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/ai +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env zsh - -if [ $(uname) = Darwin ]; then - exec hx.nvim-copilot-prompt "$@" -else - exec hx.hexai-prompt "$@" -fi diff --git a/gemfeed/examples/conf/dotfiles/scripts/brokenlinkfinder b/gemfeed/examples/conf/dotfiles/scripts/brokenlinkfinder deleted file mode 100644 index 7fe15765..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/brokenlinkfinder +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env ruby - -require 'net/http' -require 'uri' -require 'nokogiri' -require 'set' - -# Method to fetch and parse HTML from a URL -def fetch_html(url) - response = Net::HTTP.get_response(URI(url)) - response.body if response.is_a?(Net::HTTPSuccess) -rescue StandardError => e - puts "Error fetching #{url}: #{e.message}" - nil -end - -# Method to find and check links on a page -def check_links(url, domain) - html = fetch_html(url) - return unless html - - checked = Set.new - broken = Set.new - - document = Nokogiri::HTML(html) - links = document.css('a').map { |link| link['href'] }.compact - - internal_links = links.select do |link| - link.start_with?('/') || link.start_with?('./') || URI(link).host == domain - end - puts "Internal links: #{internal_links}" - - internal_links.uniq.each do |link| - full_url = link.start_with?('/') || link.start_with?('./') ? "#{url}#{link}" : link - full_url.sub!('./', '/') - next if checked.include?(full_url) - - broken << full_url unless check_link(full_url) - checked << full_url - end - - broken -end - -# Method to check if a link is broken -def check_link(url) - uri = URI(url) - response = Net::HTTP.get_response(uri) - - if response.is_a?(Net::HTTPSuccess) - puts "Working link: #{url}" - true - else - puts "Broken link: #{url} (HTTP #{response.code})" - false - end -rescue StandardError => e - puts "Error checking #{url}: #{e.message}" - false -end - -# Main program -if ARGV.length != 1 - puts 'Usage: ruby brokenlinkfinder.rb <URL>' - exit -end - -start_url = ARGV.first -domain = URI(start_url).host - -check_links(start_url, domain).each do |broken| - puts "Broken: #{broken}" -end diff --git a/gemfeed/examples/conf/dotfiles/scripts/gvim b/gemfeed/examples/conf/dotfiles/scripts/gvim deleted file mode 100755 index 5777a7ce..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/gvim +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# Hack so qutebrowser starts an editor (Helix) in a new ghostty terminal. - -declare -r FILE_PATH="$2" -#echo "$@" > /tmp/params.txt - -ghostty -e "hx $FILE_PATH" diff --git a/gemfeed/examples/conf/dotfiles/scripts/hx.aichat-prompt b/gemfeed/examples/conf/dotfiles/scripts/hx.aichat-prompt deleted file mode 100755 index 4cafcf5d..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/hx.aichat-prompt +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env zsh - -declare -xr INSTRUCTIONS='Answer only. If it is code, code only without code-block at the beginning and the end.' - -if [[ $# -eq 0 ]]; then - aichat "$(hx.prompt). $INSTRUCTIONS" -else - aichat "$@. $INSTRUCTIONS" -fi diff --git a/gemfeed/examples/conf/dotfiles/scripts/hx.chatgpt-prompt b/gemfeed/examples/conf/dotfiles/scripts/hx.chatgpt-prompt deleted file mode 100755 index e4b6047f..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/hx.chatgpt-prompt +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env zsh - -chatgpt "$(hx.prompt). Answer only. If it is code, code only without code-block at the beginning and the end." diff --git a/gemfeed/examples/conf/dotfiles/scripts/hx.goformatter b/gemfeed/examples/conf/dotfiles/scripts/hx.goformatter deleted file mode 100755 index 028fbb25..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/hx.goformatter +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -goimports | gofumpt diff --git a/gemfeed/examples/conf/dotfiles/scripts/hx.hexai-prompt b/gemfeed/examples/conf/dotfiles/scripts/hx.hexai-prompt deleted file mode 100755 index ef413c0a..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/hx.hexai-prompt +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env zsh - -declare -xr INSTRUCTIONS='Answer only. If it is code, code only without code-block at the beginning and the end.' - -if [[ $# -eq 0 ]]; then - hexai "$(hx.prompt). $INSTRUCTIONS" 2>/dev/null -else - hexai "$@. $INSTRUCTIONS" 2>/dev/null -fi diff --git a/gemfeed/examples/conf/dotfiles/scripts/hx.nvim-copilot-prompt b/gemfeed/examples/conf/dotfiles/scripts/hx.nvim-copilot-prompt deleted file mode 100755 index dcb28376..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/hx.nvim-copilot-prompt +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env zsh - -declare -r STDIN_FILE=~/.copilot_prompt_stdin.txt -declare -r INPUT_FILE=~/.copilot_chat_input.txt -declare -r OUTPUT_FILE=~/.copilot_chat_output.txt -declare INPUT_PROMPT - -if [ -f $OUTPUT_FILE.done ]; then - rm $OUTPUT_FILE.done -fi -cat > $STDIN_FILE &>/dev/null - -if [ $# -eq 0 ]; then - INPUT_PROMPT="$(hx.prompt)" -else - INPUT_PROMPT="$@" -fi - -cat <<INPUT_FILE > $INPUT_FILE -$INPUT_PROMPT for the following: - -$(cat $STDIN_FILE) - -If the result is code, print out the code only, don't print the \`\`\`-markers around the code block. -INPUT_FILE - -tmux split-window -v "nvim +':CopilotAsk'; mv $OUTPUT_FILE $OUTPUT_FILE.done" - -while [ ! -f "$OUTPUT_FILE.done" ]; do - sleep 0.2 -done -sed -n '/^## Copilot/,/^## User/ { /^## Copilot/d; /\[file:/d; /^## User/d; p; }' $OUTPUT_FILE.done diff --git a/gemfeed/examples/conf/dotfiles/scripts/hx.prompt b/gemfeed/examples/conf/dotfiles/scripts/hx.prompt deleted file mode 100755 index 8dd14dd3..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/hx.prompt +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env zsh - -declare -r REPLY_FILE=~/.hx-prompt-reply -if [ -f "$REPLY_FILE" ]; then - rm "$REPLY_FILE" -fi - -tmux split-window -v "touch $REPLY_FILE.tmp; hx $REPLY_FILE.tmp; mv $REPLY_FILE.tmp $REPLY_FILE" - -while [ ! -f "$REPLY_FILE" ]; do - sleep 0.2 -done - -cat "$REPLY_FILE" diff --git a/gemfeed/examples/conf/dotfiles/scripts/randomnote.rb b/gemfeed/examples/conf/dotfiles/scripts/randomnote.rb deleted file mode 100644 index b0c1b490..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/randomnote.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env ruby - -NOTES_DIR = "#{ENV['HOME']}/git/foo.zone-content/gemtext/notes" -BOOK_PATH = "#{ENV['HOME']}/Buecher/Diverse/Search-Inside-Yourself.txt" -MIN_PERCENTAGE = 80 -MIN_LENGTH = 10 - -class String - CLEAN_PATTERN = [ - /\d\d\d-\d\d-\d\d/, /[^A-Za-z0-9!.;,?'" @]/, - /http.?:\/\/\S+/, /\S+\.gmi/, /^\./, /^\d/, - ] - def clean - CLEAN_PATTERN.each {|p| gsub! p, '' } - gsub(/\s+/, ' ').strip - end - def letter_percentage?(threshold) = threshold <= (100 * count("A-Za-z")) / length -end - -begin - srand Random.new_seed - puts File.read((Dir["#{NOTES_DIR}/*.gmi"] + [BOOK_PATH]).shuffle.sample) - .split("\n") - .map(&:clean) - .select{ |l| l.length >= MIN_LENGTH } - .reject{ |l| l.match?(/(Published at|EMail your comments)/) } - .reject{ |l| l.match?(/'|book notes/) } - .select{ |l| l.letter_percentage?(MIN_PERCENTAGE) } - .shuffle.sample -end diff --git a/gemfeed/examples/conf/dotfiles/scripts/taskwarriorfeeder.rb b/gemfeed/examples/conf/dotfiles/scripts/taskwarriorfeeder.rb deleted file mode 100644 index 8e3096ea..00000000 --- a/gemfeed/examples/conf/dotfiles/scripts/taskwarriorfeeder.rb +++ /dev/null @@ -1,221 +0,0 @@ -#!/usr/bin/env ruby - -require 'optparse' -require 'digest' -require 'json' -require 'set' - -PERSONAL_TIMESPAN_D = 30 -WORK_TIMESPAN_D = 14 -WORKTIME_DIR = "#{ENV['HOME']}/git/worktime".freeze -GOS_DIR = "#{ENV['HOME']}/.gosdir".freeze -MAX_PENDING_RANDOM_TASKS = 11 - -def maybe? - [true, false].sample -end - -def run_from_personal_device? - `uname`.chomp == 'Linux' -end - -def random_count - MAX_PENDING_RANDOM_TASKS - `task status:pending +random count`.to_i -end - -def notes(notes_dirs, prefix, dry) - notes_dirs.each do |notes_dir| - Dir["#{notes_dir}/#{prefix}-*"].each do |notes_file| - match = File.read(notes_file).strip.match(/(?<due>\d+)? *(?<tag>[A-Z]?[a-z,-:]+) *(?<body>.*)/m) - next unless match - - tags = match[:tag].split(',') + [prefix] - due = if match[:due].nil? - tags.include?('track') ? '1year' : "#{rand(0..PERSONAL_TIMESPAN_D)}d" - else - "#{match[:due]}d" - end - yield tags, match[:body], due - File.delete(notes_file) unless dry - end - end -end - -def random_quote(md_file) - tag = File.basename(md_file, '.md').downcase - lines = File.readlines(md_file) - - match = lines.first.match(/\((\d+)\)/) - timespan = run_from_personal_device? ? PERSONAL_TIMESPAN_D : WORK_TIMESPAN_D - timespan = match ? match[1].to_i : timespan - - quote = lines.select { |l| l.start_with? '*' }.map { |l| l.sub(/\* +/, '') }.sample - tags = [tag, 'random'] - tags << 'work' if maybe? and maybe? - yield tags, quote.chomp, "#{rand(0..timespan)}d" -end - -def run!(cmd, dry) - puts cmd - return if dry - - puts `#{cmd}` - raise "Command '#{cmd}' failed with #{$?.exitstatus}" if $?.exitstatus != 0 -rescue StandardError => e - puts "Error running command '#{cmd}': #{e.message}" - exit 1 -end - -def skill_add!(skills_str, dry) - skills_file = "#{WORKTIME_DIR}/skills.txt" - skills_str.split(',').map(&:strip).each { skills[_1.to_s.downcase] = _1 } - - File.foreach(skills_file) do |line| - line.chomp! - skills[line.downcase] = line - end - File.open("#{skills_file}.tmp", 'w') do |file| - skills.each_value { |skill| file.puts(skill) } - end - return if dry - - File.rename("#{skills_file}.tmp", skills_file) -end - -def worklog_add!(tag, quote, due, dry) - file = "#{WORKTIME_DIR}/wl-#{Time.now.to_i}n.txt" - content = "#{due.chomp 'd'} #{tag} #{quote}" - - puts "#{file}: #{content}" - File.write(file, content) unless dry -end - -# Queue to Gos https://codeberg.org/snonux/gos -def gos_queue!(tags, message, dry) - tags.delete('share') - platforms = [] - %w[linkedin li mastodon ma noop no].select { tags.include?(_1) }.each do |platform| - platforms << platform - tags.delete(platform) - end - unless platforms.empty? - platforms = %w[share] + platforms - tags = ["#{platforms.join(':')}"] + tags - end - tags = %w[share] + tags if tags.size == 1 && !tags.first.start_with?('share') - tags_str = tags.join(',') - - message = "#{tags_str.empty? ? '' : "#{tags_str} "}#{message}" - file = "#{GOS_DIR}/#{Digest::MD5.hexdigest(message)}.txt" - puts "Writing #{file} with #{message}" - File.write(file, message) unless dry -end - -def task_add!(tags, quote, due, dry) - if quote.empty? - puts 'Not adding task with empty quote' - return - end - if tags.include?('tr') - tags << 'track' - tags.delete('tr') - end - tags << 'work' if tags.include?('mentoring') || tags.include?('productivity') - tags.uniq! - - if tags.include?('task') - run! "task #{quote}", dry - else - project = tags.find { |t| t =~ /^[A-Z]/ } - project = if project.nil? - '' - else - tags.delete(project) - " project:#{project.downcase}" - end - priority = tags.include?('high') ? 'H' : '' - run! "task add due:#{due} priority:#{priority}#{project} +#{tags.join(' +')} '#{quote.gsub("'", '"')}'", dry - end -end - -def task_schedule!(id, due, dry) - run! "timeout 5s task modify #{id} due:#{due}", dry -end - -# Randomly schedule all unscheduled tasks but the ones with the +unsched tag -def unscheduled_tasks - lines = `task -lowhigh -unsched -nosched -notes -note -meeting -track due: 2>/dev/null`.split("\n").drop(1) - lines.pop - lines.map { |foo| foo.split.first }.each do |id| - yield id if id.to_i.positive? - end -end - -begin - opts = { - quotes_dir: "#{ENV['HOME']}/Notes/HabitsAndQuotes", - notes_dirs: "#{ENV['HOME']}/Notes,#{ENV['HOME']}/Notes/Quicklogger,#{ENV['HOME']}/git/worktime", - dry_run: false, - no_random: false - } - - opt_parser = OptionParser.new do |o| - o.banner = 'Usage: ruby taskwarriorfeeder.rb [options]' - o.on('-d', '--quotes-dir DIR', 'The quotes directory') { |v| opts[:quotes_dir] = v } - o.on('-n', '--notes-dirs DIR1,DIR2,...', 'The notes directories') { |v| opts[:notes_dirs] = v } - o.on('-D', '--dry-run', 'Dry run mode') { opts[:dry_run] = true } - o.on('-R', '--no-randoms', 'No random entries') { opts[:no_random] = true } - o.on_tail('-h', '--help', 'Show this help message and exit') { puts o and exit } - end - - opt_parser.parse!(ARGV) - core_habits_md_file = "#{opts[:quotes_dir]}/CoreHabits.md" - - (run_from_personal_device? ? %w[ql pl] : %w[wl]).each do |prefix| - notes(opts[:notes_dirs].split(','), prefix, opts[:dry_run]) do |tags, note, due| - if tags.include?('skill') || tags.include?('skills') - skill_add!(note, opts[:dry_run]) - elsif tags.include? 'work' - worklog_add!(:log, note, due, opts[:dry_run]) - elsif tags.any? { |tag| tag.start_with?('share') } - gos_queue!(tags, note, opts[:dry_run]) - else - task_add!(tags, note, due, opts[:dry_run]) - end - end - end - - unless opts[:no_random] - if File.exist?(core_habits_md_file) - random_quote(core_habits_md_file) do |tags, quote, due| - task_add!(tags, quote, due, opts[:dry_run]) - end - end - count = random_count - - Dir["#{opts[:quotes_dir]}/*.md"].shuffle.each do |md_file| - next unless maybe? - break if count <= 0 - - random_quote(md_file) do |tags, quote, due| - task_add!(tags, quote, due, opts[:dry_run]) - count -= 1 - end - end - end - - if Dir.exist?(GOS_DIR) && !opts[:dry_run] - Dir["#{WORKTIME_DIR}/tw-gos-*.json"].each do |tw_gos| - JSON.parse(File.read(tw_gos)).each do |entry| - gos_queue!(entry['tags'], entry['description'], opts[:dry_run]) - end - File.delete(tw_gos) - rescue StandardError => e - puts e - end - end - - unscheduled_tasks do |id| - task_schedule!(id, "#{rand(0..PERSONAL_TIMESPAN_D)}d", opts[:dry_run]) - end -end |
