Leizner ⚛️

3.2K posts

Leizner ⚛️ banner
Leizner ⚛️

Leizner ⚛️

@kmichaelc

Katılım Mayıs 2017
589 Takip Edilen90 Takipçiler
Sabitlenmiş Tweet
Leizner ⚛️
Leizner ⚛️@kmichaelc·
@KR3Wmatic 1. I know things can be much better than they are if only I get shit together. 2. The understanding of my ignorance and how there are really smart, gifted/wonderful people in the world. Eg MJ, messi 3. People need me as much as I need them. I'm not alone Thread
English
3
2
4
586
Yahiya
Yahiya@yahiyadev·
Protocol buffers: Designed by Google and released openly, Protobuf encodes data as a compact binary format using a schema defined in .proto files. Field names are replaced by integer tags (field numbers), so user_id becomes just 1, a few bits instead of a full string. message User { int32 user_id = 1; string name = 2; } Memory allocation: Protobuf is dramatically more compact., typically 3x to 10x smaller than the equivalent JSON. However, deserialization still allocates a new object tree on the heap. When you call User.parseFrom(bytes), all fields are decoded and placed into a freshly allocated object. The wire bytes and the parsed object both live in memory simultaneously during parsing. Post-parse, the wire buffer can be freed. The memory footprint of the deserialized object is usually 1x to 3x the wire size, since strings and nested messages still require heap objects. Serialization/Deserialization: Faster than JSON but still a full deserialize-to-object-tree step is required before you can read any field. FlatBuffers: Also created at Google, It takes a radically different approach: the serialized binary format is the in-memory format. Data is laid out in a flat byte buffer such that fields can be accessed directly via pointer arithmetic, no parsing step at all. table User { user_id: int; name: string; } Memory allocation: This is where FlatBuffers is unique. Deserialization is essentially ZERO-COPY and ZERO-ALLOCATION. the byte buffer from the network or disk is used directly, and field access is just an offset lookup into that buffer. You never allocate a separate object tree. Memory usage equals the size of the raw buffer, period. There is no "parsed copy" sitting alongside the raw bytes. Access pattern: flatbuffers.GetRootAsUser(buf).name() reads the string directly from the buffer's offset table. The tradeoff is that building a FlatBuffer (serialization) is more complex. you must write fields in reverse order due to the bottom-up construction model, and the builder requires a scratch buffer upfront.
English
1
3
28
2.1K
Anton Zhiyanov
Anton Zhiyanov@ohmypy·
Working on something crazy these days — using Go to write regular C code. Wish me luck :)
Anton Zhiyanov tweet media
English
21
14
241
14K
Pharuk.
Pharuk.@pharukdagreat·
City can’t survive a Saturday night away at Rayo.
English
8
62
213
3.6K
🧪
🧪@FemboyFermin·
City wouldn't survive a hot afternoon match at Rayo Vallecano
English
69
950
12.7K
149.8K
random guy on the internet
random guy on the internet@KharayKrayKray·
Start up idea: The avatar programming language. A programming language that can compile syntax from any language.
English
17
4
93
3.3K
Leizner ⚛️
Leizner ⚛️@kmichaelc·
@dkrizic @0xlelouch_ Well I don't think it's a price anyone should consider paying lightly. Usually by generating boilerplate, you end up with a worse version of the 'framework' you're trying to avoid Use a framework if you want to. Use net/http of you really really know what you're doing
English
1
0
0
28
Abhishek Singh
Abhishek Singh@0xlelouch_·
If you are building a backend in Golang today, which stack would you choose? 1. Gin 2. Echo 3. Fiber 4. Chi 5. gRPC 6. net/http + custom middleware Curious what people are picking now cause Go backend has become very interesting.
English
152
11
353
47.8K
Darko Križić
Darko Križić@dkrizic·
@0xlelouch_ net/http for HTTP or gRPC, minimize dependencies. I removed all other stacks.
English
1
0
42
3.9K
Leizner ⚛️
Leizner ⚛️@kmichaelc·
@0xlelouch_ Makes more sense to define minheap with generics so Type MinHeap ~[]int | ~[]uint //extend to whatever you like More useful this way. type comparable could also be an option
English
0
0
0
23
Abhishek Singh
Abhishek Singh@0xlelouch_·
Rescheduled the interview to next week so I can use the weekend to practice LeetCode. Since I write code mostly in Go and need to solve a lot of min/max heap problems, here's a no-fluff heap implementation in Go. Will share more such code-snippets and video explanation for some of the problems! ---
Abhishek Singh tweet media
Abhishek Singh@0xlelouch_

