Skip to content

Instantly share code, notes, and snippets.

View le0pard's full-sized avatar
🕷️
Your friendly neighborhood coder

Oleksii Vasyliev le0pard

🕷️
Your friendly neighborhood coder
View GitHub Profile
@le0pard
le0pard / Gemfile
Last active October 6, 2026 16:42
Smart avatar cropping in rails: high-performance face detection with YuNet, ONNX runtime and ActiveStorage
# Face detection ONNX model runner
gem 'onnxruntime'
# Fast multidimensional matrix/array calculations
gem 'numo-narray-alt'
@le0pard
le0pard / server.rb
Created September 22, 2026 14:36
Debug http request web server
require 'socket'
server = TCPServer.new(8080)
puts "Debug HTTP server running on port 8080..."
loop do
# Threading prevents a single hanging/broken request from locking up the server
Thread.start(server.accept) do |socket|
begin
puts "\n" + "="*50
@le0pard
le0pard / README.md
Last active September 9, 2026 10:13
Щоденний відлік відвідуваності та обідів для батьків в gsheet + appscript

https://docs.google.com/spreadsheets/d/13dHKd44ItscS09RpgppBXR126M1rxYfFPImqpvDp4jU/edit?usp=sharing:

  • Users - заводимо сюди дітей, бот на /start видає TelegramChatID який сюди вписується, ChildID - унікальне і вводиться руками.
  • Responses - сюди прилітають відповіді батьків боту.
  • Vacations - по замовчуванню вихідні не турбуємо батьків повідомленнями, тут додаємо дати вихідних, коли школи нема.
  • Logs - це для дебагу якщо щось не працює - в коді треба розкоментити логування.

https://docs.google.com/spreadsheets/d/1KI2ExuE3_SABEMa0aG9Wv-EvUEsz1DpbZTCWc8p6K18/edit?usp=sharing

@le0pard
le0pard / sidekiq_healthcheck.rb
Created July 9, 2025 11:12
Sidekiq healthcheck simple endpoint
module SidekiqAliveServer
module_function
def run!
handler = ::Rackup::Handler.get(server)
Signal.trap('TERM') { handler.shutdown }
handler.run(self, Port: port, Host: host, AccessLog: [], Logger: Sidekiq.logger)
end
@le0pard
le0pard / function.sql
Created April 6, 2023 16:14
Filtered Table Estimates
CREATE FUNCTION count_estimate(query text) RETURNS integer AS $$
DECLARE
rec record;
rows integer;
BEGIN
FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP
rows := substring(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)');
EXIT WHEN rows IS NOT NULL;
END LOOP;
RETURN rows;
create function lcfirst(word text)
returns text
language plpgsql
immutable
as $$
begin
return lower(left(word, 1)) || right(word, -1);
end;
$$;
@le0pard
le0pard / hmac256.js
Created September 14, 2022 12:22
Hmac sha-256 hexadecimal on webcrypto
const ALGORITHM = {
name: 'HMAC',
hash: 'SHA-256'
}
const bufferToHex = (buffer) => (
[...new Uint8Array(buffer)]
.map(b => b.toString(16).padStart(2, '0'))
.join('')
)
@le0pard
le0pard / b64utf.js
Created October 11, 2021 12:55
Base64 in browser with Unicode support (no deprecated 'unescape' and 'escape' functions)
const b64EncodeUnicode = (str) => (
window.btoa(window.encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (_match, p1) => (
String.fromCharCode(`0x${p1}`)
)))
)
const b64DecodeUnicode = (str) => (
window.decodeURIComponent(window.atob(str).split('').map((c) => (
`%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`
)).join(''))
@le0pard
le0pard / bench.rb
Created September 10, 2021 12:15
OpenStruct vs Struct vs Hash in Ruby
require 'benchmark/ips'
require 'ostruct'
# Enable and start GC before each job run. Disable GC afterwards.
class GCSuite
def warming(*)
run_gc
end
@le0pard
le0pard / test.rb
Created September 2, 2021 15:47
unlogged tables in rails for test env
# unlogged tables used to speedup tests, but its are not crash proof
config.to_prepare do
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
end
end