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 / Gemfile
Created March 16, 2015 21:19
Benchmarks
source "http://rubygems.org"
gem 'benchmark-ips'
@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 / usage.coffee
Created June 7, 2012 20:11
Humaniser usage
# First, we'll need a bunch of helpers -- `m()` for minutes
# and `s()` for seconds:
s = (sec) -> sec * 1000
m = (min) -> min * s(60)
# Humanizer.between(from, to, includeSeconds)
#
# Returns the approximate distance in time between
# two given objects, which can either be `Date` or
@bolshakov
bolshakov / Gemfile
Last active December 11, 2015 11:58
source 'https://rubygems.org'
gem 'mechanize'
gem 'ruby-stemmer'
gem 'sequel'
gem 'sqlite3'
gem 'active_support'
gem 'i18n'
gem 'rake'
gem 'hirb-unicode'
# 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
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("&")
}
<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>
@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"
@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
# 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