This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do | |
$$ | |
declare | |
l_rec record; | |
begin | |
for l_rec in (select foreign_table_schema, foreign_table_name | |
from information_schema.foreign_tables) loop | |
execute format('drop foreign table %I.%I cascade', l_rec.foreign_table_schema, l_rec.foreign_table_name); | |
end loop; | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE VIEW public.active_locks AS | |
SELECT t.schemaname, | |
t.relname, | |
l.locktype, | |
l.page, | |
l.virtualtransaction, | |
l.pid, | |
l.mode, | |
l.granted | |
FROM pg_locks l |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE VIEW public.active_locks AS | |
SELECT t.schemaname, | |
t.relname, | |
l.locktype, | |
l.page, | |
l.virtualtransaction, | |
l.pid, | |
l.mode, | |
l.granted | |
FROM pg_locks l |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE SERVER [SERVER_NAME] | |
FOREIGN DATA WRAPPER postgres_fdw | |
OPTIONS (host '[YOUR_HOST]', port '[PORT]', dbname '[DB_NAME]', sslmode 'require'); | |
CREATE USER MAPPING FOR [DB_USER] | |
SERVER [SERVER_NAME] | |
OPTIONS (user '[FOREIGN_USER]', password '[FOREIGN_PW]'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install.packages( | |
lib = lib <- .libPaths()[1], | |
pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package, | |
type = 'source' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Downloading the latest backup from the Core Servers" | |
echo | |
curl --insecure -O https://wherever-bz2-backup-origin.sql | |
echo "Download complete" | |
echo | |
echo "Unzipping this beast, and plopping it right in the core db on AWS" | |
echo | |
bunzip2 < backup.sql.bz2 | mysql -u [USER] -pw[PW] --host [HOST] [DBNAME] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Boot chumps from your heroku free dynos | |
## PS the app | |
heroku ps -a [APP] | |
## Find that one-off process, snag that pid | |
=== run: one-off processes (1) | |
run.4570 (Free): up 2016/03/03 10:01:16 -0800 (~ 8m ago): bin/rails console | |
## Tossed like a chump |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrphanAnnie | |
class << self | |
def perform | |
fake_orphan_locations = mom_is_that_you | |
write_to_loggers("#{fake_orphan_locations}") | |
rehome_fake_orphans | |
write_to_loggers("There are #{Widget.orphans.count} orphans left.") | |
Resque.enqueue(WidgetCleanupJob) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to find duplicate website objects in a CMS! | |
#map an array of all websites 'owner_id' | |
loc_ids = Website.all.map {|web| web.owner_id} | |
#returns the duplicates | |
loc_ids.select{ |id| loc_ids.count(id) > 1}.uniq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :clean do | |
task :snags => :environment do | |
Location.all.each do |loc| | |
@pages = loc.website.web_page_templates | |
@pages.each do |i| | |
i.update_attribute(:parent_id, nil) if i.parent_id? | |
end | |
nav_id = (GardenWidget.find_by name: "Navigation").id | |
@nav_setting = (loc.website.widgets.find_by garden_widget_id: nav_id).navigation.object |