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 / 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
@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 / 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 / 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 / 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("jane.doe@example.com").job_postings
@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 / .zshrc
Created March 21, 2012 19:49
Current zshrc
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="afowler"
export EDITOR="vim"
@phudgins
phudgins / .gitconfig
Created March 21, 2012 19:55
current .gitconfig
[user]
name = XXXX
email = XXXX
[color]
diff = auto
status = auto
branch = auto
[color "status"]
changed = yellow
added = green
@phudgins
phudgins / cleanout-rvm.sh
Created April 10, 2012 12:35
Remove RVM if rvm implode doesn't work
#!/bin/bash
/usr/bin/sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm /usr/local/bin/rvm
/usr/bin/sudo /usr/sbin/groupdel rvm
/bin/echo "RVM is removed. Please check all .bashrc|.bash_profile|.profile|.zshrc for RVM source lines and delete or comment out if this was a Per-User installation."
@phudgins
phudgins / date_range.rb
Created April 25, 2012 18:13
Iterate through a Date Range
(30.days.ago.to_date..Date.today).each do |date|
puts date.to_s
end