Skip to content

Instantly share code, notes, and snippets.

View mykeels's full-sized avatar
😄
faffing!

Michael Ikechi mykeels

😄
faffing!
View GitHub Profile
@mykeels
mykeels / repository.interface.ts
Created August 5, 2023 21:05
Generic repository interface, that just might work across DBs
type Prettify<T> = {
[K in keyof T]: T[K];
};
export type Model<T> = Prettify<
T & {
_id: string;
createdAt: Date | string;
updatedAt: Date | string;
deletedAt?: Date | string | null;
@mykeels
mykeels / snake-camel.d.ts
Created May 30, 2023 23:25
Typings for the snake-camel npm package https://www.npmjs.com/package/snake-camel
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}`
? `${T extends Capitalize<T> ? '_' : ''}${Lowercase<T>}${CamelToSnakeCase<U>}`
: S
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}`
? `${T}${Capitalize<SnakeToCamelCase<U>>}`
: S
type StringKeys<TEntity extends {}> = {
[key in keyof TEntity]: key extends string ? key : never
}[keyof TEntity]
type IsLiteral<TValue> = TValue extends string | number | boolean | symbol
@mykeels
mykeels / USE_FETCH_USERS_HOOK.md
Last active April 14, 2022 14:39
A simple hook, showing dependency inversion

Here, we'll explore loosely coupling react hooks with dependency inversion as a way to manage side effects.

NB: The hooks code given here, uses react-query hooks for simplicity cos I'm rushing to write this. I hope that's not a problem. Perhaps, someone will write the equivalent implementations using out-of-the-box react hooks.

We'll consider a simple react hook, that fetches a list of users in two ways:

1. No dependency inversion

const useFetchUsers = () =&gt; {
/**
* @typedef {object} AWSCloudfrontMessageEvent
* @property {AWSCloudfrontEventRecord[]} Records
*/
/**
* @typedef {object} AWSCloudfrontEventRecord
* @property {object} cf
* @property {{ distributionId: string, eventType: string, requestId: string, distributionDomainName: string }} cf.config
* @property {AWSCloudfrontRequest} cf.request
@mykeels
mykeels / inline-email-templates.script.ts
Created April 21, 2021 23:48
A script to inline styles on *.hbs files in a directory
import { promises as fs } from 'fs';
import path from 'path';
import inlineCss from 'inline-css';
import env from '../common/config/env';
/**
* So there are multiple *.hbs files, in a directory, and one of them, contains a link reference to tailwind cdn like:
* <link rel="stylesheet" href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css">
* In this script, we inline all their styles by
* - reading each file's content
- name: President Muhammadu Buhari
ministry: Minister of Petroleum
email: [email protected]
phone: "0952335368"
- name: Mohammed Musa Bello
ministry: Minister of Federal Capital Territory, FCT
email: ""
phone: ""
@mykeels
mykeels / deploy-storybook.js
Created July 27, 2020 17:50
Script to deploy to and maintain 50 past versions of storybook in an S3 Bucket
#!/usr/bin/env node
const AWS = require("aws-sdk");
const path = require("path");
const fs = require("fs");
const mime = require("mime-types");
const { version } = require("../package.json");
const quit = message => {
console.error(message);
@mykeels
mykeels / touchpad.ps1
Created June 18, 2020 09:12
Powershell script to Disable and Re-enable the "HID-compliant Touch pad" in Windows 10
function global:touchpad()
{
Disable-PnpDevice -InstanceId "HID\SYNA2393&COL02\5&10464366&0&0001" -Confirm:$false
Enable-PnpDevice -InstanceId "HID\SYNA2393&COL02\5&10464366&0&0001" -Confirm:$false
}
@mykeels
mykeels / gh-pages-deploy.ps1
Created June 7, 2020 01:39
Will deploy to gh-pages branch from master
git branch -f gh-pages
git checkout gh-pages
git reset --hard origin/master
yarn build
cp -r build/* .
@mykeels
mykeels / Mp4ToGif.ps1
Created June 3, 2020 10:24
A powershell script for converting mp4 files to gif, using ffmpeg
function global:Mp4ToGif()
{
$input=$args[0]
Write-Output "Input: $input"
ffmpeg -i "$input" -vf "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
}