Skip to content

Instantly share code, notes, and snippets.

View marekkowalczyk's full-sized avatar

Marek Kowalczyk marekkowalczyk

View GitHub Profile
@marekkowalczyk
marekkowalczyk / text-keywords-extract.py
Created March 10, 2023 22:11
This Python code uses the OpenAI API to generate keywords from a text file. It prompts the API with the text file's contents and then extracts the generated keywords from the API's response. The text file's name is passed as a command-line argument to the program, and the API key is retrieved from an environment variable.
import os # Import the os module for working with environment variables
import openai # Import the OpenAI module for working with the OpenAI API
import json # Import the json module for working with JSON data
import sys # Import the sys module for working with command-line arguments
openai.api_key = os.getenv("OPENAI_API_KEY") # Set the OpenAI API key from an environment variable
filename = sys.argv[1] # Get the filename from the command-line arguments
with open(filename, "r") as file: # Open the file in read-only mode
@marekkowalczyk
marekkowalczyk / mdtopdf.sh
Created April 2, 2021 12:45
Convert markdown to pdf with same filename and open the pdf
#!/usr/bin/env bash
# Convert markdown to pdf with same filename and open the pdf
for file in "$@"; do
filename="${file%.*}"
extension="${file##*.}"
echo "$file" "->" "$filename".pdf
pandoc -f markdown -t pdf -o "$filename".pdf "$file"
open "$filename".pdf
done
@marekkowalczyk
marekkowalczyk / .rc.sh
Last active March 10, 2021 22:53
Bash function to edit and source *rc files; best included in .bashrc
function rc(){
# TODO XDG Path
EDITORRC="$EDITOR"
FILE=""
case "$1" in
help)
printf "aliasesicalbuddy\n"
printf "aliasestask\n"
printf "aliases\n"
CODE EFFECT NOTE
0 Reset / Normal all attributes off
1 Bold or increased intensity
2 Faint (decreased intensity) Not widely supported.
3 Italic Not widely supported. Sometimes treated as inverse.
4 Underline
5 Slow Blink less than 150 per minute
6 Rapid Blink MS-DOS ANSI.SYS; 150+ per minute; not widely supported
7 [[reverse video]] swap foreground and background colors
8 Conceal Not widely supported.
@marekkowalczyk
marekkowalczyk / comdefs.tsv
Last active December 10, 2022 01:49
Definitions of assorted commands, extracted from NAME sections of respective manpages
COMMAND DEFINITION
a2x A toolchain manager for AsciiDoc (converts Asciidoc text files to other file formats)
abduco terminal session manager
abook text-based address book program
abs integer absolute value function
ack grep-like text finder
aclocal manual page for aclocal 1.16.3
acountry print the country where an IPv4 address or host is located
acyclic make directed graph acyclic
addftinfo add information to troff font files for use with groff
@marekkowalczyk
marekkowalczyk / define.sh
Last active January 28, 2021 10:50
Print definition of COMMAND, i.e. the line following NAME in its manpage
#!/usr/bin/env bash
# Print definition of COMMAND, i.e. the line following NAME in its manpage
# https://gist.github.com/marekkowalczyk/5dcae326d2148c2757c386776ae455d7
man $1 | col -b | grep -A 3 ^NAME | sed -n 2,3p | sed -E 's/^ +//' | tr '\n' ' '
printf "\n"
-- Import a man page into DEVONthink as PDF
-- Created by Christian Grunenberg on Sat Apr 16 2005. Copyright (c) 2005-2019. All rights reserved.
-- Edited by Houthakker 2011 Feb 12 to import PDF (rather than text) version of man page (to preserve highlighting of keywords and headers)
-- Modified on 2021-01-25 by https://discourse.devontechnologies.com/u/pete31/ and https://discourse.devontechnologies.com/u/marekkowalczyk/ to add auto tagging of imported PDFs
tell application id "DNtp"
try
repeat
set page to display name editor "Man page" info "Enter the man page to import:"
if page is not "" then exit repeat
@marekkowalczyk
marekkowalczyk / rpn.awk
Last active July 23, 2022 00:08
Basic CLI RPN (Reverse Polish Notation) calculator in AWK
#! /usr/bin/awk -f
# Basic interactive CLI RPN (Reverse Polish Notation) calculator
# v1.1
# input: arithmetic expressions in RPN
# output: values of expressions
# Adapted by [email protected] from Aho, Kernighan, and Weinberger, The AWK Programming Language, 143.
# 2021-01-26 CC0 1.0 Universal (CC0 1.0)
# https://gist.github.com/marekkowalczyk/06eb0d7d850fd50497b0f65d350d0003
@marekkowalczyk
marekkowalczyk / DevonThink Search operators
Last active November 28, 2020 00:13 — forked from florido/DevonThink Search operators
DevonThink Search operators (formatted as Pandoc Markdown)
---
header-includes: \usepackage{noto}\urlstyle{tt}\usepackage{titlesec}\titlelabel{\thetitle.\quad}
numbersections: true
papersize: a4
lang: en
documentclass: article
title: DevonThink Search Operators
---
In the toolbar search field, as well as in both the interactive and the simple
@marekkowalczyk
marekkowalczyk / read.go
Last active November 15, 2020 02:05
Helper command: returns input from command line OR pipe --- but not both
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"time"
)