Skip to content

Instantly share code, notes, and snippets.

@alizhdanov
alizhdanov / uuid.js
Last active October 3, 2017 15:28
Fast and easy way to make unique id
Math.random().toString(36).slice(2)

Regexp - шпаргалка

Синтаксис для создания

var regexp = new RegExp("шаблон", "флаги");
// or
var regexp = /шаблон/; // без флагов
var regexp = /шаблон/gmi; // с флагами gmi
@alizhdanov
alizhdanov / sequence.js
Last active October 6, 2017 11:10
Generate array sequence (ES6)
[...Array(N).keys()] // will generate array sequence with N length
// example
[...Array(5).keys()] // [0,1,2,3,4]
// Don't hesitate to use map if you need array started from some specific index
[...Array(5).keys()].map(i => i+1) // [1,2,3,4,5]
// Also You can create some fancy util function
const getSequnce = (n, offset=0) => {
@alizhdanov
alizhdanov / toArray.js
Created October 19, 2017 15:55
Nodelist (HTMLCollection) to Array
// All credits and inspiration from this article https://hackernoon.com/htmlcollection-nodelist-and-array-of-objects-da42737181f9
const nodelist = document.querySelectorAll('.articles');
// Array.from method
// not supporting IE, Safari >= 9, probably will require pollyfill in your project
const array = Array.from(nodelist)
// Array.prototype.slice
// if i'm right browser support for this method even better than for HTMLColections, no pollyfils bro
import Util from './src/util'
const Default = {
toggle : true,
parent : ''
}
class Collapse {
constructor(element, config) {
this._isTransitioning = false
@alizhdanov
alizhdanov / addEventListener.js
Last active October 23, 2017 11:48
addEventListener once - cross browser
// Regular version - unfortunately supported only by very lates browsers (chrome 60+, ff 55+, edge 16+, safari 10.1+)
el.addEventListener('eventName', fn, {once: true})
// decision - working everywhere
el.addEventListener('eventName', function cb(event) {
// function code here
event.currentTarget.removeEventListener(event.type, cb)
})
@alizhdanov
alizhdanov / Content.js
Created November 8, 2017 09:18
Render vue components from string
// IF you need render from string in vue
// The beset example is a blog post, where your content are recieving from a server and you don't have control of it.
import Vue from 'vue';
import CustomComponent1 from './CustomComponent1.vue'
import CustomComponent2 from './CustomComponent1.vue'
export default {
props: ['res'],
@alizhdanov
alizhdanov / bash.sh
Created November 9, 2017 14:14
Set environment variables
// to set/create variable use export
export NODE_ENV=development
// to get variable use echo and $ prefix
echo $NODE_ENV
// will return 'development'
@alizhdanov
alizhdanov / Events.md
Last active November 14, 2017 11:18
React docs cheat sheat

Handling Events

  • React events are named using camelCase, rather than lowercase.
  • With JSX you pass a function as the event handler, rather than a string.
<button onClick={activateLasers}>
  Activate Lasers
</button>
@alizhdanov
alizhdanov / State.md
Created November 16, 2017 15:29
Vuex cheat sheet

STATE

  • Inside store
state: {
  count: 0
}