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
bsimpson / gist:4088286
Created Nov 16, 2012
Rails and Javascript UTC timestamps
View gist:4088286


ActiveSupport.use_standard_json_time_format #=> true "Returns a JSON string representing the datetime. If ActiveSupport.use_standard_json_time_format is set to true, the ISO 8601 format is used." "If the time is in UTC, add a Z directly after the time without a space. Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z"."

bsimpson / gist:4286706
Created Dec 14, 2012
I18n translation with Integers for map keys
View gist:4286706


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

    foo: 'bar'


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) {

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

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: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: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: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:
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",
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?
You can’t perform that action at this time.