help-circle
rss
[SOLVED] Having problems using crate
I've tried running [this crate](https://github.com/runfalk/ed2k-rs) and it runs fine. I've copied the code, I've modified it very little when adding it to [my project](https://git.disroot.org/hirrolot19/Jedi_Archives/src/branch/main/core/src/file/cas/ed2k/), but it's giving me a bunch of errors. Have I done something wrong when adding the repository to get so many errors? ```rust ❯ cargo test Compiling sdcore v0.1.0 (/home/user/code/rust/spacedrive/core) error[E0437]: type `OutputSize` is not a member of trait `FixedOutput` --> core/src/file/cas/ed2k/ed2k_hash.rs:71:5 | 71 | type OutputSize = typenum::U16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `FixedOutput` error[E0407]: method `finalize_into_reset` is not a member of trait `FixedOutput` --> core/src/file/cas/ed2k/ed2k_hash.rs:84:5 | 84 | fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) { | ^ ------------------- help: there is an associated function with a similar name: `finalize_into` | _____| | | 85 | | if self.num_full_chunks == 0 { 86 | | self.md4_hasher.finalize_into_reset(out); 87 | | } else { ... | 92 | | self.current_chunk_len = 0; 93 | | } | |_____^ not a member of trait `FixedOutput` error[E0437]: type `OutputSize` is not a member of trait `FixedOutput` --> core/src/file/cas/ed2k/ed2k_hasher.rs:82:5 | 82 | type OutputSize = typenum::U16; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `FixedOutput` error[E0407]: method `finalize_into_reset` is not a member of trait `FixedOutput` --> core/src/file/cas/ed2k/ed2k_hasher.rs:95:5 | 95 | fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) { | ^ ------------------- help: there is an associated function with a similar name: `finalize_into` | _____| | | 96 | | if self.num_full_chunks == 0 { 97 | | self.md4_hasher.finalize_into_reset(out); 98 | | } else { ... | 103 | | self.current_chunk_len = 0; 104 | | } | |_____^ not a member of trait `FixedOutput` error[E0433]: failed to resolve: use of undeclared crate or module `ed2k` --> core/src/file/cas/ed2k/mod.rs:147:58 | 147 | let mut zero_chunk: Vec<u8> = Vec::with_capacity(ed2k::Ed2kHasher::CHUNK_SIZE); | ^^^^ use of undeclared crate or module `ed2k` error[E0433]: failed to resolve: use of undeclared crate or module `ed2k` --> core/src/file/cas/ed2k/mod.rs:170:58 | 170 | let mut zero_chunk: Vec<u8> = Vec::with_capacity(ed2k::Ed2kHasher::CHUNK_SIZE); | ^^^^ use of undeclared crate or module `ed2k` warning: unused import: `FixedOffset` --> core/src/file/indexer/scan.rs:3:24 | 3 | use chrono::{DateTime, FixedOffset, Utc}; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `encode::ThumbnailJob` --> core/src/sys/locations.rs:2:2 | 2 | encode::ThumbnailJob, | ^^^^^^^^^^^^^^^^^^^^ warning: unused imports: `PrismaValue`, `raw` --> core/src/sys/locations.rs:8:26 | 8 | use prisma_client_rust::{raw, PrismaValue}; | ^^^ ^^^^^^^^^^^ error[E0433]: failed to resolve: use of undeclared crate or module `ed2k` --> core/src/file/cas/ed2k/mod.rs:114:32 | 114 | let mut hasher = ed2k::Ed2kHasher::new(); | ^^^^^^^^^^ not found in `ed2k` | help: consider importing this struct | 101 | use crate::file::cas::ed2k::Ed2kHasher; | error[E0433]: failed to resolve: use of undeclared crate or module `ed2k` --> core/src/file/cas/ed2k/mod.rs:152:36 | 152 | let mut hasher = ed2k::Ed2kHasher::new(); | ^^^^^^^^^^ not found in `ed2k` | help: consider importing this struct | 101 | use crate::file::cas::ed2k::Ed2kHasher; | error[E0433]: failed to resolve: use of undeclared crate or module `ed2k` --> core/src/file/cas/ed2k/mod.rs:160:36 | 160 | let mut hasher = ed2k::Ed2kHasher::new(); | ^^^^^^^^^^ not found in `ed2k` | help: consider importing this struct | 101 | use crate::file::cas::ed2k::Ed2kHasher; | error[E0433]: failed to resolve: use of undeclared crate or module `ed2k` --> core/src/file/cas/ed2k/mod.rs:175:36 | 175 | let mut hasher = ed2k::Ed2kHasher::with_legacy_hashing(true); | ^^^^^^^^^^ not found in `ed2k` | help: consider importing this struct | 101 | use crate::file::cas::ed2k::Ed2kHasher; | error[E0433]: failed to resolve: use of undeclared crate or module `ed2k` --> core/src/file/cas/ed2k/mod.rs:183:36 | 183 | let mut hasher = ed2k::Ed2kHasher::with_legacy_hashing(true); | ^^^^^^^^^^ not found in `ed2k` | help: consider importing this struct | 101 | use crate::file::cas::ed2k::Ed2kHasher; | error[E0277]: the trait bound `Ed2kHash: OutputSizeUser` is not satisfied --> core/src/file/cas/ed2k/ed2k_hash.rs:70:6 | 70 | impl FixedOutput for Ed2kHash { | ^^^^^^^^^^^ the trait `OutputSizeUser` is not implemented for `Ed2kHash` | note: required by a bound in `FixedOutput` --> /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/digest-0.10.3/src/lib.rs:91:33 | 91 | pub trait FixedOutput: Update + OutputSizeUser + Sized { | ^^^^^^^^^^^^^^ required by this bound in `FixedOutput` error[E0277]: the trait bound `Ed2kHash: OutputSizeUser` is not satisfied --> core/src/file/cas/ed2k/ed2k_hash.rs:73:59 | 73 | fn finalize_into(mut self, out: &mut GenericArray<u8, Self::OutputSize>) { | ^^^^^^^^^^^^^^^^ the trait `OutputSizeUser` is not implemented for `Ed2kHash` error[E0277]: the trait bound `Ed2kHash: OutputSizeUser` is not satisfied --> core/src/file/cas/ed2k/ed2k_hash.rs:84:66 | 84 | fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) { | ^^^^^^^^^^^^^^^^ the trait `OutputSizeUser` is not implemented for `Ed2kHash` error[E0277]: the trait bound `Ed2kHasher: OutputSizeUser` is not satisfied --> core/src/file/cas/ed2k/ed2k_hasher.rs:81:6 | 81 | impl FixedOutput for Ed2kHasher { | ^^^^^^^^^^^ the trait `OutputSizeUser` is not implemented for `Ed2kHasher` | note: required by a bound in `FixedOutput` --> /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/digest-0.10.3/src/lib.rs:91:33 | 91 | pub trait FixedOutput: Update + OutputSizeUser + Sized { | ^^^^^^^^^^^^^^ required by this bound in `FixedOutput` error[E0277]: the trait bound `Ed2kHasher: OutputSizeUser` is not satisfied --> core/src/file/cas/ed2k/ed2k_hasher.rs:84:59 | 84 | fn finalize_into(mut self, out: &mut GenericArray<u8, Self::OutputSize>) { | ^^^^^^^^^^^^^^^^ the trait `OutputSizeUser` is not implemented for `Ed2kHasher` error[E0277]: the trait bound `Ed2kHasher: OutputSizeUser` is not satisfied --> core/src/file/cas/ed2k/ed2k_hasher.rs:95:66 | 95 | fn finalize_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) { | ^^^^^^^^^^^^^^^^ the trait `OutputSizeUser` is not implemented for `Ed2kHasher` Some errors have detailed explanations: E0277, E0407, E0437. For more information about an error, try `rustc --explain E0277`. warning: `sdcore` (lib) generated 3 warnings error: could not compile `sdcore` due to 10 previous errors; 3 warnings emitted warning: build failed, waiting for other jobs to finish... Some errors have detailed explanations: E0277, E0407, E0433, E0437. warning: `sdcore` (lib test) generated 3 warnings (3 duplicates) error: build failed ```
fedilink

