Skip to content

Instantly share code, notes, and snippets.

View lloydjatkinson's full-sized avatar
🌧️
Chilling

Lloyd Atkinson lloydjatkinson

🌧️
Chilling
View GitHub Profile
@lloydjatkinson
lloydjatkinson / boolean-filter.js
Created June 19, 2018 09:59
Vue filter for user friendly display of boolean values
/**
* Returns a string representing the truthy/falsy value of the given value. Defaults to "Yes" or "No".
* @param {*} value The value to determine the truthy/falsy value of.
* @param {String} truthyString The string to use if the value is truthy.
* @param {String} falsyString The string to use if the value is falsy.
* @example {{ userSelected | boolean }}
* @example {{ userSelected | boolean('Included', 'Not Included') }}
*/
const booleanFilter = (value, truthyString, falsyString) =>
value
@lloydjatkinson
lloydjatkinson / redux-performance-mark.js
Created July 5, 2018 12:54 — forked from clarkbw/redux-performance-mark.js
A User Timing middleware for redux to create performance markers for dispatched actions
const timing = store => next => action => {
performance.mark(`${action.type}_start`);
let result = next(action);
performance.mark(`${action.type}_end`);
performance.measure(
`${action.type}`,
`${action.type}_start`,
`${action.type}_end`
);
return result;
// webpack.config.js
module.exports = {
mode: process.env.NODE_ENV || 'development',
target: 'node',
module: {
rules: [
{ test: /.js$/, exclude: /node_modules/, use: 'babel-loader' }
],
},
}
https://www.reddit.com/r/programming/comments/95nea1/are_you_caught_in_the_trap_of_sales_driven/e3ubcgk/
/**
* Throttles the users ability to click the specified button within the specified form by disabling the button once the form is submitting.
* @param {String} formSelector The selector of the form.
* @param {String} buttonSelector The selector of the button.
* @param {Number} throttlePeriod (Optional) The amount of time in milliseconds that the button should be disabled for. Defaults to 5000.
*/
function submitFormButtonThrottle (formSelector, buttonSelector, throttlePeriod) {
document.addEventListener('DOMContentLoaded', function() {
if (!formSelector) throw new Error('Selector expected for form.');
if (!buttonSelector) throw new Error('Selector expected for form button.');
@lloydjatkinson
lloydjatkinson / back-off.js
Created September 13, 2018 15:25
back-off.js
/**
* Generalised back-off function.
* @param {Function} unary The unary operator function that returns the next state given the current state (current value and invocation count).
* @param {Number} initial The initial value to start the back-off.
* @example const multiplyTenBackOff = backOff((current, count) => current * 10);
* @example const negativeBackOff = backOff((current, count) => current - 1, 1000);
*/
const backOff = (unary, initial = 0) => {
let current = initial;
let count = 0;
mounted () {
MapBoxGl.accessToken = 'pk.eyJ1IjoibGxveWRqYXRraW5zb24iLCJhIjoiY2ptdG94NnBkMmdveDNrb2VwMnpuZ2xlbiJ9.P_aB3PF24QZL0uAlNvpDVw';
this.map = new MapBoxGl.Map({
container: this.$refs.map,
style: 'mapbox://styles/mapbox/streets-v10',
center: [8, 50],
zoom: 4,
});
this.map.addControl(new MapboxGeocoder({ accessToken: MapBoxGl.accessToken }));
@lloydjatkinson
lloydjatkinson / password-confirmation-component.js
Last active December 5, 2022 19:28
Just a simple component based approach to some password validation
'use strict';
// This is a demonstration of writing clean Javascript - by adopting a component based approach.
// No jQuery, no poorly structured spaghetti code, composed of single purpose functions, has no hard coded selectors and works in IE10+.
// This is written in ES5. If build tools were used I would write this in ES7+.
// If Vue.js was used as well then a good chunk of the code wouldn't be necessary (and no need to attach to window).
window.passwordConfirmationComponent = {
selectors: {},
updatePasswordRuleFeedback: function (validation) {
const simpleMaterialDesignPalette = [
'#F44336', // Red 500
'#E91E63', // Pink 500
'#9C27B0', // Purple 500
'#673AB7', // Deep Purple 500
'#3F51B5', // Indigo 500
'#2196F3', // Blue 500
'#03A9F4', // Light Blue 500
'#00BCD4', // Cyan 500
'#009688', // Teal 500
@lloydjatkinson
lloydjatkinson / typescript.......
Created June 21, 2019 12:52
typescript.......
var closeFn: CloseSlideinFn
All destructured elements are unused.ts(6198)
Argument of type '({ state, closeFn }: PropsWithChildren<{ closeFn?: CloseSlideinFn; state: TemplateDesignerStoreState; }>) => boolean' is not assignable to parameter of type 'Element | FunctionComponent<{ closeFn?: CloseSlideinFn; state: TemplateDesignerStoreState; }>'.
Type '({ state, closeFn }: PropsWithChildren<{ closeFn?: CloseSlideinFn; state: TemplateDesignerStoreState; }>) => boolean' is not assignable to type 'FunctionComponent<{ closeFn?: CloseSlideinFn; state: TemplateDesignerStoreState; }>'.
Type 'boolean' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)>) | (new (props: any) => Component<any, any, any>)>'.ts(2345)