Last major update: 25.08.2020
- Что такое авторизация/аутентификация
- Где хранить токены
- Как ставить куки ?
- Процесс логина
- Процесс рефреш токенов
- Кража токенов/Механизм контроля токенов
| require "active_support" | |
| require "active_support/core_ext/string/output_safety" | |
| require "objspace" | |
| def assert_same_object(x, y) | |
| raise unless x.object_id == y.object_id | |
| end | |
| def assert_not_same_object(x, y) | |
| raise unless x.object_id != y.object_id |
| require 'spec_helper' | |
| require 'ostruct' | |
| class FakePostRepo | |
| attr_reader :posts | |
| def initialize | |
| @posts = [] | |
| end |
| FROM ruby:2.4.1-slim | |
| RUN apt-get update -qq \ | |
| && apt-get install -y --no-install-recommends \ | |
| apt-transport-https \ | |
| curl | |
| RUN curl --silent --location https://deb.nodesource.com/setup_8.x | bash - && \ | |
| curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ | |
| echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ |
| class Success(object): | |
| def __init__(self, value): | |
| self.value = value | |
| class Error(object): | |
| def __init__(self, value): | |
| self.value = value | |
| class wrapper(object): | |
| def __init__(self, result): |
| # web/controllers/authentication.rb | |
| module Web | |
| module Authentication | |
| module Skip | |
| def authenticate! | |
| end | |
| end | |
| def self.included(action) | |
| action.class_eval do |
When developing a program in Ruby, you may sometimes encounter a memory leak. For a while now, Ruby has a facility to gather information about what objects are laying around: ObjectSpace.
There are several approaches one can take to debug a leak. This discusses a time-based approach, where a full memory dump is generated every, say, 5 minutes, during a time that the memory leak is showing up. Afterwards, one can look at all the objects, and find out which ones are staying around, causing the
| class MyJob < ActiveJob::Base | |
| queue_as :urgent | |
| rescue_from(NoResultsError) do | |
| retry_job wait: 5.minutes, queue: :default | |
| end | |
| def perform(*args) | |
| MyService.call(*args) | |
| end |
It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:
>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
| # config/routes.rb | |
| YandexKassaIntegration::Application.routes.draw do | |
| # ... | |
| scope '/yandex_kassa' do | |
| controller 'yandex_kassa', constraints: { subdomain: 'ssl' } do | |
| post :check | |
| post :aviso | |
| get :success | |
| get :fail |