Presenting Activitypub-Rust crate
cross-posted from: https://lemmy.ml/post/341718 > [Activitypub](https://www.w3.org/TR/activitypub/) is decentralized social networking protocol recommended by the W3C. It provides a client to server API for creating, updating and deleting content, as well as a federated server to server API for delivering notifications and content. As part of the work on [Lemmy](https://join-lemmy.org/), we have implemented some high-level abstractions for handling the server-to-server protocol in Rust. These abstractions are now available as a standalone library. > > The main features are: > > - Data structures for federation are defined by the user, not the library. This gives you maximal flexibility, and lets you accept only messages which your code can handle. Others are rejected automatically during deserialization. > - ObjectId type, wraps the id url and allows for type safe fetching of objects, both from database and HTTP > - Queue for activity sending, handles HTTP signatures, retry with exponential backoff, all in background workers > - Inbox for receiving activities, verifies HTTP signatures, performs other basic checks and helps with routing > - Generic error type (unfortunately this was necessary) > - various helpers for verification, (de)serialization, context etc > > Documentation is currently lacking. If you want to get started with the library, best look at the example. > > The code has already been used in production as part of Lemmy for a long time, without any notable problems. However, ergonomics are lacking and need to be improved. There are also many additional features which would be worth implementing. See the project readme for details. Contributions and suggestions are very much welcome! > > You can find the project here: > > [https://github.com/LemmyNet/activitypub-federation-rust](https://github.com/LemmyNet/activitypub-federation-rust) > > [https://crates.io/crates/activitypub-federation](https://crates.io/crates/activitypub-federation)
fedilink


