Skip to content

Instantly share code, notes, and snippets.

// service file
export const createStockLevelChecker = (serviceLocator) => {
return async (offerId) => {
const offer = await serviceLocator.offerService.read(offerId);
if (offer) {
return "there is stock";
}
// This example allows:
//
// `age` to be zero as a valid initial value, or any other number. If its undefined the input
// will be empty instead of zero.
//
// `value` to be undefined, leaving please select as selected, or preset to any other number
// including zero.
//
// It also makes use of yup's schema.cast (post submit) to get around select values
// coming out as strings. This is better than manually having to catch these cases
@benjaminparnell
benjaminparnell / formik-addresses-test.tsx
Created August 20, 2018 22:29
formik-addresses-test.tsx
import * as React from "react";
import { render } from "react-dom";
import {
Formik,
FieldArray,
Field,
Form,
FormikProps,
ArrayHelpers
} from "formik";
var moment = require('moment-timezone')
, prevAbbr = moment.fn.zoneAbbr
, timezoneTranslations = {
'Europe/Istanbul': 'TSİ'
}
moment.fn.zoneAbbr = function () {
var customTimezoneTranslation = timezoneTranslations[this._z.name]
return customTimezoneTranslation || prevAbbr.call(this)
}
var mlcm = require('mlcm')
, frac = require('frac')
module.exports = function getMultiplier (prizes) {
if (prizes.length === 0) return 0
if (Array.isArray(prizes) === false) throw new Error('getMultiplier requires an array')
return mlcm(prizes.map(function (prize) {
return frac(prize.chance, Infinity)[2]
}))
@benjaminparnell
benjaminparnell / sort.js
Created December 7, 2016 17:37
sort.js
people.sort(function (a, b) {
return a.name > b.name
})
function map (arr, fn, ctx = this) {
return Promise.all(arr.map((item, index) => {
return new Promise((resolve, reject) => {
fn.call(ctx, item, index, arr, resolve, reject)
})
}))
}
var arr = [1, 2, 3]
git config --global user.name "YOUR REAL NAME ON GITHUB"
git config --global user.email youremail@gmail.com
git remote remove origin
git remote add origin git@github.com:yourusername/yourrepo
git push -u origin master
#include <iostream>
#include <vector>
class Shape {
public:
virtual void print() = 0;
};
class Square : public Shape {
virtual void print() {
struct NotCopyable {
// defaulted and deleted funtions are only available in C++11
NotCopyable(const NotCopyable&) = delete;
// Overriding the = operator so you can't copy one NotCopyable to another
// one
NotCopyable& operator=(const NotCopyable&) = delete;
// You would need the following line to be able to construct an instance of this
// struct at all