This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Wraps an enumerator that yields chunks of content into an IO object. It | |
# The IO is NOT rewindable. | |
# implements some essential IO methods: | |
# | |
# * IO#read | |
# * IO#readpartial | |
# * IO#gets | |
# * IO#size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Run Rubocop on save | |
" Requires vim.o.xrc = true in NeoVim config | |
lua << EOF | |
vim.api.nvim_create_autocmd("BufWritePost", { | |
pattern = "*", | |
callback = function() | |
local file = vim.fn.expand('%:p') | |
vim.fn.system('your-command ' .. file) | |
end, | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/ismasan/parametric | |
require 'parametric' | |
class InputValidator | |
def initialize(&block) | |
@schema = Parametric::Schema.new(&block) | |
end | |
# @param result [Result] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Pipeline extension to process steps concurrently | |
# Example | |
# class ConcurrentPipeline < Pipeline | |
# include ConcurrentProcessing | |
# end | |
# | |
# MyPipeline = ConcurrentPipeline.new do |pl| | |
# pl.step ValidateInput | |
# | |
# # These steps run concurrently |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'csv' | |
# ruby json_to_csv.rb /path/to/data.json > /path/to/data.csv | |
# | |
MAP_VALUE = ->(value) { | |
case value | |
when Array | |
value.join('|') | |
when Hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Hash64 | |
# Turn a string into a well distributed 64 bit integer | |
# This matches the hash_64() PGSQL function used to partition streams. | |
# | |
# @param value [String] the string to hash | |
# @return [Integer] a 64 bit integer | |
def self.call(value) | |
binary_string = ('0' + Digest::MD5.hexdigest(value)[0...16]).hex.to_s(2) | |
# Convert the binary string to a signed BigInt | |
bigint_value = binary_string.to_i(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.rebalance_consumers_all_groups() | |
RETURNS void | |
LANGUAGE plpgsql | |
AS $function$ | |
DECLARE | |
group_ids uuid[]; | |
min_last_seq bigint; | |
consumers_deleted bigint; | |
group_min_seq bigint; | |
p_group_id uuid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' | |
class ConsistentHash | |
Node = Data.define(:position, :updated_at) | |
def initialize(size = 1) | |
@hash_ring = {} | |
(0...size).each { |i| add(i) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pg' | |
require 'connection_pool' | |
require 'async' | |
DB = ConnectionPool.new(size: 5, timeout: 5) do | |
PG.connect(dbname: 'test_db') | |
end | |
class DBClient | |
def initialize(db) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Turn a line-based Enumerator into an Enumerator | |
# that parses each CSV line and yields them as Hash rows | |
# Usage | |
# csv = CSVStream.new(line_stream, headers: { product_name: 0, price: 2 }) | |
# | |
# With a bit more work it could detect CSV headers automatically, from the first line. | |
require 'csv' | |
class CSVStream | |
include Enumerable |
NewerOlder