Have an interview on Friday, have 70 hrs (more or less) These are the only leetcode problems i will be doing (feel a bit angry, should have started last week), 1) Heaps / Priority Queue (Top-K, streaming, schedulers) These map directly to “top-K from huge file”, rate limiting-ish scheduling, and resource management. 215. Kth Largest Element in an Array (min-heap size k) 347. Top K Frequent Elements (heap + hash map) 692. Top K Frequent Words (heap + custom comparator) 703. Kth Largest Element in a Stream (streaming heap) 295. Find Median from Data Stream (two heaps, classic) 621. Task Scheduler (heap + greedy) 373. Find K Pairs with Smallest Sums (heap with state) 239. Sliding Window Maximum (deque alternative; good to know vs heap) 2) Stacks / Monotonic Stack (parsing, “next greater”, histograms) Good for “log parsing”, “expression parsing”, and standard stack muscle memory. 20. Valid Parentheses 155. Min Stack 150. Evaluate Reverse Polish Notation 394. Decode String (stack + parsing) 739. Daily Temperatures (monotonic stack) 84. Largest Rectangle in Histogram (monotonic stack, interview classic) 3) Hashing / Maps (counts, dedupe, idempotency mindset) 1. Two Sum 242. Valid Anagram 49. Group Anagrams 128. Longest Consecutive Sequence 560. Subarray Sum Equals K (prefix sums + hashmap) 4) Queues / Deques / BFS (work queues, backpressure intuitions) 933. Number of Recent Calls (queue/time window; rate limiter vibe) 994. Rotting Oranges (BFS) 200. Number of Islands (BFS/DFS basic) 5) Intervals (schedulers, timelines, merging events) 56. Merge Intervals 57. Insert Interval 435. Non-overlapping Intervals 6) Binary Search (performance + “find boundary” thinking) 33. Search in Rotated Sorted Array 153. Find Minimum in Rotated Sorted Array 875. Koko Eating Bananas (binary search on answer) 74. Search a 2D Matrix 7) Linked list (LRU cache building block) 146. LRU Cache (this is very relevant to backend interviews)

English
6
5
80
6.8K
Leizner ⚛️
Leizner ⚛️@kmichaelc·
@asynctear @MarioVerbelen @psviderski Honestly it's a stylistic preference. Both are fine. I tend to favor the for range/select in cases where I'm managing/propagating context like the example above. I prefer having more control than a waitgroup would afford me
English
0
0
1
29
Pasha Sviderski
Pasha Sviderski@psviderski·
A pattern I use in Go for running long-running services or background processes. The idea is that a service implements just one blocking Run(ctx) method that does all the busy work (serves requests, watches for changes, etc) To stop it, you cancel the context. This makes the interface very simple. If you need non-blocking start/stop, you build them on the spot where you need them: stop() -> just use context.WithCancel. The returned cancel() is your stop function. start() -> wrap Run(ctx) in a closure and run it as a goroutine. The caller owns the goroutine, not the service. It keeps the service itself clean and predictable. You can also add a 'done' channel to know when Run has fully returned for graceful shutdown. This shines when you need to manage many such services together. Run them as part of an errgroup and you get: - automatic cancellation of all services if one fails - a single Wait() for all of them to finish
Pasha Sviderski tweet media
English
12
25
319
35.9K
Leizner ⚛️
Leizner ⚛️@kmichaelc·
@MarioVerbelen @psviderski This is certainly one way to do it. I generally tend to avoid using a waitgroup in these scenarios. I would rather use a for-range on a single 'signal' channel or a for-select block if I have multiple channels to listen to. This works too
English
2
0
2
23
Mario Verbelen
Mario Verbelen@MarioVerbelen·
Mario Verbelen@MarioVerbelen

How to wait correctly with #golang for a signal? If you combine that with context in your routines and pass that, you can wait for <-ctx.Done() wherever you want. Make sure that your main will wait until all routines are done with a sync.WaitGroup (or another sync mechanism). Don't use sleep, that is a stupid approach (you can't predict how long you should wait) So stay safe and wg.Wait()

QME
1
0
1
66
Leizner ⚛️
Leizner ⚛️@kmichaelc·
@MarioVerbelen @psviderski Yeah a Sigchan that you plug into a signal.Notify Tbh I prefer a simple straightforward for select block to these gymnastics
English
1
0
1
45
Mario Verbelen
Mario Verbelen@MarioVerbelen·
@psviderski Add a background function that listens to signals like sigterm. So you're also stopping cleanly when pressing ctrl-c
English
3
0
11
1.1K
Korede kimmich 🍫🪖🪖
Korede kimmich 🍫🪖🪖@spartankimmich·
Our current options in defence ~cubarsi ~martin ~araujo ~cancelo ~jack of all trades These are the only available defenders
English
50
53
1.5K
25K
(fan) 𝔸Z 𓅓
(fan) 𝔸Z 𓅓@6lack_mmba·
Two undeserved penalties for Raphina. VAR disallows atleti clean goal after a long dramatic check. Lamine yamal stat-padding with a brace before halftime. Pedri drops a generational performance. Raphinha remembers he’s Brazilian and starts cooking simione for fun. Straight red for a sorloth after a “soft” challenge stopping a Barça counter. Another atleti goal ruled out for offside by a toe nail. Barcelona score 5… then decide that’s not enough and add one more. Garcia with a MOTM-level save to kill any hope.
(fan) 𝔸Z 𓅓 tweet media
English
102
317
3.7K
90.6K
Leizner ⚛️
Leizner ⚛️@kmichaelc·
@MarioVerbelen Perks of writing Go 😌 I use otter for my caches. 50-100ns ops are very difficult to beat. It takes a lot of scaffolding but it's always tailored to my use case
English
0
0
0
1.8K