Skip to content

Instantly share code, notes, and snippets.

View an-parubets's full-sized avatar
🏠
Working from home

Anatolii Parubets an-parubets

🏠
Working from home
View GitHub Profile
@an-parubets
an-parubets / EventEmitter.js
Last active March 14, 2023 19:03
EventEmitter
class EventEmitter {
constructor() {
this.events = {};
}
/**
* @param {string} eventName
* @param {Function} callback
*/
subscribe(eventName, callback) {
@an-parubets
an-parubets / EventEmitterEmit.js
Last active December 26, 2022 16:57
EventEmitter
/**
* @param {string} eventName
* @param {any} args
*/
emit(eventName, args) {
const event = this.events[eventName];
event && event.forEach(callback => callback.call(null, args));
}
@an-parubets
an-parubets / EventEmitterUnsubscribe.js
Last active December 21, 2019 15:19
EventEmitter
/**
* @param {string} eventName
* @param {Function} callback
*/
unsubscribe(eventName, callback) {
this.events[eventName] = this.events[eventName].filter(eventCallback => callback !== eventCallback);
}
@an-parubets
an-parubets / EventEmitterSubscribe.js
Last active December 21, 2019 15:42
EventEmitter
/**
* @param {string} eventName
* @param {Function} callback
*/
subscribe(eventName, callback) {
!this.events[eventName] && (this.events[eventName] = []);
this.events[eventName].push(callback);
}
@an-parubets
an-parubets / EventEmitterEmptyClass.js
Last active December 21, 2019 12:50
EventEmitter
class EventEmitter {
constructor() {
this.events = {};
}
subscribe() {}
unsubscribe() {}
emit() {}
}
@an-parubets
an-parubets / .bash_profile
Created May 27, 2019 18:50
Bash profile with git brach
export PATH="/usr/local/opt/openssl/bin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
export EDITOR=/usr/bin/nano
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "