Skip to content

Instantly share code, notes, and snippets.

View AndrewGrossman's full-sized avatar

Andrew Grossman AndrewGrossman

View GitHub Profile

Notes pertaining to the review approach and considerations for Query 1

First Pass

For a first pass, I went through and cleaned up anything I thought that might be more presentable from comments and very basic code formatting. This is to allow my brain to more easily absorb and identify content without getting distracted by more obvious but less pertinent concerns. In a real code review, I would also be taking into account whether it was appropriate to spend resources on this and whether there might be interpersonal

@AndrewGrossman
AndrewGrossman / config.yml
Created April 10, 2022 23:21
Turn off SSL
- run:
name: Start Postgres # Start the service and add a test-running user (sudo sudo is not a typo)
command: |
# Set permissions to trust
sudo sh -c 'sed -i "s/peer/trust/g" /etc/postgresql/<< pipeline.parameters.postgres-version >>/main/pg_hba.conf'
sudo sh -c 'sed -i "s/md5/trust/g" /etc/postgresql/<< pipeline.parameters.postgres-version >>/main/pg_hba.conf'
# Disable ssl, as it can cause tests to fail likely due to use of the multiprocessing library
sudo sh -c 'sed -i "s/ssl = on/ssl = off/g" /etc/postgresql/<< pipeline.parameters.postgres-version >>/main/postgresql.conf'
@AndrewGrossman
AndrewGrossman / config.yml
Created April 10, 2022 23:11
Configure the Postgres service for trust authentication before starting
- run:
name: Start Postgres # Start the service and add a test-running user (sudo sudo is not a typo)
command: |
# Set permissions to trust
sudo sh -c 'sed -i "s/peer/trust/g" /etc/postgresql/<< pipeline.parameters.postgres-version >>/main/pg_hba.conf'
sudo sh -c 'sed -i "s/md5/trust/g" /etc/postgresql/<< pipeline.parameters.postgres-version >>/main/pg_hba.conf'
# Start the Postgres cluster service
sudo pg_ctlcluster << pipeline.parameters.postgres-version >> main start
@AndrewGrossman
AndrewGrossman / pg_hba.conf
Created April 10, 2022 23:04
Default Postgres pg_hba.conf
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
@AndrewGrossman
AndrewGrossman / config.yml
Last active April 10, 2022 22:39
Start Postgres, add a test-running user
- run:
name: Start Postgres # Start the service and add a test-running user (sudo sudo is not a typo)
command: |
# Start the Postgres cluster service
sudo pg_ctlcluster << pipeline.parameters.postgres-version >> main start
# Add the "<< pipeline.parameters.db-user >>" user in the event of a fresh db
sudo sudo -u postgres psql postgres -c "CREATE USER << pipeline.parameters.db-user >> WITH LOGIN SUPERUSER;"
@AndrewGrossman
AndrewGrossman / config.yml
Last active April 10, 2022 23:03
Install Postgres from the PostgreSQL apt repository
- run:
name: install postgres repository
command: |
# Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
- run:
@AndrewGrossman
AndrewGrossman / parameters-setup-config.yml
Created April 10, 2022 21:41
CircleCI Config w/Database Parameters
version: 2.1
parameters:
postgres-version:
type: string
default: "11"
db-user:
type: string
default: "db_user"
jobs:
@AndrewGrossman
AndrewGrossman / config.yml
Last active April 10, 2022 20:48
Initial config.yml
version: 2.1
jobs:
build:
docker:
- image: cimg/python:3.7.13
environment:
ENVIRONMENT: staging
RMP_DB_ENGINE: django.db.backends.postgresql_psycopg2
RMP_DB_NAME: app_db
RMP_DB_USER: app_user
CREATE TEMP TABLE raw_input (
line TEXT,
line_id SERIAL PRIMARY KEY
);
\COPY raw_input (line) FROM ~/Downloads/input12.txt
CREATE TEMP TABLE directions AS
SELECT LEFT(line, 1) AS command_type,
SUBSTRING(line FROM 2)::INTEGER AS command_amount,
CREATE TEMP TABLE raw_input (
line TEXT,
line_id SERIAL PRIMARY KEY
);
\COPY raw_input (line) FROM ~/Downloads/input11.txt
CREATE TEMP TABLE seats AS
SELECT *,
row_number() OVER (PARTITION BY row_id) AS column_id