Skip to content

Instantly share code, notes, and snippets.

View alekrutkowski's full-sized avatar

alek alekrutkowski

View GitHub Profile
@alekrutkowski
alekrutkowski / mschart_examples.R
Created September 27, 2022 14:10
Examples of native Microsoft Office charts (with embedded data editable with Excel) generated programmatically with R and saved within a Word (docx) file
# `mschart` and `officer` R packages are required
# `magrittr` required for the %>% pipe
scatter_plot <-
mschart::ms_scatterchart(
data=iris, x="Sepal.Length",
y="Sepal.Width", group="Species"
) %>%
mschart::chart_settings(scatterstyle="marker")
@alekrutkowski
alekrutkowski / emailAddressToInstitutionName.R
Created September 29, 2022 13:54
R function: email address ➜ institution name, quick and dirty (just the 1st hit in Bing)
# Usage example (disclaimer: fictitious email addresses, any resemblance to real ones is coincidental):
## emailAddressToInstitutionName(c('[email protected]',
## '[email protected]'))
##> "Ministère du Travail, du Plein emploi et de l'Insertion"
##> "Ministerie van Sociale Zaken en Werkgelegenheid | Rijksoverheid.nl"
# Required packages: `magrittr`, `rvest`
library(magrittr) # for the %>% operator
emailAddressToInstitutionName <- function(charvec_of_email_addresses,
@alekrutkowski
alekrutkowski / rglue.R
Created October 9, 2022 08:32
Recursive `glue::glue`
# Recursive `glue::glue` based on
# https://github.com/SuperMayo/gonfig/blob/master/R/glue.R
# but simplified
rglue <- function(string, ...) {
glued <- glue::glue(string, ...)
if (glued==string) glued else rglue(glued, ...)
}
@alekrutkowski
alekrutkowski / rstudio_bindings.json
Last active October 27, 2022 15:04
RStudio key bindings / shortcuts. See the entry for "commentUncomment" – multiple bindings possible. To find out where to save, see section "Saving and Loading" in https://support.rstudio.com/hc/en-us/articles/206382178-Customizing-Keyboard-Shortcuts-in-the-RStudio-IDE#:~:text=Saving,Kevin
{
"goToFileFunction": "Ctrl+P",
"insertPipeOperator": "Ctrl+Shift+M",
"restartR": "Ctrl+R",
"activateTerminal": "Ctrl+3",
"browseAddins": "",
"closeProject": "",
"closeTerminal": "",
"sendTerminalToEditor": "",
"newTerminal": "Ctrl+T",
@alekrutkowski
alekrutkowski / openxlsx2.extras.R
Last active November 22, 2022 08:44
Helper functions to the R package `openxlsx2`
library(openxlsx2)
library(magrittr) # for the %>% operator
# Import all sheets in the Excel file as a list of data.frames
# like in the previous package version (openxlsx)
readAllSheets <- function(xlsx_file_name, drop_empty_sheets=TRUE,
suppress_warnings=TRUE, ...)
xlsx_file_name %>%
read_sheet_names() %>%
sapply(function(x)
@alekrutkowski
alekrutkowski / InfixFunctions.jl
Last active February 24, 2023 15:59
A way to define descriptive infix operators in Julia, similar to R's user-defined %-delimited operators (https://adv-r.hadley.nz/functions.html#infix-functions)
# Copied from https://github.com/Ismael-VC/InfixFunctions.jl/blob/master/src/InfixFunctions.jl
# and updated for compatibility with current Julia (ver. 1.8.5), specifically method `isdefined`.
# See the usage examples below.
# Before using:
# 1) Download this file to your current working directory, e.g. in Julia
# julia> run(`wget https://gist.githubusercontent.com/alekrutkowski/32097fe6502c254374c406fbb71d3ef8/raw/InfixFunctions.jl`)
# 2) Type in Julia:
# julia> include("InfixFunctions.jl")
# julia> using Main.InfixFunctions
@alekrutkowski
alekrutkowski / Copy-FileWithTimestampPrefix.ps1
Created May 22, 2023 08:49
Copy file with timestamp prefixed to its name before saving in the destination (Date and Time when File Created)
## Code generated by the free-access ChatGPT May 12 Version
## Usage example:
# Copy-FileWithTimestampPrefix -SourceFilePath "F:\PRIVATE\M4ROOT\CLIP\C0040.MP4" -DestinationFolderPath "B:\Videos"
## File copied to: B:\Videos\2023-05-17_15.43.50__C0043.MP4
function Copy-FileWithTimestampPrefix {
param (
[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType 'Leaf'})]
[string]$SourceFilePath,
@alekrutkowski
alekrutkowski / README.md
Last active June 7, 2023 16:07
A simple [shinylive](https://shiny.posit.co/py/docs/shinylive.html) 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 app.py 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:

@alekrutkowski
alekrutkowski / calculate_ram_usage.sh
Created June 17, 2023 19:51
A bash script to add RAM usage percent as a new item in the XFCE panel
#!/bin/bash
# Prerequisities
# 0) XFCE
# 1) Save this script in your home directory as: /home/your_user_name/calculate_ram_usage.sh
# 2) Add a new XFCE Generic Monitor Applet item (with the settings: no label, 1 second refresh period): /home/your_user_name/calculate_ram_usage.sh
output=$(free)
# Use grep with perl-regex (-P) to extract numbers and store them in an array
numbers=($(echo "$output" | grep -oP '\d+'))
@alekrutkowski
alekrutkowski / AttachLabelsToPointsAvoidingOverlap.vba
Last active December 4, 2024 15:16
Excel macro for adding labels to scatterplot points while avoiding their overlap if points are close
Sub AttachLabelsToPointsAvoidingOverlap()
' Based on:
' https://support.microsoft.com/en-gb/topic/how-to-use-a-macro-to-add-labels-to-data-points-in-an-xy-scatter-chart-or-in-a-bubble-chart-in-excel-0f7642a5-fc9f-375c-94f1-953fb55eae06
' 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.