Skip to content

Instantly share code, notes, and snippets.

View tasdikrahman's full-sized avatar
💭
Automate everything

Tasdik Rahman tasdikrahman

💭
Automate everything
View GitHub Profile
@tasdikrahman
tasdikrahman / go-stdlib-interface-selected.md
Created July 31, 2023 15:09 — forked from asukakenji/go-stdlib-interface-selected.md
Go (Golang) Standard Library Interfaces (Selected)

Go (Golang) Standard Library Interfaces (Selected)

This is not an exhaustive list of all interfaces in Go's standard library. I only list those I think are important. Interfaces defined in frequently used packages (like io, fmt) are included. Interfaces that have significant importance are also included.

All of the following information is based on go version go1.8.3 darwin/amd64.

diff --git a/app/jobs/check_certificate_job.rb b/app/jobs/check_certificate_job.rb
index 93fb16b..76f995b 100644
+++ b/app/jobs/check_certificate_job.rb
--- a/app/jobs/check_certificate_job.rb
@@ -10,7 +10,7 @@ class CheckCertificateJob < ApplicationJob
Domain.all.each do |domain|
if domain.certificate_expiring?
Rails.logger.info("#{domain.fqdn} is expiring within the buffer period")
+ if (Figaro.env.send_expiry_notifications_to_slack == 'true') && !Figaro.env.slack_webhook_url.empty?
- if (Figaro.env.send_expiry_notifications_to_slack == true) && !Figaro.env.slack_webhook_url.empty?
@tasdikrahman
tasdikrahman / aasm_after_commit.rb
Created August 4, 2020 07:00 — forked from danielfone/aasm_after_commit.rb
AASM after_commit behaviour
# ruby 2.2.2
# activerecord 4.2.3
# aasm 4.2.0
require 'active_record'
require 'aasm'
# Setup a mock AR table
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
# app/controllers/health_check_controller.rb
class HealthCheckController < ActionController::Base
def ping
Rails.logger.info("bazbar, request-id: #{request.request_id}")
render json: { success: true, errors: nil, data: 'pong' }, status: :ok
end
end
# config/environments/development.rb
Rails.application.configure do
config.log_formatter = LogFormatter.new
end
{"level":"INFO","progname":null,"message":"bazbar, request_id: 4967a677-ab86-4a10-8a01-ea520951cqw3"}
{"level":"INFO","progname":null,"message":"{\"method\":\"GET\",\"path\":\"/ping\",\"format\":\"*/*\",\"controller\":\"HealthCheckController\",\"action\":\"ping\",\"status\":200,\"duration\":8.36,\"view\":0.22,\"db\":0.0,\"request_time\":\"2020-07-07 16:10:17 +0530\",\"application\":\"MyApplication\",\"process_id\":7869,\"params\":\"{}\",\"rails_env\":\"development\",\"request_id\":\"4967a677-ab86-4a10-8a01-ea520951cqw3\"}"}
# app/logger/log_formatter.rb
class LogFormatter < ::Logger::Formatter
def call(severity, time, program_name, message)
message = '' if message.blank?
severity = '' if message.blank?
{
level: severity,
progname: program_name,
message: message,
{"level":"INFO","progname":null,"message":"{\"method\":\"GET\",\"path\":\"/ping\",\"format\":\"*/*\",\"controller\":\"HealthCheckController\",\"action\":\"ping\",\"status\":200,\"duration\":8.36,\"view\":0.22,\"db\":0.0,\"request_time\":\"2020-07-07 16:10:17 +0530\",\"application\":\"MyApplication\",\"process_id\":7869,\"params\":\"{}\",\"rails_env\":\"development\",\"request_id\":\"4967a677-ab86-4a10-8a01-ea520951cf46\"}"}
$ curl -I localhost:3000/ping | grep -i "request"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
X-Request-Id: 4967a677-ab86-4a10-8a01-ea520951cf46
class ApplicationController < ActionController::Base
protect_from_forgery with: exception
def append_info_to_payload(payload)
super
payload[:host] = request.host
payload[:remote_ip] = request.remote_ip
payload[:ip] = request.ip
end
end