Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Iñigo dinigo

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

Example:

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');

Result:

@dinigo
dinigo / README.md
Last active Dec 14, 2017
Cache requests instead of firing them to the API
View README.md

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

Usage

const simpleCahedRun = new CachedRun(2500, ()=>Math.random());
@dinigo
dinigo / README.md
Last active Nov 30, 2017
Basic scheduler for google cloud functions
View README.md

PURPOSE

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 appscript.gs 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
dinigo / requester.js
Created Nov 17, 2017
Request rate limiter mok implementation.
View requester.js
// libs
const request = require('request');
const {RateLimiter} = require('limiter');
// config
const pool = {maxSockets: 100};
const url = 'http://google.com';
const numRequests = 10000;
const requestLimit = 5000;
const limiter = new RateLimiter(requestLimit, 'hour');
@dinigo
dinigo / primes.js
Last active Nov 15, 2017
Calculate primes till certain number, checking against the already calculated, and only with the ones higher than the sqrt
View primes.js
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
dinigo / add_user.py
Created Oct 3, 2017
Add user to Airflow
View add_user.py
#!/usr/bin/python
# 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:
# ./add_user.py <username> <user@email.com> <secretpassword>
import airflow, sys
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
View custom.js
if(document.referrer){
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';
}
}
View tree.js
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
dinigo / difference
Last active Feb 3, 2017
Script para calcular altas y bajas para el DMP
View difference
#!/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)