Skip to content

Instantly share code, notes, and snippets.

View swards's full-sized avatar

Mark Swardstrom swards

View GitHub Profile
@swards
swards / Localhost Production Bookmarklet
Created December 19, 2011 23:20
Bookmarklet for switching between localhost and production
javascript:domain=%22www.mydomain.com%22;a=document.location.href.match(/http:\/\/([^\/]+)\/(.+)/);if(a[1].match(domain)){document.location=%22http://localhost:3000/%22+a[2]}else{document.location=%22http://%22+domain+%22/%22+a[2]}
@swards
swards / erbtohaml
Last active August 29, 2015 14:03
A script to go through all erb files and convert them to haml
// Run without 'bash' to see the commands called. To be run from the root of the application folder (above the app directory)
$ find app -name '*.erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \
bash
// And a script to remove all erb files via git (remove 'git' if not in git yet)
$ find app -name '*.erb' | \
xargs ruby -e 'ARGV.each { |i| puts "git rm #{i}"}' | \
@swards
swards / gist:a9dc956c416c327372c1
Last active August 29, 2015 14:07
Migrate from Mongo to Postgres
Tested on: Rails 3.2, Mongoid 2.0.1, pg 0.12.0 gem
Using Clearance (not devise)
1. remove mongoid gem(s)
2. add pg gem
3. in application.rb re-add ActiveRecord
4. for all models
- inherit from < ActiveRecord::Base
@swards
swards / gist:e3e9442bda4adafbbed1
Last active August 29, 2015 14:19
In Ruby - List all files and order by the day they were last modified. Note, irb is launched from the rails application directory. This is very helpful if your contracting and want to see what files have changed recently.
$ irb
> puts Dir['app/**/*'].sort_by{ |f| File.mtime(f) }.map{|f| "#{f} #{" " * (80-f.length)} #{File.mtime(f).strftime('%m%d')}"}
heroku pgbackups:capture --app <appname>
curl -o private/latest.dump `heroku pg:backups public-url --app <appname>`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d <appname>-development private/latest.dump