Skip to content

Instantly share code, notes, and snippets.

View ngrnv's full-sized avatar
🏠
Working from home

Alexey Nagornov ngrnv

🏠
Working from home
  • Yerevan, Armenia
View GitHub Profile
@ngrnv
ngrnv / conventional_commit_messages.md
Created October 10, 2023 09:10 — forked from qoomon/conventional-commits-cheatsheet.md
Conventional Commit Messages

Conventional Commit Messages

See how a minor change to your commit message style can make a difference. Examples

Have a look at CLI util git-conventional-commits to ensure this conventions and generate changelogs

Commit Formats

Default

@ngrnv
ngrnv / ubuntu-nextjs-nginx-config-file
Created September 19, 2023 21:21 — forked from oelbaga/01 - Setup Nextjs site on Ubuntu Server - Terminal commands
Setup NextJS app on Digital Ocean Ubuntu server Full Terminal Commands Step by Step
#nginx config file for Nextjs App
#place in /etc/nginx/sites-available/name_of_config_file
server {
listen 80;
server_name domainname.com;
gzip on;
gzip_proxied any;
gzip_types application/javascript application/x-javascript text/css text/javascript;
gzip_comp_level 5;
@ngrnv
ngrnv / as-observables.ts
Created May 16, 2023 13:09
[ng] subscribe to many observables once
<ng-container *ngIf="
{
obs1: obs1$ | async,
obs2: obs2$ | async,
obs3: obs3$ | async
} as observables">
<!-- already expanded observable!-->
{{observables.obs1}}
</ng-container>
@ngrnv
ngrnv / cleanup.sh
Created May 9, 2022 08:06
cleanup ubuntu root
function myclean {
## Show free space
df -Th | grep -v fs
# Will need English output for processing
LANG=en_GB.UTF-8
## Clean apt cache
apt-get update
apt-get -f install
apt-get -y autoremove
@ngrnv
ngrnv / promisify.ts
Created June 24, 2021 11:36
Utility type to promisify values returned by functions in object props
type GenericFunction<TS extends any[], R> = (...args: TS) => R;
type Promisify<P> = {
[K in keyof P]: P[K] extends GenericFunction<infer TS, infer R> ? (...args: TS) => Promise<R> : P[K]
};
// example
@ngrnv
ngrnv / gist:58bf36555aac4ec50844b62924fd42f4
Created January 16, 2021 12:43
Monitor CPU temperature in macos
sudo powermetrics --samplers smc |grep -i "CPU die temperature"
@ngrnv
ngrnv / factory-with-class-types.ts
Last active February 22, 2020 08:37
Factory function with Class Types in TypeScript
class Animal {
name: string | null;
constructor() {
this.name = null;
}
}
class Bee extends Animal {
@ngrnv
ngrnv / ts-enum-mapping.ts
Created February 22, 2020 08:30
Map enum values to custom values in TypeScript
enum LogLevel {
ERROR, WARN, INFO, DEBUG
}
/**
* This is equivalent to:
* type LogLevelStrings = 'ERROR' | 'WARN' | 'INFO' | 'DEBUG';
*/
type LogLevelStrings = keyof typeof LogLevel;
@ngrnv
ngrnv / curry.js
Last active February 1, 2020 19:49
js curry implementation
function curry(fn) {
return function curried() {
return arguments.length >= fn.length
? fn.apply(null, arguments) // if there are all args - execute fn with them
: curried.bind(null, ...arguments) // return new version of curried() with prepended arg(s)
}
}
curry((x, y, z) => x + y + z)(5)(4)(1); // 10
@ngrnv
ngrnv / use-constant.ts
Created January 13, 2020 08:54
react use-constant hook
import * as React from 'react'
type ResultBox<T> = { v: T }
export default function useConstant<T>(fn: () => T): T {
const ref = React.useRef<ResultBox<T>>()
if (!ref.current) {
ref.current = { v: fn() }
}