Help Bites
-
@dkf I don't use the command line atm (I use an online editor). the computer with python and VScode is currently occupied by my dad. Otherwise you taught me a lot of stuff .
Can you list out other basic options?
-
@Gomesz785 said in Help Bites:
Can you list out other basic options?
- Installed scripts
- The
python -m
option to run a module
But seriously, master the basics first. Everything written about the other ones assumes you already know the basics.
-
@dkf said in Help Bites:
- Installed scripts
- The python -m option to run a module
I have no idea what you have just said. Is there a way to do the "invoking" without going to the cmd line?
Can I replace the sys.argv instances with a variable or something like that?
Yes, I will try out the basics, after, My father give me the laptop, we're kids, bear with it please. I am not trying to get the code and run away.
-
@Gomesz785 the questions you're asking aren't about Python itself but rather about whatever you're using to run Python. You should consult the manual of whatever you're using to run Python. If you posted a link, someone might even help you find the manual.
-
@dkf I found the command line in my web-based editor, whatever, regardless of that the solutions are limited to the cmd ine, your reply was helpful, even after finding the cmd line!
-
@Gąska I found the cmd line of my editor, thanks for the comment!
-
So. Advice on a data modeling issue (to be implemented in Typescript and persisted to an SQL datastore by hand, no ORM).
I want to represent a piece of data that's effectively an ordered mapping of entity ids (primitive type
T
) to durations (primitive numeric typenumber
).A straight map would be trivial, just use the
Map<T, number>
type. But that doesn't preserve order. Although MDN suggests thatmap
s are iterated in insertion order. But then I'd have to make sure that's preserved on persistence...I could use a list of tuples
[T, number][]
. But something about that doesn't smell right. Could be my own inability to think.In this case, I need to ensure that
- No id appears more than once
- The primary validation for the objects that will hold this mapping is that
sum(duration) == <external fixed total>
as it's effectively sub-dividing a time period into a bunch of units that need to be grouped together and presented in a fixed but user-specified order (that's what the entities represent).
Any thoughts on a good way to represent that? Preferably as simple as possible?
-
@Benjamin-Hall will the entries (almost) always be processed sequentially, or do you need fast random lookup? For the first case, forget a map and put tuples in a list (you can use
find_if
or whatever it's called in JS for occassional lookup). For the second, there's no clean solution really; I'd go with a regular ID->duration unordered map plus a separate list of Ts for ordering.
-
@Gąska said in Help Bites:
@Benjamin-Hall will the entries (almost) always be processed sequentially, or do you need fast random lookup? For the first case, forget a map and put tuples in a list (you can use
find_if
or whatever it's called in JS for occassional lookup). For the second, there's no clean solution really; I'd go with a regular ID->duration unordered map plus a separate list of Ts for ordering.For one thing, I don't think there will be many entries in each set. Where "many" is "certainly less than 25 and probably dominated by 2 or 3". So speed of processing isn't my big concern, but mainly just ease of interface.
As far as sequential vs random...probably sequential. This is part of a future design where you can "split" a position on a shift (think "I'm driving the fire truck") between two or more people. So one person is on-shift for 4 hours of the 12 hour shift and someone else needs to cover teh other 8. Or maybe a 3-way shift. Unlikely to be more than that. So the ids are to the actual positions that can be filled, unfilled, requested, etc. And the duration is "how long is this the actual position, starting from the end of the previous one." So probably sequential.
And I'm probably explaining things horribly.
-
@Benjamin-Hall said in Help Bites:
@Gąska said in Help Bites:
@Benjamin-Hall will the entries (almost) always be processed sequentially, or do you need fast random lookup? For the first case, forget a map and put tuples in a list (you can use
find_if
or whatever it's called in JS for occassional lookup). For the second, there's no clean solution really; I'd go with a regular ID->duration unordered map plus a separate list of Ts for ordering.For one thing, I don't think there will be many entries in each set. Where "many" is "certainly less than 25 and probably dominated by 2 or 3". So speed of processing isn't my big concern, but mainly just ease of interface.
Then either approach will work. Go with the list of tuples until you'll find it annoying, then switch to map-and-list. If you plan to reuse it, wrap it in a class or something.
As far as sequential vs random...
because it's just 25 elements.
-
@Benjamin-Hall It sounds like you should start from the SQL model first, where you've got a relation that associates an ID (foreign key to some other table) with some number of ranges such that the sum of the ranges for an ID is equal to some other value. Which is to say that you end up associating an entity with a list of durations (that might have other properties as well) but expressed in basic relational algebra.
That then becomes a mapping
Map<Thing,DurationThing[]>
, at least logically. (Updates will have to modify several DB rows per transaction otherwise the constraints won't hold.) TheThing
might be yourT
and theDurationThing
might be anumber
but I'm not assuming that they must be so. (I found maps to be a pain in JS/TS as they didn't make things equal in the keys that I expected, but YMMV.)
-
Electronics help
I bought a used label maker, and it turns out that it doesn't work. From what I can tell the power supply is f'd, so I thought I might use my amateur electronics skills to try to revive it. Seems like a simple enough thing:
Problem is, with my limited knowledge I can't tell why it's not working. There's nothing obvious like burn marks, and using some meter poking I've found that the resistor and capacitor are fine, and the diodes test ok when desoldered from the circuit. That leaves the blue dude at the bottom that looks kind of like a resistor but not.
I've looked up the board number, and the only information I can find is that it is indeed a power supply board for a Brother label maker, but no schematic or anything. Can anyone give me any insight? Should I just give up and chuck the whole thing, or try to find somewhere to order the part?
-
@hungrier said in Help Bites:
That leaves the blue dude at the bottom that looks kind of like a resistor but not.
It’s a fuse, pretty clear contender for a carked component.
Probably don’t need to explain this, but check that it actually passes current.
addendum: I should probably clarify that’s specifically a fusible resistor and not your “classic” wire in a glass case, should you be looking to replace it. Regardless, measured resistance and voltage drop should be minimal.
-
@kazitor I'll take a look later (all the stuff is put away, I took the picture earlier). I haven't seen fuses in that form factor before but it makes perfect sense. Thanks!
-
@hungrier: if you can, please post a photo of the other side as well. This will make it possible to trace the circuit.
-
Correct use of
yon
vsyonder
- isyon
always acceptable? When isyonder
specifically preferable?
-
@Gribnit said in Help Bites:
Correct use of
yon
vsyonder
- isyon
always acceptable? When isyonder
specifically preferable?Why do you hate helping? These are my actual problems.
-
@Gribnit Similar to
this
versusthat
, I suspect.
-
-
@PleegWat
var that = this
-
@Gąska said in Help Bites:
@PleegWat
var that = this
I've actually found
var self = this;
in our codebase. To get around JavaScript not binding to this properly in callbacks.
-
@Gribnit said in Help Bites:
Correct use of
yon
vsyonder
- isyon
always acceptable? When isyonder
specifically preferable?According to this, they're interchangeable as adverbs, but "yon" can also be an adjective or a pronoun, while "yonder" can also be a determiner or a noun.
-
@PleegWat said in Help Bites:
@Gribnit Similar to
this
versusthat
, I suspect.No, "yon" and "yonder" both mean "that/those" or "there," as evidenced by the phrases "hither and yon" and "over yonder", or the Shakespearean "What light through yonder window breaks?"
-
@dcon said in Help Bites:
what's MySQL have to do with it?
Have to do with it have to do with it
What's Aurora but a secondhand MySQL
-
@djls45 said in Help Bites:
@PleegWat said in Help Bites:
@Gribnit Similar to
this
versusthat
, I suspect.No, "yon" and "yonder" both mean "that/those" or "there," as evidenced by the phrases "hither and yon" and "over yonder", or the Shakespearean "What light through yonder window breaks?"
I'm asking because I'm trying to investigate a vague sense that
yonder
is used for bigger, further things. This may be a modern retcon of usage?
-
@Gribnit said in Help Bites:
@dcon said in Help Bites:
what's MySQL have to do with it?
Have to do with it have to do with it
What's Aurora but a secondhand MySQLI had a similar thought to yours, and I don't know what to do with this information.
-
@djls45 said in Help Bites:
@Gribnit said in Help Bites:
Correct use of
yon
vsyonder
- isyon
always acceptable? When isyonder
specifically preferable?According to this, they're interchangeable as adverbs, but "yon" can also be an adjective or a pronoun, while "yonder" can also be a determiner or a noun.
Do not encourage him.
-
@Zecc said in Help Bites:
@Gribnit said in Help Bites:
@dcon said in Help Bites:
what's MySQL have to do with it?
Have to do with it have to do with it
What's Aurora but a secondhand MySQLI had a similar thought to yours, and I don't know what to do with this information.
I can recommend the "Extremely Specific Help" thread.
-
@Gribnit said in Help Bites:
@djls45 said in Help Bites:
@PleegWat said in Help Bites:
@Gribnit Similar to
this
versusthat
, I suspect.No, "yon" and "yonder" both mean "that/those" or "there," as evidenced by the phrases "hither and yon" and "over yonder", or the Shakespearean "What light through yonder window breaks?"
I'm asking because I'm trying to investigate a vague sense that
yonder
is used for bigger, further things. This may be a modern retcon of usage?I would guess probably so, if that's the meaning garnered from your experiences. My own experiences, however, have not formed such a sense for me.
-
@topspin said in Help Bites:
@djls45 said in Help Bites:
@Gribnit said in Help Bites:
Correct use of
yon
vsyonder
- isyon
always acceptable? When isyonder
specifically preferable?According to this, they're interchangeable as adverbs, but "yon" can also be an adjective or a pronoun, while "yonder" can also be a determiner or a noun.
Do not encourage him.
Why not? That was a perfectly sensible and interesting question.
-
@djls45 said in Help Bites:
@topspin said in Help Bites:
@djls45 said in Help Bites:
@Gribnit said in Help Bites:
Correct use of
yon
vsyonder
- isyon
always acceptable? When isyonder
specifically preferable?According to this, they're interchangeable as adverbs, but "yon" can also be an adjective or a pronoun, while "yonder" can also be a determiner or a noun.
Do not encourage him.
Why not? That was a perfectly sensible and interesting question.
It wasn't. You presented natural immunity to the specific embedded hazard... there's always at least one.
-
@Gribnit said in Help Bites:
Correct use of
yon
vsyonder
- isyon
always acceptable? When isyonder
specifically preferable?Temporary Duty Yon? No way.
-
@boomzilla thanks! I assume Yon Temporary Duty is still cromulent?
-
Does anybody around here use Salt Stack for devops?
I have been using it for like 10 years now, but I took a while off and now I'm really confused by some issues.
For the purposes of this question, I have a
base
and adevel
environment.I am basically trying to make a "generic" user state, backed by a "pillar" data store. The minimal issue-causing state looks like:
{% for user in pillar('env.users', {}) %} {{ user.username}}: user.present: [] {% endfor %}
Now, if I try to apply this state to a machine in my
devel
environment, I get what currently seems like an unavoidable error:Detected conflicting IDs, SLS IDs need to be globally unique. The conflicting ID is 'foo' and is found in SLS 'base:users.default' and SLS 'devel:users.default'
So it seems like salt-stack sees my
foo
state inbase
, and then sees another one indevel
and then cries about it.I must be missing something. How do people use pillars in multi-environment scenarios?
-
Is there a way to disable access to the internet for a process/user/system in a container from within that container?
In this case, I'm restricted to running stuff inside a container (as root in the container, but not outside; I don't have any access to the outside system). I want to disable internet access for a certain process/user. In theory, I'm OK with disabling internet access for the whole container temporarily (e.g., for the duration of a few tests), though doing so for a user or process/process-tree would be preferred.
I initially tried setting up some rules with iptables, but the container has insufficient permissions to do so. Similarly, trying to disable the interface (ip link <dev> down) isn't permitted either. (In hindsight, neither of those are too surprising).
I stumbled across
unshare
, which allows you to temporarily drop namespaces, including whatever namespace is used for networking (e.g.unshare -n <command>
prevents <command> from doing network stuff). However, that isn't permitted in the container either.Any other ideas?
-
@cvi I messed around with this a bit more, and finally bit the bullet with seccomp (which I'd been avoiding for a bit).
Seccomp can whitelist/blacklist specific syscalls (optionally, with specific arguments). It's not ideal, but blacklisting
socket
with the right address families seems to stop most network access in its tracks (without messing up too many other things). I based my code on this example, which is where I specifically saw the idea with socket+filtering address families.Seccomp is permitted from userspace, works in the container, and settings are inherited by child processes. So, yay.
-
@cvi said in Help Bites:
Seccomp is permitted from userspace, works in the container, and settings are inherited by child processes. So, yay.
Dunno, isn't this excessively appropriate?
-
@Gribnit Looks like it, doesn't it?
I never used seccomp before for anything; I was just aware that it existed (or rather, I was aware you could do whatever seccomp does, but I didn't even know it was called 'seccomp'). Neither did I know that you could use as a normal user/inside a container or that filters set up with it would be inherited by child processes.
I had been avoiding it because it looked messy (it uses BPF to define the filters..). Bit the bullet yesterday - turns out my simple use case wasn't too bad, and that it did work as a normal user etc.
(It also answers a different question that I've had - namely if you can prevent a process from execv/fork. Appears you can, but there's a bit of added trickery with execve. If you load the seccomp context before you execve, you can't execve anymore. Seems you'd have to inject the seccomp context into the new program somehow after loading it.)
-
I hate malls. Usually I have a pretty good sense of direction but in these mazes of twisty little passages I always get lost. Luckily, there are those helpful screens where you can get the shortest route to a shop:
So according to this thing, the shop is somewhere beyond the elevators, through the wall, about 5m outside the building, on the 4th floorZoom, enhance!
Look how nice! It shares the venue with a dozen or so other places.
-
@LaoC said in Help Bites:
It shares the venue with a dozen or so other places.
Sounds like a local Taylor farm.
-
I'm playing around with my TV and want to
pkill
the processcom.webos.app.home
.
However, while I found a solution, I don't understand why I need to do this:root@LGwebOSTV:~# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND <snip> root 1846 0.0 0.5 200556 9968 ? S<Lsl 16:59 0:03 /usr/bin/com.webos.app.inputcommon {"event":"launch","reason":"undefined","appId":"com.webos.app.inputcommon","interfaceVersion":2,"parameters":{"snapshot":true},"interfaceMethod":"registerApp","@system_native_app":true} root 1848 0.0 2.9 245304 56336 ? SLl 16:59 0:14 /usr/bin/com.webos.app.inputcommon {"event":"launch","reason":"undefined","appId":"com.webos.app.inputcommon","interfaceVersion":2,"parameters":{"snapshot":true},"interfaceMethod":"registerApp","@system_native_app":true} root 1851 0.6 7.2 425780 137280 ? SLsl 16:59 2:11 /usr/bin/com.webos.app.home {"parameters":{"snapshot":true},"interfaceMethod":"registerApp","appId":"com.webos.app.home","reason":"undefined","event":"launch","interfaceVersion":2,"@system_native_app":true,"preload":"full"} <snip> root 2282 0.0 0.8 124280 15304 ? SLl 16:59 0:01 /usr/sbin/homekit <snip> root@LGwebOSTV:~# pgrep home 2282 root@LGwebOSTV:~# pgrep "com.webos.app.home" root@LGwebOSTV:~# pgrep -f "com.webos.app.home" 1851 root@LGwebOSTV:~#
The man page for
pgrep
/pkill
says:-f Match against full argument lists. The default is to match against process names.
Just grepping for
home
finds this substring in the process/usr/sbin/homekit
, but not in the one I'm looking for. Specifying the full process name doesn't find anything. Only when doing-f
for full arguments does it find what I'm looking for, because the process's name also happens to appear in its own command line.
Why doesn't it find the process otherwise?
-
@topspin I'd guess the 'name' in this case is the process's common name. IIRC, by default that's the first 15 characters of the binary's base name, but processes can set a different common name. There are probably half a dozen ways to get
ps
to display it, and which ones work depends on which other flags you are using as is typical forps
.
-
@PleegWat that's it!
root@LGwebOSTV:/usr/bin# pgrep com.webos.app.h 1851 root@LGwebOSTV:/usr/bin# pgrep com.webos.app.ho root@LGwebOSTV:/usr/bin
That's ... pretty stupid.
Thanks!
-
-
I'm working on a Wordpress project.
The project has a search bar that's enclosed in a
<form>
with method=get and action=search page. This used to work, and still works in production, but has stopped working in the dev environment. Now, no matter what I put in the action attribute on the template that has that form, it always points tohttps://root.of.site.com/
. As far as I can tell, the only change is that dev has updated wordpress to 6.1.1, while prod is still running an older version.Assuming this is indeed because of the wordpress update, is there a way to get it to work again? I've tried searching for various combinations of
wordpress
form
action
but so far have come up empty.
-
@hungrier Is there possibly another form in the DOM hierarchy? Forms can't be nested.
-
@error Good idea, but that's not it; the form is inside a Matryoska doll of divs but no other form element. The structure hasn't changed since it last worked.
-
@hungrier This is basic HTML functionality, it shouldn't matter that it's a WordPress site.
You say the document structure hasn't changed, but :ron-burgundy-i-don't-believe-you:
-
@error The HTML and form functionality isn't the problem. What I'm seeing is that no matter what I put in the
action
attribute in the template, when it gets served in the browser it always reverts to the root of the site. If I manually change the action attribute using devtools, it works as it's supposed to.
-
@hungrier So it's actually changing the
action
in the markup?