Skip to content

Instantly share code, notes, and snippets.

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

Stuart Illson Sillson

🛰️
🌲 🔥 🎄 🔥
View GitHub Profile
@Sillson
Sillson / db.rake
Last active August 29, 2015 14:25 — forked from hopsoft/db.rake
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@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
@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 / 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 / get-down-with-down-arrows.js
Last active April 23, 2016 15:24
Gettin down with down-arrows
</style><script>function insertAfter(referenceNode, newNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
console.log(referenceNode.parentNode);
}
var div = document.getElementsByClassName("row-grid");
var locationName = "[ENTER LOCATION NAME]";
var locationCity = "[ENTER LOCATION CITY]";
var locationState = "[ENTER LOCATION STATE]";
@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 / 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 / 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]');
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 / 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;