Skip to content

Instantly share code, notes, and snippets.

View hindenbug's full-sized avatar
💻

Manoj hindenbug

💻
View GitHub Profile
@hindenbug
hindenbug / kafka_compact_array.md
Last active January 5, 2026 11:02
TIL: Kafka's "N+1" Compact Array Strategy

The Concept

In modern binary protocols like Apache Kafka, Compact Arrays are used to save bandwidth. Instead of using a fixed 4-byte integer to store the length of a list, Kafka uses a Varint (Variable-length Integer) and an offset of 1.

What is a Compact Array?

In standard programming, an array is like a row of identical lockers. Even if you only put a tiny pebble in a locker, the locker stays the same huge size. This wastes space.

A Compact Array is "shrink-wrapped" data. It uses two main tricks to save space:

Varints: The length of the array isn't a fixed 4-byte block; it's a "stretchy" number that only uses the bytes it needs.

@hindenbug
hindenbug / gist:69ef50bd508ae924626fddf8515b6686
Created December 6, 2020 20:27
vim quote multiple lines
:%s/.*<patter>.*/"&"/
- name: Delete multiple files
file:
path: "{{ item }}"
state: absent
with_items:
- file1.txt
- file2.txt
- file3.txt
/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'
hostname -I | awk '{print $3}'
# Here's my code with a few minor improvements
class IpLookupService
def self.lookup_country(ip_address)
result = self.lookup(ip_address)
# expecting result is a object/instance returned by @g.lookup method
raise GeoIpDB::Error unless result && result.found?
(result.country && result.country.iso_code) ? result.country.iso_code.downcase : raise GeoIpDB::Error
rescue GeoIpDB::Error
"en"
require "json"
require "rspec"
require "byebug"
class Reconciler
attr_accessor :invoices, :credit_lines, :max_finance_credit, :total_debtors_invoices, :customer_credits
def financed_amount
@total_debtors_invoices = @invoices.map {|x| x[:amount] }.reduce(:+)

Keybase proof

I hereby claim:

  • I am hindenbug on github.
  • I am hindenbug (https://keybase.io/hindenbug) on keybase.
  • I have a public key ASAmvn6HfeoDODUEYwUwJlF5j6-ziUsB61XOoVIqYjk-Cgo

To claim this, I am signing this object:

@hindenbug
hindenbug / gist:88a44ccab80beef2f80e3a9b6b828324
Created October 12, 2016 12:32
Remove ctrl-M characters from a file in vim
%s/\r//g
@hindenbug
hindenbug / gist:c039da0685800ff286d0
Created June 12, 2014 06:12
PermutationCheckMissing
def solution(a)
# write your code in Ruby 1.9.3
countr = [0] * (a.max)
a.each do |v|
countr[v-1] += 1
end
if countr.include?(0) || countr.max > 1
0
def solution(a)
# write your code in Ruby 1.9.3
rsum = a.inject(:+)
lsum = 0
res = nil
a.each_with_index do |v, i|
rsum -= v
lsum += v
diff = (lsum - rsum).abs