Skip to content

Instantly share code, notes, and snippets.

View edubskiy's full-sized avatar

Evgeniy Dubskiy edubskiy

View GitHub Profile
@edubskiy
edubskiy / typescript_adapter_pattern.tsx
Created July 4, 2023 15:06
Typescript Adapter pattern Implementation and Demo
namespace AdapterPattern {
export class Adaptee {
public method(): void {
console.log("`method` of Adaptee is being called");
}
}
export interface Target {
call(): void;
@edubskiy
edubskiy / typescript_abstract_factory_pattern.ts
Last active June 27, 2023 19:38
Abstract Factory Pattern - Creates an instance of several families of classes
namespace AbstractFactoryPattern {
export interface AbstractProductA {
methodA(): string;
}
export interface AbstractProductB {
methodB(): number;
}
export interface AbstractFactory {
createProductA(param?: any) : AbstractProductA;
@edubskiy
edubskiy / text_overflow_fade.css
Created June 1, 2022 22:23
Fading out text on overflow with css if the text is bigger than allowed
.row:before {
content:'';
width:100%;
height:100%;
position:absolute;
left:0;
top:0;
background:linear-gradient(transparent 150px, white);
}
type PartiallyRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
interface Human {
name: string;
age?: number;
}
type HumanWithRequiredAge = PartiallyRequired<Human, "age">;
const dan: HumanWithRequiredAge = {
curl --location --request POST 'https://YOUR_AUTH0_DOMAIN/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=YOUR_AUTH0_CLIENT_ID' \
--data-urlencode 'username=YOUR_USERNAME' \
--data-urlencode 'password=YOUR_PASSWORD' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'scope=openid'
@edubskiy
edubskiy / restore_db_postgres.sql
Created March 22, 2021 13:05
Restores database from binary file, clear content before restoring
pg_restore --dbname <DATABASENAME> --host localhost --port 5432 --username <USERNAME> --clean --schema public <RESTORE_FILE_LOCATION>
PGPASSWORD="PASSWORD" pg_dump -U USER_NAME -h 127.0.0.1 -p 5432 DATABASE_NAME > DATABASE_NAME-$(date +%d-%m-%Y_%H-%M-%S).sql
@edubskiy
edubskiy / tree_from_array.js
Created March 5, 2021 07:57
Build tree array from flat array in javascript
const createDataTree = dataset => {
const hashTable = Object.create(null);
dataset.forEach(aData => hashTable[aData.ID] = {...aData, childNodes: []});
const dataTree = [];
dataset.forEach(aData => {
if(aData.parentID) hashTable[aData.parentID].childNodes.push(hashTable[aData.ID])
else dataTree.push(hashTable[aData.ID])
});
return dataTree;
};
@edubskiy
edubskiy / find_duplicate_records.sql
Created March 5, 2021 07:51
How to find duplicate records in PostgreSQL
select * from yourTable ou
where (select count(*) from yourTable inr
where inr.sid = ou.sid) > 1
import 'dart:isolate';
void main() async{
ReceivePort receivePort= ReceivePort();
/*
Create new Isolate, just after creating new Isolate control of this main Isolate,
start executing next instructions below the new Isolate creation line,
where as new Isolate keep working in parallel of main/other Isolates