Skip to content

Instantly share code, notes, and snippets.

View corlaez's full-sized avatar
馃彔
WFH since January 2020

Armando Cordova corlaez

馃彔
WFH since January 2020
View GitHub Profile
@corlaez
corlaez / db.js
Created July 23, 2019 22:29
A mysql wrapper that will allow to make simple read operations
const mysql = require('mysql2')
const createConnection = (connectedCB) => {
const envParams = {
host: process.env.host,
user: process.env.user,
password: process.env.password,
database: process.env.database,
}
if (Object.keys(envParams).some(k => envParams[k] == null)) {
@corlaez
corlaez / gist:a626c74c86a692c19423e8b7acee2c2e
Created March 22, 2019 11:32
Increase inotify max_user_watches in unix
echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches && echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_queued_events && echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_instances
@corlaez
corlaez / README.md
Last active March 4, 2019 02:03
Serverless Api Test Client

Serverless Api Test Client

While working with zeit now serverless functions I needed to execute my apis locally (they connected to a db and processed the data) and see if they work correctly

This code allows you to execute any api and just logs or ignores the result of the api. Useful for manual checks but could be expanded to run automated tests as well.

What I like is that you can test any api just importing the api and instanciating a client. The requests are JavaScript objects and that makes it very natural and simple to read and write api tests.

The heart of the client creator is the createExecutor higher order function, that's the real MVP.

@corlaez
corlaez / README.md
Last active December 19, 2019 15:17
Flatten an Array!
@corlaez
corlaez / Main.java
Last active October 5, 2018 19:14
Understanding WeakMap with not interned Strings
import java.util.WeakHashMap;
import java.lang.ref.WeakReference;
class Main {
public static void main(String[] args) {
WeakHashMap map = new WeakHashMap<String, Integer>();
char[] arr = {'x'};
String x = new String(arr);
String x2 = new String(arr);
@corlaez
corlaez / empty-event.proto
Created June 11, 2018 16:31
How does an empty message looks like in protobuffers
syntax = "proto3";
package com.corlaez;
message EmptyEvent {
}
@corlaez
corlaez / cerebral-runkit.js
Created May 16, 2018 22:04
Cerebral on npm.runkit.com
var {Module, Controller, Provider} = require("cerebral")
var {state, signal} = require("cerebral/tags")
var {increment} = require("cerebral/operators")
var React = require("react")
var PropTypes = require("prop-types")
var {Container, connect} = require("@cerebral/react")
var { renderToString } = require('react-dom/server')
const controller = Controller(Module({
state: {
// Continuation Passing Style (CPS)
console.log('CPS factorial')
const CPS_fact = (n, callback = log) => {
console.log('CPS_fact push stack when n = '+ n)
if(n === 0) {
//console.log(`then we call callback$${n}(1)`)
callback(1)// executed when n is 0
} else {
//console.log(`when n = ${n} then callback$${n - 1} = e => callback$${n}(e * ${n})`)
CPS_fact(n - 1, r => {
// Y combinator's lambda calculus formula:
// Y = 位f.(位x.f(x x))(位x.f(x x))
// Single line Y combinator implementation:
// const Y = f => (x => f(v => x(x)(v))) (x => f(v => x(x)(v)))
// My prefered (2 line) Y implementation (more readable IMO)
const 位fx__f_xx_ = f => x => f( y => x(x)(y) ); // helper
const Y = f => 位fx__f_xx_(f) ( 位fx__f_xx_(f) ); // The Y combinator
// factorial generator for Y (where fact is truly recursive):
const Y_factg = fact => n => n === 0 ? 1 : n * fact(n - 1)
// A factorial function generated with Y: