Skip to content

Instantly share code, notes, and snippets.

View prdanelli's full-sized avatar
👋

Paul Danelli prdanelli

👋
View GitHub Profile
@prdanelli
prdanelli / donation-tsm-current-state.rb
Created August 9, 2023 13:21
Donation TSM current state transitions
[nil,
"Pending",
"Pending",
"Pending",
"Accepted",
"Accepted",
"Accepted",
"Accepted",
"Accepted",
"Accepted",
@prdanelli
prdanelli / inbound3.json
Created August 9, 2023 13:11
Inbound Webhook Payload 3
{
"EntityId":"0688705d-ea53-4010-8cb6-570fcb44e0d4",
"OrganisationId":"dce2c439-040b-448c-879c-045d99da9193",
"BranchId":"4aa26861-251d-46bc-9261-194d7a343e94",
"ExternalDonorBranchId":"TESCO:6316",
"DonationId":"67fe8dca-de31-4500-9729-1857f450888c",
"ExternalDonationId":"d565d704-2d3b-4297-992e-68b7577c779f",
"DonationCreatedAt":"2023-08-07T18:29:37.000000Z",
"Metadata":null,
"MessageType":"OfferPending",
@prdanelli
prdanelli / inbound2.json
Created August 9, 2023 13:09
Inbound Update: 2
{
"EntityId":"0688705d-ea53-4010-8cb6-570fcb44e0d4",
"OrganisationId":"dce2c439-040b-448c-879c-045d99da9193",
"BranchId":"4aa26861-251d-46bc-9261-194d7a343e94",
"ExternalDonorBranchId":"TESCO:6316",
"DonationId":"67fe8dca-de31-4500-9729-1857f450888c",
"ExternalDonationId":"d565d704-2d3b-4297-992e-68b7577c779f",
"DonationCreatedAt":"2023-08-07T18:29:37.000000Z",
"Metadata":null,
"MessageType":"OfferPending",
@prdanelli
prdanelli / no-spacing-class-example.rb
Last active June 21, 2023 12:36
No Space Example
# Bad
class MyClass
COSNT_NAME = "boz"
attr_reader :foo, :bar, :baz
def initialize(foo, bar, baz)
@foo = foo
@bar = bar
@baz = baz
end
@prdanelli
prdanelli / block.rb
Last active March 23, 2023 22:07
Block / Class / Factory / Function processing
require 'nokogiri'
require 'uri'
require 'net/http'
require 'byebug'
require 'json'
# Block example
def requester(url, &block)
uri = URI(url)
res = Net::HTTP.get_response(uri)
require 'benchmark'
require 'dry-struct'
require 'ostruct'
require 'hashie'
require 'active_support'
class ClassCar
attr_accessor :wheels, :mileage
end
@prdanelli
prdanelli / gist:7b2d161281f517aa83845691ba220d0d
Last active March 10, 2023 11:15
Use FactoryBot methods inside Rails console

$ rails console -e test --sandbox

require 'factory_bot'; include FactoryBot::Syntax::Methods
@prdanelli
prdanelli / sentry data.rb
Created December 2, 2022 12:51
Log Extra data to Sentry
def my_method
# ...
rescue NoMethodError => e
Sentry.with_scope do |scope|
scope.set_tags(foo: "bar") # <= Searchable tags
scope.set_context('Model Attributes', @local_instance_variable.attributes) # <= Logs extra hash of data
Sentry.capture_message("A test message") # <= Your custom message
Sentry.capture_error(e) # <= Log the error
end
end
@prdanelli
prdanelli / gist:c2cce7c1403488917d16b3f3bbee9fe8
Last active February 1, 2022 13:57
Decorate class with extend/prepend

Decorate class with extend/prepend

Update indexed instance after blob analyzed

# app/jobs/active_storage/analyze_job_decorator.rb
module ActiveStorage::AnalyzeJobDecorator
  def self.prepended(base)
    base.around_perform do |job, block|
      block.call
@prdanelli
prdanelli / gist:a0dd4684022459e0d344bd0a4d6b4ec7
Last active February 1, 2022 13:44
Install PG Gem without installing Postgres locally

Install PG Gem without installing Postgres locally

The Problem

Installing the ruby PG gem requires Postgres to be instaled locally to install the gem, which is annoying and unnecessary if you're building inside of docker.

An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds before bundling.