Skip to content

Instantly share code, notes, and snippets.


Ben Simpson bsimpson

View GitHub Profile
bsimpson / circleci.rb
Created Nov 15, 2019
CircleCI Artifact Retrieval via the API
View circleci.rb
# 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 Sep 27, 2019
Proposal for Vuex Store Best Practices
View Vuex


  • 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
View Detecting a duplicate element in array
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;
}, {});
View gist:1fabe407f6c2ccf2e07e
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?
View gist:8360479
"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 Jan 1, 2016
Helium filled HDD Cost Savings
View gist:8085774
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 Sep 30, 2013
run, do, perform method rename to call
View gist:6768393
class Foo
def self.perform(foo)
puts foo
Foo.perform('foo') # => 'foo'
class Foo
bsimpson / gist:5915421
Created Jul 3, 2013
Salt and Pepper Tofu Recipe
View gist:5915421


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 Jun 20, 2013
Xor custom validation
View gist:5826663
validate :foo
def foo
errors[:base] << 'Nope' unless true ^ true
bsimpson / gist:5207880
Last active Dec 15, 2015
Git - See a file even after a hard reset
View gist:5207880


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}.

You can’t perform that action at this time.