2 Followers
0 Following
1 Posts

From a purely political perspective, if you oppose the US tariffs as a US resident, should you buy or avoid buying products subject to tariffs?

https://lemmy.world/post/27923448

From a purely political perspective, if you oppose the US tariffs as a US resident, should you buy or avoid buying products subject to tariffs? - Lemmy.World

Just curious about how this works out. At scale, would either decision make any sort of impact? I know most people, including me, will end up avoiding heavily tariffed products out of personal financial reasons. But in theory, would US residents buying or not buying tariffed products be the larger anti-tariff statement? I feel like the obvious answer is โ€œonly buy tariffed productsโ€ which is why I chose this community but Iโ€™m not entirely certain.

Why is pynput typing incorrect output, but only on Linux?

https://lemmy.world/post/27601602

Why is pynput typing incorrect output, but only on Linux? - Lemmy.World

cross-posted from: https://lemmy.world/post/27601594 [https://lemmy.world/post/27601594] > cross-posted from: https://lemmy.world/post/27385536 [https://lemmy.world/post/27385536] > > > I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect. > > > > I recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way thatโ€™s both consistent and inconsistent. > > > > The simplest possible case I found that reproduces the error is this script: > > > > python > > import time > > from pynput import keyboard > > > > # Sleep statement is just to give time to move the mouse cursor to a text input field > > time.sleep(2) > > > > my_kb = keyboard.Controller() > > > > text = '๐Ÿ†' # Eggplant emoji > > my_kb.type(text) > > > > time.sleep(1) > > > > text = '๐•ฅ๐•–๐•ค๐•ฅ' # blackboard bold test > > my_kb.type(text) > > > > time.sleep(1) > > > > text = '๐ญ๐ž๐ฌ๐ญ' # bold test > > my_kb.type(text) > > > > > > When I run that script right now, it produces the output โ€œ๐Ÿ†๐•ฅ๐•ฅ๐•ค๐•ฅ๐ญ๐ญ๐ฌ๐ญโ€. And if I run it again, itโ€™ll produce the same output. And if I change the eggplant emoji to something else, like the regular character โ€˜Aโ€™, it will still produce the same output (specifically โ€œA๐•ฅ๐•ฅ๐•ค๐•ฅ๐ญ๐ญ๐ฌ๐ญโ€). Butโ€ฆ If I log out and log back in, then the output changes to something else thatโ€™s still wrong, but differently. For example, when I changed the eggplant to a regular โ€˜Aโ€™, then relogged, the output became โ€œA๐•ฅ๐•–๐•–๐•ฅ๐ญ๐ž๐ž๐ญโ€. And then that wrong output will keep being the same wrong output until I log out and back in again. If the test strings donโ€™t change, then the incorrect outputs donโ€™t change on relog - but if they do, then they do. > > > > In the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get โ€œ๐Ÿ†๐•–๐•ค๐Ÿ†โ€. This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions. > > > > I am very new to Linux. Iโ€™m on Linux Mint. Iโ€™m running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code. On Linux there seems to be no issues with typing regular text, just special characters.

Why is pynput typing incorrect output, but only on Linux?

https://lemmy.world/post/27601594

Why is pynput typing incorrect output, but only on Linux? - Lemmy.World

cross-posted from: https://lemmy.world/post/27385536 [https://lemmy.world/post/27385536] > I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect. > > I recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way thatโ€™s both consistent and inconsistent. > > The simplest possible case I found that reproduces the error is this script: > > python > import time > from pynput import keyboard > > # Sleep statement is just to give time to move the mouse cursor to a text input field > time.sleep(2) > > my_kb = keyboard.Controller() > > text = '๐Ÿ†' # Eggplant emoji > my_kb.type(text) > > time.sleep(1) > > text = '๐•ฅ๐•–๐•ค๐•ฅ' # blackboard bold test > my_kb.type(text) > > time.sleep(1) > > text = '๐ญ๐ž๐ฌ๐ญ' # bold test > my_kb.type(text) > > > When I run that script right now, it produces the output โ€œ๐Ÿ†๐•ฅ๐•ฅ๐•ค๐•ฅ๐ญ๐ญ๐ฌ๐ญโ€. And if I run it again, itโ€™ll produce the same output. And if I change the eggplant emoji to something else, like the regular character โ€˜Aโ€™, it will still produce the same output (specifically โ€œA๐•ฅ๐•ฅ๐•ค๐•ฅ๐ญ๐ญ๐ฌ๐ญโ€). Butโ€ฆ If I log out and log back in, then the output changes to something else thatโ€™s still wrong, but differently. For example, when I changed the eggplant to a regular โ€˜Aโ€™, then relogged, the output became โ€œA๐•ฅ๐•–๐•–๐•ฅ๐ญ๐ž๐ž๐ญโ€. And then that wrong output will keep being the same wrong output until I log out and back in again. If the test strings donโ€™t change, then the incorrect outputs donโ€™t change on relog - but if they do, then they do. > > In the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get โ€œ๐Ÿ†๐•–๐•ค๐Ÿ†โ€. This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions. > > I am very new to Linux. Iโ€™m on Linux Mint. Iโ€™m running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code. On Linux there seems to be no issues with typing regular text, just special characters.

