Skip to content

Instantly share code, notes, and snippets.

@cheshirecode
cheshirecode / lighthouserc.js
Created August 6, 2022 08:24
use lighthouse ci to generate report manually
// current timeout issue https://github.com/GoogleChrome/lighthouse-ci/issues/475
module.exports = {
ci: {
collect: {
numberOfRuns: 1,
isSinglePageApplication: true,
settings: {
chromeFlags:
'--no-sandbox --disable-gpu --disable-dev-shm-usage --ignore-certificate-errors',
disableStorageReset: true,
@cheshirecode
cheshirecode / timeout.js
Created July 26, 2022 10:47
js timeout that invokes callback after delay
async function timeout(cb = () => {}, ms = 1000) {
await new Promise((resolve, reject) => {
let wait = setTimeout(() => {
cb()
clearTimeout(wait);
}, ms);
});
}
@cheshirecode
cheshirecode / extensions.list
Last active May 11, 2022 02:04
VS code setup
alefragnani.project-manager-12.5.0
arturock.gitstash-5.1.0
bradlc.vscode-tailwindcss-0.8.2
christian-kohler.path-intellisense-2.8.0
clemenspeters.format-json-1.0.2
codezombiech.gitignore-0.7.0
cssho.vscode-svgviewer-2.0.0
csstools.postcss-1.0.9
dbaeumer.vscode-eslint-2.2.2
dotjoshjohnson.xml-2.5.1
@cheshirecode
cheshirecode / utils.sh
Last active May 27, 2022 03:22
find and return only sub-directory names
#!/usr/bin/env sh
# find and return only sub-directory names
find . -maxdepth 1 -type d -not -path '.' -printf "%f\n"
# fast deletion 11
mkdir empty_dir
rsync -a --delete empty_dir/ yourdirectory/
# fast deletion -2
@cheshirecode
cheshirecode / help.md
Created January 25, 2022 07:24
add file to iOS simulator
@cheshirecode
cheshirecode / typings.ts
Created January 19, 2022 09:09
Typescript generic filtering of object keys by prefix/return
// FilterPrefixedKeys<{ a1, b1 }, 'a'> == { a }
export type FilterPrefixedKeys<T, S extends string> = T extends `${S}${infer _X}` ? T : never
// https://stackoverflow.com/questions/69038001/remove-string-from-template-literal-types-in-typescript
// GetPostPrefixSubstring<{ a1, b}, 'a'> == { 1 }
export type GetPostPrefixSubstring<T, S extends string> = T extends `${S}${infer X}` ? X : never
@cheshirecode
cheshirecode / git-helpers.sh
Last active May 24, 2022 11:44
git helper scripts
#!/usr/bin/env sh
# get dangling commits
git fsck --no-reflog \
| awk '/dangling commit/ {print $3}' \
| xargs -L 1 git --no-pager show -s --format="%ci %H" \
| sort
# https://coderwall.com/p/euwpig/a-better-git-log
# commits by author
import React from 'react';
import { IntlProvider, intlShape, injectIntl } from 'react-intl';
import { mount, shallow } from 'enzyme';
// You can pass your messages to the IntlProvider. Optional: remove if unneeded.
const messages = { foo: 'bar'} // en.json
const intlProps = { locale: 'en', messages };
const Child = () => null;
const IntlChild = injectIntl(Child);
@cheshirecode
cheshirecode / injectScript.js
Last active May 24, 2022 11:47
2 ways to dynamically load scripts in JavaScript
export default (source) => {
source || return;
const newScript = document.createElement("script");
newScript.async = true;
newScript.src = source;
const s0 = document.getElementsByTagName('script')[0];
s0.parentNode.insertBefore(newScript, s0);
}
@cheshirecode
cheshirecode / kafka-client-pod.sh
Last active August 16, 2018 06:34
minikube + Helm
#!/usr/bin/env bash
kubectl apply -f cp-helm-charts/examples/kafka-client.yaml
kubectl exec -it kafka-client -- /bin/bash
## Setup
export RELEASE_NAME=my-confluent-oss
export ZOOKEEPERS=${RELEASE_NAME}-cp-zookeeper:2181
export KAFKAS=${RELEASE_NAME}-cp-kafka-headless:9092
## Create Topic
kafka-topics --zookeeper $ZOOKEEPERS --create --topic test-rep-one --partitions 6 --replication-factor 1