Skip to content

Instantly share code, notes, and snippets.

View diversemix's full-sized avatar
🎯
Focusing

Peter Hooper diversemix

🎯
Focusing
View GitHub Profile
@diversemix
diversemix / callback-with-promise-test.js
Created May 5, 2020 22:04
Wrapping old style callbacks with a Promise - allows use of Promise.all to await all promises - result is an ordered array.
const input = [1,2,3,4];
const oldFunc = (element, callback) => {
const r = Math.floor(200 * Math.random());
setTimeout( () => {
console.log('oldFunc End', element);
callback(element + "|" + r);
}, r);
};
@diversemix
diversemix / clone-issues.sh
Created March 9, 2020 13:27
Bash script to clone repos into the repo of the cwd
#!/bin/bash
IFS=$'\n'
REPO="libero/reviewer-client"
for f in `gh issue list --repo ${REPO}`
do
title=$(echo $f | cut -d $'\t' -f2-)
num=$(echo $f | cut -d $'\t' -f1)
body="Cloned from ${REPO}/issues/${num}"
@diversemix
diversemix / createValidationFunction
Last active December 31, 2019 12:35
Code for testing an interface in typescript
import { Event } from './types';
import uuid = require('uuid');
const expectedEventProperties = {
eventType: true,
id: true,
created: true,
payload: true,
};
@diversemix
diversemix / blocking-test.js
Created November 13, 2019 15:56
Test for understanding how blocking works
const log = console;
const sleep = async ms => {
return new Promise(resolve => setTimeout(resolve, ms));
};
const asyncFunc1 = async () => {
log.log('f1 Start');
await sleep(2000);
log.log('f1 End');
@diversemix
diversemix / object-diff.js
Created July 5, 2019 08:15
Recursive (deep) difference between two objects
import { transform, isEqual, isObject } from 'lodash';
/**
* Source: https://gist.github.com/Yimiprod/7ee176597fef230d1451#gistcomment-2565071
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
@diversemix
diversemix / rebase-commands.txt
Created June 10, 2019 13:25
Re-basing a branch onto latest mainline.
git checkout develop
git pull
git checkout <my-branch-that-needs-rebasing>
git fetch origin
git rebase origin/develop
git status
git push --force
@diversemix
diversemix / wait-for-app.sh
Created April 9, 2019 19:10
Wait for app to become available after webpack
#!/usr/bin/env bash
#
# Usage: pass in the host or host:port as the first argument
#
# This will then wait for a max of 5 mins for the application to start
#
RESOURCE=http://$1/assets/app.js
CMD="timeout 1s curl -s ${RESOURCE}"
@diversemix
diversemix / Dockerfile
Created March 25, 2019 11:46
Creates small docker image for elife-xpub
# Build using latest node v9
FROM node:9 as builder
RUN mkdir /build
WORKDIR /build
COPY package.json ./
COPY yarn.lock ./
COPY client client
@diversemix
diversemix / psql_notes.md
Created March 19, 2019 09:31
psql setup commands

Notes on setting up Postgres

Useful commands (all auth should be md5)

sudo apt install postgresql
sudo vi /etc/postgresql/10/main/pg_hba.conf
sudo systemctl restart postgresql
@diversemix
diversemix / file-search.js
Created September 22, 2018 10:32
File search example with Promise and with Async
fs = require('fs')
/*
* Wrap old-style callback with promise explicitly created...
*/
const readfolderPromise = (folder) => {
if (folder === undefined) {
folder = process.cwd()
}
console.log(folder)