Skip to content

Instantly share code, notes, and snippets.

View derek-duncan's full-sized avatar

Derek Duncan derek-duncan

View GitHub Profile
@derek-duncan
derek-duncan / Project Euler Solutions
Last active December 21, 2015 01:19
ProjectEuler.net Solutions
# Project Euler Algorithems
#!/usr/bin/python3
import time
def Euler1():
numbers = [n for n in range(0, 1000) if n % 3 == 0 or n % 5 == 0]
return sum(numbers)
@derek-duncan
derek-duncan / 1-suggested-branch-naming-scheme.rb
Last active May 17, 2021 00:29
Git workflow for small teams
# [pivital-story-id]-[feature-name]
# All lowercase. Spaces replaced with dashes
94198518-cs-block-bugs
# ..just merged dev into stage
git checkout stage
# on branch stage. We have a few blockers: we don't want commits 1234-my-feature [1a613sa] and 1234-my-feature-updated [2u817n0]
git revert -n 1a613sa
git revert -n 2u817n0
git commit -m "... Except commits 1234-my-feature and 1234-my-feature-updates"
# The commits will now be excluded and can be fixed later
# Push
git push
@derek-duncan
derek-duncan / Deferred-Rendering-HOC.js
Created April 18, 2017 13:38
Assists react in mounting/unmounting large component trees. Originally inspired by mobile twitter.
import React, { Component } from 'react';
const withDeferRender = Presentational =>
class DeferRender extends Component {
state = {
shouldRender: false,
};
componentDidMount() {
window.requestAnimationFrame(() => {
@derek-duncan
derek-duncan / reusable-graphql-containers.jsx
Last active December 8, 2017 16:19
Typescript example on how to strongly type your Apollo graphql containers. These containers are completely reusable for any component, with full TS typings.
import * as React from "react";
import * as ReactDOM from "react-dom";
import gql from "graphql-tag";
import { graphql } from "react-apollo";
/**
* Using intersection types, we can allow our `graphql` injected props
* to be defined in our `Props` type.
*/
Writeback
Idle*
START_WRITEBACK -> Verify
Verify
VerifyPending
VERIFY_FAIL -> VerifyError
VERIFY_SUCCEED -> Send
VerifyError
VERIFY -> VerifyPending
VERIFY_CANCEL -> Idle
@derek-duncan
derek-duncan / react@16.7.0-alpha.0-typescript-types-hooks.d.ts
Last active January 26, 2019 18:56
React 16.7.0-alpha.0 Typescript Types for Hooks
// put me in your global.d.ts file
declare module 'react' {
/**
* Returns a stateful value, and a function to update it.
*/
function useState<TValue>(
initialState: TValue | (() => TValue)
): [TValue, (value: TValue | ((prevValue: TValue) => TValue)) => void];
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@derek-duncan
derek-duncan / machine.js
Last active August 21, 2019 20:14
Generated by XState Viz: https://xstate.js.org/viz
Machine({
context: {
entryType: null,
isPending: false,
isDropping: false,
dropStatus: 'idle',
formError: null,
locationId: null,
practiceId: null,
practices: [],
@derek-duncan
derek-duncan / machine.js
Created August 23, 2019 20:51
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions