Skip to content

Instantly share code, notes, and snippets.

@igrek8
igrek8 / compose-template.js
Created February 17, 2022 18:21
Composes a AWS CloudFormation template from multiple sources using deep-merge
#!/usr/bin/env node
const glob = require("glob");
const yargs = require("yargs");
const { hideBin } = require("yargs/helpers");
const path = require("path");
const fs = require("fs");
const yaml = require("yaml");
const lodash = require("lodash");
@igrek8
igrek8 / migrate.js
Created October 28, 2021 12:07
Migrate to Self Hosted Redash
/* eslint-disable no-param-reassign */
const fetch = require("node-fetch");
const _ = require("lodash");
const fs = require("fs");
const { format } = require("util");
const SOURCE_REDASH = "https://app.redash.io/domain";
const SOURCE_REDASH_API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXX";
@igrek8
igrek8 / main.js
Created July 1, 2021 11:07
Hide all Google calendars
(async () => {
async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
let el = document.querySelector('[aria-label="My calendars"]').children[0];
while (el) {
const label = el.querySelector("label");
const checkbox = el.querySelector("[role=checkbox]");
@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 },
@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 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 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 / 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 / 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 / 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);
}, []);