Skip to content

Instantly share code, notes, and snippets.

View HappyZombies's full-sized avatar
💯

Daniel Reguero HappyZombies

💯
View GitHub Profile
@HappyZombies
HappyZombies / DynamicExpressMiddlewares.js
Created July 30, 2021 22:13
Middleware method that will chain and optionally run other middlewares given a condition
const express = require('express');
const app = express();
const dynamicMiddlewareAddition = async (req, res, next) => {
const number = Math.round(Math.random() * 100);
const isEven = number % 2 === 0;
//given a condition, run certain middlewares chained to one another.
const middlewares = isEven ? [middleware2] : [middleware1, middleware2, middleware3];
console.log(number, isEven, middlewares);
if(middlewares.length >= 1) {
@HappyZombies
HappyZombies / cloudSettings
Last active May 17, 2018 13:06
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-05-17T13:06:04.653Z","extensionVersion":"v2.9.2"}
RM.Event.subscribe(RM.Event.ARTIFACT_SELECTED, onSelection);
var self = this;
var stringXml = [];
function onSelection(artifactArray) {
RM.Data.getAttributes(
artifactArray,
[RM.Data.Attributes.PRIMARY_TEXT],
function(opResult) {
if (opResult.code !== RM.OperationResult.OPERATION_OK) {
@HappyZombies
HappyZombies / App.js
Created May 23, 2017 02:06
React Materialize, Input component prop 'defaultValue' does not update on component re-render.
import React, { Component } from 'react'
import logo from './logo.svg'
import './App.css'
import MyForm from './MyForm'
class App extends Component {
constructor () {
super()
this.state = {name: 'Paul'}
}
@HappyZombies
HappyZombies / App.js
Created May 20, 2017 19:51
If the app has not been setup yet (based on the /setup/setup-config/ express endpoint), redirect them to the setup page no matter what URL they go to.
import React, {Component} from 'react'
import {BrowserRouter, Switch, Route} from 'react-router-dom'
import Setup from '../pages/Setup'
import Routes from '../routes'
class App extends Component {
constructor (props) {
super(props)
this.state = {setup: true} // assume true first...
}
@HappyZombies
HappyZombies / Pad.cpp
Created January 29, 2017 18:07
Unreal Engine simple Overlap sample
// Fill out your copyright notice in the Description page of Project Settings.
#include "Jack.h"
#include "Pad.h"
// Sets default values
APad::APad()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
@HappyZombies
HappyZombies / app.js
Created January 6, 2017 19:03
Sequelize Database Relations
var Sequelize = require("sequelize");
var sequelize = new Sequelize('myDatabase', 'root', '', {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 0,
idle: 10000