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
  • Barcelona, Spain
View GitHub Profile
def extended_gcd(a, b)
raise ArgumentError unless a >= b and b >= 0 and a + b > 0
if b == 0
d, x, y = a, 1, 0
else
(d, p, q) = extended_gcd(b, a % b)
x = q
y = p - q * (a / b)
end
def <=>(other)
head.match do |lm|
lm.none do
other.head.match do |rm|
rm.some { -1 }
rm.none { 0 }
end
end
lm.some do |left_head|
other.head.match do |rm|
# /etc/nginx/nginx.conf
http {
access_log /dev/stdout;
include /etc/nginx/mime.types;
default_type application/octet-stream;
proxy_cache_path /tmp levels=1:2 keys_zone=thumbs:10m inactive=24h max_size=1G;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
RSpec.shared_examples Enumerator do |enum|
describe '#each', 'without block' do
subject { enum.each }
it 'returns Enumeretator' do
is_expected.to be_kind_of(Enumerator)
end
end
end
@bolshakov
bolshakov / struct.rb
Last active March 16, 2019 11:30
destructing_struct
require 'fear'
User = Struct.new(:id, :name, :admin)
Fear.register_extractor(User, Fear.case(User, &:to_a).lift)
matcher = Fear.matcher do |m|
m.xcase('User(_, name, true)') do |name:|
puts "Hi #{name}, you are welcome"
end
m.xcase('User(_, _, false)') do
@bolshakov
bolshakov / binary_tree_set.rb
Last active March 11, 2019 09:12
Binary Tree Set implemented using pattern matching, see https://github.com/bolshakov/fear/pull/28
require 'fear'
# @example Usage
# set = BinaryTreeSet.new
# set.add(4)
# set.includes?(4) #=> true
# set.includes?(5) #=> false
# set.delete(4)
# set.includes(4) #=> false
#
ab -n 10 -c 1 http://127.0.0.1:8080/fast_scan\?file_path\=/foo/bar
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software:
Server Hostname: 127.0.0.1
code = <<-RUBY
c = fzbz = -> v {
s = v % 3 < 1 ? 'Fizz' : ''
v % 5 < 1 && s << 'Bazz'
v < 1 ? [] : c[v - 1] + [s == '' ? v : s]
}
RUBY
fzbz = eval(code)
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)