Skip to content

Instantly share code, notes, and snippets.

View notrab's full-sized avatar

Jamie Barton notrab

View GitHub Profile
@notrab
notrab / gravatar_helper.php
Created March 12, 2013 19:19
Gravatar helper for CodeIgniter
<?php
function gravatar_from_email($email, $size = '50', $rating = 'g', $default = null, $alt = null, $class = null)
{
return img(array(
'src' => 'http://gravatar.com/avatar/'.md5( strtolower( trim( $email ))).'?'.($rating != null ? '&r='.$rating : '').($size != null ? '&s='.$size : '').($default != null ? '&d='.$default : ''),
'alt' => $alt,
'class' => $class
gem 'omniauth'
gem 'omniauth-facebook'
gem 'clearance'
@notrab
notrab / door_core.rb
Created March 25, 2014 17:17
Work out the ratio and different door sizes from a given minimum and maximum door width and height.
class DoorCore
def initialize(min_width, max_width, min_height, max_height)
@width = max_width - min_width
@height = max_height - min_height
@ratio = @height / @width
end
attr_accessor :width, :height, :ratio
end
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, :class_name => "User"
def self.feeling_mutual? user_id, friend_id
return true if find_by(user_id: user_id, friend_id: friend_id) && find_by(friend_id: friend_id, user_id: user_id)
false
end
module ApplicationHelper
def title(page_title)
content_for(:title) { page_title.html_safe }
end
def smaller_page(c = nil)
content_for(:smaller_page) { 'slim' } unless c.nil?
end
def no_mobile_sidebar(c = nil)
class DoorCore
def initialize(input_width)
@min_height = 2120.to_f
@max_height = 2455.to_f
@min_width = 915.to_f
@max_width = 1080.to_f
@input_width = input_width
end
def predicted_max_height
# lib/account_detector.rb
class AcountDetector
def initialize(app)
@app = app
end
def call(env)
account = Club.find_by custom_domain: env["HTTP_HOST"]
if account
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
@notrab
notrab / gist:c8618aae2843765b7953
Created December 4, 2014 09:54
Show colours on hover
<% if product.has_colours? && (product.type_name.parameterize == 'fire-smoke' || product.type_name.parameterize == 'fire-only') %>
<div class="extended">
<h4>Colours:</h4>
<ul class="colours">
<% product.all_colours.each do |c| %>
<%= content_tag :li, c, class: c.parameterize, alt: c, title: c %>
<% end %>
</ul>
</div>
<% end %>
<%= content_tag :li, class: product.primary_collection.to_param do %>
<%= link_to collection_product_path(product.primary_collection, product) do %>
<div class="thumbnail">
<%= product_thumbnail(product) %>
</div>
<div class="summary">
<h3><%= product.name %></h3>
<p class="type"><%= product.type_name %></p>
<% if product.manufacturer_name.present? %>