Skip to content

Instantly share code, notes, and snippets.

View alekrutkowski's full-sized avatar

alek alekrutkowski

View GitHub Profile
alekrutkowski / listWithoutEmptyArgs.R
Last active March 13, 2024 13:59
R function for dealing with (ignoring) missing/empty arguments inside ellipsis (...)
listWithoutEmptyArgs <- function(...)
eval(Filter(\(x) !identical(as.character(x), "") || identical(x,""),
# > list(a=1,,b=2:10)
# Error in list(a = 1, , b = 2:10) : argument 2 is empty
# > listWithoutEmptyArgs(a=1,,b=2:10)
# list(a = 1, b = 2:10)
alekrutkowski / memory_address.R
Last active February 22, 2024 16:22
Get memory address of an R object
memoryAddress <- function(x)
strsplit(capture.output(.Internal(inspect(x))),split=" ")[[1]][1]
### Usage examples
# > abc <- c(1,2,3,10,11)
# > xyz <- abc
# > memoryAddress(abc)==memoryAddress(xyz)
# [1] TRUE
# > xyz <- abc+1
import os
import random
import string
while True:
folder_path = input("Please enter the folder path: ")
# Check if the path is a valid directory
if os.path.isdir(folder_path):
print(f"Valid directory: {folder_path}")
alekrutkowski / async_mirai.R
Last active February 23, 2024 13:39
async/non-blocking programming in R with `mirai`
### Usage:
# a = 1; b = 2
# my_result <- eval.async(a+b)
### when mirai::unresolved(my_result) == FALSE
### you can use my_result$data
### can be used like
eval.async <-
alekrutkowski / data.table_filtering_by_groups.R
Last active January 12, 2024 11:37
Concise/terse filtering R data.table rows by condition within groups (inside a magrittr)
## Pattern:
# DT[DT[,row_filtering_expression, by=grouping_column][[2]]]
## or generally
# DT[DT[,row_filtering_expression, by=.(grouping_col1,grouping_col2,etc.)][[number_of_grouping_cols+1]]]
## Example:
alekrutkowski /
Created October 29, 2023 17:56
Panoramic Image (JPEG) to panning video (MP4) converter
# Made with ChatGPT
# Required packages:
# - Pillow
# - imageio
# - imageio-ffmpeg
# - numpy
# Usage example:
# create_panning_video('My_Pano_image.jpg', 'My_Pano_video.mp4', 90, 60)
from PIL import Image
import imageio
alekrutkowski / CallPlumberAPI.vba
Last active March 1, 2024 13:37
Calling arbitrary R code from Excel with easy data input and output (Excel↔R)
Sub CallPlumberAPI()
Dim SERVER_URL As String
Dim xmlhttp As Object
Dim ws As Worksheet
Dim inputRange As Range, dataRange As Range, outputRange As Range
Dim cellAddress As String, rCode As String, outputAddress As String
Dim i As Long, j As Long
Dim tsvData As String, processedData As String
Dim outputData() As String, outputRow() As String
alekrutkowski / AttachLabelsToPointsAvoidingOverlap.vba
Last active October 5, 2023 08:23
Excel macro for adding labels to scatterplot points while avoiding their overlap of points are close
Sub AttachLabelsToPointsAvoidingOverlap()
' Based on:
' but significantly extended to reduce the overlap of labels for points which are close
' IMPORTANT: The labels for the scatterplot points are assumed to be in the column directly on the left side of the data range
' USAGE: Select the chart (scatterplot) concerned, then run the macro
' If you don't like the positioning of the labels, simply re-run the macro - new positions may be better
' because it will be based on new random numbers.
alekrutkowski /
Created June 17, 2023 19:51
A bash script to add RAM usage percent as a new item in the XFCE panel
# Prerequisities
# 0) XFCE
# 1) Save this script in your home directory as: /home/your_user_name/
# 2) Add a new XFCE Generic Monitor Applet item (with the settings: no label, 1 second refresh period): /home/your_user_name/
# Use grep with perl-regex (-P) to extract numbers and store them in an array
numbers=($(echo "$output" | grep -oP '\d+'))
alekrutkowski /
Last active June 7, 2023 16:07
A simple [shinylive]( app example with Excel input, dataframe processing, and Excel output

To compile it into a docs folder/directory which could be hosted as an app on GitHub (Pages), assuming that the and requirements.txt are in the excel_io folder/directory:

shinylive export excel_io docs

To run it (after compilation) locally:

python -m http.server --directory docs 8008

The input Excel file (used as an example) that is uploaded by a user in the running app has the following contents: