Skip to content

Instantly share code, notes, and snippets.

@andrIvash
andrIvash / test-task.js
Last active November 29, 2017 21:01
js-samples
function func (...arg) {
return (init) => {
return arg.reduce((res, fn) => {
return fn(res)
}, init);
}
}
var summ = func((a) => a+1, (b)=> b+2,(c) => c+3)(2);
@andrIvash
andrIvash / createStore.js
Created November 23, 2017 20:57
createStore
const createStore = (reducer) => {
let state;
let listeners = [];
const getState = () => state;
const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener());
}
@andrIvash
andrIvash / package.json
Last active November 20, 2017 16:15
webpack config
{
"name": "webpack-workshop",
"version": "1.0.0",
"scripts": {
"server": "node ./server/index.js",
"build": "cross-env NODE_ENV=production webpack",
"dev": "webpack-dev-server --hot --inline"
},
"private": true,
"devDependencies": {
@andrIvash
andrIvash / paginate.js
Last active November 10, 2017 19:51
pagination
class getApiDataList {
constructor (url, indexProp, sizeProp, options = {}) {
this.options = options;
this.indexProp = indexProp;
this.sizeProp = sizeProp;
this.mainUrl = new URL(url);
this.params = new URLSearchParams(this.mainUrl.search);
this._index = +this.params.get(this.indexProp);
}
@andrIvash
andrIvash / .travis.yml
Created November 10, 2017 18:35
travis base configuration
language: node_js
node_js:
- 6
os: linux
install:
- yarn install
script:
- yarn test
- yarn build
cache:
@andrIvash
andrIvash / node-sample.js
Last active August 5, 2018 10:27
get battery info with node.js
const http = require('http');
const PORT = Number(process.argv[2]) || 8080;
const child_process = require('child_process');
const Routes = {
BATTERY: /\/battery\/?/
};
const Status = {
NOT_FOUND: 404,
/**
* Resolves a Promise after a specified amount of time.
*
* @param {number} delay Milliseconds to wait before resolving.
* @param {any} value Argument to be resolved by this Promise.
*
* @return {Promise} Promise which will be resolved after passed time.
*
* @example
* const delay = require('nanodelay')
@andrIvash
andrIvash / n-decl.html
Last active November 3, 2017 18:38
N-decl custom element. Plural-rules of the data view.
<!--
made under the impression of the idea - https://github.com/tc39/proposal-intl-plural-rules
Writed by Andriy Ivashchenko
-->
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
@andrIvash
andrIvash / email.js
Created October 3, 2017 18:22
email regexp
// HTML5 input type=email regexp
const emailRegexp = /^[a-zа-я0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zа-я0-9-]+(?:\.[a-zа-я0-9-]+)+$/i;
console.log('--- ', emailRegexp.test('text@yandex.ru'));
@andrIvash
andrIvash / array_promise.js
Created August 31, 2017 18:10
Array of promises
function fetchUserDetails(arr) {
return arr.reduce(function(promise, elem) {
return promise.then(function() {
return db.getUser(email).done(function(res) {
logger.log(res);
});
});
}, Promise.resolve());
}