Skip to content

Instantly share code, notes, and snippets.

View afuggini's full-sized avatar

Ariel Fuggini afuggini

View GitHub Profile
@afuggini
afuggini / functional.js
Last active June 12, 2020 00:21
Functional Helpers (In ES6 Syntax)
const map = f => step => (a, c) => step(a, f(c));
const filter = predicate => step => (a, c) => predicate(c) ? step(a, c) : a;
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x);
const curry = (f, arr = []) => (...args) => (
a => a.length === f.length ? f(...a) : curry(f, a)
)([...arr, ...args]);
@afuggini
afuggini / ttfb.sh
Created January 11, 2019 05:29 — forked from sandeepraju/ttfb.sh
curl command to check the time to first byte
#!/bin/bash
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -o /dev/null \
-H 'Cache-Control: no-cache' \
-s \
@afuggini
afuggini / weightedMean.js
Created September 9, 2018 04:35
Weighted mean (average) in Javascript ES6
const sumArrayValues = (values) => {
return values.reduce((p, c) => p + c, 0)
}
const weightedMean = (factorsArray, weightsArray) => {
return sumArrayValues(factorsArray.map((factor, index) => factor * weightsArray[index])) / sumArrayValues(weightsArray)
}
weightedMean([251, 360, 210], [0.1, 0.5, 0.7]);
// => 270.8461538461539
@afuggini
afuggini / choose_db.md
Last active January 4, 2024 15:57
How to choose a DB engine: NoSQL vs RDBMS
  • Volume of data
  • Scaling
  • Structure strictness (data schemas)
  • Query complexity
  • Type of data
  • Depth levels of data
@afuggini
afuggini / vpaid.js
Last active April 30, 2018 02:10
VPAID container class template
class VPAIDContainer {
constructor () {
// The slot is the div element on the main page that the ad is supposed to occupy
this._slot = null
// The video slot is the video object that the creative can use to render and video element it might have.
this._videoSlot = null
}
initAd (width, height, viewMode, desiredBitrate, creativeData, environmentVars) {
// slot and videoSlot are passed as part of the environmentVars
this._slot = environmentVars.slot
@afuggini
afuggini / background.js
Created February 11, 2018 15:29 — forked from danharper/background.js
Bare minimum Chrome extension to inject a JS file into the given page when you click on the browser action icon. The script then inserts a new div into the DOM.
// this is the background code...
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
// for the current tab, inject the "inject.js" file & execute it
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
});
@afuggini
afuggini / cookies.js
Created February 2, 2018 21:26 — forked from CrocoDillon/cookies.js
Export your awesome module using AMD, CommonJS, Node.js or just as global.
/*
* Inspiration (well… copy pasting more or less) from:
* https://github.com/ScottHamper/Cookies/blob/0.3.1/src/cookies.js#L127-L140
*
* Thanks Scott!
*/
(function (global) {
'use strict';
var MyModule = function () {
@afuggini
afuggini / wrapper.js
Created January 22, 2018 17:38
Sample VPAID Video player Interface Code
// This class is meant to be part of the video player that interacts with the Ad.
// It takes the VPAID creative as a parameter in its contructor.
var VPAIDWrapper = function (VPAIDCreative) {
this._creative = VPAIDCreative
if (!this.checkVPAIDInterface(VPAIDCreative)) {
//The VPAIDCreative doesn't conform to the VPAID spec
console.error('VPAIDCreative doesn\'t conform to the VPAID spec')
return
}
this.setCallbacksForCreative()
@afuggini
afuggini / defineProperty.js
Last active October 29, 2021 17:29
Object.defineProperty polyfill
/*!
* https://github.com/es-shims/es5-shim
* @license es5-shim Copyright 2009-2015 by contributors, MIT License
* see https://github.com/es-shims/es5-shim/blob/master/LICENSE
*/
// vim: ts=4 sts=4 sw=4 expandtab
// Add semicolon to prevent IIFE from being passed as argument to concatenated code.
;
@afuggini
afuggini / install
Last active May 13, 2017 02:47
Server Deploy
#!/bin/sh
# Install GIT
sudo yum install git-all
# Install NODE
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
yum install -y nodejs