Skip to content

Instantly share code, notes, and snippets.

View pdbradley's full-sized avatar

Philip Bradley pdbradley

View GitHub Profile
@pdbradley
pdbradley / factory_doctor.rb
Created March 9, 2023 20:28 — forked from palkan/factory_doctor.rb
FactoryDoc: detect useless data generation in tests
module FactoryGirl
module Doctor
module FloatDuration
refine Float do
def duration
t = self
format("%02d:%02d.%03d", t / 60, t % 60, t.modulo(1) * 1000)
end
end
end
@pdbradley
pdbradley / find_or_create.sql
Created March 6, 2021 14:01
find_or_create SQL function
CREATE
OR REPLACE FUNCTION public.find_or_create_user(user_email text) RETURNS SETOF users LANGUAGE sql STABLE AS $ function $
INSERT INTO
users (email)
VALUES
(user_email) ON CONFLICT (email) DO NOTHING;
SELECT
*
FROM
users
@pdbradley
pdbradley / song_sheet.rb
Created February 15, 2021 13:58
Song Sheet wrapper ideas
# dinuska this is untested, just typed in, but it may give you some idea
# of how you might encapsulate a google sheet or link it to records
# in your database. I'm sure i'm getting some details wrong
# so feel free of course to reject all or part of this ha ha
require "google_drive"
class SongSheet
@pdbradley
pdbradley / robert2.rb
Last active June 25, 2020 20:01
stories re jobs and caregivers
Here are some stories:
An employer logs in and creates a Job and fills in the various criteria. This job belongs_to an employer, but does not belong_to a caregiver YET.
job
name: Home Nursing A
belongs_to employer A
@pdbradley
pdbradley / robert.rb
Last active June 25, 2020 03:16
Feedback on your associations
/*
Since I have to go to the doctor tomorrow morning:
There something Sandi Metz calls the "squint test" which means that
when you have to narrow your eyes to figure out what code is doing, you might have
overcomplicated it.
So I see you are very conversant with how to bend activerecord associations outside
of their defaults.
/*
Since I have to go to the doctor tomorrow morning:
There something Sandi Metz calls the "squint test" which means that
when you have to narrow your eyes to figure out what code is doing, you might have
overcomplicated it.
So I see you are very conversant with how to bend activerecord associations outside
of their defaults.
@pdbradley
pdbradley / Dockerfile
Created June 11, 2020 02:14
Dockerfile for hasura rails postgres
FROM ruby:2.6.6-alpine
RUN apk add --update build-base postgresql-dev tzdata nodejs
RUN apk add yarn
RUN gem install bundler
ENV APP_HOME /app
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
@pdbradley
pdbradley / docker-compose.yml
Created June 10, 2020 23:13
hasura docker compose rails postgres sample
version: '3.6'
services:
postgres:
image: postgres:12
volumes:
- './postgres:/var/lib/postgresql/data'
environment:
POSTGRES_PASSWORD: "nargh"
web:

Keybase proof

I hereby claim:

  • I am pdbradley on github.
  • I am pdbradley (https://keybase.io/pdbradley) on keybase.
  • I have a public key ASD5GtzA3z5X7nNf451URVza1LKYC1CUf3Joimi7p7X2Ago

To claim this, I am signing this object:

@pdbradley
pdbradley / keybase.md
Created February 19, 2020 18:21
keybase

Keybase proof

I hereby claim:

  • I am pdbradley on github.
  • I am pdbradley (https://keybase.io/pdbradley) on keybase.
  • I have a public key ASD5GtzA3z5X7nNf451URVza1LKYC1CUf3Joimi7p7X2Ago

To claim this, I am signing this object: