Skip to content

Instantly share code, notes, and snippets.

View wojtekmaj's full-sized avatar

Wojciech Maj wojtekmaj

View GitHub Profile
@wojtekmaj
wojtekmaj / feature-detection.js
Last active October 25, 2022 17:33
Image format feature detection
const isSafari = // ...
function getIsSupported(src) {
return new Promise((resolve) => {
const image = new Image();
image.onload = () => {
const isSupported = image.width > 0 && image.height > 0;
resolve(isSupported);
};
@wojtekmaj
wojtekmaj / github-actions-dashboard.html
Last active October 19, 2022 12:42
GitHub Actions Dashboard
<!DOCTYPE html>
<html>
<title>GitHub Actions dashboard</title>
<style>
:root {
font-size: 14px;
--background-color: rgb(246 248 250);
--canvas-background-color: rgb(255 255 255);
--canvas-border-color: rgb(216 222 228);
--canvas-shadow: rgba(140 149 159 / 15%) 0 3px 6px 0;
@wojtekmaj
wojtekmaj / migrate-package-to-typescript.sh
Last active September 28, 2022 12:10
Convert package to TypeScript automatically
# Create tsconfig.json
echo "{
\"compilerOptions\": {
\"declaration\": true,
\"esModuleInterop\": true,
\"isolatedModules\": true,
\"moduleResolution\": \"node\",
\"outDir\": \"dist\",
\"strict\": true
},
@wojtekmaj
wojtekmaj / react-add-word-break.js
Created January 25, 2022 11:08
Add word breaks to text in React
const pattern = /_/g;
function addWordBreaks(text) {
const splitText = text.split(pattern);
if (splitText.length <= 1) {
return text;
}
const matches = text.match(pattern);
@wojtekmaj
wojtekmaj / install-eslint-with-eslint-config-wojtekmaj-and-prettier.sh
Last active January 27, 2022 13:52
Install ESLint with eslint-config-wojtekmaj & Prettier
git fetch
git checkout main
git pull
git checkout -b prettier
yarn add eslint@^8.5.0 eslint-config-wojtekmaj prettier@^2.5.0 --dev
yarn dedupe
echo "{
\"printWidth\": 100,
\"singleQuote\": true,
@wojtekmaj
wojtekmaj / install-husky-and-commitlint.sh
Last active December 27, 2021 10:00
Install Husky & commitlint with conventional config using Yarn Berry
git fetch
git checkout main
git pull
git checkout -b husky
yarn add @commitlint/config-conventional @commitlint/cli husky@^7.0.0 --dev
yarn dedupe
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
# if you're on windows, check EOL sequence in the file created
yarn husky install
@wojtekmaj
wojtekmaj / names-to-test-app.txt
Last active July 10, 2021 09:37
List of names to test your app with
Enrico Fermi
Cecilia Payne-Gaposchkin
Gertrude B. Elion
Patricia S. Goldman-Rakic
Łucja Światowska
Francisca de Oliveira
Ada María Guerrero de Hernández
侯既明
شیرین مینایی
@wojtekmaj
wojtekmaj / react-add-links.js
Created May 2, 2021 21:33
Add links to text in React
@wojtekmaj
wojtekmaj / button-label-update.js
Last active April 26, 2021 10:32
Shit I need to put up with to support Safari
function Button({ buttonLabel, onClick }) {
return (
<button
/**
* Apparently iOS Safari sometimes "forgets" to update button innerHTML. So to cope with
* that, we're forcing iOS Safari to re-render the button completely on label change. Why
* all this hassle with UA? Removing a button and rendering it again causes it to lose
* focus.
*/
key={buttonLabel}
@wojtekmaj
wojtekmaj / calendar.less
Last active March 24, 2021 10:54
React-DateTime-Picker demo page styling
.react-calendar {
.rounded-corners();
width: 350px;
max-width: 100%;
background: white;
font: inherit;
line-height: 1.125em;
border: 0;
overflow: hidden;