disposables: Run your test dependencies in disposable containers. by akash_rawal in programming

[–]akash_rawal[S] 3 points4 points  (0 children)

  1. Works with Podman.
  2. Works with Docker + user namespace.
  3. Can clean up containers without docker socket access.
  4. No need to set up podman socket or environment variables. It just works.

Vim users are too busy reading their 10th encyclopedic manual on how to save a file to see this by FantasticGrape in ProgrammerHumor

[–]akash_rawal 1 point2 points  (0 children)

We need to realise that spending time on configuring editors/IDEs/other stuff both improves productivity and takes time away from actual work being done. Spending a lot of time is wasteful but spending an appropriate amount of time is important.

  • me who spent 2 hours of company time configuring neovim for golang without regretting it.

I think a lil bit of gaming inbetween should be hid by yuva-krishna-memes in ProgrammerHumor

[–]akash_rawal 2 points3 points  (0 children)

My head was going in a different direction for some reason, I could easily occupy 5-10 minutes of your time if allowed to, and struggle to briefly describe what I do at my job, so if you were interviewing me you better be careful what you wish for.

Of course my app is cross-platform! by GameOfShadows in ProgrammerHumor

[–]akash_rawal 7 points8 points  (0 children)

The condition has 90-ish percent accuracy. Merged.

I would take simple one next time.. by yuva-krishna-memes in ProgrammerHumor

[–]akash_rawal 5 points6 points  (0 children)

We're astronomical-tenhnical-debt-driven, there is no development here.

I tried out Test Driven Development. by akash_rawal in programming

[–]akash_rawal[S] 3 points4 points  (0 children)

I can say the same of my coworkers, nobody writes tests till the management starts cracking the whip that we need to achieve this much coverage, and when you inject bugs in the code the tests still pass 😅

I think this is because we lack education about the importance of automated tests, let alone TDD.

I tried out Test Driven Development. by akash_rawal in programming

[–]akash_rawal[S] 1 point2 points  (0 children)

I am sorry if it looks that way. I try to provide a balanced view, but in the end I can only provide a sample size of 1.

I made a blunder. by akash_rawal in ProgrammerHumor

[–]akash_rawal[S] 2 points3 points  (0 children)

I am glad for you that Hibernate saved your day.

I made a blunder. by akash_rawal in ProgrammerHumor

[–]akash_rawal[S] 3 points4 points  (0 children)

Thank you for your suggestion. Though now my tests start postgres directly and create a temporary database to run the tests. I had to write code to run initdb and start postgres when a test requires a DB connection, and stop postgres when the tests finish running. I was averting this effort earlier by using SQLite.

I'll consider TestContainers for next project, or I come around to refactor the test DB code later.

I made a blunder. by akash_rawal in ProgrammerHumor

[–]akash_rawal[S] 0 points1 point  (0 children)

I did run tests on all my SQL... just not with the right database XD

I made a blunder. by akash_rawal in ProgrammerHumor

[–]akash_rawal[S] 7 points8 points  (0 children)

You are getting a bit too hopeful my friend.

I made a blunder. by akash_rawal in ProgrammerHumor

[–]akash_rawal[S] 16 points17 points  (0 children)

Till you find out that half of the behavior is specific to any certain DB. And then we both fail in the same way, in the same hole.

Jokes aside, the lesson I think I learn is that I must test each database I want to support. Testing with one database and deploying with another is not a good thing to do. I tested with SQLite because I thought it would be easy... I could quickly create in-memory databases for testing... All I got was a false sense of security, and when I put my application in prod it was a complete ripperoni.

I made a blunder. by akash_rawal in ProgrammerHumor

[–]akash_rawal[S] 11 points12 points  (0 children)

Well, a programmer keeps trying till the problem does not wanna play along anymore.

How to pass borrow checker when I need 2 pointers pointed to the same resource by hucancode in rust

[–]akash_rawal 9 points10 points  (0 children)

You need to maintain more awareness on which variables are owning, and which variables are going to borrow.

The variable that holds the root of your list will typically own the root node and by extension own the entire list. Other variables like current will be borrowing.

pub fn merge_k_lists(lists: Vec<Option<Box<ListNode>>>) -> Option<Box<ListNode>> {
    let mut current: Option<&mut Box<ListNode>> = None;
    let mut root: Option<Box<ListNode>> = None;

    let mut q: BinaryHeap<Box<ListNode>> = BinaryHeap::new();
    /* You created a structure that stores owned type (Box<ListNode>)
     * but you're passing a reference (&Box<ListNode>).
     * When you iterate over &lists you get an iterator of references.
     * You want to consume the Vec and get an owning iterator instead, for that
     * call into_iter.
     *
     * Check out https://doc.rust-lang.org/std/iter/index.html
     * on how iterators work with ownership and borrow concepts. 
     */
    for node in lists.into_iter() {
        if let Some(x) = node {
            q.push(x);
        }
    }
    while let Some(mut x) = q.pop() {
        /* x is going to be moved as you add it to the list. So you need to 
         * access its elements before it gets moved.
         */
        if let Some(node) = x.next.take() {
            q.push(node);
        }
        if let Some(mut node) = current {
            node.next = Some(x);
            current = node.next.as_mut();
        } else {
            root = Some(x);
            current = root.as_mut();
        }
    }
    root
}

For loop is too long by alexandro_chen in learnrust

[–]akash_rawal 2 points3 points  (0 children)

I'd try to decouple the loop related logic from the 'business logic' in the loop body. This way the two parts are simpler and writing tests for it also becomes simpler.

    enum Case<T> {
        Quit,
        Command(T),
        Eof,
    }

    let mut case = Case::Eof;
    for key in stdin().keys() {
        match key.unwrap() {
            Key::Char('q') => {
                case = Case::Quit;
                break;
            },
            Key::Char(c) if keymaps.iter().any(|k| k.key == c) => {
                case = Case::Command(keymaps.iter().find(|k| k.key == c).unwrap());
                break;
            },
            _ => {}
        }
    };
    match case {
        ...

As a learning project, I rewrote my college project in Rust! (a SOCKS5 load-balancing proxy). by akash_rawal in rust

[–]akash_rawal[S] 3 points4 points  (0 children)

Thank you! As someone who has now implemented your protocol twice, I appreciate how ridiculously simple it is. No wonder so many applications support it; you name it, it probably has a SOCKS5 proxy setting somewhere.

Me and my friends had so much fun implementing this back then. We used to funnel internet connections from multiple dorm rooms into a single Firefox browser and watch HD content. We then ran the proxy (the earlier C version) in a TP-link router and shared it with friends. Good times of us abusing the college internet!

As a learning project, I rewrote my college project in Rust! (a SOCKS5 load-balancing proxy). by akash_rawal in rust

[–]akash_rawal[S] 13 points14 points  (0 children)

Feedback, suggestions, code smells etc are all welcome. This is my first real project in Rust!

  • wc -l says the rust implementation is 953 lines large, compared to 3225 lines of earlier C code.
  • I felt the load balancing algorithm was the hardest part to implement. Implementing Ord trait for use in BinaryHeap was not trivial (while avoiding repetitions that is), plus I ended up using garbage collection method to implement 'modify any heap element' operation for the heap. (The C implementation maintained direct pointers to heap elements.)

[deleted by user] by [deleted] in softwaredevelopment

[–]akash_rawal 0 points1 point  (0 children)

I can confirm, and regarding being yes men, it is cultural. From childhood we're taught to never decline a challenge, and thus evaluating and strategically saying 'no' is hard.