Category: Snippets

  • AWS managed AD – add user RDP permissions

    Note: This post is part of a series (Part 2):

    Situation: You have an AWS managed AD, some clients, and some AD users. Now the users should be able to log in to servers using RDP.

    Problem: Just by creating a user it does not have the appropriate permissions.

    Solution: Follow the AWS documentation or watch the AWS youtube video on the subject. This is basically it, with some screenshots and additional notes.

    Hint: It’s easiest if you perform thost actions as the DOMAIN\Admin user, so you don’t have to enter that user’s password all the time.

    • if you are paranoid check some local server configurations (it should already be correct though)
    • open AD user / group management
    • create a group
      • e.g. “AD Remote Desktop User” under Users/ in your domain
      • so if your domain is “domain.aws”, create it under “domain.aws/domain/Users/HERE”
    • add the user to the newly created group
    • open group policy editor
    • create new group under “computer configuration / preferences / control panel settings / local users and groups”
      • select Remote Desktop Users (built-in) FROM DROPDOWN!!!
      • add the previously created AD group as members
  • AWS managed AD – first steps after creation

    Note: This post is part of a series (Part 1):

    Situation: You have created a managed AD. Now you want to manage it.

    Problem: The servers probably don’t have the appropriate software installed.

    Solution:

    Hint: It’s easiest if you perform thost actions as the DOMAIN\Admin user, so you don’t have to enter that user’s password all the time.

  • Extract parts of a git repo as new one

    Situation: You have a repository with a subdirectory my/repo/part, which became large and own-project-worthy. You can copy the files into a new repo, but you’ll lose all git history.

    What would be just perfect is: From all commits ever made in this repository, …

    • only keep the parts of all commits which concern files under ./my/repo/part/**
    • remove the path prefix ./my/repo/part/.

    So, basically, rewrite and filter all git commits.

    There’s an app for that: git-filter-repo. And that’s how you use it:

    # clone the repository parallel to the existing one
    git clone git@github.com:me-and/my-repo fool-around-here
    cd fool-around-here
    
    # remove all other files except the ones you want
    # (yup, it's that easy)
    git-filter-repo --path my/repo/part
    
    # move all files to the repository root
    git-filter-repo --subdirectory-filter my/repo/part
    
    # set a new origin URL
    git remote set-url origin git@github.com:me-and/my-new-empty-prepared-repo
    
    # push.
    git push
    

    The git history has been rewritten 1984-style. For git it has always been exactly like this now.

  • jq snippets

    Delete any object which contains a "keyname": "keyvalue" pair anywhere in the JSON:

    cat x.json| jq 'del(..|select(objects and .keyname == "keyvalue"))'
    

    If keyname contains a dash (“-“), use one of those notations:

    cat x.json | jq 'del(..|select(objects and .["key-name"] == "keyvalue"))'
    cat x.json | jq 'del(..|select(objects and ."key-name" == "keyvalue"))'
    

    Delete all objects anywhere that contain a certain key:

    cat x.json | jq 'del(..|select(objects and .key?)'
    

    Delete a certain key from all objects everywhere:

    cat x.json | jq 'del(..|.response?)'
    

    Useful sources:

  • Lexoffice API notes

    Minimal invoice creation using the API.

    {
      "voucherDate": "2021-08-18T12:26:50.748Z",
      "address": {
        // if this is given the other fields become optional
        "contactId": "139bdad3-7786-43e2-acf0-8c3eaf0ee8c7"
      },
      "lineItems": [
        {
          "type": "service",
          "name": "Dienstleistungen",
          "description": "Beschreibung",
          "quantity": 5,
          "unitName": "Stunde",
          "unitPrice": {
            "currency": "EUR",
            "netAmount": 1,
            "taxRatePercentage": 19
          }
        }
      ],
      "totalPrice": {
        "currency": "EUR"
      },
      "taxConditions": {
        "taxType": "net"
      },
      "shippingConditions": {
        // the API documentation is wrong, the API only accepts: custom / none / text
        "shippingType": "none"
      },
      "title": "Rechnung",
      "introduction": "Ihre bestellten Positionen stellen wir Ihnen hiermit in Rechnung",
      "remark": "Vielen Dank für das entgegengebrachte Vertrauen"
    }
    
  • JavaScript ISO date with local timezone

    It seems JS has until today no native (!) solution to get an ISO 8601 date & time string in the local time zone (it’s always in UTC). (Super weird, but okay).

    I updated the solution on Stackoverflow a bit using “new” ES2017 functionality like this:

    function getISOLocalString() {
      let date = new Date();
      let tzo = -date.getTimezoneOffset();
    
      if (tzo === 0) {
        return date.toISOString();
      } else {
        let dif = tzo >= 0 ? "+" : "-";
        let pad = function (num, digits = 2) {
          return String(num).padStart(digits, "0");
        };
    
        return (
          date.getFullYear() +
          "-" +
          pad(date.getMonth() + 1) +
          "-" +
          pad(date.getDate()) +
          "T" +
          pad(date.getHours()) +
          ":" +
          pad(date.getMinutes()) +
          ":" +
          pad(date.getSeconds()) +
          dif +
          pad(tzo / 60) +
          ":" +
          pad(tzo % 60) +
          "." +
          pad(date.getMilliseconds(), 3)
        );
      }
    }
    
    console.log(getISOLocalString());
    
  • remark42 comments

    This is a test post. There should be a comment box below, powered by the pretty cool and really well documented remark42 commenting engine.

    Let’s see … 🙂

  • GOPATH and GOROOT

    go has some unique concepts, one of them is a system-wide (user-wide) central go directory where things “happen” (e.g. modules being downloaded, etc.). For example, if you perform hugo mod get you essentially perform go mod get, which then downloads required modules … into your $GOPATH. Or $GOROOT/something, I really don’t quite get it, and I don’t care unless it stops working. Which it did.

    You often read “Just look into $GOPATH and see if it’s there”. Unfortunately I never set the value so there is no environment variable. The default of $HOME/go does not exist on my mac. Now what?

    Thanks to 0x434d53 I now know to do this, which prints the values used by go:

    go env
    
  • Completely delete teams on a Mac

    If teams is acting up sometimes (read: almost always) the only way to stop it is by deleting it completely. Microsoft has an answer on Microsoft answers on how to do it, I put it into a script. Here it is.

    This might not be absolutely everything though, cause it still remembered my account which I used last time.

    #!/usr/bin/env bash
    
    # source: microsoft
    # https://answers.microsoft.com/en-us/msteams/forum/all/how-to-completely-remove-teams-from-mac/2499239d-d491-43cb-a9c1-acbee7223b8d
    
    
    # $1 - full path to file / dir to delete
    delete_teams_file() {
        DELETE_ME=$1
        if [[ -d $1 ]] ; then
            echo -n "DELETE      $DELETE_ME ... "
            rm -rf "$DELETE_ME"
            echo "done."
        else
            echo "Not found - $DELETE_ME"
        fi
    }
    
    set -euo pipefail
    
    # prepare sudo entry
    echo "Prepare sudo ..."
    sudo echo "sudo prep successful :)"
    
    DELETE_BASE="$HOME/Library/Caches/com.microsoft."
    for DELETE_DIR in teams teams.shipit ; do
        delete_teams_file "${DELETE_BASE}${DELETE_DIR}"
    done
    
    DELETE_BASE="$HOME/Library/Application Support/Microsoft/Teams"
    delete_teams_file "$DELETE_BASE"
    
    sudo rm -rf "/Applications/Microsoft Teams.app"
    
    echo "All done."
    
  • Auto-rebuild Docker images if base image changes using GitHub actions

    Let’s say you have a rather static docker image which is based on another image which changes frequently. Now your image should be rebuilt on two occasions: if your content changes, but also if the image yours is based on changed. This can be done relatively simple using a GitHub actions cron schedule. You just have to create an actions workflow file in your repository.

    Adjust to your needs accordingly, and probably one can optimize even more by templating this.

    # FILE LOCATION IN REPOSITORY:
    #
    #   .github/workflows/auto-build-on-base-image-change.yml
    #
    
    name: Regular base image update check
    on:
      schedule:
        - cron: "23 13 3 * *"
      workflow_dispatch:
    
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
          - uses: actions/checkout@v2
    
          - name: Docker Image Update Checker
            id: baseupdatecheck
            uses: lucacome/docker-image-update-checker@v1.1.0
            with:
              base-image: library/golang:alpine
              image: flypenguin/homepage-builder # update for your image
    
          # only execute subsequent steps if an update is actually NEEDED.
          # unfortunately we need to add an if-condition to all steps now
          # because a clean exit can't be triggered within a job it seems
          # (a cancellation is NOT the same and triggers a failure email)
          # see also https://github.com/actions/runner/issues/662
    
          - name: Login to DockerHub
            uses: docker/login-action@v1
            with:
              username: ${{ secrets.DOCKERHUB_USERNAME }}
              password: ${{ secrets.DOCKERHUB_TOKEN }}
            if: steps.baseupdatecheck.outputs.needs-updating == 'true'
    
          - name: Build and push Docker images
            uses: docker/build-push-action@v2.6.1
            with:
              context: "${{ github.workspace }}"
              push: true
              tags: flypenguin/homepage-builder:latest # update for your image
            if: steps.baseupdatecheck.outputs.needs-updating == 'true'
    

    This particular image is a builder image for Hugo sites. Hugo switched from git submodule based theme management to a Go module based theme & plugin management. So the my builder image needs Go installed now. The easiest way to do this is to base this image on the official golang image. Since installing Go on every build adds time and network traffic this seemd “uncool”, so auto-updating the base image it was.

    Sources:

    • https://git.io/JZns3
    • https://git.io/JB2AX
    • https://git.io/JB2x0