Skip to content

Instantly share code, notes, and snippets.

@slabad
slabad / sbarns.sql
Last active April 20, 2021 14:31
sql101_hw_barns #sql101
--1. Create Tables:
Create table Genres (
Id int primary key
, genre varchar(50))
-- I would recommend making all your ids IDENTITY columns so those ids are generated automatically. I'm making the comment here but this would be true across the board.
Create table Movies (
id int primary key
@slabad
slabad / fdw_setup.sql
Last active July 1, 2020 14:48
Cross Database Querying on Postgres #psql #postgres
--for a cross db query on the same host
--no hostname or password is needed.
--the following script adds the extension,
-- creates a server, maps the postgres user,
-- and imports the foreign db into a new schema
BEGIN;
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
DROP SERVER IF EXISTS fdw_server CASCADE;
@slabad
slabad / dynamic_table_create.sql
Last active June 12, 2020 19:00
Dynamic Table Creation #psql #postgres
DO
$$
BEGIN
EXECUTE format('CREATE TABLE %I AS SELECT * FROM backup', 'backup_' || to_char(CURRENT_DATE,'yyyy-mm-dd'));
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION fn_hello(v_table text)
returns void
@slabad
slabad / sp_whoisactive.sql
Created May 22, 2020 17:29
sp_whoisactive #tsql #mssql
EXEC sp_WhoIsActive
@filter = '',
@filter_type = 'session',
@not_filter = '',
@not_filter_type = 'session',
@show_own_spid = 0,
@show_system_spids = 0,
@show_sleeping_spids = 1,
@get_full_inner_text = 0,
@get_plans = 0,
@slabad
slabad / pg_check_bloat
Created March 30, 2020 14:33
pg_check_bloat #psql #postgres
WITH constants AS (
-- define some constants for sizes of things
-- for reference down the query and easy maintenance
SELECT current_setting('block_size')::numeric AS bs, 23 AS hdr, 8 AS ma
),
no_stats AS (
-- screen out table who have attributes
-- which dont have stats, such as JSON
SELECT table_schema, table_name,
@slabad
slabad / tuples.sql
Last active June 8, 2020 15:22
live and dead tuples #postgres #psql
SELECT
schemaname
,relname AS TableName
,n_live_tup AS LiveTuples
,n_dead_tup AS DeadTuples
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC
;
@slabad
slabad / reset_mac_accessibility.sh
Created February 26, 2020 13:41
Reset Mac Accessibility #alfred
sudo tccutil reset Accessibility
@slabad
slabad / powerline_mac.md
Last active April 20, 2024 22:40
Powerline Font Install for Mac #terminal

Download the pre-patched powerline symbols font file.

$ wget -c https://github.com/Lokaltog/powerline/raw/develop/font/PowerlineSymbols.otf

  • Open “Font Book” (Hit Cmd + Space to open spotlight and type Font Book).
  • Go to “File > Add Fonts” and open the PowerlineSymbols.otf file.
  • After the font is added, right click on “PowerlineSymbols” font and select “Validate Font”.
  • Now the font should be installed and ready to use.
  • If you are using iTerm, change the non-ascii font to PowerSymbols to start using the powerline fonts.
@slabad
slabad / slack_reset_black_theme.txt
Last active January 28, 2019 21:49
Slack Reset Black Theme #slack
curl -s https://gist.githubusercontent.com/mattmc3/b15e30a6715b82f8b76bfd4232583df3/raw/a80da215ac1698184b60a7f96bce719703954aa3/1-slack-dark-mode.js | sudo tee -a /Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js > /dev/null
@slabad
slabad / GenerateTlogRestoreScript.sql
Last active August 29, 2015 14:03
Generate TLog Restore Script
USE Master;
GO
SET NOCOUNT ON
-- 1 - Variable declaration
DECLARE @dbName sysname
DECLARE @backupPath NVARCHAR(500)
DECLARE @cmd NVARCHAR(500)
DECLARE @fileList TABLE (backupFile NVARCHAR(255))
DECLARE @lastFullBackup NVARCHAR(500)