Skip to content

Instantly share code, notes, and snippets.

#include <vector>
#include <string>
#include <list>
#include <deque>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <array>
#include <iostream>
@msiva21
msiva21 / tail.cpp
Created March 12, 2021 03:02 — forked from dgski/tail.cpp
#include <iostream>
#include <fstream>
#include <chrono>
#include <thread>
#include <sstream>
void tail(std::ifstream& f)
{
std::uint64_t lineCount = 0;
auto sleepTime = std::chrono::seconds(0);
#include <iostream>
#include <variant>
#include <string>
#include <vector>
#include <tuple>
struct Error {
std::string message;
Error(std::string _message) : message(std::move(_message)) {}
};
@msiva21
msiva21 / consumer.sh
Created August 29, 2020 15:44 — forked from dongjinleekr/consumer.sh
Kafka benchmark commands
## Consumer Throughput: Single consumer thread, no compression
## Consumer Throughput: 3 consumer thread, no compression
bin/kafka-consumer-perf-test.sh --topic benchmark-3-3-none \
--zookeeper kafka-zk-1:2181,kafka-zk-2:2181,kafka-zk-3:2181 \
--messages 15000000 \
--threads 1
@msiva21
msiva21 / kafka-move-leadership.sh
Created August 29, 2020 15:43 — forked from miguno/kafka-move-leadership.sh
A simple Ops helper script for Apache Kafka to generate a partition reassignment JSON snippet for moving partition leadership away from a given Kafka broker. Use cases include 1) safely restarting a broker while minimizing risk of data loss, 2) replacing a broker, 3) preparing a broker for maintenance.
#!/usr/bin/env bash
#
# File: kafka-move-leadership.sh
#
# Description
# ===========
#
# Generates a Kafka partition reassignment JSON snippet to STDOUT to move the leadership
# of any replicas away from the provided "source" broker to different, randomly selected
# "target" brokers. Run this script with `-h` to show detailed usage instructions.
template <typename Byte,
typename Data> constexpr inline auto
append_bytes(Byte* destination, const Data& data) {
static_assert(sizeof(Byte) == 1, "Byte must be exactly 8 bits");
const auto& data_ptr = &data;
memcpy(destination, data_ptr, sizeof(data));
}
template <typename Byte,
@msiva21
msiva21 / c++_perfect_forwarding_move_semantics.cc
Created August 22, 2020 09:42 — forked from nolanholden/c++_perfect_forwarding_move_semantics.cc
C++ move semantics fun, from Nicole Josuttis's CppCon 2017 talk
// C++ move semantics, from Nicole Josuttis's CppCon 2017 talk “The Nightmare
// of Move Semantics for Trivial Classes”
#include <iostream>
#include <string>
#include <type_traits>
class Customer {
public:
template <typename TString1, typename TString2 = std::string,
@msiva21
msiva21 / pseudo_scheduled_task.cc
Created August 22, 2020 09:42 — forked from nolanholden/pseudo_scheduled_task.cc
pseudo_scheduled_task
template <typename T, typename U, typename V>
void pseudo_scheduled_task(T&& action, U&& time, V&& await_time) {
using us_time_type = typename std::decay<decltype(time())>::type;
static_assert(std::is_unsigned<us_time_type>::value, "system time must be given as unsigned integral value");
static_assert(std::is_unsigned<decltype(await_time)>::value, "must await a positive integral time interval");
static us_time_type last_time = 0;
const auto& now = std::forward<U>(time)();
const auto& delta = now - last_time; // defined by ISO C++
last_time = now;
@msiva21
msiva21 / prepend_dates.sh
Created August 22, 2020 09:40 — forked from nolanholden/prepend_dates.sh
prepend mac filenames with chronologically sorted date string
regex="([0-9]{2})/([0-9]{2})/([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})"
for file in ./*; do
creation_date="$(GetFileInfo -d "${file}")"
if [[ "${creation_date}" =~ $regex ]]; then
m="${BASH_REMATCH[1]}"
d="${BASH_REMATCH[2]}"
Y="${BASH_REMATCH[3]}"
H="${BASH_REMATCH[4]}"
M="${BASH_REMATCH[5]}"
S="${BASH_REMATCH[6]}"
@msiva21
msiva21 / Base.cpp
Created August 19, 2020 20:53 — forked from sacko87/Base.cpp
Factory Pattern in C++ with templates (using the confusingly recurring template and registry patterns)
#include "Base.h"
Base::Base() :
IsRegistered_(false)
{ }
Base::Base(bool isRegistered) :
IsRegistered_(isRegistered)
{ }