Skip to content

Instantly share code, notes, and snippets.

View garystorey's full-sized avatar
:octocat:

Gary Storey garystorey

:octocat:
View GitHub Profile
@garystorey
garystorey / starrating.js
Created June 10, 2022 04:46
Star Rating
/*
https://codepen.io/codercatdev/pen/eYVjxjK
*/
const rating = stars => `★★★★★☆☆☆☆☆`.slice(5 - stars, 10 - stars);
javascript:(function(d){d.designMode='on'})(document)
@garystorey
garystorey / arraySplitter.js
Last active August 16, 2018 19:26
Splits a given array <arr> into an array of arrays of <size> size. Ex: splitter([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
function splitter(arr,size) {
var i,j,temparray=[], splitarray=[];
for (i=0,j=arr.length; i<j; i+=size) {
temparray = arr.slice(i,i+size);
splitarray.push(temparray);
}
return splitarray;
}
@garystorey
garystorey / timeout.js
Created March 28, 2018 22:32
promise based timeout
/* https://github.com/github/fetch/issues/175 */
function timeout(ms, promise) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
reject(new Error("timeout"))
}, ms)
promise.then(resolve, reject)
})
}
DECLARE @current_date DATE = GETDATE()
SELECT EOMONTH (@current_date, 0) AS LastDayOfCurrentMonth
SELECT EOMONTH (@current_date, 1) AS LastDayOfNextMonth
SELECT EOMONTH (@current_date, -1) AS LastDayOfPrevMonth
(function(reComments, reParams, reNames) {
getParamNames = function(fn) {
return ((fn + '').replace(reComments, '').match(reParams) || [0, ''])[1].match(reNames) || [];
};
})(
/\/\*[\s\S]*?\*\/|\/\/.*?[\r\n]/g,
/\(([\s\S]*?)\)/,
/[$\w]+/g
);
function tableToArray(tbl, opt_cellValueGetter) {
opt_cellValueGetter = opt_cellValueGetter || function(td) { return td.textContent || td.innerText; };
var twoD = [];
for (var rowCount = tbl.rows.length, rowIndex = 0; rowIndex < rowCount; rowIndex++) {
twoD.push([]);
}
for (var rowIndex = 0, tr; rowIndex < rowCount; rowIndex++) {
var tr = tbl.rows[rowIndex];
for (var colIndex = 0, colCount = tr.cells.length, offset = 0; colIndex < colCount; colIndex++) {
var td = tr.cells[colIndex], text = opt_cellValueGetter(td, colIndex, rowIndex, tbl);
function diffDates(startDate, endDate) {
var t, multiplier = 1;
if (startDate > endDate) {
t = startDate;
startDate = endDate;
endDate = t;
multiplier = -1;
}
var millisTotal = endDate - startDate,
function maximizeFontSize(elem, maxWidth, maxHeight, opt_dontChangeFontSize) {
var canBeBigger,
display = elem.style.display,
fontSize = elem.style.fontSize,
font = elem.style.font,
computedFont = window.getComputedStyle(elem, null).getPropertyValue('font'),
doc = elem.ownerDocument,
parentNode = elem.parentNode,
tempParent = doc.createElement('div'),
nextSibling = elem.nextSibling,
function getVideoImage(path, secs, callback) {
var me = this, video = document.createElement('video');
video.onloadedmetadata = function() {
if ('function' === typeof secs) {
secs = secs(this.duration);
}
this.currentTime = Math.min(Math.max(0, (secs < 0 ? this.duration : 0) + secs), this.duration);
};
video.onseeked = function(e) {
var canvas = document.createElement('canvas');