Skip to content

Instantly share code, notes, and snippets.

@pieterjongsma
pieterjongsma / keybase.md
Created August 5, 2019 20:58
Keybase proof

Keybase proof

I hereby claim:

  • I am pieterjongsma on github.
  • I am pieterjongsma (https://keybase.io/pieterjongsma) on keybase.
  • I have a public key ASATlYW-Nj-NDSnyWnehBvqPZVavtL14yj0m1rPzMcOhrAo

To claim this, I am signing this object:

class EventWithFriends
def initialize(object, attending_friends_by_user_id)
super(object)
@attending_friends_by_user_id = attending_friends_by_user_id
end
def attending_friends_for_user(user)
@attending_friends_by_user_id[user.id] || super(user)
end
end
class EventWithFriends < SimpleDelegator
def attending_friends_for_user(user)
super(user)
end
end
class EventsFeed
def events
@events.map { |event| EventWithFriends.new(event) }
end
class EventsFeed
include Enumerable
delegate :each, :<<, to: :events
def initialize(events:, user:)
@events = events
@user = user
end
def events
- @events.each do |event|
%ul
- event.attending_friends_for_user(current_user).each do |friend|
%li= friend.name
class Event
def attending_friends_for_user(user)
attendees.friends_for(user)
end
end
class User
scope :friends_for, -> (user) { includes(:friendships).where(friendships: { friend_id: user.id }) }
end
class User
has_many :friendships
has_many :friends, through: :friendships
has_many :attendances
has_many :events, through: :attendances
end
class Event
has_many :attendances
has_many :attendees, through: :attendances, source: :user
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :catch_escaped_fragment
protected
def catch_escaped_fragment
if fragment = params[:_escaped_fragment_]
# Build the original url
//
// ember_to_static.js
//
// This script takes a URL as argument. (In that order!)
// The script then runs the Javascript on this page and waits until Ember has finished loading.
// It then renders the resulting static HTML page to the console.
//
var fs = require('fs');
var system = require('system');
var get = Ember.get, set = Ember.set;
Ember.HashExclamationLocation = Ember.Object.extend({
init: function() {
set(this, 'location', get(this, 'location') || window.location);
},
getURL: function() {
return get(this, 'location').hash.substr(2);
},