Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Pauly bradpauly

View GitHub Profile
View configuration.rb
class Configuration
def method_missing(name)
self.class.instance_variable_get("@#{name}")
end
def self.set(name, value)
instance_variable_set("@#{name}", value)
end
def self.default(name, value)
View gist:51d8ad4216483cf3b303
class TodoSummaryJob
def self.send_daily_summary
zones_to_search = User.unique_time_zone_names
zones_ready_for_email = TimeZoneSearch.new(zones_to_search).zones_with_local_hour(8)
User.in_time_zones(zones_ready_for_email).each do |user|
UserMailer.daily_summary(user, user.todos.unfinished).deliver
end
end
end
View gist:9be51f96d750add0f8c9
class User < ActiveRecord::Base
scope :in_time_zones, -> { |zones| where(time_zone_name: zones) }
def self.unique_time_zone_names
select("DISTINCT time_zone_name").pluck(:time_zone_name).compact
end
end
View gist:2f62a4cf118baa99d75e
require 'TZInfo'
class TimeZoneSearch
def initialize(zones_to_search)
@zones_to_search = zones_to_search
end
def zones_with_local_hour(hour_to_match, utc_time = Time.now.utc.to_datetime)
zone_matches = []
utc_minute = utc_time.minute
View gist:acb7d691a412580a9cdc
require 'TZInfo'
today = Time.now
(0..23).each do |hour|
(0..45).each do |minute|
utc_time_to_check = Time.utc(today.year, today.month, today.day, hour, minute, 0)
TZInfo::Timezone.all_identifiers.each do |zone_name|
local_tz = TZInfo::Timezone.get(zone_name)
local_time = local_tz.utc_to_local(utc_time_to_check).to_datetime
if local_time.minute == 0 && local_time.hour == 8
View gist:a7b4557bb51914460dd2
class Matrix
def initialize(numbers)
@numbers = numbers
end
def rows
@rows ||= @numbers.split("\n").map{ |row| row.split.map(&:to_i) }
end
def columns
View time_zone_search.rb
# Search all zones for 8:00am.
(0..23).each do |hour|
[0, 15, 30, 45].each do |minute|
utc_time_to_check = Time.utc(2014, 6, 28, hour, minute, 0)
TZInfo::Timezone.all_identifiers.each do |zone_name|
local_tz = TZInfo::Timezone.get(zone_name)
local_time = local_tz.utc_to_local(utc_time_to_check).to_datetime
if local_time.minute == 0 && local_time.hour == 8
puts utc_time_to_check.strftime("%H:%M") + ' UTC => ' + local_time.strftime("%H:%M") + ' in ' + zone_name
end
View gist:9125697
class Pet < ActiveRecord::Base
as_enum :species, {:cat => 0, :dog => 1, :other => 2}, :prefix => true
as_enum :status, {:lost => 0, :found => 1}, :prefix => true
validates :name, :description, :zip, :species_cd, presence: true
validates :zip, numericality: { only_integer: true}
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
View .bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
You can’t perform that action at this time.