Skip to content

Instantly share code, notes, and snippets.

View chris's full-sized avatar
🏠
Working from home

Chris Bailey chris

🏠
Working from home
View GitHub Profile
@chris
chris / hash_deep_transform_values.rb
Created September 20, 2016 19:08
A "deep" version of Rails' Hash#transform_values
class Hash
class Hash
def deep_transform_values(&block)
reduce({}) do |result, (k, v)|
result[k] = v.is_a?(Hash) ? v.deep_transform_values(&block) : yield(v)
result
end
end
end
end
@chris
chris / Coders at Work highlights
Created August 9, 2017 22:18
Text I highlighted while reading Coders at Work
Yeah. At the end of the day, ship the fucking thing! It's great to rewrite your code and make it cleaner and by the third time it'll actually be pretty. But that's not the point—you're not here to write code; you're here to ship products.
Peter Seibel, Coders at Work: Reflections on the Craft of Programming, pg. 22, loc. 522
A lot of programmers have the instinct of, “You've got to present the error message!” No you don't. No one cares about that. That sort of stuff is a lot easier to manage in languages like Java that actually have an exception system. Where, at the top loop of your idle state, you just catch everything and you're done. No need to bother the user with telling them that some value was zero.
Peter Seibel, Coders at Work: Reflections on the Craft of Programming, pg. 32, loc. 702
Are you trying to write good software or are you trying to be done by next week? You can't do both.
Peter Seibel, Coders at Work: Reflections on the Craft of Programming, pg. 34, loc. 743
you want to arrange for ther
@chris
chris / blockstack.txt
Last active November 1, 2017 19:47
Blockstack verification
Verifying my Blockstack ID is secured with the address 16X2WrRuC8uJ8FuH41CQuFxecK2xGAQPVp https://explorer.blockstack.org/address/16X2WrRuC8uJ8FuH41CQuFxecK2xGAQPVp
@chris
chris / mysql_ip_address_info.sql
Last active October 13, 2024 13:36
Get list of IP addresses connected to MySQL DB, with their connection counts
SELECT
tmp.ipAddress,
-- Calculate how many connections are being held by this IP address.
COUNT( * ) AS numConnections,
-- For each connection, the TIME column represent how many SECONDS it has been in
-- its current state. Running some aggregates will give us a fuzzy picture of what
-- the connections from this IP address is doing.
FLOOR( AVG( tmp.time ) ) AS timeAVG,
@chris
chris / switchtf.sh
Created March 5, 2019 00:33
Switch Terraform version based on .terraform-version or tfstate
# Switch to Terraform version for this directory.
# Uses presence of .terraform-version file, or find in .tfstate if possible.
switchtf() {
if [ -f .terraform-version ]; then
version=`cat .terraform-version`
chtf $version
echo "Switched to Terraform $version."
else
version=`grep terraform_version .terraform/terraform.tfstate | sed -E 's/^ "terraform_version": "(.+)",$/\1/'`
if [ -n version ]; then
@chris
chris / action-postgis.yml
Created July 7, 2020 20:10
GitHub Actions Postgres PostGIS service
services:
postgres:
image: postgis/postgis:10-2.5
env:
# must specify password for PG Docker container image, see: https://registry.hub.docker.com/_/postgres?tab=description&page=1&name=10
POSTGRES_PASSWORD: password
POSTGRES_DB: your_test_db_name
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
@chris
chris / action-step-psql.yml
Created July 7, 2020 20:14
GitHub Action psql command example
steps:
- name: Import DB seed data
run: psql -d postgresql://postgres@localhost/your_test_db_name -f your_seed_data.sql
working-directory: ./test/data
env:
PGPASSWORD: password
@chris
chris / action-gotest-with-db.yml
Created July 7, 2020 20:22
GitHub action to run Go tests with Postgres DB URL
steps:
- name: Test Go code
working-directory: ./go/somemodule
run: go test
env:
CI_DB_URL: postgresql://postgres:password@localhost:5432/your_test_db_name
@chris
chris / github-action-postgis-psql.yml
Last active December 13, 2024 17:55
Example of GitHub action that sets up Postgres 16 and PostGIS 3 and uses psql
name: Test
on:
push:
paths:
- '.github/workflows/**'
- 'go/somemodule/**'
pull_request:
paths:
- '.github/workflows/**'
- 'go/somemodule/**'
@chris
chris / circleci_config.yml
Created July 7, 2020 20:44
Example of trying to get CircleCI with Postgres, PostGIS and psql working
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
# specify the version
- image: cimg/go:1.14
environment: