Skip to content

Instantly share code, notes, and snippets.

View ezzabuzaid's full-sized avatar
🎯
Focusing

ezzabuzaid ezzabuzaid

🎯
Focusing
View GitHub Profile
/**
*
* 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 / 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) => {
@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 / 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 / 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 / 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 / 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'
},