Skip to content

Instantly share code, notes, and snippets.

View zeusdeux's full-sized avatar
👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em

Mudit zeusdeux

👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em
View GitHub Profile
@zeusdeux
zeusdeux / click-outside.ts
Last active May 26, 2023 15:07
Non-💩 and dirt simple click-outside directive for Vue 3
import type { Directive } from "vue";
type ClickOutsideHandler = ($event: MouseEvent | TouchEvent) => void;
type ClickOutsideHandlerMap = Map<HTMLElement, ClickOutsideHandler> & {
initialized?: boolean;
};
const clickOutsideHandlersSymbol: symbol = Symbol.for("v-click-outside-handlers");
// @ts-ignore
@zeusdeux
zeusdeux / fail-on-select-console-calls.ts
Last active May 24, 2023 17:05
Cleaner console for jest test runs + fail on certain console messages
/**
* Fail jest test run if certain messages are logged to console (e.g., `[vuex warn] unknown getter: ....`)
* Conditionally (on CI or not) add this file and the file below to `setupFilesAfterEnv` in jest config.
*
* Example config:
*
* import type { Config } from "@jest/types"
*
* const config: Config.InitialOptions = {
* ...
@zeusdeux
zeusdeux / timed.ts
Created April 21, 2023 20:15
A function that runs async functions and prints how long they take to stderr with a given string as the prefix message
export async function timed<T>(
cb: () => Promise<T>,
message: string,
debug = (...args: any[]) => console.warn(...args),
): ReturnType<typeof cb> {
const start = performance.now();
const result = await cb();
const end = performance.now();
let timeSpent = end - start;
@zeusdeux
zeusdeux / filter-utility.ts
Last active October 17, 2022 15:23
Filtering keys from an object type based on type of value for the keys
type MixedObject = {
someFn(x: number): string
someProp: symbol
}
// using key remapping that was added in TS 4.1 wherein
// if we return `never` as a value for key in the remapping logic
// the key is dropped from the resulting type
// More: https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#key-remapping-via-as
type Filter<InputType, AllowedValueTypes> = {
@zeusdeux
zeusdeux / doSet.js
Last active May 29, 2022 22:43
Persistent set operation
function assert(cond, msg) {
if (!cond) throw new Error(msg)
}
function doSet(source, pathToSet, newValue) {
assert(Array.isArray(pathToSet), 'path being set needs to be given as an array of prop names in order of access')
const prop = pathToSet.shift()
if (typeof prop === 'undefined') {
@zeusdeux
zeusdeux / recursiveProxy.js
Created May 29, 2022 00:09
Build a recursive proxy for any provided object
function createProxyHandler() {
const handler = {
get(target, prop, receiver) {
console.log('get>', target, prop, receiver)
if (prop === '_isProxy') {
return true
}
const value = Reflect.get(target, prop, receiver)
@zeusdeux
zeusdeux / workingHours.ts
Created April 7, 2020 14:32
Intense validations using yupjs
const workingHoursSchema = yup
.object()
.shape(
{
startHour: yup.number().when(["startMinute", "endHour", "endMinute"], {
is: (...args: string[]) => args.reduce((acc, v) => !!v || acc, false as boolean), // really typescript :|
then: yup
.number()
.integer()
.min(0)
@zeusdeux
zeusdeux / hasSequence.js
Created March 16, 2020 18:29
Find if a sequence represented by an array of items in some order is in a dataset that is presented as an array as well
function assertArray(v) {
if (!Array.isArray(v)) {
throw new TypeError(`Expected ${v} to be an array`)
}
return true
}
function hasSequence(data, seq) {
assertArray(data)
assertArray(seq)
@zeusdeux
zeusdeux / tatiana-mac-speaker-rider.md
Created October 29, 2019 15:57 — forked from tatianamac/tatiana-mac-speaker-rider.md
Tatiana Mac's Speaker Rider

Speaker Rider

by Tatiana Mac

Before I'll agree to a speaking event, I try to do as much research I can around the event to ensure it aligns with my ethos. I want to share this in case it's helpful to any other speakers.

👐 Speaking comes with immense privilege. I am grateful to all the conference organisers who have brilliantly hosted me. I would love to continue to exercise this privilege to speak at conferences, and use this privilege to make the landscape more accessible and beneficial to tech's most marginalised and suppressed communities.

😫 I wish I didn't have to, but this is long because I provide a lot of explanations for those of you who never had to consider these things. And I will be honest, most thoughtful conferences I've attended check most of these boxes intrinsically, particularly when conference runners are experienced speakers. They get it.

1️⃣ All of these are based on my own ethos. I don't wish to or attempt to speak on behalf of all conference speake

Reach UI Philosophy

Reach UI is an accessible foundation for React applications and design systems.

The three equally important goals are to be:

  • Accessible
  • Composable
  • Stylable