Skip to content

Instantly share code, notes, and snippets.

View jcarroll2007's full-sized avatar

Jordan Carroll jcarroll2007

View GitHub Profile
@jcarroll2007
jcarroll2007 / README.md
Last active July 11, 2019 16:40
A codemod to transform styled-components attrs first argument into a function from an object.
@jcarroll2007
jcarroll2007 / hooksAndIntersectionObserverExample.js
Last active July 8, 2019 18:02
A brief example of how to use IntersectionObserver with React hooks to create a component that fires events when it (in this case fully) enters into the view.
import React, {
createRef,
useState,
useEffect,
useRef,
useCallback
} from 'react'
function useIntersectionObserver(onChange, options) {
const [observer, setObserver] = useState(null)
@jcarroll2007
jcarroll2007 / explanation.md
Last active October 26, 2018 13:33
JavaScript Interview Question: Flatten an array | Solved iteratively and recursively with tradeoffs declared

When I originally sought to tackle this problem I chose the easier recursive solution to solve it with. However, due to the fact that in JavaScript Proper Tail Calls (PTC) (correct me if I'm wrong) are not currently supported and it seems like there's little hope that they'll be one soon. If they were, the trade offs here might be different (I haven't really thought through that scenario yet). For more on that see TC39/#22 and the transcript of the TC30 discussion.

For those of you that don't know, if we had PTC the stack growth issue with recursion would not be a problem. Meaning our memory complexity for the stack would be constant.

Anyway, the recursive solution is obviously much much easier but limited by the stack - which is never a great thing. So, depending on the size of your inputs, it may simply fail entirely.

So, I decided to implement it i

@jcarroll2007
jcarroll2007 / gist:6862cc9dc25fff9d101c
Last active August 29, 2015 14:23
AngularJS Unit Testing With Jasmine

#AngularJS Unit Testing With Jasmine

##Directives

###Testing a Directive That Uses ControllerAs

// Replace app.moduleName with the name of the module that you want to test
describe("app.moduleName", function () {
	"use strict";
(function () {
'use strict';
function Auth($http, $rootScope, $q, url) {
var auth = {};
auth._events = $rootScope.$new();
auth._currentUser = {};
auth.getCurrentUser = function () {
if (auth._currentUserPromise) {