I hate those websites that repost stackoverflow content
They're all over the search results for common programming problems, and even for less common ones. They have less information than their original stackoverflow answer and of course are just a useless copy. AAAaaaaaaaargh whyyyyyyyyyyyyyy
fedilink

looking for a fast multi process shared dict
I have lots of multiprocessing processes which have to add to and search in a dict. Deletion of values is not needed. Atm I am using multiprocessing.Manager() and `dict = manager.dict()` This works pretty well, but I think that the manager is a huge bottleneck here. Any ideas? It has to run on older Python 3 versions, otherwise I would use this cool thing I found: https://github.com/ronny-rentner/UltraDict
fedilink

Testing video encoding program?
I have two projects, one is working and the other isn't. I want to make the first project include the same functionality from the second project, or the second project to work as the first one does. I've thought of adding tests to the first project that I can use with the second project so that they end up working the same way. But I don't know which kind of tests to write, should I be using a bunch of videos as test subjects? I think that would make testing very slow, but I don't know what else to do. https://codeberg.org/LifeSymbiont/video-diet https://codeberg.org/LifeSymbiont/reduce_video_size/
fedilink


[Solved] Show progress bar of a ffmpeg video convertion
I'm trying to print a progress bar while executing ffmpeg but I'm having trouble getting the total number of frames and the current frame being processed. The error I get is `AttributeError: 'NoneType' object has no attribute 'groups'`. I've copied the function from [this program][1] and for some reason it works there but not here, even though I haven't changed that part. [main.py][2] ``` pattern_duration = re.compile( 'duration[ \t\r]?:[ \t\r]?(.+?),[ \t\r]?start', re.IGNORECASE) pattern_progress = re.compile('time=(.+?)[ \t\r]?bitrate', re.IGNORECASE) def execute_ffmpeg(self, manager, cmd): proc = expect.spawn(cmd, encoding='utf-8') self.update_progress_bar(proc, manager) self.raise_ffmpeg_error(proc) def update_progress_bar(self, proc, manager): total = self.get_total_frames(proc) cont = 0 pbar = self.initialize_progress_bar(manager) try: proc.expect(pattern_duration) while True: progress = self.get_current_frame(proc) percent = progress / total * 100 pbar.update(percent - cont) cont = percent except expect.EOF: pass finally: if pbar is not None: pbar.close() def raise_ffmpeg_error(self, proc): proc.expect(expect.EOF) res = proc.before res += proc.read() exitstatus = proc.wait() if exitstatus: raise ffmpeg.Error('ffmpeg', '', res) def initialize_progress_bar(self, manager): pbar = None pbar = manager.counter( total=100, desc=self.path.rsplit(os.path.sep, 1)[-1], unit='%', bar_format=BAR_FMT, counter_format=COUNTER_FMT, leave=False ) return pbar def get_total_frames(self, proc): return sum(map(lambda x: float( x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':'))))) def get_current_frame(self, proc): proc.expect(pattern_progress) return sum(map(lambda x: float( x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':'))))) ``` [1]: https://github.com/JavierOramas/video-diet/blob/966b5192902e55bd60ae06a5df195ec41bcd5d71/diet_video/__init__.py [2]: https://codeberg.org/LifeSymbiont/reduce_video_size/src/commit/ef3cd0974ecd1c4d0a17b6394499650c9fc3da2b/main.py
fedilink

