Skip to content

Instantly share code, notes, and snippets.

View krzykamil's full-sized avatar
🤔

Krzysztof Piotrowski krzykamil

🤔
View GitHub Profile
/*
We have an array of objects representing different people in our contacts lists.
A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.
The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
If both are true, then return the "value" of that property.
If firstName does not correspond to any contacts then return "No such contact"
If prop does not correspond to any valid properties then return "No such property"
*/
//Setup
class Author < ActiveRecord::Base
include Concerns::Author::Searchable
...
...
end
require 'elasticsearch/model'
module Concerns
module Author
module Searchable
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
@krzykamil
krzykamil / with.sql
Created February 13, 2019 12:41
SQL WITH syntax
WITH my_subquery AS (SELECT * FROM table_name WHERE column_name_1 = value_1)
SELECT column_name_2 FROM my_subquery
WHERE coulumn_date > '2018-12-08'
@krzykamil
krzykamil / two_withs.sql
Created February 13, 2019 12:47
With double
WITH my_first_with AS (SELECT foo, c FROM bar) , my_second_with AS ( SELECT foo, c FROM my_first_with)
SELECT * FROM my_second_with
INSERT INTO
empty_new_table
SELECT
*
FROM
(WITH old_table_data AS (
SELECT
data1,
data2,
data3
document.querySelectorAll('[data-tooltip-content^="Łukasz Żarski"]').forEach(gownoWartaWiadomosc => {gownoWartaWiadomosc.parentNode.parentNode.parentNode.style.display = "none";})
class BaseService
attr_reader :result, :errors
def self.call(**args)
new(**args).tap(&:call)
end
def success?
errors.blank?
end
end
# frozen_string_literal: true
desc "example task"
task :example_task, [:for_real] => [:environment] do |task, args|
ActiveRecord::Base.transaction do
# This is the way, do your thing here
unless args[:for_real] == "for_real"
raise "Discarded all changes. To do a real run invoke this task as follows:
bundle exec rake \"#{task.name}[for_real]\"\n"
end
@krzykamil
krzykamil / ticket_adapter.rb
Created November 17, 2021 15:39
example adapter
class Dev
attr_accessor :level, :money, :tickets
def initialize
@level = (1..3).to_a.sample
@money = 0
@tickets = []
end
def take_ticket(ticket)