Skip to content

Instantly share code, notes, and snippets.

View jfolds's full-sized avatar

Jeremy Folds jfolds

View GitHub Profile
@jfolds
jfolds / utils.js
Created November 18, 2019 22:30
Some utils
/**
*
* @param {object} obj data object to parse columns from
* parses columns from an object's keys
*/
export function parseColumns(obj) {
if (!obj) {
return null;
}
return Object.keys(obj).map(key => ({ title: key, data: key }));
@jfolds
jfolds / request-with-credentials.js
Created September 13, 2019 14:53
API request with credentials via fetch/xhr/jquery
const apiBaseUrl 'https://localhost/some/api';
/** fetch */
window.fetch(`${apiBaseUrl}`, {
credentials: 'include'
})
.then(json)
.then((data) => {
console.log(data);
});
/** XHR */
const timestamp = 1555624965730;
const timeCurrent = new Date().getTime();
const timeElapsed = Math.floor((tC - timestamp) / 1000 / 60); //get time elapsed
const timeSince = (tE > 60) ? Math.floor((tE * 60) / 3600) + ' hours ago' : tE + ' minutes ago';
@jfolds
jfolds / sort.js
Last active April 15, 2019 19:36
function sortData(data, column, direction) {
const sortedData = data.sort((a, b) => {
let val1 = a[column];
let val2 = b[column];
val1 = typeof val1 === 'string' ? val1.toUpperCase() : val1;
val2 = typeof val2 === 'string' ? val2.toUpperCase() : val2;
return (val1 < val2)
? -1
: 1
? (val1 > val2)
let template = '<h1>My name is {{name}}. This is a {{adjective1}} {{adjective2}} template!</h1>';
let model = {
name: 'Jeremy',
adjective1: 'super',
adjective2: 'awesome'
};
function _template(tmpl, data) {
for (var property in data) {
@jfolds
jfolds / loading-phrases.js
Created June 23, 2016 15:38
loading-messages
this.phrases = [
'Please wait: pay no attention to the man behind the curtain',
'Please wait: at least you\'re not on hold',
'Please wait: the server is powered by a lemon and two electrodes',
'Please wait: we\'re testing your patience',
'Please wait: while the satellite moves into position',
'My other loading screen is a Ferrari',
'Please wait: as if you had any other choice',
'Adding Hidden Agendas',
'Adjusting Bell Curves',