Skip to content

Instantly share code, notes, and snippets.

View kasir-barati's full-sized avatar
Dedicated to achieve his goals

Kasir Barati kasir-barati

Dedicated to achieve his goals
View GitHub Profile
@kasir-barati
kasir-barati / my-create-angular-app
Last active September 20, 2022 10:54
A simple script which forces you to select pnpm as the package manager and install prettier as devDep
#!/bin/bash
isPackageManagerSpecified="false";
for ((i=1; i<=$#; i++))
do
nextArgumentIndex=$((i+1));
if [[ "${!i}" == "--package-manager" ]] && [[ "${!nextArgumentIndex}" == "pnpm" ]];
then
isPackageManagerSpecified="true";
fi
@kasir-barati
kasir-barati / vimrc
Created June 21, 2022 06:27
My customization for vim.
" set autoindent
" reload files when changed on disk, i.e. via `git checkout`
set autoread
" Fix broken backspace in some setups
set backspace=2
" see :help crontab
set backupcopy=yes
" yank and paste with the system clipboard
set clipboard=unnamed
" don't store swapfiles in the current directory
@kasir-barati
kasir-barati / README.md
Last active June 20, 2022 14:50
A simple script to emerges environment.ts file from .env file for an Angular app.

Some good notes:

  • With Angular you can store those information in the environment.ts files, but you need to commit them in the repository, and again, this is not what we want. If something is changing, you need to update them and in an Agile environment, you also need to pass Code Review, Test and many other steps to certify a “Done” ticket.
  • Keep in mind that in a Front End world, it is pretty much impossible to keep anything hidden from the final user (the code can always be inspected in any browser). For this reason, the use of secret keys and passwords in this world have to be considered very carefully and under a secure structure managed backend side.

Important possible improvements:

Please note that this script disclose too much data. You can filter them by using filter-env lib. In that case you can add a specific prefix to all of your envs. The other point is that this script uses the same env name as it is inside the .env file, so my suggestion to

@kasir-barati
kasir-barati / .prettierignore
Last active March 6, 2023 15:52
My public prettier ignore which I use in my projects
Docker*
**/*.tsbuildinfo
.DS_STORE
# Angular app specific
.angular
/dist/
/build/
@kasir-barati
kasir-barati / .prettierrc
Last active March 6, 2023 15:52
My default prettierrc file
{
"arrowParens": "always",
"useTabs": false,
"bracketSpacing": true,
"endOfLine": "lf",
"printWidth": 70,
"quoteProps": "consistent",
"tabWidth": 4,
"trailingComma": "all",
"semi": true,
@kasir-barati
kasir-barati / auto-generated-prisma-client.ts
Created May 1, 2022 13:14
Custom DTO for validating date
export const FlightRegionType: {
DOMESTIC: 'DOMESTIC',
INTERNATIONAL: 'INTERNATIONAL'
};
export const CabinClass: {
ECONOMY: 'ECONOMY',
BUSINESS: 'BUSINESS',
FIRST: 'FIRST'
};
@kasir-barati
kasir-barati / main.sh
Last active April 20, 2022 11:26
Postgresql: dump, restore, connect to it, etc
# Connect to postgres
PGPASSWORD="pass" psql -h localhost -p 5432 -U user -d db-name
# You can also use .pgpass, TBH it does not work in my experience. BTW this is much much safer from point of security - No track in terminal history.
touch ~/.pgpass
# Replace its values:
db_host:db_port:db_name:db_user:db_pass
# Dump from postgres
# Doc: https://www.postgresql.org/docs/14/app-pgdump.html
@kasir-barati
kasir-barati / app.module.ts
Created April 14, 2022 10:12
Global throttler, Throttler behind the proxy with custom message in nestjs
import { Module } from '@nestjs/common';
import { ThrottlerModule } from '@nestjs/throttler';
import { ThrottlerStorageRedisService } from 'nestjs-throttler-storage-redis';
import { AppService } from './service/app.service';
import { AppController } from './app.controller';
import { APP_GUARD } from '@nestjs/core';
import { GlobalThrottlerGuard } from './guards/global-throttler.guard';
@Module({
@kasir-barati
kasir-barati / many-to-many.prisma
Last active April 9, 2022 05:53
relationships in prisma linkedin
// This is your Prisma schema file
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// N:M relationship in prisma
datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}
generator client {
@kasir-barati
kasir-barati / traefik.yml
Created April 8, 2022 06:09
Traefik compose file
log:
level: DEBUG
filepath: "/etc/traefik/log/traefik.log"
api:
dashboard: true
insecure: false
debug: true
# Define ports - UDP or TCP - which will recieve packets
entryPoints: