Skip to content

Instantly share code, notes, and snippets.

View ColtHands's full-sized avatar
🐢
a turtle

Aleksei Karpenko ColtHands

🐢
a turtle
View GitHub Profile
@ColtHands
ColtHands / reactive.js
Created September 11, 2023 11:07 — forked from 1Marc/reactive.js
Vanilla Reactive System
View reactive.js
// 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;
@ColtHands
ColtHands / JS RegExp Snippets.md
Last active September 9, 2022 13:26
JS RegExp Snippets
View JS RegExp Snippets.md

JS RegExp Snippets

Match a string between two characters

(?<=\+)(.*)(?=\@) will match world in hello+world@mail.com

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

Match the string exactly

@ColtHands
ColtHands / GitSnippets.md
Last active July 10, 2023 10:56
Git Snippets
View GitSnippets.md

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 / README.md
Last active September 16, 2020 22:15
jQuery to Vanilla.js
View README.md

jQuery to Vanilla.js

Selecting elements

$("selector")

  • document.querySelector('#id')
  • document.querySelectorAll('.class > ul li')
  • document.getElementById('id')
  • document.getElementsByClassName('class')
@ColtHands
ColtHands / ogrn-array.json
Last active November 3, 2021 16:14
Ogrn array
View ogrn-array.json
[
526017964561,
525608647855,
526013197030,
526017918501,
526013196478,
526200201544,
526200024126,
526014627350,
526006502928,
@ColtHands
ColtHands / react-click-outside-component.jsx
Created August 16, 2020 18:55
React click outside of component
View react-click-outside-component.jsx
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 / vue-click-outside-element.js
Created August 16, 2020 18:25
Vue click outside element directive
View vue-click-outside-element.js
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 / vue-click-outside-component.js
Last active August 16, 2020 18:23
Vue click outside component
View vue-click-outside-component.js
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) {