Skip to content

Instantly share code, notes, and snippets.

View jkantr's full-sized avatar

Jared Kantrowitz jkantr

  • The Witzend Group
  • Metro NY Area
View GitHub Profile
@jkantr
jkantr / CartReducer.jsx
Last active December 10, 2019 00:05 — forked from ac205/CartReducer.jsx
Cart Reducer
const cartReducer = (state = {
cartItems: 0,
items: products,
cartContents: [],
}, action) => {
switch (action.type) {
case "ADD_TO_CART": {
const existingItem = state.cartContents.find(item => {
return item.id === Number(action.payload);
});
import BonusContext from './bonus-context';
class App extends Component {
static contextType = BonusContext;
render() {
return(
<li className={ this.context ? 'current' : '' }>
<NavLink
exact
// some helper fns.. maybe in a different file or not
function validateEmail(email){
return false;
}
export default (db) => {
// define some route handlers
function onPostCheckMail (req, res) {
if(validateEmail(req.body.email) === true){ //validateEmail is undefined
@jkantr
jkantr / gist:ac8dd53b53288bbd153e3f80cd8f56be
Last active August 29, 2018 23:03 — forked from philipimperato/gist:d91595917c59ff8376be1b6ea795706a
example for node blog article error handling - heroku - the route with the most H12 timeouts
routeConfig.post('/Dashboard/Index', repos.DashboardRepository.getRangeData(repos), (req, res) => {
let queries = [],
sess = req.userSession,
filter = req.rangeFilter;
queries.push(repos.PromotionRepository.getAgencyPromotions(sess.agencyId, 'all'));
queries.push(repos.DashboardRepository.getIndex(repos, filter, sess));
queries.push(repos.PolicyRepository.getPolicies(filter, true));
Promise.all(queries)
@jkantr
jkantr / 00-app.js
Last active April 10, 2018 18:25
Monstrosity of Objection.js model configuration and injection
// app.js
// ...
const models = require('./models/');
const state = {
models,
logger,
errorReporter,
};
module.exports = {
startTimer() {
return process.hrtime()
},
stopTimer(timer) {
const [s, ns] = process.hrtime(timer)
return ((s * 1e9) + ns) / 1e6
}
}
@jkantr
jkantr / .js
Last active February 16, 2018 15:42
Why (and why not) decorators
/** when wrapping a function with many other functions, the identity of the
original function quickly gets lost, and it's hard to make sense of it
at a glance */
const Timer = inject("someStore")(observer(class Timer extends React.Component {
/* ... */
}))
/** you can make it less hard to read by separating your component's definition
and it's functional wrappers **/
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const writeFileAsync = promisify(fs.writeFile);
const s3etm = require('s3-emails-to-mongo');
// MAKE THIS PART DYNAMIC LATER
s3etm.configure({
Bucket: 'zhillb-mail',
});
@jkantr
jkantr / login.js
Last active January 22, 2018 23:47 — forked from zacharyhill/login.js
Login Controller for Express Route
const Promise = require('bluebird');
const bcrypt = require('bcrypt');
const User = require('../models/user');
const { LoginError } = require('../errors');
function checkPassword(password, hash) {
return Promise.try(() => {
return bcrypt.compare(password, hash);
}).then((result) => {
if (!result) {
// do this
cache.remember('key1', 600, function() {
return mysql.MobileAction.findOne({ where: {action_id: req.query.D} })
}).then((val) => {
console.log('set: ', val);
})