Skip to content

Instantly share code, notes, and snippets.

View marselester's full-sized avatar

Marsel Mavletkulov marselester

View GitHub Profile
@marselester
marselester / main.go
Last active January 13, 2022 19:32
Reproduce EOF error in kafka-go v0.4.25 #814
/*
If the topic has no messages, the kafka reader starts to report
"the kafka reader got an unknown error reading partition x of my-topic at offset y: unexpected EOF",
see https://github.com/segmentio/kafka-go/issues/814.
$ go run main.go
2022/01/13 14:10:09 read message: fizz
2022/01/13 14:10:27 the kafka reader got an unknown error reading partition 0 of mytopic at offset 1: unexpected EOF
^C
2022/01/13 14:10:30 failed to read a message: context canceled
@marselester
marselester / backoff.go
Last active August 8, 2022 00:10
Exponential decorrelated jitter backoff from Polly project based on https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/, see an example https://play.golang.org/p/sHOTAI6wGht.
package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func main() {
@marselester
marselester / Dockerfile
Created April 6, 2021 17:29
BPF tools without LLVM, Clang, and kernel header dependencies at runtime.
FROM ubuntu:groovy as build
RUN apt-get update && \
apt-get install -y git flex bison llvm cmake clang libclang-dev libelf-dev libcap-dev python3-setuptools && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /opt/
RUN git clone https://github.com/iovisor/bcc.git && \
mkdir ./bcc/build/ && \
cd ./bcc/build/ && \
@marselester
marselester / vscode.json
Last active June 15, 2023 19:42
vscode settings
{
"editor.fontSize": 16,
"editor.autoClosingBrackets": "never",
"editor.matchBrackets": "never",
"editor.quickSuggestions": {
"comments": "off",
"strings": "off",
"other": "off"
},
"editor.renderLineHighlight": "none",
@marselester
marselester / redis.go
Created November 3, 2015 09:45
Go snippets for Redis
// redisArgs prepends a Redis key to Redis values slice.
// For example, we want to add "key1" to ["val1", "val2"] Redis values.
// The result will be ["key1", "val1", "val2"].
func redisArgs(key string, values ...string) []interface{} {
args := make([]interface{}, 0, len(values)+1)
args = append(args, key)
for _, v := range values {
args = append(args, v)
}
return args
@marselester
marselester / combinations.js
Created August 15, 2013 06:48
I did it as a test task. Given a set of integers S and a positive integer L, create a function that generates all the possible subsets of S of length L. Example: if S={1, 2, 3} and L=2, then subsets(S, L) is {1, 2}, {1, 3}, {2, 3}.
function range(n) {
list = [];
for (var i = 0; i < n; i++) {
list[i] = i;
}
return list;
}
function show_items_by_indices(source_set, indices) {
@marselester
marselester / resize_animated_gif.py
Created July 18, 2013 14:06
Resize animated gif by Wand (ctypes-based simple ImageMagick binding for Python).
# http://docs.wand-py.org
from wand.image import Image
with Image(filename='original.gif') as img:
img.rotate(90)
img.resize(150, 150)
img.save(filename='converted.gif')
{
"auto_complete": false,
"auto_match_enabled": false,
"close_windows_when_empty": false,
"open_files_in_new_window": false,
"remember_open_files": false,
"ensure_newline_at_eof_on_save": true,
"trim_trailing_white_space_on_save": true,
"translate_tabs_to_spaces": true,
"fold_buttons": false,
@marselester
marselester / gist:3986441
Created October 31, 2012 10:59
Django template tag which fits words into block.
@register.simple_tag
def fit_words_to_block(src_text, max_str_len, max_str_qty=None):
"""Truncates words from text thus they might be fitted to size of symbols block.
Also it can limit quantity of strings.
"""
if not src_text.strip():
return u''
words = []