Skip to content

Instantly share code, notes, and snippets.

View abyr's full-sized avatar
Getting things done

Oleksandr Denysenko abyr

Getting things done
View GitHub Profile
@abyr
abyr / str-pad.js
Created March 12, 2018 09:46
strPad - pad a string to a certain length with another string
/**
* Pad a string to a certain length with another string
* @param {String} input The input string
* @param {Number} padLength The length of result string
* @param {String} padStr The padding string
* @returns {String}
*/
function strPad(input, padLength, padStr) {
if (input.length < padLength) {
return strPad(padStr + input, padLength, padStr);
@abyr
abyr / react-image-fallback.js
Created November 9, 2017 13:52
React component for image with fallback source
import React from 'react';
import PropTypes from 'prop-types';
const ImageFallback = ({ src, fallbackSrc, ...other }) => {
let element;
const setFallbackSrc = () => {
element.src = fallbackSrc;
};
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function () {
var cache = {};
this.tmpl = function tmpl(str, data) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
;(function () {
function timeago(text) {
var now = new Date(),
yesterday,
date = new Date(text),
diff = (now.getTime() - date.getTime()) / 1000;
yesterday = new Date();
yesterday.setDate(now.getDate() - 1);
define(function(require) {
var Deferred = function () {
this.onDoneList = [];
this.onFailList = [];
this.execute = function (list, args) {
var len = list.length,
i = 0;
args = Array.prototype.slice.call(args);