Skip to content

Instantly share code, notes, and snippets.

Tim Evko tevko

Block or report user

Report or block tevko

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
View formatDuration.js
function formatDuration (seconds) {
if (seconds === 0) {
return 'now';
const dif = seconds * 1000;
const difSeconds = Math.floor(dif / 1000) % 60;
const difMinutes = Math.floor(dif / 60000) % 60;
const difHours = Math.floor(dif / 3.6e+6) % 24;
const difDays = Math.floor(dif / 8.64e+7) % 365;
const difYears = Math.floor(dif / 3.154e+10);
View Math Problem
Let's say I have an array of 8 objects. Each object represents a task which can be completed multiple times.
In this case, the goal is to complete each task as many times as possible, until the allotted time per task is up
and I must move on to the next task. Let's also say that I have a total of ten minutes (600 seconds) to spend on
all tasks combined. Using javascript, how can I assign a random number of seconds (no less than 45, assuming each
task takes a minimum of 45 seconds to complete once) to each object so that the combined total of seconds adds up
to exactly 600? In other words, how do I split 600 into 8 random numbers where each random number is >= 45, and
all combined numbers add to 600?
View install.js
self.addEventListener('install', function(event) {
// Perform install steps
.then(function(cache) { {
var request = new Request(url, {mode: 'no-cors'});
fetch(request).then(function(response) {
return {
tevko / romanNumeralMap.js
Created Jun 2, 2016
Roman Numeral Map Javascript
View romanNumeralMap.js
const rm = new Map([
['I', 1],
['II', 2],
['III', 3],
['IV', 4],
['V', 5],
['VI', 6],
['VII', 7],
['VIII', 8],
['IX', 9],
tevko / supportsCreateElement.js
Last active Feb 2, 2016
Elements on document supporting document.createElement
View supportsCreateElement.js
Array.apply(null, document.querySelectorAll('*')).map(function(e, i, a) {
var message;
try {
message = e.nodeName + ' supports document.createElement';
} catch (e) {
message = e.nodeName + ' does not support document.createelement';
return message
tevko / findParentAttribute.js
Created Jan 16, 2016
traverse dom upwards to find an element by it's data attribute
View findParentAttribute.js
var findParentAttribute = function(id, ctx) {
if (ctx.hasAttribute(id)) {
return ctx.getAttribute(id);
} else {
return this.findParentAttribute(id, ctx.parentElement)
return false
findParentAttribute('foo', document.querySelector('div').parentElement) // will traverse dom to find parent element with data attribute
tevko / bitwise_indexof.js
Created Jan 15, 2016
Bitwise Operator and indexOf on strings
View bitwise_indexof.js
// "Bitwise operators perform their operations on such binary representations, but they return standard JavaScript numerical values."
//It transforms -1 into 0, and 0 is false in javascript, so:
var someText = 'text';
!!~someText.indexOf('tex'); //sometext contains text - true
!~someText.indexOf('tex'); //sometext not contains text - false
~someText.indexOf('asd'); //sometext contains asd - false
~someText.indexOf('ext'); //sometext contains ext - true
tevko / Custom_Events_Everywhere.js
Created Nov 10, 2015
A custom Events utility that works in IE9 and everywhere else
View Custom_Events_Everywhere.js
var trigger = function trigger(eventName, elem, data) {
var evt;
data = data || undefined;
try {
evt = new CustomEvent(eventName, {detail: data});
} catch (e) {
evt = document.createEvent('CustomEvent');
evt.initCustomEvent(eventName, true, true, data);
tevko / respsizes.js
Last active Jan 31, 2016
Dev Tools Snippet to auto-calculate responsive image sizes value on window resize
View respsizes.js
* Paste image class / identifier in IIFE parenthesis at end of function
* */
(function(i){"use strict";var img=$(i),sizes=[];window.addEventListener("resize",()=>{var vw=Math.round(((img.offsetWidth*100)/window.innerWidth))+"vw",mq="(min-width: "+window.innerWidth+"px)",value=vw;vw!=="0vw"&&sizes.indexOf(vw)===-1&&(sizes.push(value),console.log(mq,vw))})})("PASTE CLASS OR IDENTIFIER HERE");
View responsive table html
<table class="data-table account_dashboard_orderTable" id="my-orders-table">
<colgroup><col width="1">
<col width="1">
<col width="105">
<col width="1">
<col width="150">
<tr class="first last">
<th>Order # </th>
You can’t perform that action at this time.