Skip to content

Instantly share code, notes, and snippets.

View jgcmarins's full-sized avatar

João Marins jgcmarins

View GitHub Profile
@jgcmarins
jgcmarins / esbuild-relay.js
Created February 19, 2021 19:49 — forked from sciyoshi/esbuild-relay.js
Esbuild plugin for compiling relay queries
import { promises } from "fs";
import crypto from "crypto";
import path from "path";
import { print, parse } from "graphql";
const plugin = {
name: "relay",
setup: build => {
build.onLoad({ filter: /\.tsx$/, namespace: "" }, async args => {
let contents = await promises.readFile(args.path, "utf8");
@jgcmarins
jgcmarins / devTraining.md
Created January 8, 2021 13:27 — forked from sibelius/devTraining.md
How to train your dev team

you should review every pull request of your team

  • each pull request will make understand what everyone in your team is working on
  • it will ensure you keep consistency of file location, and code patterns
  • it will catch bugs/regression early on
  • it will teach the best way to solve the problem

you should ensure consistency of the code base

you should pair programming with all devs of your team

@jgcmarins
jgcmarins / responseTime.ts
Created December 7, 2020 20:27
Koa middleware to measure response time and set X-Response-Time header
export async function responseTime(ctx, next) {
const start = new Date();
await next();
const ms = new Date() - start;
ctx.set('X-Response-Time', ms + 'ms');
}
@jgcmarins
jgcmarins / webpack.config.js
Created November 20, 2020 17:35 — forked from jkinkead/webpack.config.js
Webpack configuration for Google Cloud Functions
const webpack = require('webpack')
const path = require('path')
const nodeExternals = require('webpack-node-externals')
const StartServerPlugin = require('start-server-webpack-plugin')
module.exports = {
entry: [
'webpack/hot/poll?1000',
'./local/server'
],
watch: true,
@jgcmarins
jgcmarins / changelog.js
Created November 9, 2020 17:10
Setup to generate git tag and GitHub release with changelog based on commit messages
#!/bin/env node
// @ts-check
import fs from 'fs';
import { exec as execCb } from 'child_process';
import util from 'util';
import moment from 'moment';
import git from 'simple-git/promise';
@jgcmarins
jgcmarins / store.mjs
Created October 1, 2020 17:16 — forked from kristoferjoseph/store.mjs
store
const listeners = []
const state = {}
let noop = x => x
function subscribe (fn) {
listeners.push(fn)
}
function unsubscribe (fn) {
listeners.splice(listeners.indexOf(fn), 1)
@jgcmarins
jgcmarins / filterAsync.ts
Created July 29, 2020 14:00 — forked from sibelius/filterAsync.ts
Simple filter async
function mapAsync<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]> {
return Promise.all(array.map(callbackfn));
}
async function filterAsync<T>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]> {
const filterMap = await mapAsync(array, callbackfn);
return array.filter((value, index) => filterMap[index]);
}
@jgcmarins
jgcmarins / backup.js
Created July 26, 2020 16:28 — forked from theouerd/backup.js
Auto backup function.
const fs = require('fs');
const _ = require('lodash');
const exec = require('child_process').exec;
const path = require('path');
// Concatenate root directory path with our backup folder.
const backupDirPath = path.join(__dirname, 'database-backup');
const dbOptions = {
user: '<databaseUsername>',
// inspired by https://stackoverflow.com/questions/105034/how-to-create-guid-uuid/2117523#2117523
// @TODO - improve this
export function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}