Skip to content

Instantly share code, notes, and snippets.

🌲

Stuart Illson Sillson

🌲
Block or report user

Report or block Sillson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 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 Aug 29, 2015
Clean orion navigation nastiness after a clone
View snag.rake
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
View dupe.rb
# 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 Nov 12, 2015
Output an array of widget names & locations
View name_me_a_widget.rb
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 Apr 23, 2016
Gettin down with down-arrows
View get-down-with-down-arrows.js
</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 Jan 10, 2017
Download a remote bz2 sql backup, and dump into a remote DB.
View db_swap.sh
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 Jan 27, 2017
install latest version of all R packages that are currently installed
View upgRade.R
install.packages(
lib = lib <- .libPaths()[1],
pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
type = 'source'
)
@Sillson
Sillson / exchange_student.sql
Created Feb 14, 2017
Create a foreign data connection in postgres
View exchange_student.sql
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]');
View active_locks_view.sql
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
View psql_drop_foreign_tables.sql
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;
You can’t perform that action at this time.