Skip to content

Instantly share code, notes, and snippets.

@Naymi
Naymi / clean_code.md
Created June 2, 2024 16:09 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@Naymi
Naymi / build.mjs
Created May 19, 2023 12:06
parcel node bundle
import { Parcel } from '@parcel/core';
let bundler = new Parcel({
entries: 'src/main.ts',
defaultConfig: '@parcel/config-default',
defaultTargetOptions: {
engines: {
node: '>=18',
},
},
@Naymi
Naymi / build.mjs
Created May 11, 2023 12:05
esbuild example
import * as esbuild from 'esbuild'
import {join,dirname} from "node:path";
import {fileURLToPath} from 'node:url'
import {program} from "commander";
let options = {
entryPoints: ['src/autodoc.ts'],
bundle: true,
outfile: 'dist/autodoc.js',
format: "cjs",
@Naymi
Naymi / build.mjs
Created May 11, 2023 11:36
parcel build node example (removed shebang, compiled to one file)
import {Parcel} from '@parcel/core';
let bundler = new Parcel({
entries: 'src/autodoc.ts',
defaultConfig: '@parcel/config-default',
mode: 'production',
defaultTargetOptions: {
distDir: 'parcel-dist',
engines: {
node: '>=18',
@Naymi
Naymi / Dockerfile
Created May 3, 2023 11:26
Lerna monorepo turbo integraion
FROM node:18.12.1-alpine AS builder
RUN apk add --no-cache libc6-compat && apk update
# Set working directory
WORKDIR /app
COPY . .
RUN npx -y turbo prune --scope=examples.client --docker
# Add lockfile and package.json's of isolated subworkspace
FROM node:18.12.1-alpine AS installer
WORKDIR /app
@Naymi
Naymi / Watcher.ts
Last active September 27, 2022 11:39
Класс для реализации крона
import { setInterval } from 'timers/promises'
import { LoggerService } from '../infractructure/logger/logger.service'
class TimestampTimer {
static async waitFor(date: Date, delay = 200): Promise<void> {
for await (const _ of setInterval(delay)) {
if (new Date() >= date) return
}
}
}
@Naymi
Naymi / cert
Created April 17, 2022 10:47 — forked from sagolubev/cert
Script for certs generation
#!/bin/bash
#see https://docs.docker.com/engine/security/https/
EXPIRATIONDAYS=700
CASUBJSTRING="/C=GB/ST=London/L=London/O=ExampleCompany/OU=IT/CN=example.com/emailAddress=test@example.com"
while [[ $# -gt 1 ]]
do
key="$1"
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
alias gf='git fetch'
alias gc='git checkout'
@Naymi
Naymi / getPostfixYear.ts
Created December 3, 2019 10:02
return year postfix based based on year number
export default function getPostfixYear(age: number) {
let postfix = "лет",
count = Math.floor(Math.abs(age)) % 100
if (!(count >= 5 && count <= 20)) {
count = count % 10
if (count == 1) {
postfix = "год"
} else if (count >= 2 && count <= 4) {
postfix = "года"
}
@Naymi
Naymi / calcPlatesh.js
Last active October 7, 2019 12:34
calculate anuitete platesh
/**
* @param {number} sum credit amount
* @param {number} period credit amount (year)
* @param {number} rate rate in percenntage
* @returns {number} monthly payment
*/
export default function calcPlatesh(sum, period, rate) {
let i, koef;
// rate in month
i = rate / 12 / 100;