Skip to content

Instantly share code, notes, and snippets.

View snelson82's full-sized avatar

Stan Nelson snelson82

View GitHub Profile
@snelson82
snelson82 / elixir-pr-prep
Last active April 18, 2024 23:42
Alias to run various tasks in preparation for opening a pull request
alias pr-prep='
(time (
echo "==> Fetching deps" && \
time mix deps.get && \
echo "==> Running mix format" && \
time mix format && \
echo "==> Checking if formatted" && \
time mix format --check-formatted && \
echo "==> Cleaning unused deps" && \
time mix deps.clean --unlock --unused && \
@snelson82
snelson82 / folder_zip.rb
Last active October 21, 2022 21:24
Compressing a folder using RubyZip
require 'zip'
archive_directory_path = ''
archive_zip_path = ''
Zip::File.open(archive_zip_path, Zip::File::CREATE) do |zip_file|
Dir[File.join(archive_directory_path, "**", "**")].each do |file|
zip_file.add(file.sub("#{ archive_directory_path}/", ""), file)
end
end
SELECT
students.last_name AS "Student Last Name",
students.first_name AS "Student First Name",
students.user_canvas_id AS "Student Canvas ID",
students.user_sis_id AS "Student SIS ID",
course_dim.name AS "Course Name",
course_dim.canvas_id AS "Course Canvas ID",
course_dim.sis_source_id AS "Course SIS ID",
course_section_dim.name AS "Section",
course_section_dim.canvas_id AS "Section Canvas ID",
@snelson82
snelson82 / rainbow_vscode_styling.json
Last active July 14, 2021 02:58
Credit goes to https://dev.to/jennifer/when-you-want-a-bit-more-rainbow-in-your-vscode-10aj for the JSON to set up the Rainbow CSV to produce an actual rainbow pattern.
"bracket-pair-colorizer-2.colors": [
"DeepSkyBlue",
"DodgerBlue",
"MediumSlateBlue",
"BlueViolet",
"MediumVioletRed",
"DeepPink",
"Red",
"DarkOrange",
"Gold",
@snelson82
snelson82 / public_tables_and_counts.sql
Last active November 1, 2023 22:32
PostgreSQL - All tables and record count
SELECT
table_schema,
table_name,
(xpath('/row/cnt/text()', xml_count))[1]::text::int AS row_count
FROM (
SELECT
table_name,
table_schema,
query_to_xml(format('select count(*) as cnt from %I.%I', table_schema, table_name), FALSE, TRUE, '') AS xml_count
FROM
-- Mixed with CASE, this will extract the float/digits in the last set of `()` in the string
CASE WHEN string_to_chop LIKE '%(%-%)%' THEN
NULL
ELSE
NULLIF (REPLACE(REPLACE(REGEXP_SUBSTR (string_to_chop, '\\([[:digit:]]+.[[:digit:]]+\\)$|\\([[:digit:]]+\\)$'), '(', ''), ')', ''), '')::float
END AS chopped_string
find . -mindepth 2 -type f -print -exec mv {} . \;
@snelson82
snelson82 / csv_progress_bar.rb
Last active June 15, 2021 15:07
Progress bar added to CSV for output while parsing
require 'progress_bar'
# Extends CSV class to include progress bar enhancement
class CSV
module ProgressBar
def progress_bar
::ProgressBar.new(@io.size, :bar, :counter, :percentage, :elapsed, :eta)
end
def each