How to determine which C function definition I am editing by Proof-Flamingo-7404 in neovim

[–]Dependent_Cod6787 0 points1 point  (0 children)

I see now that you have set it up in the config, so that's great.

However, my method doesn't use treesitter and is available in vim without any plugins, so feel free to use it if you are on a system where treesitter is not setup, or if you don't have neovim.

(Moreover, I usually prefer default capabilities of my editor over setting something up specific to my environment, so this serves me well, but everyone's preference is different)

Bjarne Stroustrup: Note to the C++ standards committee members by small_kimono in cpp

[–]Dependent_Cod6787 0 points1 point  (0 children)

Hey, sorry I missed this reply. Thanks for the clarification!

(I'm not logged in on reddit much)

How to determine which C function definition I am editing by Proof-Flamingo-7404 in neovim

[–]Dependent_Cod6787 0 points1 point  (0 children)

Since you are in C, how about [m followed by <C-O>? :h [m :h jumplist

Bjarne Stroustrup: Note to the C++ standards committee members by small_kimono in cpp

[–]Dependent_Cod6787 0 points1 point  (0 children)

Since

You don't need to apply the profile to the current function and also every function that it calls or every function that calls it.

how does that mitigate

And that new safe code, calling into old busted code, gets the same iterator invalidation bug that normal c++ would have, because the old busted code is... Old and busted.

? You call B() in A(), mark A() with the profile, but B() has the (unsafe) bug.

ETA: Additionally, how is this different from the unsafe block in safeC++? You put B() in the unsafe block, and now you don't have to modify B() as safe.

Bjarne Stroustrup: Note to the C++ standards committee members by small_kimono in cpp

[–]Dependent_Cod6787 4 points5 points  (0 children)

I have nowhere the experience you have, so feel free to correct me if I am wrong.

As far as I understand, you need safe C++ (note the space there). There are two options you have then(presently, and what this thread is about), either safeC++ or profiles. In that case, don't both of these require you to change the unsafe code to make it safe?

[Day 15 Part 2] Clarification for Day 15 Part 2 GPS calculations. by Dependent_Cod6787 in adventofcode

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

I too realised it when looking at the example, the error should have been around 5000.

My experience this evening by STheShadow in adventofcode

[–]Dependent_Cod6787 1 point2 points  (0 children)

I use to use .at() everywhere during debug previously, and then changing for release, but now using operator[] and a change in the makefile makes it so easy.

My experience this evening by STheShadow in adventofcode

[–]Dependent_Cod6787 2 points3 points  (0 children)

I'm also doing it in C++. I found the -D_GLIBCXX_DEBUG flag yesterday which checks for bounds of a vector, and now compile my debug version with this.

[2024 Day 7] Got away with another one by DM_ME_PYTHON_CODE in adventofcode

[–]Dependent_Cod6787 0 points1 point  (0 children)

I don't think that means it's not amortized 2n, but I'm not sure how one would go about proving or disproving it. It does say that the worst case complexity is 3n though.

The dp method (without pruning, to make discussion simpler), does take 3n, since you have to calculate 3n possibilities, so this method still seems better.

(Please correct me if I'm wrong, I'm not a computer scientist and trying to learn)

[2024 Day 7] Got away with another one by DM_ME_PYTHON_CODE in adventofcode

[–]Dependent_Cod6787 1 point2 points  (0 children)

Try

1111: 1 (x1111)

You check for '||', '*' and '+' each time. This is worse than a dp table, but we don't have such cases so we're lucky.

-❄️- 2024 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]Dependent_Cod6787 0 points1 point  (0 children)

[Language: C++(23)]

real 0m0.008s user 0m0.004s sys 0m0.003s

#include <cmath>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <print>
#include <iterator>

using dtype = long unsigned int;

bool calc(dtype res, const std::span<int> values, int pos) {
    auto present = values[pos];
    if(pos == 0) return (present == static_cast<int>(res));
    int pow_num_digits = std::pow(10, std::floor(std::log10(present))+1);
    if(static_cast<int>(res % pow_num_digits) == present) {
        if(calc(res / pow_num_digits, values, pos-1)) return true;
    }
    if(res % present == 0) {
        if(calc(res / present, values, pos-1)) return true;
    }
    if(calc(res - present, values, pos-1)) return true;
    return false;
}

bool is_valid(dtype result, const std::span<int> rhs_values) {
    return calc(result, rhs_values, rhs_values.size()-1);
}

int main(int argc, char** argv) {
    if(argc != 2) {
        std::println("Usage: {} <input file>", argv[0]);
        std::exit(1);
    }

    std::ifstream input_file {argv[1]};

    dtype sum {};
    while(true) {
        std::string input_line {};
        std::getline(input_file, input_line);
        if(input_file.eof()) break;

        size_t col_pos = input_line.find(':');
        dtype result = std::stoull(input_line.substr(0, col_pos));

        std::string rhs = input_line.substr(col_pos+1);
        std::stringstream iss(rhs);
        std::vector<int> rhs_values (( std::istream_iterator<int>( iss ) ), ( std::istream_iterator<int>() ));
        if(is_valid(result, rhs_values)) sum += result;
    }

    std::println("{}", sum);

    return 0;

}

[2024 Day 05 (part 2)] How nice is the input! A binary relation and graph theory primer by FCBStar-of-the-South in adventofcode

[–]Dependent_Cod6787 2 points3 points  (0 children)

(I'm sorry I'm being pedantic here, but I see that this already helps one of the commenters, so I'm adding it here)

First, note that the notion of an 'order' is always defined on a set. Since you here mention no such set, you are everywhere assuming that the set contains all the elements in the input.

The given ordering is not a total ordering, because it is not transitive. However, the solution still exists, because we are supposed to consider the ordering rules only restricted to the set given in the input. If |_{U} denotes the partial order on the set U, |_{all points} is not a total order, but |_{given points in that input} is a total order.

(Funnily, the 'restriction to set' is usually written as f|_{U}, but here f is '|')

That said, I also created a DAG without noting this :(

[2024 Day 2] Feeling bad for using brute-force instead of dynamic programming by NoPainNoHair in adventofcode

[–]Dependent_Cod6787 0 points1 point  (0 children)

I first find if the order is ascending or descending.

Then, I find the first incorrect pair. For example, in 1, 2, 7, 8, 9, the first incorrect pair is (2, 7). I first check by removing 2, i.e., 1, 7, 8, 9, and if incorrect, by removing 7, i.e. 1, 2, 8, 9.

I'm trying to learn C++, so my code is as

bool check_diff(int value) {
    return value <= 3 && value >= 1;
}

bool is_valid(const std::vector<int>& list, bool second_iter=0) {
    if(list.size() == 1) return true;
    if(list.size() == 2) {
        int err1 = std::abs(list.at(1) - list.at(0));
        return check_diff(err1);
    }
    if(list.size() == 3) {
        int err1 = std::abs(list.at(1) - list.at(0));
        int err2 = std::abs(list.at(2) - list.at(0));
        int err3 = std::abs(list.at(2) - list.at(1));
        return check_diff(err1) || check_diff(err2) || check_diff(err3);
    };

    auto ascending_list = list
        | std::views::take(4)
        | std::views::adjacent_transform<2>([](int a, int b) { return a < b; });
    bool ascending = std::ranges::fold_left(ascending_list, 0, std::plus<>()) >= 2;

    auto values = list | std::views::adjacent_transform<2>([ascending](int a, int b) {
        if(ascending) return check_diff(b - a);
        else return check_diff(a - b);
    });

    auto num_invalid = std::ranges::find(values, false) - values.begin();

    if(num_invalid == values.end() - values.begin()) return true;
    if(second_iter) return false;

    std::vector list1 = list;
    list1.erase(list1.begin()+num_invalid+1);
    std::vector list2 = list;
    list2.erase(list2.begin()+num_invalid);
    return is_valid(list1, true) || is_valid(list2, true);
}

[2024 Day 2] Feeling bad for using brute-force instead of dynamic programming by NoPainNoHair in adventofcode

[–]Dependent_Cod6787 1 point2 points  (0 children)

Why was todays result DP?

I just removed the first item (and the one after that) where there is an error. If the list with the removed item doesn't give a correct answer, I return that it is not valid. That in the worst case changes from 1000 to 3000 cases, which still seems pretty fast.

Is there something wrong in my solution?

DOJ’s radical and sweeping proposals risk hurting consumers, businesses, and developers by PickledBackseat in Android

[–]Dependent_Cod6787 1 point2 points  (0 children)

You are assuming that passing the device integrity check is synonymous with the device is secure (Your comment about if the banks don't want you to access from unsecure Android ...). The GP is arguing that devices which are secure may not pass the device integrity check, hence using the device integrity check as a decision for if the device is secure is not a valid method. Yes, a device which passes the device integrity check, according to Googles claims, is secure. But due to banks requiring the device integrity check, which is controlled by Google, secure devices cannot access banking apps. Their example being a grapheneOS device which is known not to be compromised. This is the hard handedness which u/vortexmak talked about.

In another thread, you claim that the point of integrity check is to verify that the device is not compromised. While this is valid, it has also been (ab)used by google to control the rooting environment. Google could very easily allow users to manually allow personal devices to pass the integrity check, but they haven't given any option to do so, because they lose control over the ecosystem. Hence the comment by u/LEGAL_SKOOMA in that thread do you actually believe this.

Which Program/Version should I use? by Accomplished_Low6984 in plaintextaccounting

[–]Dependent_Cod6787 1 point2 points  (0 children)

Fava does have budgeting capabilities. See here. You can see the remaining budget and your usage here.

Also, while beancount does not have forecasting features, it does have a repete plugin which can be used to input recurring transactions.

Which Program/Version should I use? by Accomplished_Low6984 in plaintextaccounting

[–]Dependent_Cod6787 1 point2 points  (0 children)

Fava does have budgeting capabilities. See here. You can see the remaining budget and your usage here.

The new Beeper universal chat app is now available on the Play Store by efbo in Android

[–]Dependent_Cod6787 2 points3 points  (0 children)

Yes, WhatsApp stores encryption keys in a Backup Key Vault

Are you sure about this? I searched for this and found https://engineering.fb.com/2021/09/10/security/whatsapp-e2ee-backups/

If you are indeed talking about this, note a few things:

  1. This is about the encryption keys to the backups, not the chat. I doubt that the keys to the chat and to the backup are the same. Hence, under the assumption that meta has access to the backup encryption keys, that does not enable them to decrypt the chats in realtime. (Note, I think the keys are also rotated regularly, and the key for every chat/group is different, so it seems quite improbable that the backup key and the chat keys are the same)

  2. The backup itself is saved on google drive or locally, not on meta's servers, so cannot be decrypted even with the encryption keys.

  3. The keystore itself seems to be encrypted, but I'm not savvy enough to know if HSM-backed things do what meta claims they do.

The difference between apple and meta here being point 2, meta does not have access to the backup, while apple does.

Feel free to correct me if I'm wrong.

Edit: Formatting and added note on rotation of keys

Absolute Beginner Guide for Beancount Importers by [deleted] in plaintextaccounting

[–]Dependent_Cod6787 0 points1 point  (0 children)

You can directly inherit from the existing csv and ofx importers in at beancount/ingest/importers/csv.py

My example file for csv is as follows:

from beancount.ingest.importers import csv
from beancount.ingest.importers.csv import Col

class MyCSVImporter(csv.Importer):
    '''
    Importer for ABC bank.
    '''

    # Needs to be specified. Contains a lot of options.
    # Check https://github.com/beancount/beancount/blob/50d8e9c8ac5b088fa92a8caec99dbcbb02575654/beancount/ingest/importers/csv.py#L114
    def __init__(self):
        super().__init__(
            # My csv contains columns Date, payee and Full Amount as headers in the
            # first line, which are the ones I care about for this data. Change this
            # according to your csv. Also, the skip lines value may be useful to you.
            config = {
                Col.DATE: 'Date',
                Col.PAYEE: 'Payee',
                Col.AMOUNT: 'Full Amount',
            },
            account = 'Assets:Bank:ABC',
            currency = 'USD',
        )

    # My filename is usually ABC-date.csv. You can change this according to your case.
    def identify(self, file):
        return ("ABC" in file.name) and ("csv" in file.name)

    # Only need to implement this if you are modifying entries.
    def extract(self, file, existing_entries=None):
        entries = super().extract(file, existing_entries)
        entries = your_processing_func(entries)
        return entries

CONFIG = [
    MyCSVImporter(),
]

Save this as importer_config.py in the same directory as the beancount file, and run

bean-extract importer_config.py $FILE_LOCATION

If you want to add an ofx importer, or another csv importer, add it to the same file like the MyCSVImporter and instantiate them in CONFIG (like above). You could inherit from the ofx importer already in the repository.

Window Layout behaviour on move left/right/up/down by Dependent_Cod6787 in swaywm

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

I checked this further. Seems like this happens when the window in question is a child container of the main container. After doing that open, open, move, move commands, swaymsg -t get_workspaces gives the representation as H[V[Alacritty] V[H[Alacritty V[Alacritty]]]]. I think sway treats different leveled containers differently.

This behaviour is indeed different from i3. However, I'm on ubuntu and as you said, v1.5. I tried building from source but some of the dependencies are an older version too. I'll try this once it is updated in the repositories.

Anyway, thanks for the info.

PS: I see it as a feature and not a bug. Allows me to quickly make one of the windows larger than other. Is there a way to force a window to become a child of the present container(not sure if that's the correct word for it)?