Skip to content

Instantly share code, notes, and snippets.

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

disassembler alxekb

🏠
Working from home
  • Global
  • 01:03 (UTC +02:00)
View GitHub Profile
@alxekb
alxekb / ruby_meta.md
Created July 13, 2021 12:33 — forked from jamesyang124/ruby_meta.md
Ruby meta programming

#!/bin/ruby --verion => 2.0.0-p353

Self

In Ruby, self is a special variable that always references the current object.

  • Inside class or module definition, self refer to the Class or Module object.
  • Inside instance method, self refer to future instance object.
  • Inside class method, self refer to the class.i
@alxekb
alxekb / exception_handler.rb
Created November 4, 2020 15:04
rails api boilerplate example
# app/controllers/concerns/exception_handler.rb
module ExceptionHandler
extend ActiveSupport::Concern
class MissingToken < StandardError; end
class InvalidToken < StandardError; end
class AuthenticationError < StandardError; end
included do
@alxekb
alxekb / gist:399326126070a285af2d4b17e965d0a5
Created October 20, 2020 10:53
ruby exception subclasses
# https://ruby-doc.org/core-2.5.0/Exception.html
- NoMemoryError
- ScriptError
- LoadError
- NotImplementedError
- SyntaxError
- SecurityError
- SignalException
- Interrupt
@alxekb
alxekb / strategy.rb
Created September 29, 2020 14:14
Ruby strategy pattern
```# The Context defines the interface of interest to clients.
class Context
# The Context maintains a reference to one of the Strategy objects. The
# Context does not know the concrete class of a strategy. It should work with
# all strategies via the Strategy interface.
attr_writer :strategy
# Usually, the Context accepts a strategy through the constructor, but also
# provides a setter to change it at runtime.
def initialize(strategy)
PATH=/bin:/usr/bin:/sbin:/usr/sbin
@alxekb
alxekb / fetch_worker.rb
Created August 13, 2020 15:24 — forked from Evshved/fetch_worker.rb
same code
require 'logger'
class FetchContentAdDomainsWorker
include Sidekiq::Worker
extend IntegrationsWrapper
URL = 'https://rest.content.ad/reports/publisher?output=json'.freeze
sidekiq_options retry: 3, queue: :integrations, backtrace: true
wrap_over :network_setting, :content_ad
@alxekb
alxekb / horizontal-scroll.js
Created July 29, 2020 07:28
script to find horizontal scroll elements to apply overflow: hidden on it
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
}
);
# frozen_string_literal: true
# Abstract service class
class AbstractService
class << self
def call(*args, &block)
new(*args, &block).call
end
end
Status Code Status Message Symbol
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
201 Created :created
202 Accepted :accepted
ARG RUBY_VERSION
# See explanation below
FROM ruby:$RUBY_VERSION-slim-buster
ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG YARN_VERSION
# Common dependencies