Useful snippets

    Tech pronunciation

    Sun 26. November 2023 | 2023-11-26

    • Sql (S Q L / Sequel / Squeel )
    • xampp (Shamp)
    • Zsh (Zash)
    • C# (See sharp, see hash)
    • LaTeX (Lateck)
    • Vite (French word for "quick", pronounced /vit/, like "veet")
    • Deno ("Dino", ikke "Deno")
    • JWTs (JSON Web Token, pronounced 'jot')
    • Lua (pronounced LOO-ah)
    • RKT (pronounced like a "rocket")

    search for text appearance in a file's git history

    Sun 05. November 2023 | 2023-11-05

    Eg. Search for "use-query-params" in package.json's git history

    git grep use-query-params $(git rev-list --all -- package.json) -- package.json

    As a function in .bashrc/.zshrc-file

    # search for word in a file's git history
    # usage: filehistorysearch "use-query-params" package.json
    
    filehistorysearch() {
      git grep $1 $(git rev-list --all -- $2) -- $2
    }

    graphql fetch using multiple IDs

    Sun 05. November 2023 | 2023-11-05

    fetch all related products from a list of products, and get results merged into one response!

    const GET_RELATED_PRODUCTS = `
        query getRelatedProducts($url: [String!]) {
            products(filter: { url: { in: $url } }) {
                items {
    
                }
            }
        }
    `
    

    fetching just one product's related products

    const GET_RELATED_PRODUCTS = `
        query getRelatedProducts($url: String!) {
            products(filter: { url: { eq: $url } }) {
                items {
    
                }
            }
        }
    `
    

    SSH-keys

    Sun 29. October 2023 | 2023-10-29

    Generate an SSH key pair

    https://docs.gitlab.com/user/ssh/#generate-an-ssh-key-pair

    ssh-keygen -t ed25519 -C ""

    Add an SSH key to your GitLab account

    https://docs.gitlab.com/user/ssh/#add-an-ssh-key-to-your-gitlab-account

    linux

    xclip -sel clip < ~/.ssh/id_ed25519.pub
    

    verify that you can connect

    https://docs.gitlab.com/user/ssh/#verify-that-you-can-connect

    instance url for ssh

    ssh -T git@gitlab.com
    

    Hvordan opprette og bruke

    Github / Gitlab

    Create SSH-keys & upload to Gitlab

    Fint for å slippe å skrive inn brukernavn og passord hver eneste gang

    1. ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/paalss/.ssh/id_rsa):
    
    
    1. [Enter]
    ...
    Your public key has been saved in /home/paalss/.ssh/id_rsa.pub
    ...
    
    1. cat /home/paalss/.ssh/id_rsa.pub
    ssh-rsa <Hererenlanghashcode> paalss@Asus-VivoBook
    
    1. Gå til SSH-siden:
    1. Lim inn ssh-rsa <Hererenlanghashcode>

    Resten er rett frem

    https://docs.oracle.com/en/cloud/cloud-at-customer/occ-get-started/generate-ssh-key-pair.html

    Blir du spurt om username og password (PAT) ved git push?

    Da bruker du sannsynligvis HTTPS:

    Slik bytter du til SSH:

    git remote set-url origin git@github.com:paalss/<repo>.git

    Bitbucket

    https://peter-whyte.com/setup-ssh-keys-in-wsl/

    eval $(ssh-agent -s) && ssh-add ../pw_bitbucket

    Personal Access Token for http https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
    Kan brukes til authentication i stedet for passord

    https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519

    eller:

    ssh-add ~/.ssh/github_pw

    scroll behavior in different css-positions

    Sun 29. October 2023 | 2023-10-29

    Discovery:

    Set position: fixed|avsolute on parent element, and you can choose between instant and smooth scroll-behaviors (scroll-behavior: initial|smooth)

    But with position: sticky|relative|static you can't choose. You're stuck with smooth scrolling

    install multiple versions of same dependency

    Sun 29. October 2023 | 2023-10-29

    npm i bootstrap-toc@npm:bootstrap@5.1.3 --save-exact
    
    npm i bootstrap@5.2.3 --save-exact
    

    usage

    const bootstrap = require("bootstrap-toc/dist/js/bootstrap.bundle.min.js");
    new bootstrap.ScrollSpy(document.body, {
      target: "#scroll-nav",
      // give space for header
      offset: 100,
    });

    HTML/JSX forskjeller

    Sun 29. October 2023 | 2023-10-29

    • class -> className
    • for -> htmlFor
    • how to set default value for <select>
    • onchange -> onBlur
    • <br>, <img>, <hr> -> <hr/> (all elements must have closing tag / be self closing)
    • select default value

    JSX

    • Må ha ett root element
    • ekstra setup nødvendig i VS Code: syntaxhighlihgting og emmet support: Må legge til en javascriptreact ting i en innstillingsfil. Emmet virker stort sett.