Skip to content

Instantly share code, notes, and snippets.

Ben Simpson bsimpson

Block or report user

Report or block bsimpson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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.
Question:
Which if either of the two Bedouins is right?
View gist:8360479
{
"name": "angularjs-seed",
"description": "A starter project for AngularJS",
"repository": "https://github.com/angular/angular-seed",
"devDependencies": {
"phantomjs": "~1.9",
"karma": "~0.10.4",
"karma-junit-reporter": "~0.1",
"karma-jasmine": "~0.1.3",
"karma-ng-scenario": "~0.1",
@bsimpson
bsimpson / gist:8085774
Last active Jan 1, 2016
Helium filled HDD Cost Savings
View gist:8085774
Cost per kWh: http://www.electricchoice.com/electricity-prices-by-state.php
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:
http://www.hgst.com/press-room/press-releases/hgst-ships-6TB-Ultrastar-HE6-helium-filled
@bsimpson
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
end
end
Foo.perform('foo') # => 'foo'
class Foo
def self.call(foo)
@bsimpson
bsimpson / gist:5915421
Created Jul 3, 2013
Salt and Pepper Tofu Recipe
View gist:5915421

Intro

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

Pasta

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

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

Scenario

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

@bsimpson
bsimpson / gist:4530464
Created Jan 14, 2013
Ternary in CoffeeScript
View gist:4530464

if foo then 'bar' else 'baz'

// Generated by CoffeeScript 1.3.3

if (foo) {
  'bar';

} else {
  'baz';
@bsimpson
bsimpson / gist:4286706
Created Dec 14, 2012
I18n translation with Integers for map keys
View gist:4286706

Introduction

I18n uses YAML files to store translations, however when using an integer as a map key, the translation is then missing when referenced. This may be unexpected at first, but below describes the translation process, and why it is happening.

Sample YAML file

en:
  1:
    foo: 'bar'

Invokation

You can’t perform that action at this time.