Skip to content

Instantly share code, notes, and snippets.

=> #<ActiveRecord::Associations::HasOneAssociation:0x000000011ca70810
@association_scope=nil,
@disable_joins=false,
@loaded=true,
@owner=#<Poll:0x000000011c9b7658 id: 1, multiple: true, created_at: 2023-04-23 15:42:11.863742 UTC, updated_at: 2023-04-23 15:42:11.863742 UTC>,
@reflection=
#<ActiveRecord::Reflection::HasOneReflection:0x000000011e490510
@active_record=Poll(id: integer, multiple: boolean, created_at: datetime, updated_at: datetime),
@class_name="Post",
@foreign_key="poll_id",
=> #<ActiveRecord::Associations::HasOneAssociation:0x000000011ca70810
@association_scope=nil,
@disable_joins=false,
@loaded=true,
@owner=#<Poll:0x000000011c9b7658 id: 1, multiple: true, created_at: 2023-04-23 15:42:11.863742 UTC, updated_at: 2023-04-23 15:42:11.863742 UTC>,
@reflection=
#<ActiveRecord::Reflection::HasOneReflection:0x000000011e490510
@active_record=Poll(id: integer, multiple: boolean, created_at: datetime, updated_at: datetime),
@class_name="Post",
@foreign_key="poll_id",
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", "7.0.4.2"
@briu
briu / users.rb
Last active October 12, 2020 12:45
create two classes with same interfaces
# User attributes name surname
class User < ApplicationRecord
end
class Guest
def name
'test'
end
end
@briu
briu / modules.rb
Last active May 5, 2020 14:05
extend module B when including module M
module M
def test
end
module B
def hard_test
puts "hey, bro"
end
end
end
@briu
briu / transaction.rb
Created April 2, 2020 12:25
transaction
ApplicationRecord.transaction do
user.update(name: "test_user")
order.update(user_id: user.id)
CalculatePayoutJob.perform_later(user, order)
raise ActiveRecord::Rollback if order.errors.present?
end
@briu
briu / best.sql
Last active July 9, 2019 15:42
выбрать игру для пользователя с наибольшим количеством часов
create database tmp_db1;
\c tmp_db1;
CREATE TABLE users (
id integer,
email varchar(255)
);
CREATE TABLE stats (
id integer,
CREATE TABLE orders (
id integer,
name varchar(255),
address varchar(255)
);
CREATE TABLE order_items (
id integer,
price integer,
CREATE TABLE tmp4(tmp_id integer);
insert into tmp4 (tmp_id) values (1), (2), (null);
select count(order_id <> 1) from (values (null),(1),(2)) t(order_id);
count
-------
2
select count(*) from tmp4 where tmp_id <> 1;
count
@briu
briu / nulls.sql
Last active September 18, 2019 06:57
CREATE TABLE tmp4(tmp_id integer);
insert into tmp4 (tmp_id) values (1), (2), (null);
select count(tmp_id <> 1) from tmp4;
select count(*) from tmp4 where tmp_id <> 1;