Skip to content

Instantly share code, notes, and snippets.

View jbranchaud's full-sized avatar

Josh Branchaud jbranchaud

View GitHub Profile
@jbranchaud
jbranchaud / advent_of_code_2020_day_9_part_one.sql
Last active December 10, 2020 01:25
Advent of Code 2020, Day 9, Part One, SQL
-- create temp table with sample input
insert into xmas_data (value) values (35), (20), (15), (25), (47), (40), (62), (55), (65), (95), (102), (117), (150), (182), (127), (219), (299), (277), (309), (576);
-- starter subquery
select
v1.id v1id,
v2.id v2id,
v1.value,
v2.value,
v1.value + v2.value sum

Congratulations! Josh Branchaud 🏆:

Check your terminal for next steps 👀

@jbranchaud
jbranchaud / switch_pg_server_client_versions.bash
Last active January 15, 2025 00:22
Bash function for switching asdf postgres versions and stopping/starting servers
function switch_pg {
local version_to_run=$1
local currently_running_version=$(psql --no-psqlrc -t -c 'show server_version;' postgres | xargs)
# check if you're erroneously switching to the same version
if [ "$version_to_run" = "$currently_running_version" ]; then
echo "Postgres $version_to_run is already running."
return 1
fi
@jbranchaud
jbranchaud / thing.rb
Created February 4, 2021 18:15
Returning out of a Ruby begin block
class Thing
def initialize(value)
@value = value
end
def call(other_value)
@other_value = other_value
puts final_value
end
@jbranchaud
jbranchaud / retry.rb
Created February 8, 2021 23:10
Ruby's rescue exception and retry functionality
def sometimes_fails
puts "Beginning of sometimes_fails"
begin
retries ||= 0
puts "About to do a thing (#{retries})"
raise StandardError if rand(5) != 4
puts "Success!"
@jbranchaud
jbranchaud / summary.rb
Last active February 21, 2021 18:26
TIL Repo: Generate List of Links For Past Week's TILs
results = `git log HEAD@{'7 days ago'}..HEAD --oneline | sed 's/^\([[:alnum:]]*\) .*$/\1/'`
commit_list = results.split(/\n/).map do |item|
item.split(' ', 2)
end.filter do |sha, commit_message|
commit_message.start_with?('Add ')
end
commit_data = commit_list.map do |sha, commit_message|
diff_tree_result = `git diff-tree --no-commit-id --name-only -r #{sha}`
@jbranchaud
jbranchaud / README.md
Created June 10, 2021 18:51
Change `work_mem` configuration for PostgreSQL Database

Change work_mem configuration for PostgreSQL Database

Let's say you are experiencing a Postgres error that reads like this: "Postgres running out of temp space".

A potential fix to this is adjusting the work_mem value for the database. This will require some tuning to optimize the database for the particular query load that it experiences. So, some trial and error.

Before getting started, you'll want to take note of the specs of your Postgres instance where these errors occur. You'll be interested in both the available RAM and the number of supported connections.

@jbranchaud
jbranchaud / markdown-link-active-tab.js
Created November 5, 2022 20:58
A ScriptKit script for putting a markdown link on your clipboard for the active Chrome tab
@jbranchaud
jbranchaud / close-active-taco-bell-tab.js
Created November 6, 2022 01:51
ScriptKit script to close the active Chrome tab if it is open to Taco Bell
let jxa = await npm("@jxa/run")
let result = await jxa.run(() => {
let app = Application("com.google.Chrome")
let windows = app.windows()
let frontWindow = windows[0]
let tab = frontWindow.activeTab()
let closedTabData = {
id: tab.id(),