Skip to content

Instantly share code, notes, and snippets.

@igrek8
igrek8 / parse-redux-form-field.js
Created June 6, 2018 07:36
Parse complex string redux-form
const escapeRegex = /([^\\])\./g;
export const normalizeToken = index => (str, prev) => {
if (
typeof str === 'string' ||
typeof str === 'number' ||
typeof str === 'boolean') {
const groups = prev.toString()
.replace(escapeRegex, '$1¬')
document.body.style.paddingBottom = '250px';
const div = document.createElement('div');
Object.assign(div.style, {
position: 'fixed',
bottom: 0,
left: 0,
right: 0,
height: '250px',
opacity: 0.90,
color: 'white',
@igrek8
igrek8 / App.jsx
Created May 6, 2019 15:14
Prevent useCallback rerendering children components
import React, { useState, useRef, useCallback } from "react";
import Button from "./Button";
function App() {
const [state, setState] = useState("");
const ref = useRef(state);
const handleChange = useCallback(event => {
ref.current = event.target.value;
setState(event.target.value);
}, []);
@igrek8
igrek8 / App.jsx
Last active May 6, 2019 15:15
Prevent useCallback rerendering children components https://codesandbox.io/embed/o5o3znl656
import React, { useState, useRef, useCallback } from "react";
import Button from "./Button";
function App() {
const [state, setState] = useState("");
const ref = useRef(state);
const handleChange = useCallback(event => {
ref.current = event.target.value;
setState(event.target.value);
}, []);
@igrek8
igrek8 / webpack.config.js
Created July 4, 2019 16:49
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const env = process.env.NODE_ENV;
const publicPath = process.env.PUBLIC_PATH ? `${process.env.PUBLIC_PATH}/` : process.env.PUBLIC_PATH;
if (!['development', 'production'].includes(env)) {
throw new Error('Invalid NODE_ENV');
@igrek8
igrek8 / query.sql
Created July 18, 2019 10:34
Postgres: Flatten JSON keys and keys paths
WITH RECURSIVE doc_key_and_value_recursive (
KEY,
value
) AS (
SELECT
t.key,
t.value
FROM
stories_collection AS item,
json_each(item.data) AS t
@igrek8
igrek8 / README.md
Last active November 23, 2019 08:36
Inject docker envrionments in create-react-app

Run the script in docker runtime

chmod +x webenv.sh
# load global envrionments with filter
(env | grep ^REACT_APP_ | webenv.sh) > env.js

Include <script> in index.html

@igrek8
igrek8 / README.md
Last active November 26, 2019 10:58
knex.js typescrips migrations (fix the migration directory is corrupt)

TypeScript migrations for knex.js

Fix the migration directory is corrupt

Migrations will work in both production/development environments. You may also have declrations/source maps generated in the migrations directory and the migration source will skip them.

@igrek8
igrek8 / README.md
Last active November 25, 2019 11:51
match markdown code block
(?:^`{3})(?:(.*$\n)?((?:.|\n)*?))(?:`{3}$)
@igrek8
igrek8 / README.md
Last active December 6, 2019 12:27
Jest get coverage programmatically (gitlab pipelines)
node getCoverage.js

=>

CoverageSummary {
  data: {
 lines: { total: 10, covered: 10, skipped: 0, pct: 10.0 },