Skip to content

Instantly share code, notes, and snippets.

Avatar

koptionalsoftware

View GitHub Profile
View cloudSettings
{"lastUpload":"2020-11-18T05:26:31.722Z","extensionVersion":"v3.4.3"}
View express-main.js
const drawSignatures = require("./drawSignatures");
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post("/", async (request, response) => {
try {
const bytes = await drawSignatures.drawSignatures(request.body.doc, request.body.signature);
return response.send(bytes);
View fastify-main.js
const drawSignatures = require("./drawSignatures");
const fastifyImp = require("fastify");
const fastify = fastifyImp({
logger: true
});
fastify.post("/", async (request, reply) => {
// Some sort of request validation
const bytes = await drawSignatures.drawSignatures(request.body.doc, request.body.signature);
reply.send(bytes);
});
View vuex-hygen.sh
#create an action and some mutations. Use camelCasing for the action!
hygen asyncaction new fetchData
## The above is equivalent to:
# hygen action new fetchData
# hygen mutation new fetchDataStart
# hygen mutation new fetchDataSuccess
# hygen mutation new fetchDataFailure
View project-setup.sh
npm i -g hygen
# Or yarn global add hygen
git clone https://github.com/koptionalsoftware/vuex-hygen-templates.git
cd vuex-hygen-templates
View action-styles.js
// What I do
export const FETCH_DATA = "FETCH DATA";
// Things other people sometimes do
export const fetchData = "fetchData";
export const fetchData = "FETCH_DATA";
export const fetchData = "FETCH DATA";
// and about every combination of camel / underscore casing
View data.module.js
// Example module
import api from './api';
import {
FETCH_DATA
} from './actions.types.js';
import {
FETCH_DATA_START,
FETCH_DATA_SUCCESS,
FETCH_DATA_FAILURE
View mutations.types.js
// mutations.types.js
export const FETCH_DATA_START = "FETCH DATA START";
export const FETCH_DATA_SUCCESS = "FETCH DATA SUCCESS";
export const FETCH_DATA_FAILURE = "FETCH DATA FAILURE";
View actions.types.js
// actions.types.js
export const FETCH_DATA = "FETCH DATA";
@koptionalsoftware
koptionalsoftware / cleanDB.js
Last active Nov 15, 2019
Clears everything recursively in your Firestore database. Useful in the cleanUp routine of any tests.
View cleanDB.js
const clearCollection = db => async collections => {
await Promise.all(
collections.map(async collection => {
// get documents
const documents = await collection.listDocuments();
await Promise.all(
documents.map(async doc => {
const collections = await db.doc(`${doc.path}`).listCollections();
// If document has a sub collection delete that first
if (collections.length > 0) {
You can’t perform that action at this time.