help-circle
rss
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

How can I evaluate a variable before appending with tee?
I need to evaluate this variables before appending this lines to a few files: ``` sudo tee -a /etc/profile /etc/zshenv /etc/zsh/zshenv &>/dev/null <<EOF export XDG_CONFIG_HOME="$SYNC"/config export XDG_CACHE_HOME="$HOME"/.cache export XDG_DATA_HOME="$HOME"/.local/share export XDG_STATE_HOME="$HOME"/.local/state export ZDOTDIR="$XDG_CONFIG_HOME"/zsh EOF ```
fedilink

How to avoid part of a bash script from executing twice when re-running the script?
For example I have a function that appends to a file a few lines. But if something else fails in the script I wouldn't want to fix it and execute it again, and then have those lines duplicated.
fedilink




How to improve this fix permissions function efficiency?
How do I improve this function efficiency so that it only searches once instead of three times: ``` # Fixes permissions for files and directories in the given folder or the current folder fixperms() { find "${1:-.}" -type f -executable -exec chmod 744 {} \; find "${1:-.}" -type f ! -executable -exec chmod 644 {} \; find "${1:-.}" -type d -exec chmod 755 {} \; } ```
fedilink

How to clear zsh configuration?
I think it was `zsh -z` but I'm not sure. It's for doing this: ``` reload_zsh() { echo "Reload zsh" zsh -z [ -f $ZSHRC ] && source $ZSHRC } ```
fedilink

How to let every file know the absolute path of the root of a project and be able to change a folder path easily?
I want to let every file know the path of the root of a project. For example let's consider this the root: `/home/username/.config/project`. If I have a folder in the project and every file in the folder has a line like `ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"` (gets the absolute path of the parent directory) whenever I move the folder to another location I may have to change that line for every file in the folder. Is there a better option to let every file know the path of the project root?
fedilink


Mass import from StackOverflow to HeapOverflow.ml
> I’d be down for mass import as long as it’s done well. My idea is either do it with selenium, simulating the usage of a normal user on the website. In that case, every post would have my user as the creator and would generate a lot of spam in the front wall. Or it could be done directly to the database, but that would create bogus users that would be unavailable to use for anyone else. I think it would be better to do the later but with a reserved user that you create only for that purpose and has a descriptive name like "bot". Let me know your ideas.
fedilink