nocin.eu

Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[Mint] Transmission Remote GUI: download directory path is not absolute

Every few months, I run into this issue when adding a torrent to transgui:

Although there is a 5-year-old closed issue on this bug, which also led to a code adjustment, this bug still seems to exist: https://github.com/transmission-remote-gui/transgui/issues/1270
The user Kethsar has probably already found the right cause and gives some hints on how to solve it. At least it helped me to find a workaround:

  • close transgui if it’s running, otherwise your changes will get overwritten again
  • nano ~/.config/Transmission\ Remote\ GUI/transgui.ini
  • search for the [AddTorrent.transmission]section
  • remove some entries which a related, e.g.
Folder1=/my/path/1
FolHit1=1
FolExt1=
LastDt1=18.02.2024

Folder2=/my/path/2
FolHit2=3
FolExt2=
LastDt2=18.02.2024

...
  • save & quit nano
  • start trangui again and try to add a torrent again

It seems like the issues occurs, when the [AddTorrent.transmission] section reaches Folder50.

[Home Assistant] Mushroom Template card – Badge Icon

Somehow, I’ve only just realized that a badge icon can be used to display another entity status on a template card, even though it’s written in the documentation. I now use it to display the status of presence or motion sensors in the respective rooms.

badge_icon: >-
  {{ "mdi:motion-sensor" if states("binary_sensor.0xb4e3f9fffeb689d4_occupancy")  == "on" }}
badge_color: >- 
  {{ "green" if states("binary_sensor.0xb4e3f9fffeb689d4_occupancy") == "on" }}

[ABAP] xsdbool

Somehow I always forget that there is a boolean function in ABAP. That’s why I’m writing this post to hopefully remember it better. 🙂

If you just want to check something for truthiness, you can do it in the following three ways:

IF sy-subrc = 0.
  result = abap_true.
ELSE.
  result = abap_false.
ENDIF.
result = SWITCH #( sy-subrc WHEN 0 THEN abap_true
                                   ELSE abap_false ).
result = xsdbool( sy-subrc = 0 )

[nodejs] Merge PDFs using pdf-lib

https://github.com/Hopding/pdf-lib

const { PDFDocument } = require('pdf-lib')

// files = [{ fileName: 'test1.pdf, content: arraybuffer },{ fileName: 'test2.pdf, content: arraybuffer }]

mergePdfs: async function (files) {
        try {
            const mergedPdf = await PDFDocument.create()

            for (let file of files) {
                const pdf = await PDFDocument.load(file.content)
                const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices())
                copiedPages.forEach((page) => mergedPdf.addPage(page))
            }

            const mergedPdfFile = await mergedPdf.save()
            const buffer = Buffer.from(mergedPdfFile)
            return await buffer.toString('base64') // return as buffer or base64 encoded file
        } catch (err) {
            console.error(err.message)
        }
}

[Home Assistant] Confirmation dialog

Just noticed that you can add a confirmation dialog on a tab action.

https://www.home-assistant.io/dashboards/actions/

https://www.home-assistant.io/dashboards/actions/#options-for-confirmation

Very helpful to prevent things from being activated by mistake.

type: entity
entity: input_boolean.sleep_status
tap_action:
  action: toggle
  confirmation:
    text: Activate sleep mode?
icon: mdi:sleep
icon_color: indigo

[PDF.js] Get PDF Viewer when it’s available in DOM and fully initialized

https://github.com/mozilla/pdf.js/wiki/Third-party-viewer-usage

<iframe id="pdf-js-viewer" src="/pdf/web/viewer.html?file=" title="webviewer" frameborder="0" width="100%" height="700" allowfullscreen="" webkitallowfullscreen=""/>
            displayPdf: async function (id) { 
                const pdfArrayBuffer= await getPdf(id)
                const pdfViewerIFrame = await getPdfViewer()
                await pdfViewerIFrame.contentWindow.PDFViewerApplication.initializedPromise
                await pdfViewerIFrame.contentWindow.PDFViewerApplication.open(pdfArrayBuffer)
            },

            getPdfViewer: function (id = 'pdf-js-viewer') {
                return new Promise((resolve, reject) => {
                    let pdfViewerIFrame = document.getElementById(id)
                    //if already loaded in DOM, return it
                    if (pdfViewerIFrame?.contentWindow?.PDFViewerApplication) {
                        resolve(pdfViewerIFrame)
                    } else {
                        //if not loaded yet, set up eventListener
                        document.addEventListener("webviewerloaded", async () => {
                            pdfViewerIFrame = document.getElementById(id)
                            resolve(pdfViewerIFrame)
                        })
                    }
                })
            }

This logic helped me to get the PDFViewerApplication in every situation correctly, for example when reloading the page with F5 or when having the PDF viewer already loaded and just wanting to open another PDF file.