Skip to content

Instantly share code, notes, and snippets.

View johntimothybailey's full-sized avatar

John Bailey johntimothybailey

View GitHub Profile
@johntimothybailey
johntimothybailey / Example.stories.tsx
Last active February 2, 2024 23:48
Testing Library and Tanstack Query
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import React from 'react'
import type { Meta, StoryObj } from '@storybook/react'
import { Example } from './Example'
const meta: Meta<typeof Example> = {
title: 'Example',
component: Example,
tags: ['autodocs'],
@johntimothybailey
johntimothybailey / jquery.append.js
Created April 29, 2012 21:21
Polyfills for jQuery to work in IE5.5
jQuery.fn.append = function( ) {
var element = this.get(0);
var appending = arguments[0];
if( appending.charAt(0) === "<" ){
throw Error("This appears to be a dom element represented as a string. Please create the element then append");
} else{
// Wonder if there is a better way to do this
element.innerHTML = element.innerHTML + appending;
}
};
@johntimothybailey
johntimothybailey / underscore.isviable.js
Created March 29, 2012 23:15
Underscore function for determining if a given object is viable
!function(root){
'use strict';
/**
* Determine if an object is viable according to specifications given or the defaults provided
* @param value The object to evaluate for viability
* @param options (optional) The options for changing the viability criteria. If an array is provided then it is assumed to be the property "nonViables" Possible options:
* nonViables An array of properties and functions that describe the value as being nonviable. These will be added to the default nonviables
* defaultNonViables An array of the default nonviables. These will override the functions default nonviables.
* originally developed at: http://jsfiddle.net/johntimothybailey/6UUD5/
* @contribution: RJ Regenold (https://gist.github.com/4927b3ba864d86209f7e). "The reduce idea and implementation is super clean" - John of the Bailey's
@johntimothybailey
johntimothybailey / bindmethods.js
Created February 28, 2012 19:25
Method Scoping Workaround - Underscore
_.mixin({
/**
* Convenience for simplifying scoping methods workaround in javascript for a given context
* @param context The context where the methods are found
* @param exclude An array of method names (strings) to exclude in the binding
*/
bindMethods: function(context,exclude){
exclude = exclude || [];
_.bindAll.apply(context, [context].concat(_.difference(_.methods(context),exclude)));
return context;
@johntimothybailey
johntimothybailey / underscore.logmethods.js
Created February 27, 2012 18:32
Log Method Invocation - An Underscore Mixin
_.mixin({
/**
* Logs method invocation of a provided instance
*
* @param target Currently must be an instance
* @param options Possible options are as follows
* prefix - A prefix String for the logging (e.g. "Person instance")
* logMethod - The function to use for doing the logging (default: console.log)
*/
logMethodInvocation : function(target,options) {