Skip to content

Instantly share code, notes, and snippets.

View weyus's full-sized avatar

Wes Gamble weyus

View GitHub Profile
def show_flash(level = :notice)
unless flash[level].nil?
html = <<-EOT
<blockquote id="flash-#{level.to_s}" class="#{level.to_s}">
<p>#{flash[level]}</p>
</blockquote>
EOT
unless level == :error
html << update_page_tag do |page|
@weyus
weyus / gist:899848
Created April 2, 2011 20:26
Simple way to default all fields of a table when there are NOT NULL columns that you don't want to set (Rails 2.3.8)
def after_initialize
if new_record?
Mergeinfo.columns.select {|c| (! c.null) && (c.name != Mergeinfo.primary_key)}.each do |c|
default_value = case c.type
when :integer
0
when :string
''
when :boolean
false
@weyus
weyus / gist:1036855
Created June 20, 2011 23:24
Cron job to allow for arbitrarily timed Heroku tasks without using a worker dyno.
#The following assumes an object named "obj" with an action named "meth" that you want to execute at a certain time.
#It is assumed that 'obj' has some notion of what weekday and time (hours and minutes) it needs to be executed.
#For the purposes of this example, it will be attached directly to obj., but could just as easily come from some associated object.
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
current_time = Time.now
if obj.day == current_time.wday && obj.hour == current_time.hour
sleep(obj.min * 60)
obj.meth
end
@weyus
weyus / correlated_subquery
Created December 27, 2011 20:06
SQL output of ActiveRelation or Arel query that I would like
SELECT user_id, fb_request_id
FROM monitor_requests mr
WHERE current_state = '#{MonitorRequest::DENIED}'
AND fb_id IS NULL
AND fb_name IS NULL
AND created_at < '#{1.week.ago}'
AND user_id IS NOT NULL
AND fb_request_id IS NOT NULL
AND EXISTS (SELECT * FROM monitor_requests WHERE current_state = '#{MonitorRequest::PENDING}' AND fb_request_id = mr.fb_request_id)
@weyus
weyus / gist:460e5a50e4b0944914945e7e82ef2010
Created July 20, 2017 22:27
Failed rvm install of ree
$ LDFLAGS='-L/usr/local/opt/openssl/lib' CPPFLAGS='-I/usr/local/opt/openssl/include' PKG_CONFIG_PATH='/usr/local/opt/openssl/lib/pkgconfig' rvm reinstall --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2j ree-1.8.7-2012.02
ree-1.8.7-2012.02 - #removing src/ree-1.8.7-2012.02......
ree-1.8.7-2012.02 - #removing rubies/ree-1.8.7-2012.02......
Installing Ruby Enterprise Edition from source to: /Users/gamblew/.rvm/rubies/ree-1.8.7-2012.02
ree-1.8.7-2012.02 - #fetching (ruby-enterprise-1.8.7-2012.02)
ree-1.8.7-2012.02 - #extracting ruby-enterprise-1.8.7-2012.02 to /Users/gamblew/.rvm/src/ree-1.8.7-2012.02.................
Checking requirements for osx.
Missing required packages: [email protected]
Somehow it happened there is no executable 'openssl',
run 'brew doctor' and make sure latest '[email protected]' is installed properly.