Why is pynput typing incorrect output, but only on Linux?

https://lemmy.world/post/27385536

Why is pynput typing incorrect output, but only on Linux? - Lemmy.World

I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect. I recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way thatโ€™s both consistent and inconsistent. The simplest possible case I found that reproduces the error is this script: python import time from pynput import keyboard # Sleep statement is just to give time to move the mouse cursor to a text input field time.sleep(2) my_kb = keyboard.Controller() text = '๐Ÿ†' # Eggplant emoji my_kb.type(text) time.sleep(1) text = '๐•ฅ๐•–๐•ค๐•ฅ' # blackboard bold test my_kb.type(text) time.sleep(1) text = '๐ญ๐ž๐ฌ๐ญ' # bold test my_kb.type(text) When I run that script right now, it produces the output โ€œ๐Ÿ†๐•ฅ๐•ฅ๐•ค๐•ฅ๐ญ๐ญ๐ฌ๐ญโ€. And if I run it again, itโ€™ll produce the same output. And if I change the eggplant emoji to something else, it still will produce the same output. Butโ€ฆ If I log out and log back in, then the output changes to something else thatโ€™s still wrong, but differently. For example, when I changed the eggplant to a regular โ€˜Aโ€™, then relogged, the output became โ€œA๐•ฅ๐•–๐•–๐•ฅ๐ญ๐ž๐ž๐ญโ€. And then that wrong output will keep being the same wrong output until I log out and back in again. In the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get โ€œ๐Ÿ†๐•–๐•ค๐Ÿ†โ€. This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions. I am very new to Linux. Iโ€™m on Linux Mint. Iโ€™m running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code.

What happens when I ignore the cookie preference dialogue on websites?

https://lemmy.world/post/26071915

What happens when I ignore the cookie preference dialogue on websites? - Lemmy.World

Does the GDPR define what the default behavior should be when the user refuses to specify? Does it vary by site? Is it like clicking either โ€œAccept allโ€ or โ€œReject allโ€?

YSK you can use uBlock Origin to block Lemmy posts containing certain words

https://lemmy.world/post/24545370

YSK you can use uBlock Origin to block Lemmy posts containing certain words - Lemmy.World

Why YSK: Certain topics are stressful and tend to spread all over the site, including to unrelated communities. Blocking communities can be overkill and ineffective, and likewise for blocking individual users. To do so, open up the uBlock Origin dashboard, go to the โ€˜My filtersโ€™ tab, and add this filter: lemmy.world##article.row:has-text(/word1|word2|word3|word4/i) For example: lemmy.world##article.row:has-text(/Trump|Elon|Musk|nazi/i) Then apply the changes and reload any open tabs, and all posts which contain any of your filtered words will simply not show up. Youโ€™ll have to change โ€œlemmy.worldโ€ at the start to whatever your actual instance is. You can filter as many or as few words as you want, just keep the / at the start, the /i at the end, and separate words with | pipes. Whatโ€™s actually being filtered is a case-insensitive regex, if you want to get fancy with it. Here are equivalent filters for reddit and Ars Technica: reddit.com##div.thing[data-context="listing"]:has-text(/word1|word2|word3|word4/i) arstechnica.com##:not(:not(head>title:has-text(/^Ars Technica/))) article:has-text(/word1|word2|word3|word4/i) As a disclaimer, I made these myself, and Iโ€™m not particularly familiar with creating uBlock Origin filters. There may be better ways to do this. Also the reddit one is specific to old.reddit.com [http://old.reddit.com], and the lemmy filter is made to work with the default lemmy.world web UI and may not work on other UIs without tinkering. Yes, I know Iโ€™m just hiding my head in the sand.

Coin-flipping game - Lemmy.World

Weโ€™re playing a game. I flip a coin. If it lands on Tails, I flip it again. If it lands on Heads, the game ends. You win if the game ends on an even turn, and lose otherwise. Define the following events: A: You win the game B: The game goes on for at least 4 turns C: The game goes on for at least 5 turns What are P(A), P(B), and Pยฉ? Are A and B independent? How about A and C?

