Skip to content

Instantly share code, notes, and snippets.

View BollaBerg's full-sized avatar

Andreas Bjelland Berg BollaBerg

  • Norway
View GitHub Profile
@BollaBerg
BollaBerg / dragElementTo.ts
Created May 7, 2024 13:40
React testing-library method for testing drag-and-drop functionality
import { fireEvent } from '@testing-library/react';
function dragElementTo(element: HTMLElement, target: HTMLElement) {
fireEvent.dragStart(element);
fireEvent.dragEnter(target);
fireEvent.dragOver(target, { clientX: 1, clientY: 1 });
fireEvent.dragEnd(element, { dataTransfer: { dropEffect: 'copy' } });
}
@BollaBerg
BollaBerg / tap.kt
Created March 20, 2024 11:48
A method for tapping into a Kotlin stream. Gotten from https://gist.github.com/g0t4/01a49114553c9fe0d0d8
fun <T: Any, R> T.tap(tap: (T) -> R): T {
tap(this)
return this
}
@BollaBerg
BollaBerg / useSearchParams.ts
Created March 18, 2024 09:13
A React-hook for using search params, when not using React Router
import { useCallback, useEffect, useState } from 'react';
const SEARCH_PARAMS_EVENT_KEY = 'SEARCH-PARAMS-UPDATED';
interface UseSearchParams {
searchParams: URLSearchParams;
setSearchParam: (key: string, value: string) => void;
removeSearchParam: (key: string) => void;
}
@BollaBerg
BollaBerg / mockSearchParams.ts
Created March 18, 2024 09:06
Mock and read search parameters (for testing React)
export const mockSearchParams = (params: Record<string, string>) => {
const baseURL = window.location.href.split(/[?#]/)[0];
const formattedParams = Object.entries(params)
.map(([key, value]) => `${key}=${value}`)
.join('&');
window.history.replaceState(null, '', formattedParams ? `${baseURL}?${formattedParams}` : baseURL);
};
export const getSearchParam = (key: string) => new URLSearchParams(window.location.search).get(key);
@BollaBerg
BollaBerg / nmcli-connect-eduroam.sh
Last active August 25, 2025 13:43
Configure Eduroam for NMCLI
# Heavily inspired by https://haluk.github.io/posts-output/2020-10-19-linux/
# Replace <IFNAME> with wifi device name
# Replace <IDENTITY> with student identity (i.e. <USERNAME>@ntnu.no)
# Replace <PASSWORD> with user password
nmcli con add \
type wifi \
ifname <IFNAME> \
con-name eduroam \
ssid eduroam \