Skip to content

Instantly share code, notes, and snippets.

View tammersaleh's full-sized avatar
🚀
Orbiting?

Tammer Saleh tammersaleh

🚀
Orbiting?
View GitHub Profile
ready: function(fn) {
// Attach the listeners
bindReady();
// If the DOM is already ready
if ( jQuery.isReady )
// Execute the function immediately
fn.call( document, jQuery );
// Otherwise, remember the function for later
# I add authorization query methods to every ActiveRecord model (through ActiveRecord::Base).
#
# Each model is given the following methods:
#
# == Class methods:
#
# Model.creatable?
# Model.creatable_by? user
#
# == Instance methods:
mislav-will_paginate --version '= 2.3.11' --source http://gems.github.com
justinfrench-formtastic --version '= 0.2.2' --source http://gems.github.com
josevalim-inherited_resources --version '= 0.8.5' --source http://gems.github.com
thoughtbot-paperclip --version '= 2.3.1' --source http://gems.github.com
authlogic --version '= 2.1.1'
yard --version '= 0.2.3.5'
class ProductState < ActiveRecord::Base
attr_accessible :name, :description
acts_as_enumeration :new, :active, :locked, :sold, :expired, :removed, :deleted
validates_presence_of :description
def to_s
name
end
end
module IdEnumeration
def acts_as_enumeration(*ordered_list_of_values)
ordered_list_of_values.map(&:to_s).each_with_index do |value, index|
const_set(value.upcase, index + 1)
self.class.send(:define_method, "find_#{value}!") do
find(const_get(value.upcase))
end
self.class.send(:define_method, "find_#{value}") do
class ShoppingCart < ActiveRecord::Base
has_many :shopping_cart_items
def remove_product(product)
for item in shopping_cart_items do
if item.product == product then
item.destroy
shopping_cart_items.reload
break
end
#header {
color: black;
.navigation; /* this is a mixin, cause it doesn't have a {}? */
.logo { /* this is a scoped rule cause it does? */
width: 300px;
:hover { text-decoration: none }
}
}
d1d466fa50fb8ffe876161bdf42d454e2951291e foo bar - Tammer Saleh
cda4cc825c031f8c72069acbf06dfa20e9ba5a1d bar - Tammer Saleh
c15cd6ce3468c44bb537bdbeb6147398fd14cc18 foo - Tammer Saleh
31d5f34297a231493c3db68536c64ef0ec273b2c more work - Tammer Saleh
d772be305b23b54da42cdb8a8e978ce6c936c29e stuf - Tammer Saleh
27a7952319856dca1325c64b3ad137643dc4b018 stuff. - Tammer Saleh
19e0bb28a3d67a2588454f9cf769f0b577464e33 more. - Tammer Saleh
8fd6ef48ffc7321da2c87b6f8b3d60061e0f4d0a moved files into files. duh. - Tammer Saleh
scroll_page_to: function(element, doc) {
if (element.length < 1) { log("Error: cannot find element for scrolling."); };
var offset = element.offset().top;
log("scrolling to element " + element.attr("id") + " at " + offset);
$('html').animate({scrollTop: offset}, 500);
}
class Counterpoint < ActiveRecord::Base
belongs_to :owner, :class_name => "User"
validate :ensure_owned_by_journalist
def self.creatable?
return false unless user_from_session
return false if user_from_session.company_representative?
return true
end