Skip to content

Instantly share code, notes, and snippets.

View joncode's full-sized avatar
🏠
Working from home

Jon Gutwillig joncode

🏠
Working from home
View GitHub Profile
@joncode
joncode / gist:ba9325652ab51bf32c70
Last active August 29, 2015 14:05
Resque commands
http://www.rubydoc.info/gems/resque/frames
Resque.info
{:pending=>0, :processed=>157473, :queues=>7, :workers=>21, :working=>0, :failed=>0, :servers=>["redis://barb.redistogo.com:9497/0"], :environment=>"production"}
Resque.workers
returns an array of workers available
Resque.workers.each {|w| w.prune_dead_workers }
kills dead workers
w = Resque.workers[0]
@joncode
joncode / gist:4887c23a894731e79fff
Created August 7, 2014 00:06
to see what foreign keys in your app havent been indexed
c = ActiveRecord::Base.connection
c.tables.collect do |t|
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{t}: #{unindexed.join(", ")}"
end
end
@joncode
joncode / gist:9dcb021e2ef11c632b14
Created July 24, 2014 23:04
Retry code for resque jobs
module RetryOnTermJob
def around_perform_retry_on_term(*args)
begin
yield *args
rescue Exception => e
if e.message =~ /SIGTERM/
# when a worker `extend`s this class, self is that worker class
Resque.enqueue(self, *args)
else
raise
@joncode
joncode / gist:6980048
Last active December 25, 2015 12:59
changing databases heroku psql

go to heroku.com the site you are upgrading

  1. add the new database - we chose 'CRANE' for 50$ / month

     heroku addons:add heroku-postgresql:crane        
    
  2. in console

     heroku pg:wait --remote staging
    
@joncode
joncode / gist:6702230
Created September 25, 2013 16:28
MOVING A BRANCH POINTER
git reset --hard 10123974102937840192374
this moves the pointer to that commit. This is what you want most of the time
git reset --soft 0238947293842937429384723
this moves the pointer and via an index that you commit , very strange.
@joncode
joncode / gist:6601579
Created September 17, 2013 22:30
STASH apply
git stash
stash the last commit
git stash apply
applies the last stash
git stash apply stash@{2}
if you want one of the older ones
git stash drop with the name of the stash to remove:
@joncode
joncode / gist:6300104
Last active December 21, 2015 11:38
Creating a .CSR and making a domain SSL
@joncode
joncode / gist:6274015
Last active December 21, 2015 07:49
Attachinary how to add ...

Setup


  1. add the cloudinary and attachinary Rails 4 gems

    gem 'cloudinary'

    gem 'attachinary', git: 'git://github.com/rochers/attachinary.git', branch: 'rails4'

@joncode
joncode / gist:6160888
Last active December 20, 2015 16:19
Removing any SECRET_TOKEN from source control
1. make a new secret token at the command line
rake secret
2. set the var in staging and production, run for each
heroku config:set SECRET_TOKEN=9813745901y30fhi2304ify1034yf1083y5r013yfr0813gf9 --remote <stagingORproduction>
3. remove the secret_token.rb code in favor of the GETTER for ENV['SECRET_TOKEN"]
YourAPP::Application.config.secret_key_base = if Rails.env.development? or Rails.env.test?
"3eb6db5a9026c547c72708438d496d942e976b252138db7e4e0ee5edd7539457d3ed0fa02ee5e7179420ce5290462018591adaf5f42adcf855da04877827def2"
else
@joncode
joncode / gist:6082450
Created July 25, 2013 18:31
LINKS that popup new windows and new tabs !
<%= link_to "NEW TAB", merchants_path, :target => '_blank' %>
<%= link_to "POPUP!",
merchants_path,
:onclick=>"window.open(this.href,'popup_form', 'height=371, width=460, top=200px, left=100px, directories=no, location=no, menubar=no, status=no, titlebar=no, toolbar=no, status=no');return false;" %>