Skip to content

Instantly share code, notes, and snippets.

View bolshakov's full-sized avatar

Tëma Bolshakov bolshakov

  • Spain
View GitHub Profile
package main
import (
"bytes"
"flag"
"fmt"
"log"
"net/http"
"os/exec"
"regexp"
RSpec::Matchers.define :be_identical_docx_file_to do |expected_docx_file|
match do |actual_docx_file|
expected_file = extract_zip_file(expected_docx_file)
actual_file = extract_zip_file(actual_docx_file)
expected_file == actual_file
end
# @param path [String] path to docx file
# @return [{String => String}] maps file names to file content
private def extract_zip_file(path)
@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'