Skip to content

Instantly share code, notes, and snippets.

Avatar

Samoilenko Yuri kinnalru

View GitHub Profile
@kinnalru
kinnalru / docker-compose.yml
Last active Mar 31, 2021
Portainer service description
View docker-compose.yml
version: "3.7"
x-log: &log
options:
max-size: '50m'
max-file: '3'
labels: com.docker.compose.service
driver: json-file
x-base: &base
@kinnalru
kinnalru / docker-compose.yml
Last active Mar 3, 2021
docker-compose.yml
View docker-compose.yml
version: "3.7"
x-base: &base
restart: unless-stopped
logging:
options:
max-size: '50m'
max-file: '3'
driver: json-file
@kinnalru
kinnalru / iframe_exmaple.rb
Created Feb 25, 2021
Iframe embed example
View iframe_exmaple.rb
Lusnoc::Mutex.new('/some/key').synchronize do |mx|
# do some work
mx.renew if mx.need_renew? # manualy renew session if needed
# do other work
mx.renew if mx.need_renew? # manualy renew session if needed
# ...
rescue Lusnoc::ExpiredError => e
# Session was invalidated and mutex was lost!
end
@kinnalru
kinnalru / bench_http.rb
Created Feb 25, 2021
Скрипт для бенчмарка кешированных HTTP-соединений в ruby
View bench_http.rb
require 'benchmark'
require 'timeout'
require 'logger'
require 'net/http'
require 'webrick'
require 'terminal-table'
require 'thin'
require 'colorize'
class Base
@kinnalru
kinnalru / http4.rb
Created Feb 25, 2021
StartWebrickDocker
View http4.rb
class StartWebrickDocker < Base
def start
cmd = "
require \"webrick\"
require \"logger\"
WEBrick::HTTPServer.new(Host: \"0.0.0.0\", Port: 80, MaxClients: 3000, ShutdownSocketWithoutClose: true, Logger: Logger.new(IO::NULL), AccessLog: []).start"
exec "docker run --rm -p #{@port}:80 --name http ruby:2.5-alpine /usr/local/bin/ruby -e '#{cmd}'"
end
def stop(_pid)
system("docker rm -f http &> /dev/null")
View http3.rb
class StartWebrick < Base
def start
server = WEBrick::HTTPServer.new Host: '0.0.0.0', Port: @port, MaxClients: 3000, ShutdownSocketWithoutClose: true, Logger: Logger.new(IO::NULL), AccessLog: []
server.mount_proc('/') { |req, res| res.body = 'hello' }
server.start
end
def stop(pid)
Process.kill("KILL", pid)
end
end
@kinnalru
kinnalru / http2.rb
Created Feb 25, 2021
make_requests_single
View http2.rb
def make_requests_single(uri, duration)
count = 0
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.max_retries = 0
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t) < duration do
data = "/#{count}"
http.get(uri + data).body
count += 1
end
@kinnalru
kinnalru / http1.rb
Created Feb 25, 2021
make_requests_each
View http1.rb
def make_requests_each(uri, duration)
count = 0
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t) < duration do
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.max_retries = 0
data = "/#{count}"
http.get(uri + data).body
count += 1
end
View rufus_2.rb
require 'rufus-scheduler'
require 'lusnoc/mutex'
mutex = Lusnoc::Mutex.new('/locks/jobs', ttl: 20)
mutex.synchronize(timeout: 10) do |mx|
scheduler = Rufus::Scheduler.new.tap do |s|
mx.on_mutex_lost do
exit!(1)
View rufus_1.rb
require 'rufus-scheduler'
scheduler = Rufus::Scheduler.new.tap do |s|
s.in '1h' do
RefreshCurrencyJob.perform_later
end
end
scheduler.join