Skip to content

Instantly share code, notes, and snippets.

View ali-kamalizade's full-sized avatar
🎩
Sunhat

Ali ali-kamalizade

🎩
Sunhat
View GitHub Profile
@ali-kamalizade
ali-kamalizade / .eslintrc.json
Last active June 26, 2024 11:40
ESLint configuration (simplified) with CSpell plugin to detect spelling issues
{
"files": ["*.ts"],
"excludedFiles": ["*.spec.ts"],
"parserOptions": {
"project": ["tsconfig.json"],
"createDefaultProgram": true
},
"plugins": ["@cspell"],
"rules": {
"@cspell/spellchecker": [
@ali-kamalizade
ali-kamalizade / cspell.config.yaml
Created June 26, 2024 11:00
CSpell configuration file
---
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
# using this configuration, ESLint checks TypeScript files for spelling errors
# the paths are relative to the location of the following directory
globRoot: './'
# skip excluded files
useGitignore: true
@ali-kamalizade
ali-kamalizade / service-worker-bypass.interceptor.ts
Created June 25, 2024 10:49
Bypassing HTTP requests when using service worker in Angular applications
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable } from 'rxjs';
/**
* See https://angular.io/guide/service-worker-devops#bypassing-the-service-worker for more info.
* This interceptor is used to bypass the service worker when making HTTP requests as there are some cases where the service worker might run into issues.
* Since we are not using the service worker for caching HTTP requests, we can safely bypass it.
* Attention: make sure that this header is explicitly allowed (e.g. by your file storage provider else file fetches might fail due to CORS).
*/
@ali-kamalizade
ali-kamalizade / dnd.component.html
Last active October 13, 2022 20:41
Angular CDK drag & drop
<div #formDropArea="cdkDropList" class="formFieldsDropArea" cdkDropList (cdkDropListDropped)="onDrop($event)">
<div *ngFor="let formField of formFields; let index = index; trackBy: trackByIndex" class="columns" cdkDrag (cdkDragStarted)="onDragStart()">
<div class="column is-narrow">
<i class="fas fa-fw fa-grip-vertical" cdkDragHandle title="Drag to reorder"></i>
</div>
<div class="column">
<input [ngModel]="formField.title" (ngModelChange)="onFormFieldChange(formField, $event)"">
<button (click)="deleteField(index)">Delete</button>
</div>
</div>
@ali-kamalizade
ali-kamalizade / postgresql-container.ts
Last active September 16, 2022 21:03
A function to create a Postgres container with Testcontainers. Written in TypeScript.
import { GenericContainer, StartedTestContainer } from 'testcontainers';
import { AbstractStartedContainer } from 'testcontainers/dist/modules/abstract-started-container';
import { RandomUuid } from 'testcontainers/dist/uuid';
const POSTGRES_PORT = 5432;
export async function createDatabaseContainer() {
// reusing the same container for all tests is considerably faster than starting a new one for each test
const container = await new PostgreSqlContainer().withReuse().start();
const host = container.getHost();
@ali-kamalizade
ali-kamalizade / jest-global-setup.ts
Last active September 16, 2022 21:55
Jest globalSetup which creates a Docker container before executing any tests
// helpful if you use Nx - else you can omit this import
import 'tsconfig-paths/register';
import { createDatabaseContainer } from './e2e/testing-setup.helpers';
export default async () => {
await createDatabaseContainer();
};
@ali-kamalizade
ali-kamalizade / jest-global-teardown.ts
Last active March 29, 2023 21:43
Jest globalTeardown function to stop and remove containers (e.g. Postgres) which were started as part of the test run
// helpful if you use Nx - else you can omit this import
import 'tsconfig-paths/register';
import { getContainerById } from 'testcontainers/dist/docker/functions/container/get-container';
export default async () => {
const containerId = process.env.TEST_POSTGRES_CONTAINER_ID!;
const container = await getContainerById(containerId);
await container.stop();
// deletion of docker volume after running all tests
await container.remove({ v: true }));
@ali-kamalizade
ali-kamalizade / jest.config.js
Created September 16, 2022 20:45
A Jest configuration with globalSetup and globalTeardown
/**
* @type {import("ts-jest/dist/types").InitialOptionsTsJest}
*/
module.exports = {
globalSetup: './jest-global-setup.ts',
globalTeardown: './jest-global-teardown.ts',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
isolatedModules: true
@ali-kamalizade
ali-kamalizade / ci-with-path-filter.yml
Created May 18, 2022 21:51
A sample GitHub workflow using paths filters that can be referenced on the step and job level (e.g. to skip a job if there were no related code changes)
jobs:
changes:
runs-on: ubuntu-latest
name: Check changes
outputs:
functions: ${{ steps.filter.outputs.functions }}
steps:
- uses: actions/checkout@v3
name: Checkout project to determine changed files
with:
@ali-kamalizade
ali-kamalizade / ci-with-ref-check.yml
Created May 18, 2022 21:41
A sample GitHub workflow using the GitHub ref to conditionally skip steps
ci_web:
name: "Build & Tests & Lint"
runs-on: ubuntu-latest
steps:
- name: "Checkout project"
uses: actions/checkout@v3
- name: "Use Node.js"
uses: actions/setup-node@v3