Skip to content

Instantly share code, notes, and snippets.

@ahnl
ahnl / main.py
Created September 12, 2023 17:33
Transfer PDF annotations from broken.pdf to fixed.pdf
import PyPDF2
def transfer_annotations(src_pdf, dest_pdf, output_pdf):
# Open the source and destination PDF files
with open(src_pdf, 'rb') as src, open(dest_pdf, 'rb') as dest:
src_reader = PyPDF2.PdfFileReader(src)
dest_reader = PyPDF2.PdfFileReader(dest)
pdf_writer = PyPDF2.PdfFileWriter()
# Check the number of pages match in both PDFs
@ahnl
ahnl / covid19case.js
Created April 1, 2021 17:01
Esimerkkiskripti THL koronatilastojen lukemisesta NodeJSällä
const axios = require("axios")
axios("https://sampo.thl.fi/pivot/prod/fi/epirapo/covid19case/fact_epirapo_covid19case.csv?row=508804L&column=measure-444833&fo=1")
.then(({data}) => {
// Pilko rivien mukaan arrayhin
data = data.split("\n")
// Poista ensimmäinen rivi, siinä ei ole dataa
data.shift()
@ahnl
ahnl / script.js
Created December 5, 2020 20:07
Vauva.fi automaattinen bottivarmistuksen täyttäminen
document.getElementById('edit-captcha-questions-answer-given').value = document.getElementsByName('captcha_questions_question')[0].value.split(' ').map(a => ['nolla', 'yksi', 'kaksi', 'kolme', 'neljä', 'viisi', 'kuusi', 'seitsemän', 'kahdeksan', 'yhdeksän'].indexOf(a)).join('');