Skip to content

Instantly share code, notes, and snippets.

@ALoecken
ALoecken / merge_first_page.bat
Created May 2, 2022 21:03
Reads all PDFs in a folder and merges the first pages to a single PDF. Why? Because I wanted to print the first pages of a folder full of papers with 4 pages per A4 sheet and did not care to find another way ;)
@ECHO OFF
SET PATH=%PATH%;C:\Program Files\gs\gs9.27\bin
SETLOCAL ENABLEDELAYEDEXPANSION
REM 0. create tmpdir to put all the temporary files
RMDIR /S /Q tmp_pdf_folder
DEL first_pages.pdf
mkdir tmp_pdf_folder
@ALoecken
ALoecken / tabloader.R
Last active July 15, 2021 12:55
Reads all .tab files of the current folder into a single data.frame in R
# go through all files in the folder
files <- list.files(path=".", pattern="*.tab", full.names=TRUE, recursive=FALSE)
# read all of them into a list of data.frames
# Note: "lapply" is much faster than a for-loop, but I am not sure how it sorts
table_list <- lapply(files, function(x) {
x <- read.table(x, sep="\t", header=F)
colnames(x) <- c("count", "x", "y")
x
})
@ALoecken
ALoecken / drag_and_drop_compress.bat
Last active June 30, 2021 16:26
This short batch can be used in combination with the compress_pdf.bat to compress multiple PDFs using Drag'n'Drop.
@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR %%a IN (%*) DO (
SET filename=%%a
REM https://gist.github.com/ALoecken/c01eff8bbc181599b6530fcb0cb8266a
CALL %0\..\compress_pdf.bat -h "%%a" "!filename:~0,-4!_compr.pdf"
)
@ALoecken
ALoecken / count_colored_pages.bat
Created April 1, 2021 11:24
Quick and Dirty way to count the number of colored pages using ghostscript.
@ECHO OFF
:: The location of your Ghostscript installation...
SET PATH=%PATH%;C:\Program Files\gs\gs9.26\bin
IF ""%1""=="""" GOTO HELP
SET FN=%1
SET FN=%FN:"=%
ECHO Counting the number of colored pages in "%FN%".
:: count number of colored pages:
@ALoecken
ALoecken / compress_pdf.bat
Last active June 30, 2021 15:35
Quick batch script to compress a pdf using ghostscript
@ECHO OFF
::SET PATH=%PATH%;C:\Program Files\gs\gs9.26\bin
SET gs=gs
:: Searching for ghostscript
WHERE %gs% >nul 2>nul
IF %ERRORLEVEL% NEQ 0 SET gs=gswin
WHERE %gs% >nul 2>nul
IF %ERRORLEVEL% NEQ 0 SET gs=gswin64