Skip to content

Instantly share code, notes, and snippets.

Avatar
👾
totally not a horse in sunglasses

Mudit Ameta zeusdeux

👾
totally not a horse in sunglasses
View GitHub Profile
@zeusdeux
zeusdeux / workingHours.ts
Created Apr 7, 2020
Intense validations using yupjs
View workingHours.ts
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 Mar 16, 2020
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
View hasSequence.js
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)
View tatiana-mac-speaker-rider.md

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

View Reach Philosophy.md

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
@zeusdeux
zeusdeux / boop.js
Created Aug 30, 2019
How to cress?
View boop.js
import React from 'react'
import { Cress } from './path/to/Cress.js';
// looks like dead-code right?
new Cress('.my-selector', {
css() {
return `
this {
font-family: cursive;
}
@zeusdeux
zeusdeux / jwtRS256.sh
Created Aug 23, 2019 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
View jwtRS256.sh
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@zeusdeux
zeusdeux / .eslintrc.js
Created Jul 26, 2019
eslint override ordering example
View .eslintrc.js
module.exports = {
...
overrides: [
{
files: ['src/**/*.js'],
rules: {
'some-rule': 'error',
'some-other-rule': 'error'
}
},
@zeusdeux
zeusdeux / Either.ts
Last active May 23, 2020
Another Maybe and Either implementation in Typescript without making the value constructors (Just, Nothing, Left and Right) types themeselves as in the previous attempt
View Either.ts
// Either monad using discriminated unions
export type Either<L, R> =
| { type: "left"; value: L }
| { type: "right"; value: R };
export function Left<L, R>(a: L): Either<L, R> {
return {
type: "left",
value: a
};
@zeusdeux
zeusdeux / have_i_been_pwned.sh
Last active Aug 20, 2019
My goto script to check if any of my passwords have been compromised using HIBP's password API (https://haveibeenpwned.com/API/v2#PwnedPasswords). Your password never leaves your local system!
View have_i_been_pwned.sh
#!/usr/bin/env bash
# enable when debugging
# set -o errexit
# set -o errtrace
# set -o xtrace
# set -o nounset
# set -o pipefail
plsno () {
@zeusdeux
zeusdeux / sumTypesWithNever.ts
Created Jan 5, 2019
Sum types with never in typescript
View sumTypesWithNever.ts
// never is dropped from sum types
let x: string | never // string
let y: Exclude<'a' | 'b', 'b'> // y has the type 'a'
/*
* Explanation:
* Given that Exclude is defined as: type Exclude<T, U> = T extends U ? never : T
* Exclude<'a' | 'b', 'b'> checks if 'a' extends 'b'.
* It doesn't and hence 'a' is returned
* Type system then checks if 'b' extends 'b'.
You can’t perform that action at this time.