Skip to content

Instantly share code, notes, and snippets.

@lgk-bsw
lgk-bsw / read-file.js
Last active July 26, 2024 07:16
Read files with "UTF-8" and "UTF-8 with BOM" using Node.js fs
const fs = require("fs")
const path = require("path")
const filePath = path.resolve(__dirname, "index.md")
/**
* By default, Visual Studio saves files with a BOM (Byte Order Mark) which can be a problem when reading files in Node.js.
* The replace function below removes the BOM from the file.
*/
function readFileSync(filePath) {
@lgk-bsw
lgk-bsw / dropdown.css
Last active March 25, 2024 10:58
Click outside of dropdown menu to close it, CSS only
.dropdown-content {
visibility: hidden;
opacity: 0;
}
.dropdown.dropdown-open .dropdown-content,
.dropdown:not(.dropdown-hover):focus .dropdown-content,
.dropdown:focus-within .dropdown-content {
visibility: visible;
opacity: 1;
@lgk-bsw
lgk-bsw / .prettierrc
Last active January 9, 2024 13:34
Prettier Config for SvelteKit projekts
{
"useTabs": true,
"singleQuote": false,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }],
"tabWidth": 4,
"semi": false
}
@lgk-bsw
lgk-bsw / gist:ee32fad9535b60ad0f0fb2bcd53411e1
Created August 14, 2023 10:29
Bootstrap Grid System Elements Queries
@import "~bootstrap/scss/mixins";
/**
CSS Elements Queries (https://github.com/marcj/css-element-queries) support for Bootstrap's Grid System.
Just add the class name ".element-query" to the parent element.
*/
@mixin make-grid-columns-eq(
$columns: $grid-columns,
$gutter: $grid-gutter-width,
@lgk-bsw
lgk-bsw / bootstrap-icons-svg-1em.js
Last active March 16, 2023 08:16
The SVG code examples on the Bootstrap Icons docs use 16px for width and height. This script allows to use 1em instead.
// Use this together with this browser extension (Chrome/Edge) and enable it for https://icons.getbootstrap.com:
// https://chrome.google.com/webstore/detail/custom-javascript-for-web/ddbjnfjiigjmcpcpkmhogomapikjbjdk
/**
* This code adds a switch checkbox on the Bootstrap Icons pages.
* For example on: https://icons.getbootstrap.com/icons/x-lg/
* If enabled, the SVG code will be changed to use `1em` for width and height instead of `16`(px).
*/
if (location.pathname.startsWith("/icons/")) {
// Use this together with this browser extension (Chrome/Edge) and enable it for GitHub:
// https://chrome.google.com/webstore/detail/custom-javascript-for-web/ddbjnfjiigjmcpcpkmhogomapikjbjdk
// The following code checks if your branch you want to merge, contains "lts-"
// and offers to set the correct base branch.
if (location.pathname.includes("/bruegmann/florence/compare/")) {
let params = location.pathname.split("/")
let compareBranchs = params[params.length - 1].split("...")
@lgk-bsw
lgk-bsw / delete-closed-branches.js
Created July 5, 2021 12:08
Run this on the branches page of a GitHub repo to delete all merged or closed branches
const rows = document.querySelectorAll("div[data-target='branch-filter.result'] .Box-row")
for (const r of rows) {
const stateEl = r.querySelector(".State")
if (stateEl && (stateEl.title.includes("Merged") || stateEl.title.includes("Closed"))) {
r.querySelector(`button[data-target="branch-filter-item.destroyButton"]`).click()
}
//confirm("Continue?")
}
@lgk-bsw
lgk-bsw / get-cherry-pick-commands.js
Last active July 5, 2021 08:12
Run this on the commits tab in a PR to get a list of cherry-pick commands
let queries = []
const rows = document.querySelectorAll(".TimelineItem-body .Box-row")
for (const r of rows) {
const label = r.querySelector(".Details .Link--primary")
const link = r.querySelector("a.BtnGroup-item")
const splitted = link.href.split("/")
queries.push(`${label.innerText}<br><code>git cherry-pick ${splitted[splitted.length - 1]}</code>`)
}
@lgk-bsw
lgk-bsw / js-object-to-query-string.js
Last active September 7, 2020 09:42
A handy way to convert a JS object to a query string you can pass to an API
const params = {type: "G6.USID", key: "AllgFilter", listPkey: "~ 000G6.USID"};
const query = Object.keys(params)
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
.join("&")
// Will become: type=G6.USID&key=AllgFilter&listPkey=~%20%20%20000G6.USID
// Usage
@lgk-bsw
lgk-bsw / trac-link-to-svn-file.txt
Last active September 3, 2020 07:10
Trac Verlinkung auf Datei im SVN