Skip to content

Instantly share code, notes, and snippets.

View stuart-haas's full-sized avatar
🏠
Working from home

Stuart Haas stuart-haas

🏠
Working from home
View GitHub Profile
@stuart-haas
stuart-haas / baby.js
Created May 27, 2022 17:05
Code Baby
const assert = (...args) => {
this.args = args
return {
equals: (arg) => {
console.log(`${this.args.join(' + ')} = ${arg}`)
return this.args
}
}
return this;
@stuart-haas
stuart-haas / asyncRequest.js
Created October 15, 2021 14:22
Express route controller async wrapper
/**
Throw uncaught errors to the next middleware automatically
and avoid having to use try/catch in the controller methods
router.get('/', asyncRequest(controller.index));
with asyncRequest...
index: async(req, res) => {
const data = await Model.findAll();
@stuart-haas
stuart-haas / modal.js
Created September 25, 2021 19:57
Nuxt modal plugin
export default (context, inject) => {
const dialog = {
open: (options) => {
window.$nuxt.$emit('dialog', { ...options, open: true });
},
close: (options) => {
window.$nuxt.$emit('dialog', { ...options, open: false });
}
};
inject('dialog', dialog);
@stuart-haas
stuart-haas / main.scss
Last active September 25, 2021 16:56
Default Styles
.button {
padding: 2px;
background: none;
border-radius: 2px;
cursor: pointer;
text-align: center;
&--confirm {
padding: 8px 8px 6px 8px;
border: none;
@stuart-haas
stuart-haas / index.vue
Last active September 25, 2021 20:08
Dialog Modal Default Layout
<template>
<div>
<button class="button button--confirm" @click="openDialog">Open Dialog</button>
<DialogModal />
</div>
</template>
<script>
export default {
methods: {
@stuart-haas
stuart-haas / DialogModal.vue
Last active September 26, 2021 20:33
Vue Dialog Modal
<template>
<transition name="fade">
<div v-if="open" class="modal-backdrop">
<div class="modal">
<div class="modal-body">
<p>{{ message }}</p>
</div>
<div class="modal-footer">
<button class="button button--confirm" @click.stop="confirm">Confirm</button>
<button class="button button--cancel" @click.stop="cancel">Cancel</button>
@stuart-haas
stuart-haas / DialogModal.vue
Last active September 25, 2021 20:07
Nuxt Dialog Modal
<template>
<transition name="fade">
<div v-if="open" class="modal-backdrop">
<div class="modal">
<div class="modal-body">
<p>{{ message }}</p>
</div>
<div class="modal-footer">
<button class="button button--confirm" @click.stop="confirm">Confirm</button>
<button class="button button--cancel" @click.stop="cancel">Cancel</button>
@stuart-haas
stuart-haas / node-path-alias.js
Last active July 21, 2021 20:55
Global function to resolve paths for NodeJS modules
// This is ugly
// const Service = require('../app/services/Service');
// Try this instead
// const Service = alias('service/Service')
const path = require('path');
const aliases = {
config: './config',
@stuart-haas
stuart-haas / setup.sh
Created September 10, 2020 19:06
Typeorm project setup
# Install dependencies
echo "Installing dependencies"
npm install --prefix ./client && npm install --prefix ./server && npm install
# Copy the .env.example to .env
cd server
if [ ! -f .env ]; then
echo "\nCreating the .env file"
cp -v .env.example .env
@stuart-haas
stuart-haas / hyper.js
Created August 29, 2020 01:39
My hyper.js config
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
activeTab: '🚀',