Skip to content

Instantly share code, notes, and snippets.

View ThePlenkov's full-sized avatar

Petr Plenkov ThePlenkov

View GitHub Profile
@ThePlenkov
ThePlenkov / mount_vhdx_to_wsl.md
Last active November 21, 2024 11:11
Organize your workspace by mounting external VHDX drive to WSL

Why?

I am a permanent Windows user and I do not choose Mac on purpose, because of some specfic vendor software I'm used to work with all my career.

At same time I'm a software engineer and I'm used to manage all my projects in Linux only. Luckily Windows delivers WSL, and especially with WSL2 life became much simpler.

When you work with large amount of projects ususally you organize kind of workspace, a folder containing all the projects. At least I do like this.

However next question is - where do we create such a workspace. Initally i tried to work in a workspace stored on windows drive C: opened via /mnt/c folder in wsl. It didn't took me much time to realise this is a bad idea. Ther reason for this is that Windows using NTFS volume format and Linux doesn't work well with it. At same time Linux works just perfectly with ext4 format.

@ThePlenkov
ThePlenkov / pre-commit
Created November 13, 2024 14:15
NX autoformatting on commit
# .husky/pre-commit
nx format:write --uncommitted
git update-index --again
@ThePlenkov
ThePlenkov / boot.sh
Last active November 19, 2024 14:59
Resolve WSL DNS automatically
#!/bin/bash
# Remove existing "nameserver" lines from /etc/resolv.conf
sed -i '/nameserver/d' /etc/resolv.conf
# Run the PowerShell command to generate "nameserver" lines and append to /etc/resolv.conf
# we use full path here to support boot command with root user
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '(Get-DnsClientServerAddress -AddressFamily IPv4).ServerAddresses | ForEach-Object { "nameserver $_" }' | tr -d '\r'| tee -a /etc/resolv.conf > /dev/null
@ThePlenkov
ThePlenkov / markdownToConfluenceServer.ts
Last active June 13, 2023 00:11
Convert markdown to Confluence XHTML
import {MarkdownTransformer} from "@atlaskit/editor-markdown-transformer";
import {defaultSchema} from "@atlaskit/adf-schema/schema-default";
import {ConfluenceTransformer} from "@atlaskit/editor-confluence-transformer";
import {JSDOM} from "jsdom";
test("Create a new page", async () => {
const md = new MarkdownTransformer(defaultSchema);
const ct = new ConfluenceTransformer(defaultSchema);
@ThePlenkov
ThePlenkov / convert.ts
Created May 27, 2021 17:30
Convert generated with hana-cli CDS to another one with renamed fields ( like all to snake|camel|kebab case )
import cds from "@sap/cds";
import {struct} from "@sap/cds/apis/csn";
import fs from "fs/promises";
import {toSnakeCase} from "js-convert-case";
import {Command} from "commander";
const program = new Command();
interface Options {
schema: string;
@ThePlenkov
ThePlenkov / get-npm-package-version
Last active April 10, 2021 00:29 — forked from DarrenN/get-npm-package-version
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g'
| awk '{$1=$1};1'
)
echo $PACKAGE_VERSION