Padding oracle attack - Wikipedia
>In symmetric cryptography, the padding oracle attack can be applied to the CBC mode of operation, where the "oracle" (usually a server) leaks data about whether the padding of an encrypted message is correct or not. Such data can allow attackers to decrypt (and sometimes encrypt) messages through the oracle using the oracle's key, without knowing the encryption key. It's a pretty genius way to break cipher-block-chained encryption!
fedilink

[Solved] Need to understand and simplify this function that converts a video with ffmpeg while showing a progress bar
This function is giving me an error but I've copied it from [the video-diet program](https://github.com/JavierOramas/video-diet/blob/81a5df4ad27e8cd6fff1be4974067631343a4354/diet_video/__init__.py#L42) and I don't really understand it so I can't simplify it. Could someone who understands it, explain it step by step? ```py def convert_video_progress_bar(self, manager, cmd): name = self.path.rsplit(os.path.sep, 1)[-1] proc = expect.spawn(cmd, encoding='utf-8') pbar = None try: proc.expect(pattern_duration) total = sum(map(lambda x: float( x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':'))))) cont = 0 pbar = manager.counter( total=100, desc=name, unit='%', bar_format=BAR_FMT, counter_format=COUNTER_FMT, leave=False ) while True: proc.expect(pattern_progress) progress = sum(map(lambda x: float( x[1])*60**x[0], enumerate(reversed(proc.match.groups()[0].strip().split(':'))))) percent = progress/total*100 pbar.update(percent-cont) cont = percent except expect.EOF: traceback.print_exc() finally: if pbar is not None: pbar.close() proc.expect(expect.EOF) res = proc.before res += proc.read() exitstatus = proc.wait() if exitstatus: raise ffmpeg.Error('ffmpeg', '', res) ```
fedilink

E0515: Returns a value referencing data owned by the current function
I'm getting a `returns a value referencing data owned by the current function` on line 17 on `.unwrap_or("/tmp/")`. This is the first time I try something on rust after finishing the book. I still don't know enough to debug this. ``` use clap::{Arg, Command}; fn main() { args = parse_args(); println!("The directory passed is: {}", args[0]); } fn parse_args() -> Vec<&str> { let matches = Command::new("Parse Torrent") .arg(Arg::new("dir") .short('f') .long("dir") .takes_value(true) .help("input directory of your computer, example /disk1/dir1/")) .get_matches(); matches.value_of(dir).unwrap_or("/tmp/") } ```
fedilink