SolutionFor both of these, itโ€™s sufficient to consider only sin(x)^sin(x). It stands to reason that the maximums will happen when sin(x)^sin(x) is at its maximum value, and its minimums will happen when sin(x)^sin(x) is at its minimum value. The x^ part really just makes the function prettier to look at. The function lacks any continuity when sin(x) is negative, so we can consider just the regions where sin(x) is positive. For the maximums, this is very easy: The largest sin(x) can be is 1, and so the largest value for sin(x)^sin(x) is also 1. So the monotonically increasing function which passes through each local maximum is y = x^1, or just y = x. For the minimums itโ€™s a bit trickier: The smallest sin(x) can be is 0, and while 0^0 is indeterminate, it happens to approach 1 in this case - our minimum is somewhere else (side note: sin(x)^sin(x) approaching 1 for these values is why our max function also exactly bounds the flailing arms of the function). So we turn to derivatives. We can do this using either sin(x)^sin(x) or x^x - I chose to use sin(x)^sin(x) here and x^x (sort of) in the extra credit. Using sin(x)^sin(x) here has the added benefit of also showing the maximums are when sin(x) = 1. y = sin(x)^sin(x) y = e^(ln(sin(x)) * sin(x)) yโ€™ = sin(x)^sin(x) * (cos(x)/sin(x) * sin(x) + ln(sin(x)) * cos(x)) โ†’ Chain rule, product rule, and chain rule again yโ€™ = sin(x)^sin(x) * (cos(x) + ln(sin(x)) * cos(x)) โ†’ Simplify yโ€™ = sin(x)^sin(x) * cos(x) * (1 + ln(sin(x))) โ†’ Factor We can set each of these factors to 0. sin(x)^sin(x) will never be 0. cos(x) will be 0 when x = ฯ€/2 + 2ฯ€n (2ฯ€n instead of ฯ€n because weโ€™re skipping over the solutions where sin(x) is negative). These are the maximums, because when x = ฯ€/2 + 2ฯ€n we have sin(x) = 1. 1 + ln(sin(x)) = 0 ln(sin(x)) = -1 sin(x) = e^-1 = 1/e And thatโ€™s actually sufficient for our purposes - we could of course say x = arcsin(1/e), but our goal is to calcualte the value of sin(x)^sin(x). Since sin(x) = 1/e, we have sin(x)^sin(x) = (1/e)^(1/e). So our monotonically increasing function which hits all the minimums is y = x^((1/e)^(1/e)), or: y = (e-th root of e)-th root of x. Graphed solution visible here. For the extra credit, we can do the same basic idea: Find the maximum of |sin(x)|^sin(x). Since we know weโ€™re in a region where sin(x) is negative, we can model this as x^-x, and the solution will be valid as long as x is something between 0 and 1, within sin(x)โ€˜s positive range. y = x^-x = e^(ln(x) * -x) yโ€™ = x^-x * (-1 - ln(x)) x^-x wonโ€™t ever be 0, and -1 - ln(x) will be 0 when ln(x) = -1, or x = 1/e again, same as before. So our maximum value happens at (1/e)^(-1/e), which simplifies to e^(1/e). In other words, our new maximum function is x^(e^(1/e)), or x to the power of the e-th root of e. Graph of all three solution functions And, finally - I mentioned that we should also be able to expand the function to its less-defined regions using y = x^-|sin(x)|^sin(x). I donโ€™t care enough to post the full work here, but the reciprocal of the three answer solutions above are what works here: y = 1/x, y = 1/x^((1/e)^(1/e)), and y = 1/x^(e^(1/e)). Graph. Note that the upper function here only applies in regions where the original function is already defined, and so the other parts of this extension are invalid - you can toggle the main function at the top off to see only the parts that truly apply. Nothing particularly interesting happens if you extend things to values of x less than 0 - the graphs (more or less) just reflect across the y-axis. Bonus graph with everything + phase shifts and pretty colors
Desmos | Graphing Calculator

Desmos
Background / incredibly minor spoilers:Unlike the other problems Iโ€™ve posted, this is the only one (so far) that I came up with on my own - back in high school while playing around with my calculator I entered this function at some point, and got curious about the minimums. I was in pre-calculus at the time, so it took me a while - but I did eventually work out the solution. Needless to say I was pretty happy the answer was something as cool as it was. I actually didnโ€™t ever work out (or try to work out) the extra credit portion until I wrote up the problem for this post, so it was a nice revisit of a very old problem. The language asking for an โ€œincreasingโ€ function is mostly to avoid smartasses who might submit the original equation as a technically correct solution. Basically I want the simplest possible function that passes through the described points.
Bounding a function - Lemmy.World

Consider the function defined by y = x^(sin(x)^sin(x)). Observe [https://www.desmos.com/calculator/mczhlgyfau] its graph. Find an increasing function which passes through each of its local maximums, and another increasing function which passes through each of its local minimums. Extra credit: Youโ€™ll notice the graph isnโ€™t drawn for x-values which make sin(x) negative. This is because most of those values make the function undefined - though it is defined for infinitely many points in those intervals, it just also has infinitely many holes. Since it lacks continuity here, it has no true local maxes or local mins, and doesnโ€™t impact the original problem. We can nonetheless cheat and fill in the holes by expanding the function to these regions with y = x^|sin(x)|^sin(x) [https://www.desmos.com/calculator/kvmyhygpfp] (Using x^-|sin(x)|^sin(x) should also be technically valid, but is being ignored because itโ€™s discontinuous with the rest of the graph and not as pretty, but will be mentioned in my solution). Doing so adds more local maxes and local mins. The new local mins should line up with your function that finds the local maxes for the original function - but, find a new function which hits all of the new local maxes.