Skip to content

Instantly share code, notes, and snippets.

View typomaker's full-sized avatar
🎯
Focusing

Albert Sultanov typomaker

🎯
Focusing
View GitHub Profile
@typomaker
typomaker / docker-entrypoint.sh
Created February 16, 2021 20:02
Set env variables from one string URI for https://hub.docker.com/_/postgres
#!/bin/bash
set -Eeo pipefail
# check to see if this file is being run or sourced from another script
_is_sourced() {
# https://unix.stackexchange.com/a/215279
[ "${#FUNCNAME[@]}" -ge 2 ] \
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
&& [ "${FUNCNAME[1]}" = 'source' ]
}
#!/usr/bin/env bash
set -Eeo pipefail
# check to see if this file is being run or sourced from another script
_is_sourced() {
# https://unix.stackexchange.com/a/215279
[ "${#FUNCNAME[@]}" -ge 2 ] \
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \
&& [ "${FUNCNAME[1]}" = 'source' ]
}
@typomaker
typomaker / docker-entrypoint.sh
Created February 16, 2021 19:54
Nginx docker-entrypoint.sh with generating self signed certs for dev-mode and .conf with using environment variables
#!/usr/bin/env bash
set -eo pipefail
echo "DOMAIN=${DOMAIN}";
if [[ "$ENV" == "development" ]]; then
if [[ ! -d /ssl/certs ]]; then
echo "Creating /ssl/certs"
mkdir -p /ssl/certs
fi
@typomaker
typomaker / typed_condition_tree.ts
Created February 16, 2021 19:46
Strongly typed query condition as in Yii2 (PHP). [typscript 4.1 literal templates]
export type Path<T> =
T extends Array<infer S> ? Path<S> & string :
(T extends object ? {
[K in keyof T]: T[K] extends Array<any> ? Path.Item<T, K> : K & string | Path.Item<T, K>
}[keyof T] : never)
export namespace Path {
export type Item<T, K extends keyof T> = `${K & string}.${Path<T[K]> & string}`
export type Type<T, Q extends Path<T>> =
T extends Array<infer S> ? (Q extends Path<S> ? Type<S, Q> : never) :