Skip to content

Instantly share code, notes, and snippets.

View nilscox's full-sized avatar

nilscox nilscox

View GitHub Profile
@nilscox
nilscox / wofi-bitwarden.sh
Created April 18, 2024 14:23
Wofi script to copy passwords from bitwarden (requires bitwarden-cli, wl-clipboard and jq)
#!/usr/bin/env bash
session=$(systemctl --user show-environment | grep '^BW_SESSION=' | sed 's/^BW_SESSION=//')
if [ -n "$session" ]; then
items=$(bw --session "$session" list items)
[ "$?" -ne 0 ] && unset session
fi
if [ -z "$session" ]; then
/* cspell:disable */
export {};
declare module 'solid-js' {
namespace JSX {
interface MjmlMjmlAttributes {
/** if set to "desktop", switch force desktop version for older (self-hosted) version of Outlook.com that doesn't support media queries (cf. this issue) (default = none) */
owa?: string /* string */;
/** used as <html lang=""> attribute (default = und) */
import { JSX } from 'solid-js';
function assert(condition: unknown, message: string): asserts condition {
if (!condition) {
throw new Error(message);
}
}
type Values = Record<string, JSX.Element | ((children: JSX.Element) => JSX.Element)>;
@nilscox
nilscox / async-thunk-lifecycle.ts
Created January 4, 2024 16:21
Redux slice to track the lifecycles of redux toolkit's async thunks
import {
SerializedError,
createSelector,
createSlice,
isAsyncThunkAction,
isFulfilled,
isPending,
isRejected,
} from '@reduxjs/toolkit';
@nilscox
nilscox / use-set.tsx
Created August 31, 2023 08:46
React hook to manipulate a JavaScript Set
import { useReducer, useMemo } from 'react'
type UseSetReturn<T> = [
Set<T>,
{
add: (value: T) => void
delete: (value: T) => void
toggle: (value: T) => void
clear: () => void
}
@nilscox
nilscox / map-set.spec.ts
Created July 29, 2023 11:47
Map of sets
import { MapSet } from './map-set';
describe('MapSet', () => {
it('creates an empty map of sets', () => {
const map = new MapSet<string, number>();
expect(map.get('a')).toBeUndefined();
});
it('adds values to a map of sets', () => {
@nilscox
nilscox / use-list.spec.tsx
Created May 11, 2023 09:39
React hook to handle a list of items
import { act, renderHook } from '@testing-library/react'
import { useList } from './use-list'
describe('useList', () => {
it('creates an empty list', () => {
const { result } = renderHook(() => useList())
expect(result.current[0]).toEqual([])
})
@nilscox
nilscox / emitter.spec.ts
Last active May 3, 2023 14:49
Event emitter
import { Mock } from 'vitest';
import { Emitter } from './emitter';
enum TestEvent {
move = 'move',
jump = 'jump',
}
type TestEventsMap = {
@nilscox
nilscox / storage.spec.ts
Created April 11, 2023 09:07
Browser storage abstraction
import { Storage, StorageApi, storedString, storedValue } from './storage'
class MockStorageApi implements StorageApi {
public items = new Map<string, string>()
getItem(key: string): string | null {
return this.items.get(key) ?? null
}
setItem(key: string, value: string): void {
@nilscox
nilscox / use-wait-for.spec.ts
Created January 25, 2023 13:12
React hook to wait for some check to be true
import { act, renderHook } from '@testing-library/react'
import { useWaitFor } from './use-wait-for'
describe('useWaitFor', () => {
beforeEach(() => {
jest.useFakeTimers()
})
it('calls then when the condition is true', () => {