Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View gouegd's full-sized avatar

Gregory Desfour gouegd

  • Canva
  • Auckland, NZ
View GitHub Profile
@gouegd
gouegd / bindingProxy.js
Created October 25, 2016 20:13
Use ES6 Proxy to bind functions en masse
/**
Say you have some methods in an object, and they rely on the context (this).
If you want to use them providing context, you typically would use Function.prototype.bind, apply or call
(maybe storing the bound methods in a new object, going through all the methods).
ES6 Proxies (only available on Node as I write this) provide an alternative to building a second object,
while still not having to pass the context on every call.
Is it better ?
Memory-wise, I'd say yes (though a hash of bound methods should seldom be a memory issue).
@gouegd
gouegd / remoteLinesToJsonArray.js
Created January 18, 2016 11:03
Grab the HTTPS URL passed as 1st arg, and outputs it as a JSON array, each element representing a line of the response.
#!/usr/bin/env node
"use strict";
const https = require('https');
const linesToJsonArray = data => console.log(JSON.stringify(data.split('\n'), null, 2));
const firstArg = process.argv[2];
const url = firstArg ? firstArg.trim() : null;
if (!url || !url.startsWith('https://')) {
console.error('Please pass an HTTPS URL, with the protocol, as the 1st argument');
@gouegd
gouegd / get URLs
Last active August 29, 2015 14:08 — forked from spennyf/get URLs
Parse.Cloud.job("saveCurrentDayItems", function(request, response) {
var utcDate = new Date();
var utcHour = utcDate.getHours();
utcDate.setHours(utcHour-4);
var currentDate = utcDate;
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
//var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];