Skip to content

Instantly share code, notes, and snippets.

@ColtHands
ColtHands / vue-click-outside-component.js
Last active August 16, 2020 18:23
Vue click outside component
Vue.directive('click-outside-component', {
bind(el, binding, vnode) {
el.clickOutsideEvent = function(event) {
if (!(vnode.context.$el == event.target || vnode.context.$el.contains(event.target))) {
vnode.context[binding.expression](event)
}
}
document.body.addEventListener('click', el.clickOutsideEvent)
},
unbind(el) {
@ColtHands
ColtHands / vue-click-outside-element.js
Created August 16, 2020 18:25
Vue click outside element directive
Vue.directive('click-outside-element', {
bind(el, bind, vn) {
el.cO = event => {
if (!(el == event.target || el.contains(event.target))) {
if(vn.context[bind.expression]) {
vn.context[bind.expression](event)
}
}
}
document.body.addEventListener('click', el.cO)
@ColtHands
ColtHands / react-click-outside-component.jsx
Created August 16, 2020 18:55
React click outside of component
componentDidMount() {
document.addEventListener('click', this.clickOutside.bind(this), true);
}
componentWillUnmount() {
document.removeEventListener('click', this.clickOutside.bind(this), true);
}
clickOutside(event) {
const domNode = ReactDOM.findDOMNode(this);
@ColtHands
ColtHands / ogrn-array.json
Last active November 3, 2021 16:14
Ogrn array
[
526017964561,
525608647855,
526013197030,
526017918501,
526013196478,
526200201544,
526200024126,
526014627350,
526006502928,
@ColtHands
ColtHands / README.md
Last active September 16, 2020 22:15
jQuery to Vanilla.js

jQuery to Vanilla.js

Selecting elements

$("selector")

  • document.querySelector('#id')
  • document.querySelectorAll('.class > ul li')
  • document.getElementById('id')
  • document.getElementsByClassName('class')
@ColtHands
ColtHands / GitSnippets.md
Last active July 10, 2023 10:56
Git Snippets

Git Snippets

How to remove file that was added to .gitignore after it was commited.

git rm {file_name} --cached

How to add changes to previous not pushed commit.

git commit --amend --no-edit

@ColtHands
ColtHands / JS RegExp Snippets.md
Last active September 9, 2022 13:26
JS RegExp Snippets

JS RegExp Snippets

Match a string between two characters

(?<=\+)(.*)(?=\@) will match world in [email protected]

  1. start at + with (?<=\+)
  2. select all characters with (.*)
  3. end at @ with (?-\@)

Match the string exactly

@ColtHands
ColtHands / reactive.js
Created September 11, 2023 11:07 — forked from 1Marc/reactive.js
Vanilla Reactive System
// Credit Ryan Carniato https://frontendmasters.com/courses/reactivity-solidjs/
let context = [];
export function untrack(fn) {
const prevContext = context;
context = [];
const res = fn();
context = prevContext;
return res;