Skip to content

Instantly share code, notes, and snippets.

View alekrutkowski's full-sized avatar

alek alekrutkowski

View GitHub Profile
@alekrutkowski
alekrutkowski / _README.md
Last active November 7, 2025 10:50
Chrome/Edge addon/extension to translate the current web page to a pre-set language when the addon's icon is clicked
@alekrutkowski
alekrutkowski / app.R
Created November 6, 2025 15:05
R/Shiny app similar to Google Translate whole page translation (when you paste a URL)
#### Prerequisites -- in Linux terminal:
# Once:
# pipx install libretranslate
# Run in the background:
# libretranslate
#### Test:
# Open the following page in a web browser
# (but first modify your.shiny-server.domain and your_translate_app_name):
# https://your.shiny-server.domain/your_translate_app_name/?url=https://example.com/&from=en&to=fr
@alekrutkowski
alekrutkowski / app.R
Created November 3, 2025 09:38
R/Shiny app as a simple GET request handler
# Save it as /srv/shiny-server/your_app_name/app.R
library(shiny)
ui <- function(request) {
query <- parseQueryString(request$QUERY_STRING)
txt <- query$txt
a <- as.numeric(query$a)
b <- as.numeric(query$b)
@alekrutkowski
alekrutkowski / app.R
Last active October 31, 2025 13:39
R/Shiny app which (re)publishes an RSS feed
# Shiny app that serves a transformed RSS feed immediately at "/".
# It fetches the source RSS on every request, appends a single space to the end
# of each line, and returns it with the correct RSS content type so feed readers
# can subscribe directly.
# This particular app fixes the annoying problem in Inoreader, which concatenates
# the words in the descriptions of new R packages.
library(shiny)
@alekrutkowski
alekrutkowski / index.md.txt
Last active October 20, 2025 14:55
Observablehq's "Observable Framework" markdown file example with Web-R (https://docs.r-wasm.org/webr), Grid.js table (https://gridjs.io), and a global spinner
---
toc: false
theme: [dashboard]
footer: ""
---
<link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet" />
<script src="https://unpkg.com/gridjs/dist/gridjs.umd.js"></script>
@alekrutkowski
alekrutkowski / index.md.txt
Last active October 5, 2025 05:00
Observablehq's "Observable Framework" markdown file example with a nice input output layout (1:3), Excel file upload, processing, and download
---
toc: false
theme: [dashboard]
footer: ""
---
# My Dashboard
```js
// Message displayed before the first Excel file upload
@alekrutkowski
alekrutkowski / double_range_slider.md.txt
Last active October 1, 2025 15:08
Double range slider (2 values, e.g. min and max) for Observablehq's "Observable Framework" markdown
---
toc: false
---
```js
function DoubleRange({
min = 0,
max = 100,
step = 1,
value = [min, max],
@alekrutkowski
alekrutkowski / using_selectize_in_observable_framework.md.txt
Last active October 1, 2025 15:02
Using selectize-like input in Observablehq's "Observable Framework" markdown
<!-- https://tom-select.js.org/#:~:text=Additional%20CLI%20usage-,jsDelivr,-The%20fastest%20way -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/tom-select.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/tom-select.complete.min.js"></script> <!-- Leave space below! -->
<!-- https://tom-select.js.org/examples/#:~:text=%3C-,select%20multiple,-%3E -->
```js
const mystates =
view(html`<select id="select-state" name="state[]" multiple placeholder="Select a state..." autocomplete="on">
<option value="">Select a state...</option>
<option value="AL">Alabama</option>
@alekrutkowski
alekrutkowski / fetchCSVtoObjects.js
Last active September 23, 2025 08:17
JavaScript function to fetch a CSV and put its rows into an array of objects, e.g. fetching data from Eurostat. Useful for feeding data into e.g. "Observable Framework" plots.
async function fetchCSVtoObjects(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch CSV: ${response.status} ${response.statusText}`);
}
const text = await response.text();
const lines = text.trim().split(/\r?\n/);
if (lines.length < 2) {
@alekrutkowski
alekrutkowski / installMissingPackages.R
Created September 15, 2025 16:12
Re-install missing R packages when you migrate from one R version to another (e.g. from 4.3 to 4.5)
### Usage example:
# installMissingPackages(4.3, 4.5)
library(magrittr)
getPackages <- function(version) {
stopifnot(is.numeric(version),
length(version)==1,
version==round(version,1))