Skip to content

Instantly share code, notes, and snippets.

View bolshakov's full-sized avatar
💭
It doesn't matter what you create If you have no fun

Tëma Bolshakov bolshakov

💭
It doesn't matter what you create If you have no fun
  • Toptal
  • Barcelona, Spain
View GitHub Profile
@bolshakov
bolshakov / action.rb
Last active February 12, 2018 16:09
Active action
# frozen_string_literal: true
require 'dry/validation'
require 'dry/core/class_attributes'
require 'active_action/action/params'
module ActiveAction
# This module provides validation logic for controller actions.
# @example
# class CreateUserAction
# frozen_string_literal: true
require 'dry/validation'
require 'dry/core/class_attributes'
require 'active_action/action/params'
module ActiveAction
# This module provides validation logic for controller actions.
# @example
# class CreateUserAction
@bolshakov
bolshakov / a.cr
Created September 27, 2017 08:16
abstract struct A
def self.build(value)
if value.nil?
B.new
else
C.new
end
end
end
@bolshakov
bolshakov / example_spec.coffee
Created September 8, 2017 12:06 — forked from madtrick/example_spec
Jasmine and RequireJS together. Easy way
require ['fileA', 'fileB'], (A, B) ->
describe "An example", ->
it "depends on A and B"
<item>
<name>Editor mode</name>
<appendix>Navigate:</appendix>
<appendix>* Cmd+I to UP</appendix>
<appendix>* Cmd+K to DOWN</appendix>
<appendix>* Cmd+J to LEFT</appendix>
<appendix>* Cmd+L to RIGHT</appendix>
<appendix>* Cmd+U to Option+LEFT</appendix>
<appendix>* Cmd+O to Option+RIGHT</appendix>
<appendix></appendix>
def unbind(key: String, pagination: Pagination): String = {
val limit: Option[String] = pagination.limit.map(key + "[limit]=" + _)
val offset: Option[String] = pagination.offset.map(key + "[offset]=" + _)
return Seq(limit, offset).filter(_.isDefined).map(_.get).mkString("&")
}
@bolshakov
bolshakov / pagination.rb
Last active August 29, 2015 14:21
Trailblazer use case: listing items
module Pagination
extend ActiveSupport::Concern
included do
contract do
property :limit, validates: { numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 50 } }
property :offset, validates: { numericality: { greater_than_or_equal_to: 0 } }
end
end
end
@bolshakov
bolshakov / Gemfile
Created March 16, 2015 21:19
Benchmarks
source "http://rubygems.org"
gem 'benchmark-ips'
@bolshakov
bolshakov / gist:2240761b9280110bb2da
Last active July 3, 2023 14:11
SOLID Code Smells

Single Responsibility

A class should have one, and only one, reason to change.

  • Large Class
    • You can't easily describe what the class does in one sentence.
    • You can't tell what the class does without scrolling.
    • The class needs to change for more than one reason.
    • The class has more than seven methods.
    • The class has a total flog score of 50.
# Project-specific .irbrc
if Dir.pwd != File.expand_path("~")
local_irbrc = File.expand_path '.irbrc'
if File.exist? local_irbrc
puts "Loading #{local_irbrc}"
load local_irbrc
end
end