[SOLVED] Get list of strings from a messed multiline string
I want to do the following but I don't know how to get the name and percentage: `mymodule_test.py` ``` import unittest from unittest import TestCase from mymodule import get_wanted_cards, get_percentage class GetCardsTestCase(TestCase): def test_get_wanted_cards(self): s = ''' ↑ A Little Chat 92 (1%) 0 (0%) NEW ↑ An Offer You Can't Refuse 88 (87%) 0 (0%) NEW ↑ Angelic Observer 92 (91%) 0 (0%) NEW ''' expected = ["4 An Offer You Can't Refuse", "4 Angelic Observer"] actual = get_wanted_cards(s) self.assertEqual(actual, expected) def test_get_percentage(self): s = "92 (1%)" expected = 1 actual = get_percentage(s) self.assertEqual(actual, expected) if __name__ == '__main__': unittest.main() ``` `mymodule.py` ``` import re from typing import List def get_wanted_cards(s: str) -> List[str]: res = [] for line in s.splitlines(): array = line.split("\t") if len(array) < 5: continue name = array[1] percent = get_percentage(array[2]) if percent >= 50: res += "4 " + name return res def get_percentage(s: str) -> int: return int(re.match(r'\(([0-9]*)%\)', s).group(1)) if __name__ == "__main__": pass ```
fedilink

Where can I learn how to use the Lemmy api?
cross-posted from: https://fuckreddit.tryp.digital/post/72 > As the title says, I'm trying to create my own discord bot that takes channel comments and posts them on lemmy but I'm woefully underprepared. I definitely just need some more baseline info because as always I'm already in much deeper than I should be. Thanks for any help! > > I've already setup a bot (on the same server as lemmy, exactly how it's described in the linked doc) and can successfully ping it from my server. [I used this to set it up which uses Lua](https://github.com/SinisterRectus/Discordia/wiki/Writing-Your-First-Bot) and I'm unsure if that will be an issue. I can setup node.js if need be. > > I also installed the `lemmy-js-client`. I guess I have a few questions but really I'll take any help I can get :) > > - Does the js client need to be installed in a certain location? > - Where does the block of text on the api docs go? Just in my `bot.lua` file? > - websocket or http? Does it matter? > - I need to make a POST request to lemmy to uyt the content there after I grab the comment from discord? > - Can someone recommend me a resource so I can learn more about using [the API here](https://join-lemmy.org/api/#usage)? More than willing to do the legwork on my own but I'd like to know I'm going in the right track first. > > Additionally I was trying to use [pipedream](https://pipedream.com/) for assistance. I can optionally run code right on the site as shown in the picture below but also I can use any API account or make a POST request which are 2nd and 3rd photos below respectively. I'm taking a stab at the http POST workflow in between typing this. > > ![](https://fuckreddit.tryp.digital/pictrs/image/12769013-ffaf-4725-8e43-7c9cbbda5ea1.png) > > ![](https://fuckreddit.tryp.digital/pictrs/image/e4213bf7-894c-4316-89bf-3c6543e1cf9a.png) > > ![](https://fuckreddit.tryp.digital/pictrs/image/f811173a-4dab-4ad0-a101-12fc9815a97f.png)
fedilink

[Common Lisp] How do I read a 32-bit integer from a binary (file) stream?
I can't figure out how to read multiple bytes. I'm trying to read a 32-bit integer so that I can store it to be used by a class. My (truncated) code: ``` (let ((version-buffer (byte 4 0))) (read-sequence version-buffer input-stream) (cond ((> version-buffer 10) (read-sequence minor-version-buffer input-stream)) (t t)) (setf (navigation-mesh-version temp-mesh) `(,(version-buffer)) ) ) ``` EDIT: Truncated the code further.
fedilink

How do I insert control characters into a string with hex?
I'm trying to read a string and verify it's magic number (0xFEEDFACE); but I don't know how to insert an ascii character (as a number) into strings. Here is my code: ``` ;; Parser library for the Source Engine Nav mesh format. (defun parse-nav-string (input-string) "Parses string as Nav file." ;; Test for magic string 0xFEEDFACE. (cond (string= (subseq input-string 0 3) (concatenate (code-char #xCE) (code-char #xFA) (code-char #xED) (code-char #xFE)) ) (t (format *error-output* "Magic string not found!") ) ) () ) ```
fedilink

VMs and VM management for your home
What do you use, prefer? I have mostly used KVM with qemu, but I want to try out other things. I have heard of proxmox and all kinds of cool management things, what's a solid setup that supports easy backups and such things? KVM and qemu is solid and pretty easy to understand. Basic control of the VMs can be done with virt-manager, which is a basic but solid tool.
fedilink

How to write an advanced search?
I want to do an advanced search, something similar to the one in [scryfall](https://scryfall.com/advanced) where I can use either syntax or buttons to search, using multiple filter and logical operators. I have difficulty knowing how to create the SQL query dynamically. If it's possible I'd like to see a guide on how to do something like that. If there isn't a guide a high level description on how to do this would be useful. Useful resources. Off-the-shelf search engine server: - [OpenSearch aka ElasticSearch](https://github.com/opensearch-project) - [Toshi](https://github.com/toshi-search/Toshi) - [Apache Solr](https://lucene.apache.org/solr/): an enterprise search server with a powerful REST API - [Sonic](https://github.com/valeriansaliou/sonic): Fast, lightweight & schema-less search backend. An alternative to Elasticsearch that runs on a few MBs of RAM - [Searx](https://github.com/searx/searx) - [meilisearch](https://github.com/meilisearch/meilisearch) Libraries to build your own search engine server: - Bleve & [tantivy](https://github.com/quickwit-oss/tantivy) are search engine projects, respectively written in Golang and Rust, inspired by Apache Lucene and its algorithms (e.g., tf-idf, short for term frequency-inverse document frequency). Such as Lucene, both are libraries to be used for any search project; however they are not ready-to-use APIs. - [Apache Lucene](https://lucene.apache.org/): the full-text search library > [@Helix@feddit.de](https://lemmy.ml/post/183491/comment/126228) > > If you use Hibernate as your data access layer you can use [Hibernate Search](https://www.baeldung.com/hibernate-search) > [@Thann•](https://lemmy.ml/post/183491/comment/125178) > > 1. you need a database to store and index the information. > 2. you need an API to access the information. > > There are a million ways you could do this; pretty much any database will do, and there are a bunch of options for API’s. OpenSearch (AKA ElasticSearch) might be a good starting point. GraphQL is a powerful API option as well.
fedilink

How to disable reading password timeout?
I know I can disable password aging with: ``` sudo visudo ``` And adding: ``` Defaults timestamp_timeout=-1 ``` But how can I disable timeout when reading passwords instead? To avoid this kind of error: ``` [sudo] password for user: sudo: timed out reading password sudo: a password is required -> exit status 1 ```
fedilink

I reinstalled *Manjaro Cinnamon 21.2.2-220123-linux515* trying to get rid of this error with no luck. I've only copied my dotfiles from an external drive and run the installation script. Whenever I try a `git init` in any empty repository I get `/git: permission denied`. Which doesn't tell me anything. I've found that the error is produced because of this lines in the installation of my dotfiles: ``` sudo tee -a /etc/profile /etc/zshenv /etc/zsh/zshenv &>/dev/null <<EOF export XDG_CONFIG_HOME=$XDG_CONFIG_HOME export ZDOTDIR=$ZDOTDIR EOF ``` If I change the lines appended to those files and restart the system it doesn't give me an error, but then my configuration isn't loaded. But that could mean the error happens anywhere in my configuration and I don't know how to find it.
fedilink

Check for sudo access in bash script
Is this the correct way to check for sudo access? ``` has_sudo() { if [[ "$EUID" = 0 ]]; then exit 0 else sudo -k # make sure to ask for password on next sudo if sudo true; then exit 0 else exit 1 fi fi } load_zshenv_on_startup() { if has_sudo; then append_zshenv_to_global_files else link_zshenv_to_home_directory fi } ```
fedilink