Skip to content

Instantly share code, notes, and snippets.

View fedek6's full-sized avatar
🎯
Focusing

Konrad Fedorczyk fedek6

🎯
Focusing
View GitHub Profile
@fedek6
fedek6 / convetions.md
Created May 13, 2022 08:37
React props naming conventions

Props naming

  • Array – use plural nouns. e.g. items
  • Number – use prefix num or postfix count, index etc that can imply a number. e.g. numItems, itemCount, itemIndex
  • Bool – use prefix is, can, has
    • is: for visual/behavior variations. e.g. isVisible, isEnable, isActive
    • can: fore behavior variations or conditional visual variations. e.g. canToggle, canExpand, canHaveCancelButton
    • has: for toggling UI elements. e.g. hasCancelButton, hasHeader
  • Object – use noun. e.g. item
  • Node – use prefix node. containerNode
@fedek6
fedek6 / auth-worker.js
Created April 21, 2022 11:47
Clooudflare worker for basic auth
/**
* @param {string} USERNAME User name to access the page
* @param {string} PASSWORD Password to access the page
* @param {string} REALM A name of an area (a page or a group of pages) to protect.
* Some browsers may show "Enter user name and password to access REALM"
*/
const USERNAME = 'demouser'
const PASSWORD = 'demopassword'
const REALM = 'Secure Area'
@fedek6
fedek6 / gatsby-node.js
Created April 7, 2022 09:01
Better cache busting for Gatsby (using date hash)
const fs = require("fs");
const path = require("path");
const md5 = require("md5");
const util = require("util");
const glob = require("glob");
/**
* Cache busting
*/
const hash = md5(`${new Date().getTime()}`);
@fedek6
fedek6 / .htaccess
Created April 5, 2022 08:03
Rewrite everything to maintenance page when IP does not equal
RewriteCond %{REMOTE_ADDR} !=95.160.157.10
RewriteCond %{REQUEST_URI} !=/maintenance.html
RewriteRule ^(.*)$ /maintenance.html [L]
@fedek6
fedek6 / .htaccess
Created April 5, 2022 08:01
Rewrite WordPress assets from develop to production
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$
RewriteRule ^(.*)$ https://producion.com/$1 [QSA,L]
</IfModule>
@fedek6
fedek6 / rollup.config.js
Created March 22, 2022 09:05
Disable SVGR (SVGO) prefixes in Rollup
import ts from "rollup-plugin-ts";
import { nodeResolve } from "@rollup/plugin-node-resolve";
// import peerDepsExternal from "rollup-plugin-peer-deps-external";
import svgr from "@svgr/rollup";
import { terser } from "rollup-plugin-terser";
import commonjs from "@rollup/plugin-commonjs";
import externals from "rollup-plugin-node-externals";
// import postcss from "rollup-plugin-postcss";
// import autoprefixer from "autoprefixer";
@fedek6
fedek6 / main.js
Created March 22, 2022 09:04
Disable SVGR (SVGO) prefixes in Storybook
const path = require("path");
module.exports = {
stories: [
"../stories/**/*.stories.mdx",
"../stories/**/*.stories.@(js|jsx|ts|tsx)",
],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
@fedek6
fedek6 / DocsContainer.js
Created March 17, 2022 08:18
Sorybook with dark mode support for docs (using stitches, but this can be edited)
import React from "react";
import { DocsContainer as BaseContainer } from "@storybook/addon-docs/blocks";
import { useDarkMode } from "storybook-dark-mode";
import { themes } from "@storybook/theming";
export const DocsContainer = ({ children, context }) => {
const dark = useDarkMode();
return (
<BaseContainer
@fedek6
fedek6 / .md
Created March 9, 2022 11:54
Aspect ratio padding bottom (for CSS usage)
Aspect Ratio Padding-Bottom
1:1 100%
16:9 56.25%
4:3 75%
3:2 66.66%
8:5 62.5%
@fedek6
fedek6 / console.js
Last active December 13, 2021 08:36
Virtual console for JSFiddle
// Init DOM
const consoleContainer = document.createElement("div");
consoleContainer.classList.add("console");
const legend = document.createElement("small");
legend.textContent = "Console";
consoleContainer.append(legend);
const vConsole = document.createElement("pre");
consoleContainer.append(vConsole);
window.addEventListener('DOMContentLoaded', (event) => {