Skip to content

Instantly share code, notes, and snippets.

View phudgins's full-sized avatar

Pete Hudgins phudgins

  • Dominion Enterprises
  • Norfolk, VA
View GitHub Profile
@phudgins
phudgins / counts_by_day_for_job_posting.rb
Created February 14, 2012 19:50
Getting count of JobApplications by day for a specific JobPosting
def counts_by_day_for_job_posting(job_posting_id)
results = JobApplication.where(job_posting_id: job_posting_id).
where(created_at: 1.month.ago..Time.now).
group('date(created_at)').count
counts = []
results.each do |result|
h = { date: Date.parse(result.first),
job_posting_id: job_posting_id,
application_count: result.last }
counts << h
@phudgins
phudgins / sort_job_postings.rb
Created February 8, 2012 13:44
Sort collection of job_postings by 'status' and 'posted_at DESC' on Orion
def status_value(status)
return 1 if status=='pending'
return 2 if status=='active'
return 3 if status=='closed'
end
# Sort collection of job_postings by 'status' and 'posted_at DESC' on Orion
@jps = User.find_by_email("[email protected]").job_postings
@phudgins
phudgins / whitespace_bye_bye.rb
Created January 9, 2012 20:14
Remove whitespace from HTML tags with only whitespace
str = "<strong> </strong> <p> Hello dere! </p> <ul> <li> </li> <li> I am list </li> </ul>"
# Remove only whitespace
str.gsub(/((<[^>\/]+>)(\s+)(<\/[^>\/]+>))/, '\2\4')
#=> "<strong></strong> <p> Hello dere! </p> <ul> <li></li> <li> I am list </li> </ul>"
# Remove tags that contain only whitespace
str.gsub(/\s*<[^>\/]+>\s+<\/[^>\/]+>\s*/, '')
#=> "<p> Hello dere! </p> <ul><li> I am list </li> </ul>"
@phudgins
phudgins / clean_string.rb
Created January 5, 2012 20:04
Remove non-UTF8 chars from a string
require 'active_support/core_ext/string'
str = "<p>Seeking self-motivated Senior SQL Server DBA who will work closely with development teams and support the enterprise databases for four automotive businesses.</p> <p>  </p> <p> We are seeking a team player, who is a great communicator, that is well versed in SQL Server 2005 and 2008.</p> <p>  </p> <p> This person should possess skills in SQL Server database administration including: performance tuning, backup and recovery, log shipping, and T-SQL.</p> <p>  </p> <p> With limited supervision, the Sr DBA will be responsible for:</p> <p>  </p> <ul> <li> The administration and maintenance of Enterprise level SQL Server 2005 and 2008 database systems for three Dominion companies supplying websites and CRM tools for automotive dealerships in an environment requiring 24 X 7 up time</li> <li> The management and administration of 30+ TB of data in a NetApp/EMC SAN environment in two hosting facilities</li> <li> Excellent internal customer service and decision-making a
@phudgins
phudgins / meme_capt.rb
Created December 7, 2011 19:45
meme capt api call
require 'typhoeus'
require 'yajl/json_gem'
require 'active_support/core_ext/hash'
require 'active_support/core_ext/object'
hydra = Typhoeus::Hydra.new
params = { u: "http://memecaptain.com/all_the_things.jpg",
tt: "All the things",
tb: "use memecaptain api!" }.to_param
@phudgins
phudgins / time_remaining.rb
Created May 10, 2011 13:13
Determining the estimated completion of Delayed Jobs
include ActionView::Helpers::DateHelper
def time_remaining
start_count = Delayed::Job.count
if start_count == 0
rate = 0
start_time = Time.now
time_remaining = distance_of_time_in_words(start_time, start_time)
else
sleep(10)
end_count = Delayed::Job.count