« first day (4496 days earlier)      last day (435 days later) » 

7:23 AM
0
Q: how to remove non breaking space (nbsp) from json in python?

Rakesh{ value:"RHEUMATOID ARTHRITIS" } there is NBSP in between, how can we replace that with regular space?

I'm pretty sure the duplicate is incorrect
Question seems to be about Unicode nbsp character, not an HTML nbsp
 
Agreed
 
7:38 AM
How do I convince people that doing a specific thing isn't what fixed the problem?
 
In my experience, you either invest a handful of hours and 3 increasingly maximal MREs proving your point, or... you don't
 
maximal MRE?
 
increasingly maximal
or decreasingly minimal
 
ok, that's clearer
 
You: "Here's a piece of code proving my point"
OP: "This is so different from my code. It doesn't prove anything"
You: "Here's a piece of code proving my point that looks more like your code"
OP: "Still not similar enough"
 
7:51 AM
okay but in this case OP is convinced that adding __init__.py resolved an import issue where it is definitely irrelevant (and this is a common canard)
 
i dont know context, but im gonna go ahead and say the op will come around to it maybe 1 or 2 years later, if at all. and it will be like bashing your head against the wall trying to convince them otherwise.
 
8:21 AM
fair enough
 
8:38 AM
@KarlKnechtel sometimes they don't remember or don't take into account other things they did while doing that specific thing they mention fixed the problem
 
8:52 AM
wiggles rear view mirror
 
