Skip to content

Instantly share code, notes, and snippets.

@vilusa
vilusa / customer delete.sql
Last active February 3, 2023 15:22
customer sql
DELETE FROM customers WHERE id IN(
SELECT id FROM (
SELECT c.id FROM customers c
LEFT JOIN feedbacks f ON c.id = f.creator_id
WHERE
c.node_id = 'b2bfa5ea-579a-46fe-9e45-1ebc8df44082'
AND f.creator_id IS NULL
AND c.email IS NULL
AND c.phone_number IS NULL
AND c.external_id IS NULL
@vilusa
vilusa / error.md
Created January 26, 2022 15:26
gprc error
Installing grpc 1.13.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/vilusa/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/grpc-1.13.0/src/ruby/ext/grpc
/Users/vilusa/.rbenv/versions/2.5.8/bin/ruby -r ./siteconf20220126-17740-1uqx4va.rb extconf.rb
Building internal gRPC into /Users/vilusa/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/grpc-1.13.0/src/ruby/ext/grpc/libs/opt
[C]       Compiling third_party/zlib/adler32.c
[C]       Compiling third_party/zlib/compress.c
[C] Compiling third_party/zlib/crc32.c
@vilusa
vilusa / error.md
Created January 25, 2022 11:37
libv8 error
➜  voice git:(master) gem install libv8 --version 8.4.255 -- --with-system-v8
Building native extensions with: '--with-system-v8'
This could take a while...
ERROR:  Error installing libv8:
        ERROR: Failed to build gem native extension.

    current directory: /Users/vilusa/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/libv8-8.4.255.0/ext/libv8
/Users/vilusa/.rbenv/versions/2.5.8/bin/ruby -r ./siteconf20220125-58008-1un33av.rb extconf.rb --with-system-v8
creating Makefile
@vilusa
vilusa / environment.rb
Created September 3, 2021 18:56
Rails Redis Cache Configuration
# For TLS Connections
config.cache_store = :redis_cache_store, {
url: ENV.fetch('CACHE_STORE_REDIS_TLS_URL') { ENV['CACHE_STORE_REDIS_URL'] || 'redis://127.0.0.1:6379' },
db: 0,
connect_timeout: 20, # Defaults to 20 seconds
read_timeout: 1, # Defaults to 1 second
write_timeout: 1, # Defaults to 1 second
reconnect_delay: 1.5 ,
reconnect_delay_max: 10.0,
reconnect_attempts: 10, # Defaults to 0
@vilusa
vilusa / aws_ses.rb
Last active January 13, 2023 13:37
Ruby on Rails AWS SES SMTP Configurations
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'email-smtp.eu-west-1.amazonaws.com',
port: 587,
enable_starttls_auto: true,
user_name: ENV['AWS_SES_SMTP_USERNAME'],
password: ENV['AWS_SES_SMTP_PASSWORD'],
authentication: :login
}
@vilusa
vilusa / basic_authentication.rb
Created September 2, 2021 14:18
Rails Basich Authentication Concern
# frozen_string_literal: true
module BasicAuthentication
extend ActiveSupport::Concern
included do
before_action :basic_authenticate
end
private
@vilusa
vilusa / client.rb
Created August 23, 2021 19:12
Ruby Faraday Client Base
require 'faraday'
module ActionClient
class Client
attr_reader :status_code, :response, :data
def self.request(method: :get, path:, body: nil)
raise ArgumentError, "#{self.class.name} API Key not provided." if ActionClient.api_key.nil?
@vilusa
vilusa / example.rb
Last active September 2, 2021 14:18
Uniq user name as clean non ascii characters
first_and_last_name = "#{first_name}#{last_name}".downcase
first_and_last_name.gsub!("ğ", "g")
first_and_last_name.gsub!("ı", "i")
first_and_last_name.gsub!("ş", "s")
first_and_last_name.gsub!("ü", "u")
first_and_last_name.gsub!("ö", "o")
first_and_last_name.gsub!("ç", "c")
first_and_last_name.gsub!(/[^0-9A-Za-z]/, '')
index = 0
unique_user_name = loop do
@vilusa
vilusa / util.rb
Last active December 29, 2020 09:18
ActiveStorage::Util
module ActiveStorage
module Util
class << self
def image(resource, **options)
return '/no_image.png' unless resource.attached?
size = handle_size?(options)
return resource.service_url unless size
resource.variant(resize_to_fill: size).processed.service_url
@vilusa
vilusa / enum_presenter.rb
Created December 10, 2020 07:43
Enum Presenter
# frozen_string_literal: true
module EnumPresenter
class << self
def collect(model_class, enum_field, **options)
i18ns = model_class.send("#{enum_field}_i18n")
keys = if options[:except].present?
model_class.send(enum_field).except(*options[:except])
else
model_class.send(enum_field)