Skip to content

Instantly share code, notes, and snippets.

View predragnikolic's full-sized avatar

Предраг Николић predragnikolic

View GitHub Profile
@predragnikolic
predragnikolic / index.js
Created March 10, 2023 12:37
Visualise Postgres with d2
const { Client } = require('pg')
const fs = require('fs');
const relations= []
async function main() {
const client = new Client({
connectionString: '', // e.g. postgres://user:password@host:5432/database
})
await client.connect()
const res = await client.query(`
@predragnikolic
predragnikolic / unique.ts
Created January 25, 2023 12:54
unique yup fields
import * as Yup from 'yup'
import { ObjectShape } from 'yup/lib/object'
declare module 'yup' {
interface ObjectSchema<TShape extends ObjectShape> {
unique(uniqueKey: string, message: string): ObjectSchema<TShape>;
}
}
Yup.addMethod(Yup.object, 'unique', function (uniqueKey: string, errorMessage: string) {
/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable jsx-a11y/anchor-has-content */
import { Trans } from "react-i18next"
const ALLOWED_TAGS = {
"a": <a />,
"b": <b />,
"i": <i />,
"u": <u />,
"s": <s />,
@predragnikolic
predragnikolic / 001-init-migrations.sql
Created June 22, 2022 09:40
Sql migration thing :D
-- @UP
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- Migration
-- This table will keep a list of migrations that have been run on this database.
--
CREATE TABLE migration (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
file TEXT NOT NULL,
hash TEXT NOT NULL,
/*
This script *tries* to find unused tranlations. :)
Do not expect 100% perfect detection, but it should give good enough results.
This script can detect:
```
t('some_translation_key') // can be detected
let x: TranslationKey = "some_translation_key" // can be detected, because of the use of `t()`
let x = "some_translation_key" as TranslationKey // can be detected, because of the use of TranslationKey
<Trans i18nKey="some_translation_key"` /> can be detected, because of the use of prop i18nKey
@predragnikolic
predragnikolic / FocusTrap.tsx
Last active March 14, 2022 09:44
Trap focus. Useful for trapping focus within a modal, or an open dropdown...
// inspired by
// https://hiddedevries.nl/en/blog/2017-01-29-using-javascript-to-trap-focus-in-an-element
import { ReactNode, useEffect, useRef } from "react"
type FocusableHTMLElement = HTMLButtonElement
type Props = {
children: ReactNode
}
export function FocusTrap({ children }: Props) {
@predragnikolic
predragnikolic / gist:fd6714ddc7f5af9ba828ed0372bbc4f0
Created March 15, 2020 14:56
~/.recordWindow 10 -c good.gif
#!/bin/bash
# INSTALL
# 1) clone to a folder (I have a ~/software one)
# 2) Add the following to your ~/.bashrc
# alias byzanz-record-window='/home/todd/software/byzanz-record-window'
# Delay before starting
DELAY=3
convert transparent.png -fuzz 5% -fill none -draw "matte 0,0 floodfill" -channel alpha -blur 0x1 -level 50x100% +channel -background transparent -flatten result.png