Skip to content

Instantly share code, notes, and snippets.

@QueueHammer
QueueHammer / promise.js
Created April 17, 2018 05:23
Better Promise
const fs = require('fs');
const http = require('http');
getConfig()
.then(getWeather)
.then(workWithResult)
function getConfig () {
return new Promise((resolve, reject) => {
fs.readFile('./config.json', 'utf8', (err, data) => {
@QueueHammer
QueueHammer / asynchronous.js
Last active April 17, 2018 02:51
Asynchronous Example
const fs = require('fs');
const http = require('http');
fs.readFile('./config.json', 'utf8', (err, data) => {
if (err) { throw err; }
var cfg = JSON.parse(data);
var query = Object.keys(cfg.apiData)
.map(key => [key, cfg.apiData[key]].join('='))
.join('&');
@QueueHammer
QueueHammer / synchronous.js
Created April 16, 2018 22:47
Synchronous Example
const fs = require('fs');
const request = require('sync-request');
var cfg = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
var query = Object.keys(cfg.apiData)
.map(key => [key, cfg.apiData[key]].join('='))
.join('&');
var res = request('GET', `${cfg.apiUrl}?${query}`);
@QueueHammer
QueueHammer / isMax-and-isMin-Date.js
Last active December 27, 2020 21:55
Creation of a isMaxDate and isMinDate for the Date object in JavaScript.
//Inspired by http://stackoverflow.com/a/11526569/46810
(function () {
//Max possible value for Date() +/- of 0
var max = 8640000000000000;
Object.defineProperties(Date.prototype, {
isMaxDate: {
get: function () { return this.valueOf() === max; }
},
isMinDate: {
get: function () { return this.valueOf() === -max; }
(function () {
if(window.console) { return; }
var newConsole = {};
function noop() {};
//First class logging attributes
(['assert', 'count', 'dir', 'error', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'table', 'time', 'timeEnd', 'trace', 'warn'])
.forEach(function (key) {
newConsole[key] = noop;
});
angular.module('index', ['data'])
.controller('IndexController', ['routeList', function (routeList) {
//*
routeList.getAjaxData(function (data) {
this.routeList = routeList.sort(data);
});
/*/
this.get = function () {
//routeList.getAjaxData();
this.routeList = routeList.getAjaxData();