Skip to content

Instantly share code, notes, and snippets.

@joeljackson
joeljackson / Working
Created August 13, 2011 05:33
Facebook init
<script>
FB.init({
appId : '<%= FACEBOOK_ID %>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
</body>
</html>
@joeljackson
joeljackson / Commented out
Created August 13, 2011 05:34
Facebook init
initialize_with_facebook: ->
#FB.init @facebook_settings
FB.getLoginStatus (response) =>
exports.session = response.session
@user = new User(response.session, @userCreatedCallback)
__hasProp = Object.prototype.hasOwnProperty,
__extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key))
child[key] = parent[key];
}
function ctor() {
this.constructor = child;
}
ctor.prototype = parent.prototype;
tr {
th {
.orange_table_header;
}
td:first-child{
width:10px;
cursor: pointer;
span.xfire_tooltip_body{
display: none;
color: white;
@joeljackson
joeljackson / Gemfile
Created February 13, 2013 07:13
Gemfile, Better Errors
# Replay of errors and other awesomeness
gem 'better_errors'
gem 'binding_of_caller'
@joeljackson
joeljackson / FragmentCache.html.erb
Last active December 13, 2015 22:28
Fragment Cacheing
<% cache(:action_suffix => "game_card.#{I18n.locale}", :expires_in => 1.hour) do %>
<%= render :partial => 'game_card', :locals => { :game_product => @game.product } %>
<% end %>
@joeljackson
joeljackson / FragmentCache.html.erb
Last active December 13, 2015 22:29
Fragment Cacheing, Done Right
<% cache({:action_suffix => "game_card.#{I18n.locale}"}, :expires_in => 1.hour) do %>
<%= render :partial => 'game_card', :locals => { :game_product => @game.product } %>
<% end %>
@joeljackson
joeljackson / CacheDelete.rb
Last active December 13, 2015 22:29
Clearing out the Fragment Cache
Rails.cache.delete("views/#{fully_qualified_domain}/#{url}?action_suffix=#{whatever I named the suffix}&expires_in=3600")
@joeljackson
joeljackson / photo.rb
Created February 21, 2013 08:08
Your class, no refactoring
class Photo < ActiveRecord::Base
belongs_to :user
has_many :notifications
has_attached :picture
after_create :notify_users
def notified_users
User.where("id in (?)", self.notifications.map(&:user_id))
@joeljackson
joeljackson / new_code.rb
Created February 21, 2013 08:21
And after some simple refactoring
module Notifiable
def self.included(klass)
klass.has_many :notifications
end
def notified_users
User.where("id in (?)", self.notifications.map(&:user_id)
end
end