Skip to content

Instantly share code, notes, and snippets.

View sgoley's full-sized avatar

sgoley sgoley

  • Remote
View GitHub Profile
@sgoley
sgoley / M365PrincessPy.omp.json
Created February 17, 2023 00:13
ohmyposh theme update w/ python segment
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"type": "text",
"style": "diamond",
"leading_diamond": "\ue0b6",
@sgoley
sgoley / fmtdeploy.yml
Last active September 14, 2022 19:35
creates a github action workflow for a dbt repository to automatically sqlfmt the files in the current PR and then kickoff a CI/CD dbtCloud run job with a schema override. Requires a few secret variables to be set on the repo for the dbt cloud action to run.
# GitHub Action that uses sqlfmt to reformat the sql in an incoming pull request.
# If all sql in the pull request is compliant with sqlfmt then this Action does nothing.
# Otherwise, sqlfmt is run and its changes are committed back to the incoming pull request.
name: fmtdeploy
on: [pull_request]
jobs:
fmt:
runs-on: ubuntu-latest
steps:
@sgoley
sgoley / backup_conda_envs.sh
Created August 27, 2021 01:14
Creates a backup of all envs that exist for a conda installation
#!/bin/bash
NOW=$(date "+%Y-%m-%d")
mkdir $HOME/tmp/envs-$NOW
ENVS=$(conda env list | grep '^\w' | cut -d' ' -f1)
for env in $ENVS; do
source activate $env
conda env export > $HOME/tmp/envs-$NOW/$env.yml
echo "Exporting $env"
done
@sgoley
sgoley / settings.json
Created August 5, 2021 15:06
VS Code venv windows default python. Place at <project>/.vscode/settings.json
{
"python.defaultInterpreterPath": ".venv/scripts/python.exe"
}
@sgoley
sgoley / uuid_v4_excel_formula.txt
Created February 26, 2021 22:19 — forked from msubel/uuid_v4_excel_formula.txt
An Excel Fromula to generate a UUID v4
=LOWER(CONCATENATE(DEC2HEX(RANDBETWEEN(0;POWER(16;8));8);"-";DEC2HEX(RANDBETWEEN(0;POWER(16;4));4);"-";"4";DEC2HEX(RANDBETWEEN(0;POWER(16;3));3);"-";DEC2HEX(RANDBETWEEN(8;11));DEC2HEX(RANDBETWEEN(0;POWER(16;3));3);"-";DEC2HEX(RANDBETWEEN(0;POWER(16;8));8);DEC2HEX(RANDBETWEEN(0;POWER(16;4));4)))
@sgoley
sgoley / vacuum-analyze-dbtCloud.md
Last active August 24, 2020 13:17 — forked from jthandy/vacuum-analyze-sinter.md
Running vacuum and analyze on Redshift via dbtCloud

Running vacuum and analyze in dbtCloud

dbt and dbtCloud have the ability to run regular Redshift maintenance jobs. It's great to set these up early on in a project so that things stay clean as the project grows, and implementing these jobs in dbtCloud allows the same easy transparency and notifications as with your other dbt jobs.

This document will go through the specific steps necessary to configure vacuum and analyze jobs in the current version of dbt and dbtCloud. In the future, there will likely be a more idiomatically consistent way to express this logic using native dbt operations. Currently, this does work even if it is not elegant.

Step 1: Create the macros

macros/redshift_maintenance.sql

@sgoley
sgoley / create function manage_magic_timestamp_c.sql
Created August 24, 2020 02:22
easiest way to manage both "created" and "updated" timestamps on a record in postgesql
-- in schema as procedure:
create function manage_magic_timestamp_columns() returns trigger
strict
cost 1
language plpgsql
as
$$
BEGIN
-- is a new record?
@sgoley
sgoley / concepts_db.sql
Created August 20, 2020 15:34
Concepts database for concept / idea storage and "remixing" by Derek Sivers
-- author: Derek Sivers (https://github.com/sivers)
-- description: simple ideas / concepts / tagging table layout for PostgreSQL
CREATE TABLE concepts (
id integer primary key,
created_at date not null default CURRENT_DATE,
title varchar(127) not null unique CONSTRAINT title_not_empty CHECK (length(concepts."title") > 0),
concept text not null unique CONSTRAINT concept_not_empty CHECK (length(concepts."concept") > 0)
);
CREATE TABLE urls (
@sgoley
sgoley / grant_select_on_schemas.sql
Created August 19, 2020 01:50
dbt macro to grant select usage and select for all tables of a schema
{% macro grant_select_on_schemas(schemas, user) %}
{% for schema in schemas %}
grant usage on schema {{ schema }} to "{{ user }}";
grant select on all tables in schema {{ schema }} to "{{ user }}";
alter default privileges in schema {{ schema }}
grant select on tables to "{{ user }}";
{% endfor %}
{% endmacro %}
@sgoley
sgoley / condaenv.txt
Created June 24, 2020 16:42 — forked from pratos/condaenv.txt
To package a conda environment (Requirement.txt and virtual environment)
# For Windows users# Note: <> denotes changes to be made
#Create a conda environment
conda create --name <environment-name> python=<version:2.7/3.5>
#To create a requirements.txt file:
conda list #Gives you list of packages used for the environment
conda list -e > requirements.txt #Save all the info about packages to your folder