Skip to content

Instantly share code, notes, and snippets.

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

Stuart Illson Sillson

🛰️
🌲 🔥 🎄 🔥
View GitHub Profile
@Sillson
Sillson / cred_finder.rb
Created April 21, 2017 20:44
heroku pg creds
class CredFinder
attr_accessor :cred_hsh
def initialize(urn)
puts "***** \nSapSucking Creds For -- \n#{urn} \n*****"
@cms_urn = urn
@cred_hsh = {'dbname'=>'','host'=>'','port'=>'','user'=>'', 'password'=>''}
build_creds
end
def build_creds
@Sillson
Sillson / drop_foreign_tables_and_reimport.sql
Created April 7, 2017 16:19
drop foreign schema and reimport
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;
@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
@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 / 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 / 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