Skip to content

Instantly share code, notes, and snippets.

View ezzabuzaid's full-sized avatar
🎯
Focusing

ezzabuzaid ezzabuzaid

🎯
Focusing
View GitHub Profile
@ezzabuzaid
ezzabuzaid / sql-query-object.js
Last active December 1, 2020 16:55
create sql query using a function
const schema = {
id: {
type: 'int UNSIGNED',
value: 'AUTO_INCREMENT',
key: 'PRIMARY KEY'
},
title: {
type: 'VARCHAR(255)',
value: 'NOT NULL'
},
@ezzabuzaid
ezzabuzaid / path-mapper.js
Created January 25, 2020 21:29
Map typescript path in node js to work with require function
const tsconfig = require('./tsconfig.json');
const path = require('path');
const fs = require('fs');
(function () {
const sliceAsterisk = (url) => url.split('/*')[0];
const getFilePath = (url) => {
const urlParts = url.split('/');
urlParts.splice(0, 1);
return urlParts.join('/');
@ezzabuzaid
ezzabuzaid / ftp-upload.js
Created January 26, 2020 09:20
Upload your static site over FTP protocol using on command `node ftp-upload.js --from="localFolder" --to="serverFolder"`
const fs = require('fs');
const path = require('path');
const Client = require('ftp');
const program = require('commander');
const client = new Client();
client.connect({
user: "",
password: "",
@ezzabuzaid
ezzabuzaid / automapper.dart
Created May 19, 2020 19:18
Dart automapper to serialize and deserialize JSON
import 'dart:mirrors';
class Person {
String firstname;
String lastname;
}
main() {
final json = {"firstname": "ezz", "lastname": "abuzaid"};
Person person = deserialize(json, Person);
@ezzabuzaid
ezzabuzaid / eventemitter.js
Created May 28, 2020 22:25
Custom EventEmitter
class EventEmitter {
constructor() {
this.callbacks = {};
this.noEventYet = [];
}
addEventListener(eventName, callback) {
const callbacks = this.callbacks[eventName];
@ezzabuzaid
ezzabuzaid / compute.js
Last active April 17, 2024 05:49
Simple inline web worker helper. compute version of Dart in JavaScript.
function compute(computation, ...message) {
const delegate = () => {
onmessage = ({ data: { computation, message } }) => {
const wrapper = (fn) => Function('"use strict"; return (' + fn.toString() + ')')();
const result = wrapper(computation)(...message);
postMessage(result);
};
}
const functionBody = delegate.toString().replace(/^[^{]*{\s*/, '').replace(/\s*}[^}]*$/, '');
return new Promise((resolve, reject) => {
/**
*
* Wrap database calls within transaction
*
* @param computation an action function with {EntityManager} argument that will be executed after starting the transaction
*
*/
export async function useTransaction<TResult>(computation: (manager: EntityManager) => Promise<TResult>) {
let queryRunner = getConnection().createQueryRunner();
@ezzabuzaid
ezzabuzaid / singularize.pipe.ts
Created December 8, 2020 10:31
Angular Pipe to Singularize or pluralize word
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'singularize'
})
export class SingularizePipe implements PipeTransform {
public transform(value: any, count: number = 1): string {
return count > 1 ? plural(value) : singular(value);
@ezzabuzaid
ezzabuzaid / path-resolver.js
Created March 26, 2021 22:10
Node.js TypeScript path alias resolver
const tsConfig = require('../tsconfig.json');
const tsConfigPaths = require('tsconfig-paths');
tsConfigPaths.register({
baseUrl: __dirname,
paths: tsConfig.compilerOptions.paths,
});
@ezzabuzaid
ezzabuzaid / page_object.ts
Last active November 29, 2021 19:40
Angular Page Object
import { ComponentType } from '@angular/cdk/portal';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { DebugElement, InjectionToken } from '@angular/core';
import { ComponentFixture, TestBed, TestModuleMetadata } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Subject } from 'rxjs';
export class Page<T> {
private _fixture: ComponentFixture<T>;
constructor(