Skip to content

Instantly share code, notes, and snippets.

View bsimpson's full-sized avatar

Ben Simpson bsimpson

View GitHub Profile
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"
LIMIT = 100
bsimpson / Vuex
Last active September 27, 2019 16:03
Proposal for Vuex Store Best Practices


  • 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


In Store

  • Create a property name on the state object with a default value
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;
}, {});
A hungry bloke staggering through the desert finds two Bedouins, and asks if he can share bread with them.
The tall Bedouin has 5 loaves, the short Bedouin has 3 loaves of bread.
They welcome the visitor, and the three of them consume the 8 loaves of bread.
The stranger thanks the Bedouins for their hospitality, and leaves them with 8 gold coins.
The tall Bedouin takes 5 coins, leaving three.
But the short Bedouin says they both shared their bread, and therefore should split the 8 coins four and four.
Which if either of the two Bedouins is right?
"name": "angularjs-seed",
"description": "A starter project for AngularJS",
"repository": "",
"devDependencies": {
"phantomjs": "~1.9",
"karma": "~0.10.4",
"karma-junit-reporter": "~0.1",
"karma-jasmine": "~0.1.3",
"karma-ng-scenario": "~0.1",
bsimpson / gist:8085774
Last active January 1, 2016 03:29
Helium filled HDD Cost Savings
Cost per kWh:
GA $12.17
MA $15.86
Kilowatt = 1000 Watts
Watt = The unit, defined as one joule per second, measures the rate of energy conversion or transfer.
Press release on energy savings:
bsimpson / gist:6768393
Created September 30, 2013 18:58
run, do, perform method rename to call
class Foo
def self.perform(foo)
puts foo
Foo.perform('foo') # => 'foo'
class Foo
bsimpson / gist:5915421
Created July 3, 2013 04:17
Salt and Pepper Tofu Recipe


Salt and Pepper Tofu on Spinach Fettuccini bed Feeds 2 Prep time 5 minutes Cook time 10 minutes


Boil 4-5 spinach fettuccini nests in boiling water with salt (to taste) and olive oil (to keep from sticking)

bsimpson / gist:5826663
Created June 20, 2013 21:08
Xor custom validation
validate :foo
def foo
errors[:base] << 'Nope' unless true ^ true
bsimpson / gist:5207880
Last active December 15, 2015 05:19
Git - See a file even after a hard reset


I make changes to a file, and then subsequently reset my branch using git reset --hard to origin. I want to recover the contents of that file, even after a hard reset

Finding the revision before the reset

git reflog | grep <branch name>

Look for an entry like b65de9d HEAD@{75}: reset: moving to origin/<branch name>. This is the point at which you reset your branch to origin. You want to use the point before that revision (e.g. increment the number by one to go back in history just before). In this case, it would be HEAD@{76}.