Skip to content

Instantly share code, notes, and snippets.

View vaidd4's full-sized avatar

David vaidd4

  • France
View GitHub Profile
@vaidd4
vaidd4 / StringifyDuration.js
Last active November 29, 2017 11:49
Simple durations stringifier for Moment.js
/**
* Simple durations stringifier for Moment.js
* Return a human readable string representing the given moment duration
* Based on @cogwirrel comment (https://github.com/moment/moment/issues/348#issuecomment-346233713)
*
* TODO:
* - Add simple lang support (fr, en)
*/
function stringifyDuration (duration) {
@vaidd4
vaidd4 / checkDeepObject.js
Last active August 31, 2017 09:46
A function to make deep checking on objects
/**
* Run a simple check on every attribute of an object
* It returns true if any attribute (non object) passes the test function
*/
function checkDeep(obj, fun) {
for (let k in obj) {
if (!obj.hasOwnProperty(k)) continue
if (Array.isArray(obj[k])) {
if (obj[k].some(fun))
@vaidd4
vaidd4 / xblihapi.js
Last active April 25, 2019 08:15
eXtended Blih API project
/**
* This is a proxy for making w3c compliant requests to the EPITECH's BLIH API.
* It allows to make such calls fron any w3c compliant source (e.g. XHR requests).
* The proxy uses https for security reasons.
* To check BLIH API status simply make a GET request on '/'.
*
* TODO:
* - Add endpoint showing every endpoint available (API documentation).
*/
@vaidd4
vaidd4 / ConsoleWatch.js
Last active March 22, 2018 13:45
A console.watch() implementation
/**
* Watch for object properties
* you can log on each property change and even add a breakpoint
*/
function consoleWatch (oObj, sProp) {
let sPrivateProp = `_${sProp}_$`
oObj[sPrivateProp] = oObj[sProp]
Object.defineProperty(oObj, sProp, {
get: () => { return oObj[sPrivateProp] },
set: value => {
@vaidd4
vaidd4 / DocumentLog.js
Last active July 18, 2017 13:33
A document.log() implementation
/**
* Add a 'pre' tag, with a specified id, to the page and log the arguments passed to it
*
* WIP:
* - support array & object deep log
* - option to log in console (last parameter)
*/
function documentLog (...arg) {
if (!arg || !arg.length) return
if (!((typeof arg[0]) === 'string')) return