diff --git a/LICENSE b/LICENSE index 081ef01..abfb1f5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 -Copyright © 2007 Free Software Foundation, Inc. +Copyright © 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -208,25 +208,25 @@ If you develop a new program, and you want it to be of the greatest possible use To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. - lazy-code - Copyright (C) 2024 eplots + code_snippets + Copyright (C) 2023 eplots This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see . + You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - lazy-code Copyright (C) 2024 eplots + code_snippets Copyright (C) 2023 eplots This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. -You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . +You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . -The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . diff --git a/README.md b/README.md index a9b6d2e..ab69991 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # lazy-code -A collection of lazy-code for making my life easier (sometimes)... \ No newline at end of file +A collection of lazy-code for making my life easier (sometimes)... diff --git a/bash/deploy-hugo.sh b/bash/deploy-hugo.sh new file mode 100644 index 0000000..1c1c46d --- /dev/null +++ b/bash/deploy-hugo.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +echo 'Checking if Hugo Docker development server is running...' +echo 'If nothing happens after this, start the development server using:' +echo 'docker run -p 1313:1313 --rm -v /opt/containers/hugo/site/:/src --name hugo klakegg/hugo:0.111-3-ext-alpine server' + +if [ -n "$(docker ps -f "name=hugo" -f "status=running" -q )" ]; then + while true; do + read -p "Do you want to build the website? " yn + case $yn in + [Yy]* ) docker exec -it hugo hugo build; break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no.";; + esac + done + + while true; do + read -p "Do you want to upload the website? " yn + case $yn in + [Yy]* ) scp -q -r /opt/containers/hugo/site/public/* websrv:/home/eplots/eplots.xyz/blog/static/; break;; + [Nn]* ) exit;; + * ) echo "Please answer yes or no.";; + esac + done + echo "Done!" +fi diff --git a/bash/reset-websrv.sh b/bash/reset-websrv.sh new file mode 100644 index 0000000..9eade92 --- /dev/null +++ b/bash/reset-websrv.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# One-liner to reset websrv +sed -i '/^185.193.125.246/ d' ~/.ssh/known_hosts && cat ~/.ssh/websrv.pub | xclip -sel c diff --git a/bash/sb-vpn b/bash/sb-vpn new file mode 100644 index 0000000..2747448 --- /dev/null +++ b/bash/sb-vpn @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +ip -o -4 a show tun0 | awk '/inet 10\./ {print $4}' | cut -d'/' -f1 diff --git a/bash/scp-dir.sh b/bash/scp-dir.sh new file mode 100644 index 0000000..1f0da44 --- /dev/null +++ b/bash/scp-dir.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Store destination paths in variables +nasty="eplots@192.168.50.212:~/NASty/hackz" + +# Parse directory path to get directory name only and store it in a variable +dir="$(basename $2)" + +# If $1 variable equals "NASty", format SCP to copy dir ($2) to NASty: +[ "$1" == nasty ] && scp -P 1886 -r "$2" "$nasty"/"$dir" diff --git a/bash/scp-file.sh b/bash/scp-file.sh new file mode 100644 index 0000000..8c0bd87 --- /dev/null +++ b/bash/scp-file.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Store destination path in variable +nasty="eplots@192.168.50.212:~/NASty/hackz" + +# Parse filepath to get filename only and store in variable +file="$(basename $2)" + +# If $1 variable equals "nasty", format SCP to copy file ($2) to NASty: +[ "$1" == nasty ] && scp -P 1886 "$2" "$nasty"/"$file" diff --git a/bash/webp.sh b/bash/webp.sh new file mode 100644 index 0000000..0e9c272 --- /dev/null +++ b/bash/webp.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# One-liner to convert all *.png to *.webp +for x in ls *.png; do cwebp -q 80 $x -o ${x%.png}.webp; done diff --git a/mssql/SUP-7719.sql b/mssql/SUP-7719.sql new file mode 100644 index 0000000..1ede24d --- /dev/null +++ b/mssql/SUP-7719.sql @@ -0,0 +1,37 @@ +/* + Control code that should be run after the year. + This control goes against case SUP-7719. + Probably need to check the dates below before running it. + + Save this file for future questions, especially when updating. +*/ + +USE FAST2; + +DECLARE @fomdat VARCHAR(8) +DECLARE @tomdat VARCHAR(8) +DECLARE @uppldat VARCHAR(8) + +SET @fomdat = '20220101' +SET @tomdat = '20220401' +SET @uppldat = '20221201' + +SELECT DISTINCT * + FROM ((((avr a + INNER JOIN pr p + ON a.avr_avtnr = p.pr_avtnr) + INNER JOIN obj o + ON a.avr_objnr = o.obj_objnr) + INNER JOIN pr pr_hg1 + ON a.avr_avtnr = pr_hg1.pr_avtnr) + INNER JOIN pku u + ON p.pr_kundnr = u.pku_kundnr) + INNER JOIN pku pku_hg1 + ON pr_hg1.pr_kundnr = pku_hg1.pku_kundnr + INNER JOIN spin s + ON p.pr_avtnr = s.spin_parent_key + WHERE (a.avr_fomdat BETWEEN @fomdat AND @tomdat) + AND ( o.obj_obotyp LIKE 'P%' + OR o.obj_obotyp LIKE 'G%') + AND a.avr_tomdat = 'TV' + AND a.avr_uppldat >= @uppldat diff --git a/mssql/avtals_forhandlingar.sql b/mssql/avtals_forhandlingar.sql new file mode 100644 index 0000000..33280d7 --- /dev/null +++ b/mssql/avtals_forhandlingar.sql @@ -0,0 +1,33 @@ +SELECT + OBJ.OBJ_OBJNR AS 'Objektsnr', + PKU.PKU_HNAMN AS 'Hyresgäst', + OBJ.OBJ_GYTA AS 'Yta kvm', + AVR.AVR_NORMALHYRAMAN AS 'Årshyra', + AVR.AVR_FOMDAT AS 'Avtal startdatum', + AVR.AVR_TOMDAT AS 'Avtal t o m', + AVR.AVR_KONTRAKTSLUT AS 'Kontraktslut', + AVR.AVR_AVRFRL AS 'Förlängningstid', + AVR.AVR_UPSTID AS 'Uppsägningstid' +FROM + AVR + INNER JOIN OBJ ON AVR.AVR_OBJNR = OBJ.OBJ_OBJNR + INNER JOIN OBT ON OBJ.OBJ_OBOTYP = OBT.OBT_OBOTYP + AND OBJ.OBJ_OBJTYP = OBT.OBT_OBJTYP + INNER JOIN OBO ON OBJ.OBJ_OBOTYP = OBO.OBO_OBOTYP + INNER JOIN BG ON OBJ.OBJ_BYGNR = BG.BG_BYGNR + AND OBJ.OBJ_FASTNR = BG.BG_FASTNR + INNER JOIN FT ON BG.BG_FASTNR = FT.FT_FASTNR + LEFT OUTER JOIN PKU ON AVR.AVR_KUNDNRINFLYTT = PKU.PKU_KUNDNR + LEFT OUTER JOIN PKU PKU_A ON AVR.AVR_KUNDNRHG2INFLYTT = PKU_A.PKU_KUNDNR +WHERE + ( + AVR.AVR_OBJNR > '' + AND (AVR.AVR_OBJNR) IS NOT NULL + ) + AND AVR.AVR_KORR = 'N' + AND FT.FT_BESK LIKE 'Niten 11' + AND OBJ.OBJ_OBOTYP LIKE 'L%' + AND PKU.PKU_HNAMN != 'HG AVIDENTIFIERAD' + AND AVR.AVR_TOMDAT = 'TV' +ORDER BY + Objektsnr ASC \ No newline at end of file diff --git a/mssql/check_xp_cmdshell.sql b/mssql/check_xp_cmdshell.sql new file mode 100644 index 0000000..1008110 --- /dev/null +++ b/mssql/check_xp_cmdshell.sql @@ -0,0 +1,3 @@ +SELECT CONVERT(INT, ISNULL(value, value_in_use)) AS config_value +FROM sys.configurations +WHERE name = 'xp_cmdshell' ; \ No newline at end of file diff --git a/mssql/clean_numbers.sql b/mssql/clean_numbers.sql new file mode 100644 index 0000000..cb5b4be --- /dev/null +++ b/mssql/clean_numbers.sql @@ -0,0 +1,25 @@ +/* +Hur man tar bort alla andra tecken förutom siffror i en query. +*/ +( + SELECT + ( + SELECT + CAST( + CAST( + ( + SELECT + SUBSTRING(PKU_TFNOVR, Number, 1) + FROM + master..spt_values + WHERE + Type = 'p' + AND Number <= LEN(PKU_TFNOVR) + AND SUBSTRING(PKU_TFNOVR, Number, 1) LIKE '[0-9]' FOR XML PATH('') + ) AS xml + ) AS VARCHAR(MAX) + ) + ) + FROM + PKU +) \ No newline at end of file diff --git a/mssql/datatypes.sql b/mssql/datatypes.sql new file mode 100644 index 0000000..0d674d9 --- /dev/null +++ b/mssql/datatypes.sql @@ -0,0 +1,20 @@ +SELECT + [Name] = c.[name] +, [Type] = + CASE + WHEN tp.[name] IN ('varchar', 'char', 'varbinary') THEN tp.[name] + '(' + IIF(c.max_length = -1, 'max', CAST(c.max_length AS VARCHAR(25))) + ')' + WHEN tp.[name] IN ('nvarchar','nchar') THEN tp.[name] + '(' + IIF(c.max_length = -1, 'max', CAST(c.max_length / 2 AS VARCHAR(25)))+ ')' + WHEN tp.[name] IN ('decimal', 'numeric') THEN tp.[name] + '(' + CAST(c.[precision] AS VARCHAR(25)) + ', ' + CAST(c.[scale] AS VARCHAR(25)) + ')' + WHEN tp.[name] IN ('datetime2') THEN tp.[name] + '(' + CAST(c.[scale] AS VARCHAR(25)) + ')' + ELSE tp.[name] + END +, [RawType] = tp.[name] +, [MaxLength] = c.max_length +, [Precision] = c.[precision] +, [Scale] = c.scale +, [IsNullable] = c.is_nullable +FROM sys.tables t +JOIN sys.schemas s ON t.schema_id = s.schema_id +JOIN sys.columns c ON t.object_id = c.object_id +JOIN sys.types tp ON c.user_type_id = tp.user_type_id +WHERE s.[name] = 'dbo' AND t.[name] = 'FN' \ No newline at end of file diff --git a/mssql/duplicate_values.sql b/mssql/duplicate_values.sql new file mode 100644 index 0000000..cd94851 --- /dev/null +++ b/mssql/duplicate_values.sql @@ -0,0 +1,22 @@ +USE FAST2; + +--real_estate: +SELECT ft_fastnr, + COUNT(*) + FROM ft + GROUP BY ft_fastnr +HAVING COUNT(*) > 1 + +--building: +SELECT bg_bygnr, + COUNT(*) + FROM bg + GROUP BY bg_bygnr +HAVING COUNT(*) > 1 + +--object: +SELECT obj_objnr, + COUNT(*) + FROM obj + GROUP BY obj_objnr +HAVING COUNT(*) > 1 \ No newline at end of file diff --git a/mssql/kopoang.sql b/mssql/kopoang.sql new file mode 100644 index 0000000..67c3502 --- /dev/null +++ b/mssql/kopoang.sql @@ -0,0 +1,30 @@ +/* + KÖTID FRÅN BOKÖ TILLS MAN SKRIVIT AVTAL. EJ INFLYTTNING! + VILKEN SORTERING/GRUPPERING SKALL DET VARA? + VILKA PARAMETRAR SKALL SÄTTAS UPP? + VEM FIXAR LAYOUTEN? +*/ + +SELECT + OBJ.OBJ_OBOTYP, + OBJ.OBJ_OBJNR, + OBJ.OBJ_BOSOK1_OMR_BCD, + CAST(LEFT(RIGHT(SPIN_TEXT, LEN(SPIN_TEXT) - CHARINDEX('inflyttning: ', SPIN_TEXT, 1) - 12),8) AS DATE) AS 'Ködatum', + CAST(SPIN_DATESTAMP_NY AS DATE) AS 'Borttagen', + DATEDIFF(dd,CAST(LEFT(RIGHT(SPIN_TEXT, LEN(SPIN_TEXT) - CHARINDEX('inflyttning: ', SPIN_TEXT, 1) - 12), 8) AS DATE),CAST(SPIN_DATESTAMP_NY AS DATE)) AS dagar + --AVG(DATEDIFF(dd,CAST(LEFT(RIGHT(SPIN_TEXT, LEN(SPIN_TEXT) - CHARINDEX('inflyttning: ', SPIN_TEXT, 1) - 12), 8) AS DATE),CAST(SPIN_DATESTAMP_NY AS DATE))) AS 'snitt' +FROM + SPIN + INNER JOIN PKU ON SPIN.SPIN_PARENT_KEY = PKU_KUNDNRINTERN + INNER JOIN OBJ ON PKU.PKU_KUNDNR = OBJ.OBJ_KUNDNR +WHERE + SPIN_SOKNAMN LIKE 'Borttagen%' + AND SPIN_TEXT LIKE '%Köplats%borttagen%inflyttning%' + AND SPIN_TYP = 'BOKO' + AND YEAR(SPIN_DATESTAMP_NY) >= '2022' + AND OBJ.OBJ_OBJTYP LIKE 'B%' + --AND SPIN_TEXT LIKE '%intern:62120%' -- Alex interna kundnr + +SELECT TOP 1 * FROM SPIN WHERE SPIN_TYP = 'BOKO' AND SPIN_SOKNAMN LIKE 'Borttagen%' + +SELECT * FROM SPIN WHERE SPIN_PARENT_KEY = '62120' \ No newline at end of file diff --git a/mssql/moms_koll.sql b/mssql/moms_koll.sql new file mode 100644 index 0000000..b695b84 --- /dev/null +++ b/mssql/moms_koll.sql @@ -0,0 +1,46 @@ +USE FAST2; + +-- Företag som parameter? + +SELECT DISTINCT o.OBJ_OBJNR, + o.OBJ_OBJTYP, + o.OBJ_ADR, + o.OBJ_HNAMN, + o.OBJ_MOMSMARK, + r.AVR_MOMSPL, + p.PKO_PKT_MOMSKOD + FROM OBJ o + INNER JOIN AVT h ON o.OBJ_AVTNR = h.AVT_AVTNR + INNER JOIN AVR r ON h.AVT_AVTNR = r.AVR_AVTNR + INNER JOIN PKO p ON o.OBJ_OBJNR = p.PKO_OBJNR + WHERE o.OBJ_OBOTYP NOT LIKE 'P%' + AND o.OBJ_HNAMN NOT IN ('PROJEKT', 'RENOVERING') + --AND o.OBJ_FTGNR = 'EHB' + AND o.OBJ_OBOTYP NOT LIKE 'G%' + AND o.OBJ_AVTNR != '999999999' + AND p.PKO_PKTYP NOT IN ('3614', 'VVMJUST', 'KVMJUST', 'ELBJUST', 'VVMSCHAB', 'KVMSCHAB', 'TFVATT', 'T880') + AND p.PKO_PKTYP NOT LIKE 'HBO%' + AND p.PKO_HTYP = 'HYRA' + AND (p.PKO_TOMDAT >= CONVERT(VARCHAR(8), GETDATE(), 112) OR p.PKO_TOMDAT = 'TV') + AND o.OBJ_OBJNR = r.AVR_OBJNR + AND NOT (o.OBJ_MOMSMARK = 'N' AND r.AVR_MOMSPL = 'N' AND (p.PKO_PKT_MOMSKOD = '0' OR p.PKO_PKT_MOMSKOD = 'MOMSFR')) + AND NOT (o.OBJ_MOMSMARK = 'J' AND r.AVR_MOMSPL = 'J' AND p.PKO_PKT_MOMSKOD = 'FULLMO') + AND ( + OBJ_IAKTDAT IS NULL + OR OBJ_IAKTDAT = '' + OR OBJ_IAKTDAT >= CONVERT( + VARCHAR(8), + GETDATE(), + 112 + ) + ) + AND ( + OBJ_FORSALJDATUM IS NULL + OR OBJ_FORSALJDATUM = '' + OR OBJ_FORSALJDATUM >= CONVERT( + VARCHAR(8), + GETDATE(), + 112 + ) + ) +ORDER BY o.OBJ_OBJNR \ No newline at end of file diff --git a/mssql/search_for_columns.sql b/mssql/search_for_columns.sql new file mode 100644 index 0000000..cce6486 --- /dev/null +++ b/mssql/search_for_columns.sql @@ -0,0 +1,6 @@ +SELECT c.name AS ColName, + t.name AS TableName + FROM sys.columns c + JOIN sys.tables t + ON c.object_id = t.object_id + WHERE c.name LIKE '%FU_STATUS%' \ No newline at end of file diff --git a/mssql/tmp_tbl.sql b/mssql/tmp_tbl.sql new file mode 100644 index 0000000..9f274e1 --- /dev/null +++ b/mssql/tmp_tbl.sql @@ -0,0 +1,18 @@ +/* +Hur man skapar en temptabell i minnet på databasen. +*/ + +--visible only to me, in memory (SQL 2000 and above only) +declare @test table ( + FOL_RSN bigint, + FOL_ID bigint, + FOL_BESK VARCHAR(50), + FOL_VISAS CHAR(1) +); + +INSERT INTO @test (FOL_RSN, FOL_ID, FOL_BESK, FOL_VISAS) --VALUES (1,1,'asdf',1) + +SELECT * FROM FU_ORIGIN_LIST AS a + + +SELECT * FROM @test \ No newline at end of file diff --git a/mssql/ue_ao_dump.sql b/mssql/ue_ao_dump.sql new file mode 100644 index 0000000..cf16939 --- /dev/null +++ b/mssql/ue_ao_dump.sql @@ -0,0 +1,17 @@ +USE FAST2; + +SELECT f.FU_FELRADNR AS 'ao_nr', + f.FU_REGDAT AS 'reg_datum', + s.SPIN_SOKNAMN AS 'spin_rubrik', + s.SPIN_DATESTAMP_NY AS 'spin_tid', + s.SPIN_IDSTAMP_NY AS 'spin_id', + REPLACE(REPLACE(s.SPIN_TEXT, CHAR(13), ''), CHAR(10), '') AS 'spin_text', + FROM FU f + INNER JOIN SPIN s ON f.FU_FELRADNR = s.SPIN_PARENT_KEY + WHERE f.FU_RESURS = 'BUNECO' + AND f.FU_REGDAT BETWEEN '20230401' AND '20240111' + AND s.SPIN_TYP NOT IN ('AOEPOSTPKU', 'AOSMSPKU', 'AOSENT') + AND s.SPIN_TEXT NOT IN ('Registrerad') + AND s.SPIN_TEXT NOT LIKE '%Föregående utförare: %' + AND s.SPIN_TEXT NOT LIKE '%Ny utförare: %' + ORDER BY ao_nr ASC diff --git a/nvim/ExportMarkdownToPDF.vim b/nvim/ExportMarkdownToPDF.vim new file mode 100644 index 0000000..5f6c15f --- /dev/null +++ b/nvim/ExportMarkdownToPDF.vim @@ -0,0 +1,19 @@ +function! ExportMarkdownToPDF() + let l:input_file = expand('%') " Hämtar det aktuella filnamnet + let l:output_file = input('Ange filnamn för PDF: ', expand('%:r') . '.pdf', 'file') + if l:output_file == '' + echo 'Inget filnamn angivet. Export avbruten.' + return + endif + let l:command = 'python3 /path/to/your/script/md_to_pdf.py ' . shellescape(l:input_file, 1) . ' ' . shellescape(l:output_file, 1) + execute '!' . l:command + echo 'PDF genererad: ' . l:output_file + " Lägg till ett kommando för att öppna PDF med Zathura + if filereadable(l:output_file) + silent execute '!zathura ' . shellescape(l:output_file, 1) . ' &' + redraw! + endif +endfunction + +command! ExportToPDF call ExportMarkdownToPDF() +nnoremap :ExportToPDF diff --git a/nvim/PythonCodeInNvim.vim b/nvim/PythonCodeInNvim.vim new file mode 100644 index 0000000..753bf30 --- /dev/null +++ b/nvim/PythonCodeInNvim.vim @@ -0,0 +1,2 @@ +autocmd FileType python map :w:exec '!python3' shellescape(@%, 1) +autocmd FileType python imap :w:exec '!python3' shellescape(@%, 1) diff --git a/powershell/jasper-kontroll.ps1 b/powershell/jasper-kontroll.ps1 new file mode 100644 index 0000000..cb14ee9 --- /dev/null +++ b/powershell/jasper-kontroll.ps1 @@ -0,0 +1,5 @@ +$datum = Get-Date -Format "yyyy-MM-dd"; $path = "C:\din\mapp\sökväg"; $outputFile = "C:\sökväg\till\jasper-resultat-$datum.md"; "Filename | Last Modified Time", "-------- | -----------------" | Set-Content $outputFile; Get-ChildItem -Path $path -Filter *.jasper | Sort-Object LastWriteTime -Descending | ForEach-Object { "$($_.Name) | $($_.LastWriteTime)" | Add-Content $outputFile } + +$datum = Get-Date -Format "yyyy-MM-dd"; $path = "C:\din\mapp\sökväg"; $outputFile = "C:\sökväg\till\jasper-resultat-$datum.md"; "| Filename | Last Modified Time |", "| -------- | ----------------- |" | Set-Content $outputFile; Get-ChildItem -Path $path -Filter *.jasper | Sort-Object LastWriteTime -Descending | ForEach-Object { "| $($_.Name) | $($_.LastWriteTime) |" | Add-Content $outputFile } + +Compare-Object (Get-Content "C:\sökväg\till\fil1.md") (Get-Content "C:\sökväg\till\fil2.md") | Where-Object { $_.SideIndicator -ne '==' } | ForEach-Object { if ($_.SideIndicator -eq '<=') {"File1: $($_.InputObject)"} else {"File2: $($_.InputObject)"} } | Set-Content "C:\sökväg\till\diffresultat.md" diff --git a/powershell/jasper-rapporter.ps1 b/powershell/jasper-rapporter.ps1 new file mode 100644 index 0000000..2cee907 --- /dev/null +++ b/powershell/jasper-rapporter.ps1 @@ -0,0 +1,5 @@ +# Production-server: +$datum = Get-Date -Format "yyyy-MM-dd"; $path = "\\appsrv31\Rapport"; $outputFile = "C:\Users\patsto\Desktop\produktions-jasper-$datum.md"; "| Filename | Last Modified Time |", "| --- | --- |" | Set-Content $outputFile; Get-ChildItem -Path $path -Filter *.jasper | Sort-Object LastWriteTime -Descending | ForEach-Object { "| $($_.Name) | $($_.LastWriteTime) |" | Add-Content $outputFile } + +# Testing-server: +$datum = Get-Date -Format "yyyy-MM-dd"; $path = "\\tst-appsrv31\Rapport"; $outputFile = "C:\Users\patsto\Desktop\produktions-jasper-$datum.md"; "| Filename | Last Modified Time |", "| --- | --- |" | Set-Content $outputFile; Get-ChildItem -Path $path -Filter *.jasper | Sort-Object LastWriteTime -Descending | ForEach-Object { "| $($_.Name) | $($_.LastWriteTime) |" | Add-Content $outputFile } diff --git a/python/md_to_pdf.py b/python/md_to_pdf.py new file mode 100644 index 0000000..1893d62 --- /dev/null +++ b/python/md_to_pdf.py @@ -0,0 +1,124 @@ +import markdown +from weasyprint import HTML, CSS +import sys +import re +from datetime import datetime + +def extract_date(markdown_text): + # Försök att hitta ett datum i formatet "Datum: YYYY-MM-DD" + match = re.search(r'\*\*Datum\*\*:\s*(\d{4}-\d{2}-\d{2})', markdown_text) + return match.group(1) if match else datetime.now().strftime('%Y-%m-%d') + +def markdown_to_pdf(input_file, output_file): + # Läs markdown från fil + with open(input_file, 'r', encoding='utf-8') as file: + markdown_text = file.read() + + # Extrahera datumet + date = extract_date(markdown_text) + + # Konvertera markdown till HTML + html_text = markdown.markdown(markdown_text, extensions=['tables']) + + # HTML-mall med anpassad teckenstorlek + html_template = f""" + + + + + + +
+ {f'DATUM: {date}' if date else ""}
+ Eskilstuna Kommunfastigheter AB +
+ {html_text} + + + """ + + # Generera PDF + html = HTML(string=html_template) + html.write_pdf(output_file) + + print(f"PDF-filen {output_file} har skapats.") + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("Användning: python script.py input.md output.pdf") + else: + input_filepath = sys.argv[1] + output_filepath = sys.argv[2] + markdown_to_pdf(input_filepath, output_filepath) diff --git a/python/ssh_honeypot.py b/python/ssh_honeypot.py new file mode 100644 index 0000000..ea592a6 --- /dev/null +++ b/python/ssh_honeypot.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import socket +import paramiko +import threading + +class SSHServer(paramiko.ServerInterface): + + def check_auth_password(self, username: str, password: str) -> int: + print(f'{username}:{password}') + return paramiko.AUTH_FAILED + +def handle_connection(client_sock): + transport = paramiko.Transport(client_sock) + server_key = paramiko.RSAKey.from_private_key_file('key') + transport.add_server_key(server_key) + ssh = SSHServer() + transport.start_server(server=ssh) + +def main(): + server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server_sock.bind(('', 2222)) + server_sock.listen(100) + + while True: + client_sock, client_addr = server_sock.accept() + print(f'Connection from {client_addr[0]}:{client_addr[1]}') + t = threading.Thread(target=handle_connection, args=(client_sock,)) + t.start() + +if __name__ == "__main__": + main() diff --git a/python/taskwarrior-task2cal.py b/python/taskwarrior-task2cal.py new file mode 100644 index 0000000..d57971e --- /dev/null +++ b/python/taskwarrior-task2cal.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +from tasklib import TaskWarrior +import sys + +tw = TaskWarrior('~/.local/share/task/') + +# Parse appointments +apts = tw.tasks.filter('(status:pending or status:waiting or status:completed)', type='cal') +for apt in apts: + start = apt['scheduled'] + if start is None: + sys.stderr.write(f"Apt '{apt}' has no sched date!\n") + continue + + summary = str(apt) + + if start.hour == 0 and start.minute == 0: + start_fmt = start.strftime("%m/%d/%Y") + print(f"{start_fmt} [1] {summary}") + else: + start_fmt = start.strftime("%m/%d/%Y @ %H:%M") + + if apt['due']: + end_fmt = apt['due'].strftime("%m/%d/%Y @ %H:%M") + else: + end_fmt = strt_fmt + + print(f"{start_fmt} -> {end_fmt}|{summary}") + +# Parse due dates for next actions and projects +tasks = tw.tasks.filter('(status:pending or status:waiting) and (type:next or type:objective or type:standby)') + +for task in tasks: + for date_type, label in [('due', "Slutdatum: "), + ('scheduled', "Startdatum: ")]: + if not task[date_type]: # Skip tasks with no date + continue + start = task[date_type] + + proj = "Project: " if task['type'] == "objective" else "" + + summary = label + proj + str(task) + + if start.hour == 0 and start.minute == 0: + start_fmt = start.strftime("%m/%d/%Y") + print(f"{start_fmt} [1] {summary}") + else: + start_fmt = start.strftime("%m/%d/%Y @ %H:%M") + end_fmt = start_fmt + print(f"{start_fmt} -> {end_fmt}|{summary}") diff --git a/sqlite3/newsboat-reset.sql b/sqlite3/newsboat-reset.sql new file mode 100644 index 0000000..f612c61 --- /dev/null +++ b/sqlite3/newsboat-reset.sql @@ -0,0 +1,4 @@ +-- Reset entire rss-feed +UPDATE rss_item + SET unread = 1 + WHERE feedurl = '' -- get from urls file