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
# 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
// Copyright (c) 2017 Ismael Celis | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// The above copyright notice and this permission notice shall be included in all |
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
// fileResponseWriter wraps an http.ResponseWriter and a File | |
// passing it to an http.Handler's ServeHTTP | |
// will write to both the file and the response. | |
type fileResponseWriter struct { | |
file io.Writer | |
resp http.ResponseWriter | |
multi io.Writer | |
} |
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
/* | |
The MIT License (MIT) | |
Copyright (c) 2014 Ismael Celis | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
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) |
NewerOlder