Skip to content

Instantly share code, notes, and snippets.

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

Mateusz Bialowas mateuszbialowas

🏠
Working from home
View GitHub Profile
@mateuszbialowas
mateuszbialowas / Dockerfile
Last active May 4, 2023 15:23
Dockerfile, esbuild, tailwind
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.1
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
# Rails app lives here
WORKDIR /rails
# Set production environment
@mateuszbialowas
mateuszbialowas / app_services_example.rb
Created April 16, 2023 17:08
Testing sidekiq - code snippets
class Example
def initialize(employee_id)
@employee_id = employee_id
end
def call
ExampleJob.perform_async(@employee_id)
end
end
# frozen_string_literal: true
require 'rails_helper'
require 'benchmark'
describe Users::Roles::Create do
subject(:service) { described_class.new(user, role_params).call }
let(:user) { create(:user) }
@mateuszbialowas
mateuszbialowas / model.rb
Last active June 6, 2022 14:13
authenticate method
def authenticate(*credentials, &block)
raise ArgumentError, 'at least 2 arguments required' if credentials.size < 2
if credentials[0].blank?
return authentication_response(return_value: false, failure: :invalid_login, &block)
end
if @sorcery_config.downcase_username_before_authenticating
credentials[0].downcase!
end
@mateuszbialowas
mateuszbialowas / scratch.rb
Created May 25, 2022 17:36
ar-mapping-custom-pk-fk
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pry'
gem "sqlite3"
gem 'activerecord'
end
class Booking < ApplicationRecord
belongs_to :room, primary_key: :room_id, foreign_key: :room_id
belongs_to :guest, primary_key: :guest_id, foreign_key: :guest_id
end
class Guest < ApplicationRecord
has_many :bookings, primary_key: :booking_id, foreign_key: :booking_id
end
class Room < ApplicationRecord
@mateuszbialowas
mateuszbialowas / main.rb
Created May 23, 2022 20:18
BSK/Create user in gorest.co.in
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'json', require: false
gem 'httparty'
gem 'pry'
end