Skip to content

Instantly share code, notes, and snippets.

View bsimpson's full-sized avatar

Ben Simpson bsimpson

View GitHub Profile
const array = [1,2,3,4,4];
function findDuplicate(inArr) {
inArr.reduce((sum, entity, idx) => {
sum[entity] = true;
if (Object.keys(sum).length != idx+1) {
throw `Duplicate found at index ${idx} in value ${entity}`;
}
return sum;
}, {});
@bsimpson
bsimpson / Vuex Implementation.md
Last active September 27, 2019 16:03
Proposal for Vuex Store Best Practices

Goals

  • Consistency - Standardize state/getter/mutation naming
  • Easier to read - less boilerplate by accessing literal properties without constants, reducing unnecessary getters
  • Organization - Any helper functions go inside getter/mutation/action context - not at top level

State

In Store

  • Create a property name on the state object with a default value
@bsimpson
bsimpson / circleci.rb
Created November 15, 2019 21:43
CircleCI Artifact Retrieval via the API
# Finds a CircleCI job of a given name, and retrieves an artifact from a given CircleCI project build
# Usage:
# $ API_TOKEN=xxx GITHUB_USERNAME=bsimpson GITHUB_PROJECT=some-project TARGET_JOB=lighthouse ARTIFACT=averages_pageload ruby ./circleci.rb
require "net/http"
require "json"
API_TOKEN = ENV["API_TOKEN"]
LIMIT = 100
GITHUB_USERNAME = ENV["GITHUB_USERNAME"]