Skip to content

Instantly share code, notes, and snippets.

View alonn24's full-sized avatar

Alon alonn24

View GitHub Profile
@alonn24
alonn24 / pg-index-usage.sql
Created February 9, 2023 08:20
Check index usage in postgress DB
SELECT
relname table_name,
idx_scan index_scan,
seq_scan table_scan,
100*idx_scan / (seq_scan + idx_scan) index_usage,
n_live_tup rows_in_table
FROM
pg_stat_user_tables
WHERE
seq_scan + idx_scan > 0 and 100 * idx_scan / (seq_scan + idx_scan) < 95 and
@alonn24
alonn24 / update-cloudfront-distribution.sh
Last active March 31, 2022 11:51
Update cloudfront distribution by tag
if [ $# -ne 2 ]
then
echo "No arguments supplied"
echo "usage: $0 <tag> <sha>"
exit 1
fi
for dist in $(aws cloudfront list-distributions | jq -r ".DistributionList.Items[].ARN")
do
if [ "$(aws cloudfront list-tags-for-resource --resource $dist | jq -r ".Tags.Items[].Value")" == "$1" ]
@alonn24
alonn24 / appWithTranslation.tsx
Last active February 22, 2022 19:55
appWithTranslation for exported nextjs apps
import i18n from 'i18next';
import Fetch from 'i18next-fetch-backend';
import React from 'react';
import { useRouter } from 'next/router';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { I18nextProvider } from 'react-i18next';
import type { AppProps } from 'next/app';
import { i18n as I18NextClient } from 'i18next';
import { defaultLanguage } from '../services/i18n/language';
@alonn24
alonn24 / run-page-speed.js
Created February 17, 2021 16:31
run-page-speed
import fetch from 'node-fetch';
function setUpQuery(url) {
const api = 'https://www.googleapis.com/pagespeedonline/v5/runPagespeed';
const parameters = {
url: encodeURIComponent(url)
};
let query = `${api}?`;
for (let key in parameters) {
query += `${key}=${parameters[key]}`;
@alonn24
alonn24 / use-disable-body-scroll.js
Last active November 20, 2019 17:02
Disable the body scroll for modals with a fix for ios devices.
import { useEffect } from 'react';
export default (ref: any, shouldDisable = true) => {
useEffect((): any => {
if (!shouldDisable) return null;
const element = ref.current.querySelector('.bw-allow-scroll');
if (element) {
element.ontouchmove = (e: Event) => {
e.stopPropagation();
};
@alonn24
alonn24 / mocha-wrappers.ts
Last active August 14, 2018 18:34
wrap mocha describe and it with custom before and after to reduce testing boilerplate
import {noop} from 'lodash'
const describeWrapper = (context, describe, before = noop, after = noop) => (...args) => {
const [_, impl, options] = args
args[1] = function(...descArgs) {
before.call(this, context, options)
impl.apply(this, [...descArgs, context])
after.call(this, context, options)
}
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
export class PolymerWordCount extends PolymerElement {
constructor() {
super();
}
static get is() {
return 'polymer-word-count';
}
<dom-module id='polymer-word-count'>
<template>
<style>
.title {
font-weight: bolder;
}
.log {
background: #aaa;
}
.word-count {
@alonn24
alonn24 / react-word-count.tsx
Created June 2, 2018 18:55
react wrapper for a word counter custom component
import './word-count/word-count';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
declare global {
namespace JSX {
interface IntrinsicElements {
@alonn24
alonn24 / web-component-word-count-template.html
Created June 2, 2018 18:36
native web component template for a work count component
<template id="template-word-count">
<style>
.title {
font-weight: bolder;
}
.log {
background: #aaa;
}
.word-count {
color: red;