Skip to content

t/rubber-duck-club

Rubber Duck Club: top posts

The most useful posts in this topic, by likes from the community.

Posts

  1. Question

    Django endpoint does 300+ queries, select_related vs prefetch_related confusion

    Hi, I am intern at a fintech, writing internal API in Django REST Framework. Endpoint /api/transfers/ returns 50 transfers and django-debug-toolbar shows 312 queries xD Models: Transfer has two ForeignKeys to Account (sender, receiver), Account has ForeignKey to Customer , and Transfer has ManyToMany tags . class TransferViewSet(viewsets.ReadOnlyModelViewSet): queryset = Transfer.objects.select_related("sender",…

    Kacper Nowicki13likes9comments

  2. Question

    Python script works when I run it, does nothing in cron. What am I missing?

    Quick one. Practicing Linux for the transition (ETS in 7 months, SkillBridge after that if it gets approved). Wrote a Python script that pings a list of hosts and writes the results to a CSV. Works fine when I run it from my home directory. Put it in crontab -e to run every 5 minutes. Nothing. No CSV, no error, nothing. */5 * * * * python3 pinger.py What I checked: cron is running ( systemctl status cron says…

    Ray Alvarez10likes6comments

  3. Question

    Recursion confusion: why does my function print the numbers in reverse order?

    Assalam o Alaikum all. I am a 2nd year CS student. I am having a confusion in recursion. Here is my code: #include <stdio.h> void print(int n) { if (n == 0) return; print(n - 1); printf("%d ", n); } int main() { print(5); return 0; } I expected 5 4 3 2 1 but it prints 1 2 3 4 5 . When I move the printf above the recursive call, it prints 5 4 3 2 1 . Why is the position of one line changing the whole order? Our…

    Zainab Malik7likes8comments

  4. Question

    rust: cannot borrow `*self` as mutable because it is also borrowed as immutable

    making the pong game for @tomasz_k (long story) and im stuck on the borrow checker. i have a game struct with a list of entities and i want to update each one, but update needs to call a method on self struct Game { items: Vec<Entity>, score: u32, } impl Game { fn tick(&mut self) { for item in self.items.iter() { self.update(item); } } fn update(&mut self, item: &Entity) { // moves the item, maybe changes score } }…

    Olivia Martin4likes4comments

Get the best of Dynamo Geeks weekly

One email each Monday with the most useful posts. No spam; unsubscribe in one click.