This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this is a another test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new_arr = [] | |
arr = [{:a=>"test1", :b=>1, :c=>2}, {:a=>"test1", :b=>4, :c=>6}, {:a=>"test2", :b=>4, :c=>5}] | |
types = arr.collect{|item| item[:a] }.uniq | |
types.each do |type| | |
related_hashes = arr.select {|item| item[:a] == type } | |
new_arr.push({ | |
b: related_hashes.inject(0) {|sum, hash| sum + hash[:b]}, | |
c: related_hashes.inject(0) {|sum, hash| sum + hash[:c]} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Group | |
has_many :things | |
# external data would look like: | |
# { | |
# things: { | |
# 1: "some data for 1", | |
# 2: "some data for 2", | |
# etc... | |
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HstoreAccessor | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def hstore_accessor(hstore_attribute, type, *keys) | |
Array(keys).flatten.each do |key| | |
# Dynamic setter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pin_hidden_container{ display: none; } | |
#pin_container{ | |
width: 298px; | |
height: 248px; | |
background-color: #fff; | |
position: relative; | |
font-size: 12px; | |
font-family: Arial, Helvetica, sans-serif; | |
padding: 1px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pinterest = { | |
init: function(){ | |
var ad_container = document.getElementById("ad"); | |
ad_container.innerHTML = pinterest.template(); | |
pinterest.pull_in_stylesheet(); | |
google.setOnLoadCallback(pinterest.get_feed); | |
}, | |
pull_in_stylesheet: function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# provided the query is right.... | |
User.all(:joins => 'LEFT JOIN ad_scripts ON ad_scripts.user_id = users.id', :group => 'users.id', :having => 'COUNT(ad_scripts.id) = 0').each |user| do | |
user.send_later_slow(:create_ad, "300x250", "Staree", "desktop", 45, 0, 1) unless user.has_desktop_big_ad? | |
user.send_later_slow(:create_ad, "300x250", "Staree", "desktop", 45, 0, 2) unless user.has_desktop_small_ad? | |
user.send_later_slow(:create_ad, "320x50", "Mobile", "mobile", 45, 0, 3) unless user.has_mobile_ad? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sql select you were using | |
medias = Media.find_by_sql("SELECT user_id, name, comment, COUNT(medias.id) FROM medias INNER JOIN users ON medias.user_id = users.id WHERE comment <> "" AND upload_source IN ('Facebook Importer', 'Twitter Importer') GROUP BY comment HAVING COUNT(medias.id) > 1 ORDER BY COUNT(medias.id) DESC;") | |
# loop through all records found | |
medias.each do |media| | |
# get the duplicate records for a particular user | |
uploads = Media.find(:all, :conditions => {:user_id => media["user_id"], :comment => media["comment"]}) | |
# loop through them |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gh = { | |
setup: function(){ | |
$(".gh_tag").live("click", gh.tags.cycle); | |
$(".ghx-corner").live("click", gh.time.update); | |
gh.subtasks.summarize(); | |
}, | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# some view: | |
# V1: | |
<% actions.each do |action| %> | |
<%= render :partial => "actions/#{action.class.to_s.downcase}", :object => action %> | |
<% end %> | |
# V2: | |
<% actions.each do |action| %> | |
<%= render :partial => action.partial_name, :object => action %> |
NewerOlder