Skip to content

Instantly share code, notes, and snippets.

View js2me's full-sized avatar
🚙
I may be slow to respond.

Sergey S. Volkov js2me

🚙
I may be slow to respond.
View GitHub Profile
@js2me
js2me / dom_helpers.js
Last active November 5, 2018 21:48
compact dom helper
import _ from 'lodash'
const dom = (query, asArray) =>
document[`querySelector${asArray ? 'All' : ''}`](query)
/*
dom.new('a', {
text: 'Click me!',
attrs: {
@js2me
js2me / pretty-colors.less
Created December 26, 2018 14:23
Nice implementation of the mixin which will generate child classes with colors. This file will create many count of color classes (.blue-grey, blue-grey-lighten-1, blue-grey-text-lighten )
// MIXIN
.make-sub-colors(@colors, @prefix) {
.sub-color(@index) when (@index =< length(@colors)) {
@value: extract(@colors, @index);
@item: ~".@{prefix}-@{index}";
&@{item} {
color: @value !important;
}
.sub-color(@index + 1);
@js2me
js2me / uuid.js
Last active August 16, 2019 04:11
Random max safe integer number
export function uuid(a) {
return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuid);
}
@js2me
js2me / generatePassword.js
Created February 3, 2019 23:05
Generate hard password with using JavaScript <3
export const generatePassword = (
length = 16,
stringWithChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'
) => {
var pass = ''
const chars = stringWithChars.split('')
for (var j = 0; j < length; j++) {
pass = pass + chars[Math.floor(Math.random() * (chars.length - 1 + 1))]
}
return pass
@js2me
js2me / reducer_helpers.js
Last active February 3, 2019 23:07
Reducer helpers
import _ from 'lodash'
import { createActions as createReduxActions } from 'redux-actions'
// That is simple functions (getFromStorage -> (key, fromSession) => window[fromSession ? 'sessionStorage' : 'localStorage'].getItem(key)
import { getFromStorage, saveToStorage } from './storage'
const convertStringToReduxPath = str => _.upperCase(str).replace(/ /g, '_')
export const createReducer = (map, name, modificator) =>
_.reduce(
map,
@js2me
js2me / shape-divider.svg
Created February 18, 2019 12:41
shape divider
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@js2me
js2me / size-mixin.scss
Created April 8, 2019 11:26
Size mixin needed to combine a couple css property into one or it can have name - square
@mixin size($size) {
height: $size;
width: $size;
}
@js2me
js2me / placeholder-mixin.scss
Created April 8, 2019 11:27
Mixin for mystery css property ::placeholder
@mixin placeholder() {
&::-webkit-input-placeholder,
&::-moz-placeholder,
&:-ms-input-placeholder,
&:-moz-placeholder,
&::placeholder {
@content;
}
}
@js2me
js2me / unixTimeToDate.js
Created April 18, 2019 09:57
convert unix time to date
/**
* @name unixTimeToDate
*
* @param {number} unixTimeStamp
* @param {boolean} fromNow = add current time to unix timestamp
*
* @returns {Date} JavaScript Date type
*/
export const unixTimeToDate = (unixTimeStamp, fromNow = false) =>
// store.js
import { StonexStore } from 'stonex'
import modules from './modules'
const store = new StonexStore(modules)