Skip to content

Instantly share code, notes, and snippets.

View Sillson's full-sized avatar
🛰️
🌲 🔥 🎄 🔥

Stuart Illson Sillson

🛰️
🌲 🔥 🎄 🔥
View GitHub Profile
@Sillson
Sillson / psql_drop_foreign_tables.sql
Created April 7, 2017 16:15
Drop foreign schema tables
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;
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
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
@Sillson
Sillson / exchange_student.sql
Created February 14, 2017 18:13
Create a foreign data connection in postgres
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]');
@Sillson
Sillson / upgRade.R
Created January 27, 2017 21:50
install latest version of all R packages that are currently installed
install.packages(
lib = lib <- .libPaths()[1],
pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
type = 'source'
)
@Sillson
Sillson / db_swap.sh
Created January 10, 2017 17:59
Download a remote bz2 sql backup, and dump into a remote DB.
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]
@Sillson
Sillson / GetOutMyRailsConsole
Last active August 30, 2017 03:44
Boot sorry suckers out of a heroku rails console
## 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
@Sillson
Sillson / name_me_a_widget.rb
Last active November 12, 2015 18:12
Output an array of widget names & locations
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
@Sillson
Sillson / dupe.rb
Created August 13, 2015 17:07
Find dupes
# 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
@Sillson
Sillson / snag.rake
Last active August 29, 2015 14:25
Clean orion navigation nastiness after a clone
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