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
# Let's say you have a join between Address and Job | |
# You want to use a scope on Job to limit the jobs that have to be joined otherwise you would join all jobs. | |
# So you try this | |
Address.joins('INNER JOIN jobs ON jobs.id = addresses.addressable_id AND addresses.addressable_type = "Job" AND ' \ | |
'addresses.address_type = "physical"').where(Job.in_the_future) | |
# What you get is an error like so | |
# Job Load (1.1ms) SELECT `jobs`.* FROM `jobs` WHERE (start_datetime > '2014-04-28 16:06:12') | |
# (pry) output error: #<TypeError: Cannot visit ActiveRecord::Relation::ActiveRecord_Relation_Job> |
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
// job quote make the following assumptions: | |
// 1 hr job during the week (normal/standard rate) | |
// travel costs are included | |
// includes interp minimum job hours (some interps have a requirement for two hours) | |
// does not include tax | |
{ "job_quote": { "min_cost": "$20", "max_cost": "$65" } | |
"interpreters": | |
[ | |
{ "cityState": "Austin, TX 78758", "latitude": 123.456, "longitude": 123.456, "hourlyRate": "$45" }, | |
{ "cityState": "San Antonio, TX 77577", "latitude": 456.789, "longitude": 456.789, "hourlyRate": "$65" }, |
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
loglevel notice | |
logfile "" | |
dir vendor/redis/db/ |
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
en: | |
helpers: | |
submit: | |
offer: | |
create: "Make Offer" | |
bid: | |
create: "Place Bid" | |
activerecord: | |
errors: | |
models: |
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
def twitter_links(txt) | |
match = [] | |
#link @user | |
if match = txt.scan(/@([A-Za-z0-9_]+)/i) | |
match.each do |user| | |
txt.gsub!('@'+user[0], '<a href="http://twitter.com/' + user[0] + '">@' + user[0] + '</a>') | |
end | |
end | |
#link #hash_tags | |
if match = txt.scan(/\B#\w*[a-zA-Z]+\w*/i) |
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
def active_link(path, match_top_dir=false) | |
debugger | |
if match_top_dir == true | |
req_path_a = request.path.to_s.split('/') | |
path_a = path.split('/') | |
if req_path_a[1] == path_a[1] | |
return 'selected' | |
end | |
else | |
if path == request.path |
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
#requires time_diff gem | |
def time_ago(time) | |
parsed_time = Time.parse(time) | |
time_diff = Time.diff(parsed_time, Time.now) | |
formated_time = "" | |
if time_diff[:day] > 0 || time_diff[:month] > 0 || time_diff[:year] > 0 | |
formated_time += "#{parsed_time.day}" if time_diff[:day] > 0 | |
formated_time += " #{parsed_time.strftime("%b")}" if time_diff[:month] > 0 | |
formated_time += " #{parsed_time.strftime("%y")}" if time_diff[:year] > 0 | |
else |
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
convert original.jpg -resize 200x200^ -gravity Center -crop 200x100+0+0 +repage thumbs.jpg |
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 Array | |
def chunk(pieces=2) | |
len = self.length; | |
mid = (len/pieces) | |
chunks = [] | |
start = 0 | |
1.upto(pieces) do |i| | |
last = start+mid | |
last = last-1 unless len%pieces >= i | |
chunks << self[start..last] || [] |
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
def split_paragraphs(text,limit,wrapper_id_short=nil,wrapper_id_long=nil) | |
results = text.scan(/<p>.*?<\/p>/) | |
i = 0 | |
length = 0 | |
short_p = "" | |
while length < limit && i <= results.count - 1 | |
short_p << results[i] | |
length += results[i].length - 7 | |
i+= 1 | |
end |
OlderNewer