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 / boop.js
Created August 30, 2019 12:12
How to cress?
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 August 23, 2019 14:25 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
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 July 26, 2019 14:04
eslint override ordering example
module.exports = {
...
overrides: [
{
files: ['src/**/*.js'],
rules: {
'some-rule': 'error',
'some-other-rule': 'error'
}
},
@zeusdeux
zeusdeux / Either.ts
Last active February 19, 2024 19:20
Another Maybe and Either implementation in Typescript without making the value constructors (Just, Nothing, Left and Right) types themeselves as in the previous attempt
// 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 June 7, 2023 08:08
Check if any passwords have been compromised using HIBP's password API (https://haveibeenpwned.com/API/v2#PwnedPasswords). Your password never leaves your local system!
#!/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 January 5, 2019 17:39
Sum types with never in typescript
// 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'.
@zeusdeux
zeusdeux / transaction.js
Created November 20, 2018 10:14
Simple transaction in js
/**
* @description
* Returns a transaction object which is composed of operations.
* The transaction resolves only when all operations it is made of succeed.
* If any operation fails, it reverts ALL operations and rejects the transaction.
* If any of the reverts also fail, then it rejects the transaction as well
* with an error that can help the developer manually make data consistent.
*
* @param {function} transaction - A function that builds operations and calls run on them
*
@zeusdeux
zeusdeux / Either.ts
Created September 4, 2018 08:54
Either monad in typescript
export type Either<L,R> = Left<L> | Right<R>
export class Left<L> {
constructor(private readonly value: L) {}
public getValue() {
return this.value
}
}
export class Right<R> {
@zeusdeux
zeusdeux / variadic.hs
Created May 17, 2018 13:02
Variadic function type in haskell
class Foo t where
returnLast :: Int -> t
class Integral i => IntsBro i where
toInt :: i -> Int
instance IntsBro Integer where
-- toInt :: Integer -> Int
toInt i = fromIntegral i :: Int
@zeusdeux
zeusdeux / intersectionObserver.js
Created May 13, 2018 19:52
IntersectionObserver weirdness
// navigate to https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Intersection_observer_concepts_and_usage
// open console and run the code below
const target = document.getElementById('How_intersection_is_calculated')
const observer = new IntersectionObserver(entries => console.log(entries[0], entries[0].isIntersecting), {root: null, threshold: 0.9})
observer.observe(target)