This is quite an interesting implementation detail between del and .pop()`
5
 
weird. that needs to be a special case for index 0 I'm sure
and then, I can't see a reason why it couldn't be applied equally to both... ?
ah, that's discussed
 
Yeah. I haven't had time to go through the github discussion that was linked, as apparently similar, but it does indeed seem to be a strange omission
Judging by the jump in views we might have just made this a HNQ :P
 
9:12 AM
the last time I looked at how list worked, I think I learned that insert appended the element passed to it if the index was bigger than the length of the list
I don't think this is in the docs, but I did see that on SO too
 
I do quite like stumbling over these things when you challenge basic wisdom and stumble over strange implementations. I discovered it was faster to copy numpy array slices rather than iterate a view on the array a while back... I was not expecting that one!
@NordineLotfi That one is easily testable
a = [1, 2, 3]
a.insert(0, 4)
print(a)
a.insert(10, 5)
print(a)
Also unexpected, actually. I guess it's similar to being able to slice to indices beyond the length of a list even when you can't index them directly
 
I don't like this behaviour
 
@roganjosh Ah, so this is where the new upvotes are from :-)
 
I'd expect the item to be added at the index or not at all
 
yeah, but how you would handle cases where the index is bigger than the length? would you just throw an error instead?
 
9:26 AM
yeah, probably
 
@KellyBundy I like that you went looking for the source :P It's a nice question
 
@matszwecja I guess this would make more sense, but a lot of algorithms (especially combinatorics and whatnot) depends on that behavior. I could even imagine some libraries using this "trick" so they don't need to use an if block to check if the index is bigger than the length, which would be slower than directly using the default behavior
even if it get changed later on, it would break tons of stuff probably
 
I just posted my theory on the del vs pop thing: stackoverflow.com/questions/75354384/…
 
@roganjosh The documentation does say that s.insert(i, x) is "same as s[i:i] = [x]".
 
@KellyBundy yes, but it doesn't explicitly explain it like you did in your answer
yours is more detailed
 
9:34 AM
@KellyBundy At what bytearray size does del become noticeably faster than pop(0)? I suspect the difference would be negligible for <200 bytes, maybe even <2k bytes. But that's just a guess based on experience timing various list & bytearray optimisations.
 
@roganjosh yeah, thinking of it that way does help :o I was surprised too since I actually did that a lot of times without ever noticing this was actually appending
 
@NordineLotfi In my two combinatorial domains I wouldn't want this behaviour. For my production scheduling algo, it just switch things at set indices and for vehicle routing, appending to the end of a route would be an error since I've now overshot the return location and "inserted" a job out of bounds. So I'm less sure about this argument
 
The argument above wasn't for every combinatorial problem, just "generally", or I guess a naive argument, since I don't know how many this could be used in.
 
But that's a narrow view on the whole field, I guess. Still, something has gone terribly wrong in both of those cases for me and I'd prefer a crash
 
@NordineLotfi also I said answer here, instead of "the answer on your post/question"
@roganjosh Definitely, but given we're all indirectly used to it because of slicing behaviors (as you mentioned earlier), it's probably not too bad...could be worse
 
9:44 AM
Hello, is there any way to encrypt some urls.
Application: Each of 30 teachers open a small pyqt5 app.
In this app they choose their username and password.
If the credentials are correct then a web browser is open in a specific link, different for each teacher.

I don't want a teacher to hack the url link of another teacher using decompiling tools.
Is that possible?
 
I don't use pyqt but isn't the browser app handled by something entirely separate?
 
This sounds like a job for cookies, not URLs.
 
when the link opens the app will be closed.
 
@roganjosh The -u unbuffered option is pretty extreme. I guess it's ok to think of it as equivalent to adding a flush() to every print() call, but it's a bit different because it eliminates the buffer in the underlying binary stream.
Text streams can have buffering in addition to the buffering of their binary stream. Binary streams may be unbuffered, or they can have line or block buffering. And (of course) the OS level I/O streams have buffering as well. docs.python.org/3/library/io.html?module-io#module-io has the details, but I must admit it's not one of the more user-friendly parts of the docs...
 
i just don't want the users to have access to python code somehow. (using decompiling tools in pyinstaller .exe producable).
 
9:52 AM
@ChrisP so what you're saying is, you want to prevent bruteforcing or collision for the urls?
 
Yes something like that
 
@ChrisP That's something entirely different than encrypting URLs.
 
@ChrisP please can we be specific about "app"? What I think you're saying is that you have a "pyqt app" that launches a "browser app" and then the pyqt app closes?
 
@ChrisP you could probably get around that by 1. not compiling using pyinstaller, since it is easily reversible, 2. use some encryption/hash setup, so even if someone have access to the code, they won't know how to get access to a specific url or even be able to bruteforce it
 
@PM2Ring I didn't check at what size del becomes noticeably faster. Would complicate the testing code, as I can't delete more than the size, so I'd have to add a level of repetition in order to get stable benchmark times.
 
9:55 AM
@PM2Ring yeah, that's why I mentioned this was more of a "general" way of doing it, vs doing it using a specific argument (eg: for print), which is more fine-grained. I didn't know this eliminates the buffer however :o
 
Is this question related: stackoverflow.com/questions/67868395/… ?
 
something like that could help too: stackoverflow.com/questions/11612032/…
I'm not an expert in cryptography though, so take my recommendation with a grain of salt :P
ah, always wanted to say that in that context
 
I'm still super-confused about what is being asked. On one side we have some attempt at code obfuscation, then we have what I thought was only a desktop application tool launching a web browser window, and within that we need to encrypt URLs instead of using cookies as MM suggested. This is a hodgepodge?
 
@KellyBundy Fair enough. What I usually do in that kind of scenario is to I have an outer loop that doubles the data size but halves the number of timeit loops.
 
@roganjosh Yes, I thought others might like the question, maybe even be able to use the knowledge about the optimization some day. (If that sounds odd: yes, I already knew the answer, just preferred to have others answer it. I had noticed ob_start while looking at the bytearray struct, got curious, noticed the pop/del discrepancy, and decided to share it this way.)
 
10:05 AM
@PM2Ring oh, ok, that's way more nuclear than I expected. Thanks for making me realise it affected more than just a print buffer
@NordineLotfi I think we need to pepper them with some more questions yet to understand the full context
 
yeah, you're right
 
(I was following up on your salt comment, just hard to work it into a sentence)
 
wait, I think I saw what you did
 
@PM2Ring I often do that, too, but here it's not that simple, as I can't just increase the number of loops for small arrays.
 
I think we may need more to use something stronger than simple condiments, but hopefully we don't need to resort to an IV injection...
 
10:10 AM
aside from pepper and salt, I don't see any alternative...my cooking jokes are sadly unsavory
I think I heard there was Ginger extract in certain IV injection. Don't know if it's true or not (think I saw it somewhere on SE network on a non-related post)
 
I would try continue the cryptography references but I fear I'd just make a hash of it
 
This conversation is certainly helping us curry favor with the cooking and pun enthusiasts
 
There'll be an avalanche of new visitors
 
The cherry on top would be someone coming here and bringing cabbage with them
 
There's an endless supply of food puns, but you can't make much dough from them.
 
10:22 AM
I wonder if that's what they're all doing in the cooking.SE chat room. I would (unless it makes some people there sour)
 
10:35 AM
@ChrisP If your users can get access to each other's private data by hacking their local copy of your app, there's sonething drastically wrong with how you're handling security. The first rule of crypto is: never roll your own crypto. And when you use proper crypto code written by experts you need to have a strong understanding of what you're doing, and how to properly use that software to achieve your goals.
The second rule of crypto is: assume that the adversary has your software, and understands exactly how it works. You can't hide your code, but you must hide your keys. And you don't put keys anywhere that some hacker can access.
 
I wonder, is there a downside to annotating a generator function simply with typing.Iterator[T]? It's more readable to me if I don't use send type and return type.
@NordineLotfi cbg
 
:D Cabbage!
 
Does the generator use send? Does it return anything (apart from None)?
 
@Arne Technically, you also use the generator API such as close. In practice I find this rarely needed.
 
@PM2Ring no it doesn't, now that I re-read my message I see that it was unclear: "I annotate with typing.Iterator whenever I write a generator that doesn't use send or return. Is there a downside?"
seems it is ok. I should have read to the bottom of the paragraph before asking here
@MisterMiyagi TIL that I can tell a generator to close and throw
 
 
1 hour later…
11:56 AM
is there a way to sort the list of dictonary different type one datetime object, which are accessed with different name? like data = [obj_typ1(settlement_at), obj_typ2(units_transferred_at), ] , so sort this based on this ?
dont want to copy the same field in the object ie obj_typ1['units_transferred_at'] = obj_typ1['settlement_at']
 
something like this?
class Obj_typ1:
    pass
class Obj_typ2:
    pass
def keyfunc(val):
    if isinstance(val, Obj_typ1):
        return val['units_transferred_at']
    elif isinstance(val, Obj_typ2):
        return val['settlement_at']
then you pass that keyfunc to sort function
If you have access to class of the object you can also implement common property interface for them and sort based on that
class Obj_typ1:
    @property
    def sort_key(self):
        return self['units_transferred_at']
class Obj_typ2:
    @property
    def sort_key(self):
        return self['settlement_at']
s = sorted(l, key=lambda x: x.sort_key)
 
12:37 PM
@matszwecja nice, thanks, second one is solving it better for me
 
 
1 hour later…
1:42 PM
You could also overload __lt__
 
2:08 PM
nope, using it will create unnecessary burden, Just want to implement FIFO logic, so sorted data based on keys is ok for now
 

« first day (4496 days earlier)      last day (435 days later) »