Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Nixey peternixey

View GitHub Profile
View clearest if statement
user_is_recently_created = user.created_at < 10.minutes.ago
invitation_is_unsent = !user.invitation_token
user_has_not_yet_edited_profile = (user.created_at == user.updated_at)
if user_is_recently_created
&& invitation_is_unsent
&& user_has_not_yet_edited_profile
...
View better if statement
if (new_user.created_at < 10.minutes.ago)
&& !new_user.invitation_token
&& (new_user.created_at == new_user.updated_at)
View garbled if statement
if (u2.made < 10.minutes.ago)
&& !u2.tkn
&& (u2.made == u2.l_edit)
...
View process_text
def process_text string
end
@peternixey
peternixey / ga_last_x_days.js
Created Jun 28, 2012
Google Analytics bookmark to show just the last X days of data
View ga_last_x_days.js
javascript: function analyticsURL(){ var properties = { profileID: 'EDIT__YOUR_ANALYTICS_REPORT_ID', daysToShow: EDIT__NUMBER_OF_DAYS_TO_SHOW,includeToday: EDIT__INCLUDE_TODAY_TRUE_OR_FALSE, report_url: 'EDIT__URL_OF_REPORT_YOU_WANT_TO_SHOW' }; function stringify(date){ return date.getFullYear().toString() + pad(date.getMonth() + 1) + pad(date.getDate()); }; function pad(numeral){ return numeral<10 ? '0' + numeral.toString() : numeral.toString(); }; void(properties.report_url = properties.report_url.replace(/([^/])$/, '$1/')); var endDate = new Date(); var startDate = new Date(); properties.includeToday ? false : endDate.setDate( endDate.getDate()-1 ); startDate.setDate( endDate.getDate() - properties.daysToShow + 1 ); return properties.report_url + properties.profileID + '/%3F_.date00%3D' + stringify(startDate) + '%26_.date01%3D' + stringify(endDate) + '/'; }; window.location = analyticsURL();
// INSTRUCTIONS
// 1. In the URL above, change the following four variables at the s
@peternixey
peternixey / securing_rails_updates.md
Created Mar 5, 2012
How Homakov hacked GitHub and how to protect your application by Peter Nixey
View securing_rails_updates.md

##How Homakov hacked GitHub and the line of code that could have prevented it


Please note: THIS ARTICLE IS NOT WRITTEN BY THE GITHUB TEAM or in any way associated with them. It's simply hosted as a Gist because the markdown formatting is excellent and far clearer than anything I could manage on my personal Tumblr at peternixey.com.

If you'd like to follow me on twitter my handle is @peternixey


@peternixey
peternixey / a
Created Jan 20, 2012
Some changes I made to the vanilla Rails / Spork / RSpec setup to ensure models get reloaded
View a
# make sure your rspec block has the cli => drb line:
guard 'rspec', :cli => "--drb", :version => 2 do
View test.rb
a = 2
class Test
end
You can’t perform that action at this time.