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 / 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 / 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 / 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 / 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 / overmindGists.ts
Created July 23, 2019 23:16
Overmind snapshots of different files of a project. Just to get a feel of it.
/* state.ts
* Here we define the initial state of the application.
* I have ommited the types for Newspapers, Table and State for brevity.
*/
export const state: State = {
table: {
selected: null,
newspapers: [],
},
}
@corlaez
corlaez / useMousePosition.ts
Created July 23, 2019 23:17
useMousePosition react hook
import { useState, useEffect } from 'react'
export const useMousePosition = () => {
const [position, setPosition] = useState({ x: 0, y: 0 });
useEffect(() => {
const setFromEvent = (e: any) => setPosition({
x: e.clientX,
y: e.clientY
});
window.addEventListener("mousemove", setFromEvent);
@corlaez
corlaez / runme
Created August 7, 2019 14:30
Killing processes using a given port unix. Runs in terminal
netstat -ano | findstr :PORT
taskkill /PID_NUMBER /F
netstat -ano | findstr 3000
taskkill /9052 /F
function merge(l1, l2) {
const se = new Set(l1);
l2.forEach(e => se.add(e))
return [...se]
}
const x = Object.keys(old).reduce((acc, cur) => {
acc[cur] = merge(old[cur], neww[cur]);
return acc
}, {})
@corlaez
corlaez / mixin.js
Created September 27, 2019 23:42
Hooks predecesors
import React from "react";
var MyMixin = {
componentDidUpdate() {
this.componentMethod()
},
mixinMethod() {}
};
const MyComponent = React.createClass({