Skip to content

Instantly share code, notes, and snippets.

View VoltanBro's full-sized avatar
🇺🇦

Vitalii Molchanov VoltanBro

🇺🇦
View GitHub Profile
@VoltanBro
VoltanBro / sql_query_delete_duplicates_records.sql
Last active February 20, 2023 13:13
This SQL statement will delete all rows in violation of not having a unique something_id field. you can also add more columns to this by comma separation.
SELECT * FROM user_accounts WHERE id IN (
SELECT
id
FROM (
SELECT
id,
ROW_NUMBER() OVER w AS rnum
FROM user_accounts
WINDOW w AS (
PARTITION BY user_profile_id
@VoltanBro
VoltanBro / download_spec.rb
Last active February 7, 2023 09:28
rspec download helper
module DownloadHelper
TIMEOUT = 3
PATH = Rails.root.join("tmp/downloads")
module_function
def downloads
Dir[PATH.join("*")]
end
@VoltanBro
VoltanBro / trait_with_transient.rb
Last active July 12, 2022 19:11
advanced factory transient
trait :my_custom do
transient do
params {{}}
end
after(:build) do |field, evaluator|
field.name = evaluator.params[:name]
end
end
@VoltanBro
VoltanBro / todo_fixme_etc_list
Created July 8, 2022 23:35
todo fixme bug and etc comments
[Line 1] ✐ NOTE: This is here because sometimes an intermittent issue appears.
[Line 7] ↻ OPTIMIZE: This could be reworked to not do a O(N2) lookup.
[Line 9] ✓ TODO from John: Add a check here to ensure these are always strings.
[Line 24] ✄ HACK: I am doing something here that is horrible, but it works for now...
[Line 89] ✗ XXX: Let's do this better next time? It's bad.
[Line 136] ☠ FIXME: We sometimes get an undefined index in this array.
[Line 211] ☢ BUG: If the user inputs "Easter" we always output "Egg", even if they wanted a "Bunny".
# frozen_string_literal: true
class CustomerCreator < BaseInteractor
def call
validate_bot_owner
create_stripe_customer
end
private
@VoltanBro
VoltanBro / rails-jsonb-queries
Created December 21, 2021 20:34 — forked from mankind/rails-jsonb-queries
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
AllCops:
TargetRubyVersion: 2.7.2
NewCops: enable
Exclude:
- 'db/**/*'
- 'bin/*'
Layout/LineLength:
Max: 120
@VoltanBro
VoltanBro / vanilla-js-cheatsheet.md
Created February 6, 2021 07:47 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet
requestBody:
content:
application/json:
schema:
type: object
properties:
courier:
type: object
email:
type: string
Started POST "/api/v1/sign_in" for 127.0.0.1 at 2020-06-06 03:00:06 +0300
(0.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by Api::V1::SessionsController#create as JSON
Parameters: {"courier"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "session"=>{"courier"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}}
Courier Load (0.4ms) SELECT "couriers".* FROM "couriers" WHERE "couriers"."id" = $1 ORDER BY "couriers"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Completed 500 Internal Server Error in 23ms (ActiveRecord: 4.8ms | Allocations: 9516)
TypeError (no implicit conversion of nil into String):