Skip to content

Instantly share code, notes, and snippets.

Dan Kerimdzhanov kerimdzhanov

Block or report user

Report or block kerimdzhanov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kerimdzhanov
kerimdzhanov / Random-string
Created Apr 9, 2018 — forked from 6174/Random-string
Generate a random string in JavaScript In a short and fast way!
View Random-string
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
@kerimdzhanov
kerimdzhanov / README.md
Created Jan 4, 2018
Redux Query Middleware – Automatically add request headers using custom network interface interceptor.
View README.md

Example Usage

You need to have the following in your initialization file (index.js or redux/index.js):

...
import {createStore, combineReducers, applyMiddleware, compose} from 'redux';
import {entitiesReducer, queriesReducer} from 'redux-query';
import reduxQueryMiddleware from './middleware/reduxQuery';
@kerimdzhanov
kerimdzhanov / 001_getting_started.md
Last active Dec 3, 2017
VPS Deployment Instructions
View 001_getting_started.md

Prerequisites

  • A working Debian/Ubuntu Linux instance

Preparing the deployment server

After creating a VPS drop/node, login as root and update a newly installed system:

$ ssh root@12.34.56.78
@kerimdzhanov
kerimdzhanov / next-second.js
Last active Oct 16, 2018
Executes a given `fn` at the beginning of the next second
View next-second.js
/**
* Executes a given `fn` at the beginning of the next second.
* @param {function} fn – a function to execute
* @return {number} setTimeout's resulting timeout id, to give ability to cancel execution
*/
function nextSecond(fn) {
const time = (new Date()).getTime();
return setTimeout(fn, (Math.ceil(time / 1000) * 1000) - time);
}
@kerimdzhanov
kerimdzhanov / mocha.conf.js
Last active Aug 3, 2018
Setup mocha/chai.js/sinon stack w/ es6 features
View mocha.conf.js
const chai = require('chai');
// globalize sinon
global.sinon = require('sinon');
// initialize chai plugins
chai.use(require('sinon-chai'));
chai.use(require('chai-as-promised'));
chai.use(require('chai-datetime'));
@kerimdzhanov
kerimdzhanov / async-each-promise.js
Last active Jan 11, 2017
Iterate through an array asynchronously one by one using the ES6 promises
View async-each-promise.js
const array = []; // array to iterate
const promise = array.reduce((p, entry) => {
p.then(() => {
return new Promise((resolve, reject) => {...});
});
}, Promise.resolve());
promise
.then(() => console.log('done!'))
@kerimdzhanov
kerimdzhanov / chaijs-cheatsheet.js
Last active Jul 6, 2016
Chai.js expectations cheatsheet
View chaijs-cheatsheet.js
// instead of using `expect(object).to.exist`, assert things
// through `.to.be.a(type)` which make failures more informative
expect(result).to.be.an('object')
.that.includes({
foo: 'bar',
baz: 'quux'
});
// to assert property value types i.e. date:
expect(result)
@kerimdzhanov
kerimdzhanov / custom-error.js
Last active May 6, 2016 — forked from justmoon/custom-error.js
Creating custom Error classes in Node.js
View custom-error.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
View sum-big-numbers.js
/**
* Sum two big numbers given as strings.
*
* @param {string} a
* @param {string} b
* @return {string}
*/
function sumStrings(a, b) {
var zrx = /^0+/; // remove leading zeros
a = a.replace(zrx, '').split('').reverse();
@kerimdzhanov
kerimdzhanov / polling-callback.js
Last active Aug 29, 2015
Javascript polling functions
View polling-callback.js
// The polling function
function poll(fn, callback, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
(function p() {
// If the condition is met, we're done!
if (fn()) {
callback();
}
You can’t perform that action at this time.