Skip to content

Instantly share code, notes, and snippets.

View dinigo's full-sized avatar

Daniel Iñigo dinigo

View GitHub Profile
  1. Dependencies
  • brew: run /usr/bin/ruby -e "$(curl -fsSL"
  • node and npm: run brew install node npm
  1. Download the script
  2. Give permissions to run chmod +x
  3. Run ./
  4. Trust the cert
  • Run open ~/.config/ssl
  • Double click the cert
  • Double click the cert inside keychain
dinigo /
Last active December 18, 2017 17:35
Basic Assert in javascript ES5 (syntax) for Appscript


Assert.true(true,'This is truthful');
Assert.true(false,'This is truthful');
Assert.false(false,'This is a lie');
Assert.false(true,'This is a lie');
Assert.equals(typeof 'hola', 'string', 'This variable contains a message');
Assert.equals(typeof 3, 'string', 'This variable contains a message');


dinigo /
Last active December 14, 2017 23:44
Cache requests instead of firing them to the API

Cached Runner

Receives a period of time and a request function, and performs all async operations to get the data. If you retry the request in a time shorter than the period it returns the cached result instead.

You can also set a postprocess function and another function that runs every time.

Simple example


const simpleCahedRun = new CachedRun(2500, ()=>Math.random());
dinigo /
Last active November 30, 2017 10:12
Basic scheduler for google cloud functions


It's not trivial to deploy a cron scheduler on Google Cloud. Here I purpose a simple way to prototype it. Since most part of tasks will only need a basic frequency trigger the hourly / daily / weekly / monthly percision will suffice.

1. Create the Appscript on Google Drive

Just drop the code insdie a freshly created appscript project. Name the project with an easily recognizable name since Google Drive doesn't let you filter by appscript file type.

2. Add the triggers

dinigo / requester.js
Created November 17, 2017 14:32
Request rate limiter mok implementation.
// libs
const request = require('request');
const {RateLimiter} = require('limiter');
// config
const pool = {maxSockets: 100};
const url = '';
const numRequests = 10000;
const requestLimit = 5000;
const limiter = new RateLimiter(requestLimit, 'hour');
dinigo / primes.js
Last active November 15, 2017 09:44
Calculate primes till certain number, checking against the already calculated, and only with the ones higher than the sqrt
function primes(max) {
let calculated = [1, 2, 3]; // already calculated primes
let num = 4; // current number being checked
let factors; // factors for the given number
let sqrt; // sqrt for a given number
// if the input is too low to be calculated, just return the default primes
if (max < 5) return calculated;
// otherwhise calculate for each number till you reach max
while (num < max) {
// discard even numbers
dinigo /
Created October 3, 2017 08:18
Add user to Airflow
# This little script creates users in an airflow instance so it can be open to the public.
# It gets the password in plain text so be careful where you run it.
# You can properly invoke the script as follows:
# ./ <username> <> <secretpassword>
import airflow, sys
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
var url = new URL(document.referrer)
console.log("Check refferer and redirect: " + document.referrer);
if(url.pathname === '/customer/account/create/'){
console.log("Redirecting to post-register form");
window.location.href = '/post_register';
function searchAndInsert(node, trigger, name) {
var results = [];
if (node == {})
return false;
for (child in node) {
for (t of trigger) {
console.log('child', child, 'trigger', t);
if (child == t && !child[name]) {
//console.log('node', node, 'child(trigger)', node[child],'name', child[name])
node[child][name] = {};
dinigo / difference
Last active February 3, 2017 09:41
Script para calcular altas y bajas para el DMP
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
base_file <- paste0(getwd(),'/',args[1])
delta_file <- paste0(getwd(),'/',args[2])
altas_file <- paste0(getwd(),'/',args[3])
bajas_file <- paste0(getwd(),'/',args[4])
cat('cargando base... \n');
base <- read.csv(base_file,sep=',',header=FALSE)