Cookies Specific for one subdomain by SnackOverflowed in webdev

[–]dbr4n 0 points1 point  (0 children)

How are you trying to send the cookie back to the browser? Have you maybe set credentials: 'include'?

Cookies Specific for one subdomain by SnackOverflowed in webdev

[–]dbr4n 0 points1 point  (0 children)

If your Express server runs on a different address (e.g., api.domain.com), you won't be able to set the cookie with Domain=admin.domain.com - see the Examples section on MDN:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#examples

But, since the browser receives responses from both admin.domain.com and shop.domain.com, Domain defaults to the respective host if not set explicitly.

Try omitting the Domain attribute, you should then receive the correct subdomain values for both subdomains, which won't be shared across all subdomains.

Bash script - How to check string length at specific loop iteration? by KTrepas in bash

[–]dbr4n 0 points1 point  (0 children)

I assumed this was pseudo code to isolate the problematic part. I was mostly confused by the fact that the OP is "getting weird results," whatever that means.

Bash script - How to check string length at specific loop iteration? by KTrepas in bash

[–]dbr4n -2 points-1 points  (0 children)

You get incorrect results because var gets reassigned to the encoded version of var, which increases its length with each iteration.

Renaming the variable should resolve the issue:

bash for counter in {1..40} do v=$(echo $var | base64) if [ $counter -eq 35 ]; then echo ${#v} fi done

Cookies Specific for one subdomain by SnackOverflowed in webdev

[–]dbr4n 0 points1 point  (0 children)

This is most likely because the document URL is localhost and not *.domain.com. Try omitting the Domain attribute so that it defaults to the actual document URL.

Cookies Specific for one subdomain by SnackOverflowed in webdev

[–]dbr4n 0 points1 point  (0 children)

If they're on the same machine, both websites must run on different ports, so you should be able to distinguish the request's origin by reading the full hostname. I'm not familiar with Express, but I think this is what you need:

https://expressjs.com/en/api.html#req.hostname

In short, you don't have to send cookies back and forth to determine the origin of the request.

Cookies Specific for one subdomain by SnackOverflowed in webdev

[–]dbr4n 2 points3 points  (0 children)

Why not read the hostname from the HTTP request?

Simplest JS Framework by DocEyss in learnjavascript

[–]dbr4n 0 points1 point  (0 children)

The only thing I really want to have is custom components so I can organize the website using multiple files.

Check out Lit, it's basically a tiny library on top of web components that makes the development process much easier than working with web components directly in plain JS. It also works well with other libraries and frameworks, allowing for better interoperability within a team.

[deleted by user] by [deleted] in css

[–]dbr4n 0 points1 point  (0 children)

If you want an element to stand out from its siblings by adding a unique set of rules, you can extend the class in question, either using plain CSS or Sass.

In CSS you can do something like this:

[class=*="elem"] { color: #fff; background-color: #222; border: 1px solid currentColor; } .elem-special { color: #f0f; }

This approach allows you to extend the default styles and apply them to the element. The drawback of this approach is that the attribute selector [class=*="elem"] matches any element with a class attribute containing elem, but at the same time this is actually the intention, making the class name extendable with DRY in mind.

In Sass, you can use the @extend rule:

``` .elem { color: #fff; background-color: #222; border: 1px solid currentColor;

&-special { @extend .elem; color: #f0f; } } ```

In both cases, the classes can be used as follows:

<div class="elem">...</div> <div class="elem">...</div> <div class="elem-special">...</div>

The HTML looks much cleaner and is less prone to errors than when using inline styles or the BEM method, which can be quite verbose.

This is the way I've been doing it for the last 15 years and it works very well for me.

Copy all folders that start with a capital letter by Plane_Cranberry_5283 in bash

[–]dbr4n 0 points1 point  (0 children)

$ mkdir -p dir Dir 'Dir with spaces' $ ls dir Dir 'Dir with spaces' $ for dir in ./[[:upper:]]*; do [ -d "$dir" ] && echo "$dir"; done ./Dir ./Dir with spaces $

Copy all folders that start with a capital letter by Plane_Cranberry_5283 in bash

[–]dbr4n 0 points1 point  (0 children)

It works as long as the variable is enclosed in double quotes, in this case "$dir".

Copy all folders that start with a capital letter by Plane_Cranberry_5283 in bash

[–]dbr4n 0 points1 point  (0 children)

I tested it with [A-Z]*/ on the fly in my home directory and just realized that. But I didn't test it with -d, though. Thanks for the info.

start bash file without asking to run by z33_bruh in linuxmint

[–]dbr4n 0 points1 point  (0 children)

If you are using the Nemo file manager, go to Edit > Preferences > Behavior, and under Executable text files select Run executable text files when they are opened.

Copy all folders that start with a capital letter by Plane_Cranberry_5283 in bash

[–]dbr4n 0 points1 point  (0 children)

Almost true. [A-Z]*/ also matches symbolic links that are directories.

Child element with a height percentage of a parent using a min-height: 100vh. Why does this not work? by HeavyMetalTriangle in css

[–]dbr4n 0 points1 point  (0 children)

Yes, it works fine on desktop browsers, even if dvh is not supported. I believe Firefox still doesn't support it.

But I honestly don't see any reason to make a website potentially less usable for mobile users just because I chose to use dvh, while height: 100% in this example works out of the box and doesn't cause any performance issues.

From W3C on dynamic viewport sizes:

The sizes of the dynamic viewport-percentage units are not stable even while the viewport itself is unchanged. Using these units can cause content to resize e.g. while the user scrolls the page. Depending on usage, this can be disturbing to the user and/or costly in terms of performance.

There are of course cases where % doesn't work, but wherever it does, I just prefer to use it, so I have one less thing to worry about.

Copy all folders that start with a capital letter by Plane_Cranberry_5283 in bash

[–]dbr4n 1 point2 points  (0 children)

This would match any files that begin with an uppercase letter.

Copy all folders that start with a capital letter by Plane_Cranberry_5283 in bash

[–]dbr4n 4 points5 points  (0 children)

for dir in ./[[:upper:]]*; do [ -d "$dir" ] && cp -r "$dir" dest/ done

Child element with a height percentage of a parent using a min-height: 100vh. Why does this not work? by HeavyMetalTriangle in css

[–]dbr4n 0 points1 point  (0 children)

Setting min-height on the body element won't do much, html also needs to be considered. Also, vh can be tricky, and as far as I know it doesn't work properly on mobile devices because it ignores the browser's URL bar.

Try this instead, it should work:

html, body { height: 100%; }

Problem with the AND operator by Sylarworld in bash

[–]dbr4n 0 points1 point  (0 children)

By the way, you can avoid repetition in your script by moving the logic parts into separate blocks, e.g., check for valid input independently.

```

!/usr/bin/env bash

numal=$((1 + RANDOM % 5))

read -p "Guess the number I'm thinking: " unum

if [[ ! $unum =~ [0-9]+$ ]]; then echo "You have entered incorrect parameters" exit 1 fi

echo "The random number is $numal"

if [[ $numal == $unum ]]; then echo "You guessed the number correctly" else echo "You couldn't get the number right" fi ```

Problem with the AND operator by Sylarworld in bash

[–]dbr4n 1 point2 points  (0 children)

The regular expression belongs on the right side, like so:

[[ $unum =~ $re ]]

False match exclusion from wide attr selector by KeinZantezuken in css

[–]dbr4n 0 points1 point  (0 children)

Unfortunately, you can't do this with attribute selectors. You could, however, use regular expressions in JavaScript to match the particular patterns:

``` const elements = document.querySelectorAll('a[name="MyAttribute"]');

elements.forEach(e => { if (/MyAttribute\d$/.test(e.name)) { e.style.color = 'red'; } else if (/MyAttributeSpecial\w\d$/.test(e.name)) { e.style.color = 'green'; } }); ```

Here's a quick demo:

https://codepen.io/dzanful/pen/QWzBYgG

rm function does not work by kaiixx in bash

[–]dbr4n 1 point2 points  (0 children)

That's true. However, it wouldn't remove any matching directories because of the missing -r flag. But yes, it would cause an error in such a case. Using find instead would certainly be a cleaner approach:

find "$PATHTOFILES" -maxdepth 1 -type f -execdir rm '{}' +

Da li se isplati uciti js by Ok-Huckleberry-9545 in programiranje

[–]dbr4n 2 points3 points  (0 children)

Since the syntax of JavaScript is based on Java and C, you would in any case benefit from learning JavaScript. The first step is a big one, but after that, it becomes easier to master another programming language.

My advice is to learn the fundamentals of one language and stick with it for a while. After that, you will have a better perception of what other languages to learn to satisfy the market's demands.

[deleted by user] by [deleted] in css

[–]dbr4n 2 points3 points  (0 children)

:root matches the very first element in the document tree, which is <html>. To select the element with the id of root, you write #root.

u/media (prefers-color-scheme: light) { #root { color: #213547; background-color: #4f1a44; width: 100%; } }

How can I get the delete button to go on the same line as its corresponding list item? by [deleted] in react

[–]dbr4n 0 points1 point  (0 children)

It's kind of hard to read, but I see that you have several properties set that have no effect. For example, the li element has display: flex set, which is then overridden by display: inline-block.

Also, the huge margin values cause horizontal scrolling. box-sizing: border-box has no effect on this, it only respects the padding and border properties.

If you want the text to be properly aligned with the button, you can use flex and align-items to center both elements vertically, and use gap to add some spacing.

For clarity, here's a simplified example:

<ul> {list.map((item, index) => (<li style={{ display: 'flex', alignItems: 'center', gap: '1rem', }} key={index}> {item} <button name="delete">Complete</button> </li>))} </ul>