Skip to content

Instantly share code, notes, and snippets.

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
...
if (new_user.created_at < 10.minutes.ago)
&& !new_user.invitation_token
&& (new_user.created_at == new_user.updated_at)
if (u2.made < 10.minutes.ago)
&& !u2.tkn
&& (u2.made == u2.l_edit)
...
def safe_convert_to_html string
...
end
def process_text string
end
@peternixey
peternixey / ga_last_x_days.js
Created June 28, 2012 11:24
Google Analytics bookmark to show just the last X days of data
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 March 5, 2012 13:10
How Homakov hacked GitHub and how to protect your application by Peter Nixey

##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 January 20, 2012 12:44
Some changes I made to the vanilla Rails / Spork / RSpec setup to ensure models get reloaded
# make sure your rspec block has the cli => drb line:
guard 'rspec', :cli => "--drb", :version => 2 do
@peternixey
peternixey / test.rb
Created December 9, 2011 12:27
test gist
a = 2
class Test
end