Skip to content

Instantly share code, notes, and snippets.

View john-doherty's full-sized avatar
🎯
Focusing

John Doherty john-doherty

🎯
Focusing
View GitHub Profile
@anandsunderraman
anandsunderraman / arrayToCSV.js
Created September 23, 2019 20:16
Robo 3T array to csv
//function to print CSV from an array for robomongo
//place this in .robomongorc.js which should be present in your home directory
//inspired by https://github.com/Studio3T/robomongo/wiki/How-to-export-to-CSV
function toCSV(array) {
let deliminator = ',';
let textQualifier = '\"';
let headers = [];
var data = {};
var count = -1;
@sarthology
sarthology / regexCheatsheet.js
Created January 10, 2019 07:54
A regex cheatsheet 👩🏻‍💻 (by Catherine)
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"
@alexellis
alexellis / README.md
Last active May 23, 2019 07:24
OpenFaaS Cloud Community Cluster instructions
@benoitv-code
benoitv-code / index.js
Last active November 13, 2022 18:21
d3, jsdom, node.js: server-side rendering
// Instructions:
// npm install --save d3 jsdom
const fs = require('fs');
const d3 = require('d3');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const fakeDom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
@manix
manix / sample.js
Last active March 1, 2024 23:51
Improved "fieldSorter"
function fieldSorterOptimized(fields) {
var dir = [], i, l = fields.length;
fields = fields.map(function(o, i) {
if (o[0] === "-") {
dir[i] = -1;
o = o.substring(1);
} else {
dir[i] = 1;
}
return o;
@ziluvatar
ziluvatar / token-generator.js
Last active April 11, 2024 07:10
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');
// https://webreflection.medium.com/using-the-input-datetime-local-9503e7efdce
Date.prototype.toDatetimeLocal =
function toDatetimeLocal() {
var
date = this,
ten = function (i) {
return (i < 10 ? '0' : '') + i;
},
YYYY = date.getFullYear(),
MM = ten(date.getMonth() + 1),
@mattbell87
mattbell87 / datetime-js.md
Created July 15, 2016 01:12
Setting the current date and time on a HTML5 date or datetime field with Javascript

Setting the current date and time on a HTML5 date or datetime field with Javascript

By default date.toISOString returns UTC time instead of local time. So you'll need to calculate the timezone offset first.

//Get the local date in ISO format
var date = new Date();
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
var datestr = date.toISOString().substring(0, 10);
@Montoya
Montoya / fileStorage.js
Last active February 2, 2020 20:26 — forked from rally25rs/fileStorage.coffee
Cordova File API Wrapper
/* modified from https://codingwithspike.wordpress.com/2014/12/29/using-deferreds-with-the-cordova-file-api/ */
/* requires rsvp.js */
/* tested and working in iOS and Android on latest Cordova (5.2.0) and File plugin (4.0.0) */
/* uses dataDirectory which is not synced to iCloud on iOS. You can replace each reference to syncedDataDirectory, but then you will need to set cordova.file.syncedDataDirectory = cordova.file.dataDirectory on Android to maintain compatibility */
window.fileStorage = {
write: function (name, data) {
var name_arr = name.split('/');
var name_index = 0;
@nhagen
nhagen / PromisAllWithFails.js
Last active November 15, 2022 18:11
Wait until all promises have completed even when some reject, with Promise.all
var a = ["sdfdf", "http://oooooolol"],
handleNetErr = function(e) { return e };
Promise.all(fetch('sdfdsf').catch(handleNetErr), fetch('http://invalidurl').catch(handleNetErr))
.then(function(sdf, invalid) {
console.log(sdf, invalid) // [Response, TypeError]
})
.catch(function(err) {
console.log(err);
})