Skip to content

Instantly share code, notes, and snippets.

View marekkowalczyk's full-sized avatar

Marek Kowalczyk marekkowalczyk

View GitHub Profile
@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 / 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