« first day (3901 days earlier)      last day (1038 days later) » 
00:00 - 20:0020:00 - 23:00

12:32 AM
@TheShortestMustacheTheorem please don't ask for help here with fresh questions on the main site as per our rules
 
@AndrasDeak: OK. Thank you for informing!
 
cbg
 
 
3 hours later…
4:03 AM
cabbage cabagge
who can help me?
import cv2 as cv
import os
import numpy as np

image = cv.imread(os.getenv("RESOURCES") + "\\family.jpg")
image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
image = cv.resize(image, (4, 5))
output = image

def onInvalidator(pos):
    print(output)
    output = image * pos / 10.
    print(output)
    cv.imshow("Output", output)


cv.namedWindow("Output", cv.WINDOW_NORMAL)
cv.createTrackbar("Level", "Output", 5, 10, onInvalidator)

onInvalidator(5)

cv.waitKey()
The first print(output) is said to be invalid by IDE.
output variable is undefined. Hmmmm.. why? I have declared it globally actually.
 
 
1 hour later…
5:16 AM
@TheShortestMustacheTheorem What does that mean? If you got an exception, please post the full text of that exception.
@TheShortestMustacheTheorem You're trying to print(output) on the line before it's been declared! It doesn't exist yet. So delete the first print(output) statement.
def onInvalidator(pos):
    print(output).#  <--- 'output' doesn't exist yet!!!
    output = image * pos / 10.  # <--- now 'output' exists!
    print(output)
 
6:00 AM
you need to say global output if you want to refer to the global variable and not the local scope
if you genuinely want to print the global version and then have the code refer to a local version after that, use a different variable name for your local variable
 
@tripleee: OK. I am trying...
 
I guess it doesn't need mentioning that global is bad for other reasons anyway
 
6:29 AM
I see. I did the following and it works. :-)
def onInvalidator(pos):
    global output
    print(output)
    output = image * pos / 10.
    print(output)
    cv.imshow("Output", output)
 
i find it weird you're going through all this trouble to use the variable output and then you use image in the next line, which is effectively the same as output anyways.
def onInvalidator(pos):
    print(image) # just print image if that's what you wanted.
    output = image * pos / 10.
    print(output)
    cv.imshow("Output", output)
then you don't need to even write the line output = image up above.
 
@ParitoshSingh: Thank you. I wonder why we can use the global image without the keyword global in onInvalidator?
 
because there's no conflict with a local variable
whereas you're trying to use a local output variable as well
 
Python is confusing.
 
6:42 AM
def onInvalidator(pos):
    print(output).#  <--- 'output' doesn't exist yet!!!
    output = image * pos / 10.  # <--- now 'output' exists!
    print(output)
It is smci's comment above.
 
output = image * pos / 10. what is the scope of this variable output?
 
global
must be global
 
no.
def func():
    a = 42
 
assigning global variable
 
what is the scope of a in the code above?
 
6:45 AM
If there is a global variable of the same name, it must be global assignment.
 
that's the problem. you're assuming things that simply arent true then, you should revisit how python figures out scopes.
 
OK. It is because of the lack of explicit declaration.
 
to put it simply: if python sees an assignment within a function, it treats it as a local variable
you're assuming the wrong default behaviour.
 
OK. I understood now.
 
anyway, the proper design is to pass the inputs the function needs as arguments, and not have any globals
 
6:47 AM
^ this is the main thing. you don't even need to worry about these things if you simply pass things a function needs properly
 
OK. But if the callback only need one args, how can I pass more than one variables to the callback function?
 
very good question. i was wondering if that was the issue
 
I also hate globally defined variables.
 
this is where you can use partial functions such as functools.partial to turn a multiple arg function into a single arg function.
 
that's not a beginner topic, though
 
i suppose there's also a quick and dirty trick you could use, by making a default 2nd arg with the value set to your variable as needed
Im not sure what's the stance on whether that's a good idea or not, just thought of it
 
@tripleee Please just don't teach the kids to use globals. They introduce a new, less easily debugged, set of problems. NameErrors teling people when stuff isn't defined are healthy.
@ParitoshSingh Don't make things complicated. The OP's function defines output from pos, so there's no need to pass output into the function. Agreed? Just keep things simple.
 
@smci ofcourse. it's not about passing output, it's about discussing whether to pass image at this stage
 
Can we change the passed variables to point to other from within the function body?
 
@TheShortestMustacheTheorem hm, same rules of variable assignment apply. you could always freely write any re-assignment as necessary. however, i wonder what's your intent behind asking this question. (it's quite possible that whatever it is, it might be a bad idea)
 
6:59 AM
What is the python equivalent for the following?
#include <iostream>

void foo(int &x)
{
    x = 10;
}

int main()
{
    int x = 0;
    foo(x);
    std::cout << x << std::endl;
}
 
x = foo(x)
 
^ explicitly return, explicitly reassign
 
well, not exactly, because you can't pass a reference to an immutable
 
def foo(x):
    x=10


x=0
foo(x)
print(x)
 
if x was a list you would get something quite similar by passing the containing list and modifying its first member
 
7:02 AM
it is a bad idea to mutate globals from within functions (even though it can be done)
@TheShortestMustacheTheorem return x from the function and assign. don't try doing this.
def foo(x):
    x = 10
    return x


x = 0
x = foo(x)
print(x)
 
Jun 13 at 21:14, by Aran-Fey
Someone should tell C++ that parameters are for inputs, not for outputs
 
Agree. I also love y=f(x).
Thank you all. I continue my learning.
 
aye, and in principle functions should be pure. it makes the code easier to reason about, and bugs easier to find. explicitly pass what it needs, and explicitly return what it needs to return
 
7:51 AM
@TheShortestMustacheTheorem take a hint. Don't post non-python here, and especially don't post non-python to make others translate it for you. Learn both languages, pay a consultant, or ask elsewhere. I heard the python discord is very eager to help.
 
Excellent
 
class MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        QtWidgets.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.calc_tax_button.clicked.connect(self.calculate_tax)
Is this considered multiple inheritance?
Are you able to use super function here given there's 2 parent classes?
 
Yes, it's multiple inheritance, and multiple inheritance is exactly why super exists.
 
You can, but it's a bit ugly. super().__init__() followed by super(QMainWindow, self).__init__()
 
7:57 AM
Does QtWidgets.QMainWindow.__init__ properly call super().__init__?
 
Actually you'd probably have to use super(QWidget, self).__init__(), I think. But I don't know Qt, so...
 
It does work though
When I do super().__init() followed by super(Ui_MainWindow,self).__init__()
 
That's not what I wrote, but ok
 
I do get NameError: name 'QMainWindow' is not defined when I use QMainWindow so I just tried using Ui_MainWindow
 
If you really have to use multiple inheritance, I'd recommend doing it without super there
 
8:02 AM
Yeah i suppose it's best to spell out the parent class like in the example
 
@Pherdindy Obviously I meant QtWidgets.QMainWindow :|
 
@Aran-Fey obviously not obviously
 
super(QtWidgets.QMainWindow,self).__init__()
TypeError: PySide6.QtWidgets.QWidget isn't a direct base class of MyWindow
 
Yeah, classes written in C and super don't mix
Generally speaking
 
Calling super(QtWidgets.QMainWindow,self) is just wrong here. It starts the MRO search one level too deep.
Only ever use super() or super(__class__, self) unless you know exactly what you are doing.
 
8:06 AM
@MisterMiyagi he usually does ;)
 
So it's best to actually only use super() alone for single inheritance
Best to spell out each class with super(__class__,self) with more than 1?
 
cabbage
 
@MisterMiyagi It's not wrong. super().__init__() calls every __init__ in the MRO up until (and including) QMainWindow.__init__. Then it stops there because Qt clearly doesn't use super. So super(QtWidgets.QMainWindow,self).__init__() continues where we left off
It's only wrong here because Qt doesn't cooperate with super
@Pherdindy I'd say "Always use super unless you have to use it twice in the same method". If you have to use it twice, that means you're working with a base class that isn't designed to support what you're doing.
 
We might be talking past each other here, but super().__init__() will only call one single __init__ (the next in the MRO). It's the next __init__'s responsibility to again call super().__init__().
But if "Then it stops there because Qt clearly doesn't use super." then most bets are off and the classes are basically not suitable for multiple inheritance.
 
@MisterMiyagi you're talking about cooperative classes
 
8:13 AM
Right. If everyone does their job properly, then the __init__ calls will eventually reach QMainWindow.__init__. But we know for a fact that it stops there
 
@AndrasDeak In the same way I am talking only about bicycles with two wheels, yes. :P
 
There's something about GUIs that drives everyone designing libraries for them insane.
 
class MyWindow(PySide6.QtWidgets.QMainWindow, MainWindow.Ui_MainWindow)
| Method resolution order:
| MyWindow
| PySide6.QtWidgets.QMainWindow
| PySide6.QtWidgets.QWidget
| PySide6.QtCore.QObject
| PySide6.QtGui.QPaintDevice
| Shiboken.Object
| MainWindow.Ui_MainWindow
| builtins.object
 
I initially thought we were dealing with a setup like this, where 2 super calls would get the job done. But in reality we're dealing with python wrappers around a class hierarchy written in C, so... I can't even create an accurate example with only python code, but it would be something even messier than this
 
    super().__init__()
    super(Ui_MainWindow, self).__init__()
Does work well though I guess the first super just does the job automatically despite the messy-ness
 
8:22 AM
super(Ui_MainWindow, self).__init__ can't be correct because it doesn't call Ui_MainWindow.__init__
 
If you know which classes are the correct "supers", calling them explicitly is likely more robust than messing with super in that case.
 
@MisterMiyagi until someone subclasses your class, right?
 
@AndrasDeak Nah, that should work at that point. It gets messy when someone multiple inherits from the class, since that messes up the MRO – but that would break super(Ui_MainWindow_Child, self) dispatch as well.
 
Subclassing will work fine. The only thing you lose by not using super is the ability to inject new classes in the middle of the MRO (and have their __init__s called automatically)
 
@MisterMiyagi right
 
8:28 AM
Can I interest you in the Religion of Composition?
 
Preaching to the choir as far as I'm concerned
Multiple inheritance hurts my brain, bit like recursion does
 
The student seeks to master complexity. The master seeks to study simplicity.
8
 
Thanks gonna have to work on simpler examples to understand inheritance better lol
 
 
1 hour later…
9:54 AM
Hi everyone I might have a stupid question but there is this mandrill(also known as mailchimp transactional ) api I am looking at(link: mailchimp.com/developer/transactional/docs/activity-reports). I need to get some data related to activity but so far all requests that I have seen on their page is of POST type. Does this mean I have no other option but to use webhooks for this purpose? Also if webhook is the only way to go , what does post to url mean? How should I give that URL?
 
10:10 AM
I don't get how you jumped from "POST request" to "webhook". A webhook means they contact you when something happens (i.e. triggers the webhook). I don't think that's what you want, is it?
 
Been watching and reading forums for about an hour about super and I found this which is really as clear as it can get for me
Most stuff i've seen didn't really explore the basics as much as this one. Well for my comprehension it helped a lot
 
@RaphX sounds like there's some confusion in your concepts. a POST request is perfectly normal (and rather common) for APIs, no webhooks needed. POST is a type of request that usually sends extra information with the request, but not as part of the URL. (usually POST requests use jsons to send some data along with it)
 
10:37 AM
ok so I need to access this information to get what I want right? @ParitoshSingh
mailchimp.com/developer/transactional/api/ips -> How do I do that for any of the apis shown here ?
 
click expand and it will show you an example
looks like you need to send a data such as '{"key":""}' with a valid key
have you used apis before? what library/tool do you use to access APIs, if any.
 
import mailchimp_transactional as MailchimpTransactional <- wat
 
Related to my previous sentence at chat.stackoverflow.com/transcript/message/52462037#52462037, I now understood the essence. Numpy functions always use (row,col) format, OpenCV matrix objects are accessed with (row,col) format, but OpenCV functions that accepts arguments of type Size use (col,row) format (for example cv.resize()). The end of discussion. :-)
 
guess which one's the python developer and which one's the Java Developer :P
 
try:
    client = MailchimpTransactional.Client("<API_KEY>")
    response = client.exports.activity()
    print(response)
except ApiClientError as error:
    print("An exception occurred: {}".format(error.text))
I tried something like above and I got this:
{'id': '2021-06-21 09:45:30.80559', 'created_at': '2021-06-21 09:45:30', 'type': 'activity', 'finished_at': None, 'state': 'waiting', 'result_url': None}
 
10:42 AM
looks like that works
 
Its supposed to create a zip file according to the docs but it didn't do anything, am I missing something ?
 
just those lines as supposed to make a zipfile? i dont see how they would.
 
It's supposed to start the export of the activity
You have to follow up with mailchimp.com/developer/transactional/api/exports/… if you want to see whether the export already finished
 
general question to the room regulars. which docstring style do you tend to prefer? and when do you tend to write docstrings? before writing the function or immediately after. or do you let it sit for a while and come around to it when a module is ready for use.
 
thanks! @Aran-Fey @ParitoshSingh , just curious, can I get it in JSON format in some way instead of a zip?
 
10:48 AM
Don't think so
 
so this cannot be automated programmatically right?
 
Why not? Can't your program work with a zip file?
 
you can always write code to do whatever you want. just keep pinging to check whether the export finished, and then access the zip yourself perhaps
(i should add, at this stage, i get the feeling Aran has a better grasp of what the tool does specifically, im just spitballing general advice)
 
I've used MailChimp a bit in the past, but never the API, so I'm also pretty much just guessing over here
 
thanks again! @ParitoshSingh@Aran-Fey
 
10:56 AM
@ParitoshSingh I often write docstrings very late. When the code is still under heavy construction, I usually don't bother documenting much because things are likely to change and usually I'm not even sure what will be part of the public API and what won't. In those cases, I make everything work first and then document everything when I'm ready to publish.
But if I already know that I'm gonna write a docstring sooner or later, I usually write it while implementing the function/class. For example, when I make a decision about the behavior ("If X happens, should it do A or B?"), I implement and document that behavior immediately
 
Docs Driven Development. Catchy!
only one step away from TDD via doctests ;)
 
Makes sense, i find myself having to write docstrings, and it seems like a lot of effort trying to maintain both the code and docstrings as i go
 
I don't think it's a problem if you start with the code and add the docs later. (As long as "later" doesn't mean "next month")
 
11:47 AM
scale = 0.5
h, w = logo.shape[:2]

logo = cv.resize(logo, (int(w * scale), int(h * scale)))
Is there any simpler way to multiply a tuple (w,h) with scale and convert it to integer-valued tuple?
 
Nope
 
@Aran-Fey: OK. Thank you! I am leaving to continue my coding. :-)
 
you don't really have to announce that every time you leave
 
Actually I am expecting something like int(scale*(w,h)). :-)
 
keep expecting
I could give you a numpy alternative but what you have is readable for everyone
 
11:54 AM
cryptic alternative is also fine for others. :-)
as long as it is less verbose
 
different kind of verbose
cv.resize(logo, (np.array(logo.shape[:2])*scale).astype(int))
whoops, wrong operation
if you care about rounding you can throw in a .round() in the middle
And if scale is always 0.5 then you should use // 2
 
The small glitch detected, the array passed to resize must be swapped. :-)
 
ah, yes
Then np.array([w, h]) if you already have those.
 
OK. Thank you!
logo = cv.resize(logo, (np.array(logo.shape[::-1][1:]) * scale).astype(int))
 
12:10 PM
Nice you made it a lot worse
 
@ParitoshSingh I've started writing function signatures and docstrings first these days. If it's easy to explain, it's probably a good design. If not, well...
 
@TheShortestMustacheTheorem KISS
 
@Aran-Fey Sometimes cryptic code is good for brain teaser. :-)
 
and that's why I knew I shouldn't help
 
We should help each other.
 
12:18 PM
right
 
12:46 PM
Milestone: I may actually use logging for the project I'm working on, rather than just barf a lot of diagnostics onto stdout using print
 
Nice. Although the thought of being in a situation where you need logs is a bit scary
 
hi
i am php developer and i want to learn python
 
The volume of data is no different from usual, but I think it will pay dividends if I take extra care to get my debug info all nice and clean and categorized
 
@RakeshkumarOad Hi. If you're looking for tutorials, see here
 
12:53 PM
My highest priority is to be able to easily compare logs of consecutive runs on different inputs. In my prototype, I removed all newlines from my output and bent over backwards to ensure that each log message had a static length.
Here's an example. Six executions, six lines
 
fancy
 
@Kevin You should probably check out structlog
 
I will do so
My prototype worked quite well, until I got to the part of my algorithm where I need to loop a non-static number of times. For example, input #0 loops 117 times, and input #3 loops 0 times. If I print all loops, then the output afterwards doesn't line up. If I print N loops, where N = min(num_loops(input) for input in inputs), then I'll print 0 loops.
And that's where I left things off last night. I could create a second log file just for loops, and put each loop's output on its own line... I think that would serve my needs well enough.
But if structlog or whatever else can do that kind of thing for me, I may as well skip reinventing the wheel
 
I don't quite follow how/what needs to be aligned, but structlog can at least help with creating machine-readable logs. Should make it fairly easy to extract/process the information you want
 
Oh good. I've been kicking around the idea of machine-readable diagnostics, so I can run the actual code once and then experiment with different kinds of visualizations on the logs
I almost used... XML. [lightning strikes in the distance]
 
1:18 PM
morning cabbages, folks
 
cbg
 
 
1 hour later…
2:51 PM
Ok, multi-file logging established, and my code is only 60% of a rat's nest
 
rat are great, we should have more of them in our homes
 
^ unpopular opinion
 
I can't type today
 
a remote access tool in 127.0.0.1? that does sound like... an idea
 
Does anyone know a library that lets me have a progress bar in the terminal while also printing other stuff?
 
3:03 PM
@Aran-Fey tqdm
it does the progress bar but it's really versatile
odds are you can use it to do what you want
I'm only familiar with the simplest application where tqdm.tqdm can wrap any iterable to display progress
 
I wonder if any research has been done into the art of making good progress bars for algorithms that aren't easily measurable. The Windows file transfer progress bar used to be infamously bad, and now it's merely mediocre. What specifically did they do to improve things?
 
To clarify, I want to do something like this without wrecking my progress bar
 
Does your OS and/or shell support curses? IIRC it has rudimentary support for statically positioned status-bar-like fields. If all else fails you can micromanage every character yourself.
 
@Aran-Fey what is the expected behaviour?
sounds like something that's deceptively hard to pull off in general (general terminals, terminal emulators, command prompts etc.)
disclaimer: this is again an uneducated guess
 
@Kevin I think my terminal is up to the task, although I've never tried
@AndrasDeak Progress bar should stay in the bottom line, other output should appear above
 
3:12 PM
The lowest-common-denominator shell is too dumb to go up to a previous line and overwrite it, so anything requiring backtracking of that level will be somewhat challenging
 
@Aran-Fey so you'd have to intercept stdout/stderr, notice when something's printed with a newline, replace the current progressbar line with whatever the output is and print again?
 
On the other hand, going back to a previous character on the current line, is pretty well supported. "\r" and "\b" move the cursor leftwards on many shells.
 
from tqdm import tqdm
import threading
import time


def print_stuff():
    for _ in range(5):
        time.sleep(1)
        tqdm.write('hello')

threading.Thread(target=print_stuff).start()


for _ in tqdm(range(5)):
    time.sleep(1)
 
Hmm, if the progress bar is always at the bottom, maybe a "\r"-based solution is possible... I will be in my prototyping dome
 
@AndrasDeak Yeah, that should work. But I'll need a way to figure out how wide the terminal is so that I can reliably overwrite the previous line. Let me ask my duck if it knows how to do that...
 
3:15 PM
@Aran-Fey check my last message first
the message you replied to was more of a "this is why I think this would be a pain in the butt to implement"
 
cabbage
 
@AndrasDeak Oh, perfect!
 
wow, the bright chat is blinding after using dark mode SO
 
Need a dark theme for it? I can send you mine if you want
 
3:17 PM
@Code-Apprentice I've been doing that since they turned on dark mode. Not great, but not terrible.
@Aran-Fey what does it run on?
 
@Aran-Fey sure...I wonder if I have one enabled on my personal machine...
 
I've been toying with a dark theme, but too lazy to install yet another something manager...
 
Is it too much to ask for a screenshot? :)
if it isn't, I'd like to ask for a screenshot
 
3:24 PM
Anyone able to help me apply this answer to my problem? stackoverflow.com/a/7554619/5090081
 
@bendl depends on what "my problem" is
@Aran-Fey hmm, but is that your default?
Oh yeah, I also toyed with the idea of something like stylus because on some SE site chat rooms links are barely visible with my redshift
 
The top image is very close to default settings. The orange is a little darker per default
 
@Aran-Fey Seeing a regular's avatar in full size is... totally radical.
 
My example string is {{{nsi|{{{ns|{{{ThisIsIt}}}r}}}}}}, and I need it to match ThisIsIt (or{{{ThisIsIt}}} i don't really care at this point)
Specifically it needs to get the smallest possible contents of three curly brackets, but regex matches left to right
 
3:29 PM
@MisterMiyagi Just wait until you see this version
 
I was looking for that :D
 
I regret saving that as a gif. I need to re-record that someday
 
Good god, I swear to god the only way to figure something out is to ask someone else
 
@Aran-Fey *squee*
 
the answer is (?<={{{)([^{}]+)(?=}}})
 
3:30 PM
@bendl nice
Is there no chance for that mess to be avoided in the first place?
@Aran-Fey thanks, I think I'll give it a shot
 
There sort of is, but it involves some messy recursion
 
I mean avoiding that messy data.
 
oh god I wish
 
heh
 
Thank wiktionary for their insanity
 
3:33 PM
ooh, nice
Is there no wikimedia parser you could use then?
 
None that I've seen so far that parse their templates
 
hoping that someone has already sacrificed their sanity so you don't have to
I take it you've checked pypi.org/project/mediawiki-parser?
> However, it does not intent to be bug-for-bug compatible with MW. For instance, using HTML entities in template calls (e.g.: ‘{{temp&copy;late}}’) is currently not supported.
If there can be bugs in template calls then perhaps there's some support there?
Sorry if you're already past this and I just gave it a cursory glance. But it's better to be safe than sorry annoyingly inquisitive than unhelpful
 
@AndrasDeak 😂
I think I remember considering that, and eschewing it for github.com/tatuylonen/wiktextract
That provides preprocessed data, because parsing all of english wiktionary takes hundreds of hours
And all I need is a subset
 
OK, just checking
 
The only downside is I need inflected forms, and they're given like this: kaikki.org/dictionary/Old%20Norse/meaning/a/al/alfr.json
"inflection": [{"1": "alf", "template_name": "non-decl-m-i2"}],
 
3:39 PM
Ahaha, good luck
 
thanks - I think with this it will finally be easy
 
@Aran-Fey Here is a \r-based proof of concept. pastebin.com/Jsez7CAn. It's a bit of a pain to use because you need to manually add N spaces to the end of all of your non-progress-bar print calls, and the "100% complete" messages gets permanently overwritten if any output occurs afterwards. But it is what it is.
 
Thanks, but Andras already found a solution :)
 
Yes, but it just doesn't feel right for me to emerge from my prototyping dome without announcing a prototype
 
3:45 PM
Black smoke rises; a new prototype has been found.
 
I'm not sure if I will be able to make myself clear but here is an attempt. I have a way to create a file as well as to choose a file, certain functions uses this filepath, but how will I know if the filepath is an existing one or a newly created one by the user. I did try to make an MCVE but I failed in that area too :(
 
What's the difference between "existing one" and "newly created one by the user"?
Either the user created it outside your program, in which case it's an "existing one", or they created it inside your program, in which case you know it's new because you created it.
 
newly created is when user creates their own database within the program, existing is when they choose an already created database(maybe with or without this app).
 
So... just keep track of files created within your program?
 
recbg
 
3:57 PM
Hmmmm now that I am think about it, I used two variables for filepath for existing and new, maybe I should just use one variable? So the existing one is going to get rewritten each time something new is chosen or created. That might solve this
 
Any specific solution will depend on how you intend to use these paths in your code, so don't expect much help from us.
 
Advice which is vague to the point of unhelpfulness: whether an object is created brand-new or loaded from the file system, after it has been initialized you should treat it exactly the same
 
Ha, noted :)
 
Ah, but here's a good exception. When you load an object from the file, the path/filename should later be accessible to the object saving logic, so it doesn't have to ask the user for information it already had.
 
So perhaps have to store it inside something?
 
4:06 PM
For example. in MS Paint, there is almost no indication of whether the canvas I'm drawing on is a new image, or something loaded from a file. All painting operations are 100% identical. But ctrl-S has a small distinction. it instantly saves when the image was pre-existing, and it opens a file-ask dialog when the image is new.
 
@CoolCloud While this might solve it, I have also thought of another approach, once the user creates a database and initialize it with a password, the user is redirected to use the database directly, but usually apps like Facebook and all requires you to log in once you made an account right? Or am I mistaken? Anyway which approach is nice, logging in after creating an account or just redirecting them directly to the authorized page?
 
@CoolCloud Yeah. If all else fails, "something" can be a global.
 
@Kevin Ah yea true
 
(Unless the user can open open multiple files simultaneously, then you should strongly consider a non-global design)
 
@CoolCloud either is fine really, pick what's easier to code. heck, there's a case to be made for making someone type the password they just saved.
regardless, at worst, this is a minor inconvenience
 
4:09 PM
I have a vague suspicion that Facebook's approach is for security purposes, although I don't know what kind of attack it's defending against.
Chesterton's Fence is in effect -- try to understand why the barrier is there before you decide you don't need it
 
Ha, the latter it is, then
 
Yes, but Cargo Culting is in effect -- try to understand why the barrier is there before you decide you need it
 
I need help from an aiohttp guru... How can I make an accurate progress bar for an aiohttp download? I can get the file size with the Content-Length header, but if the server has compressed the data then the size on disk will exceed the Content-Length. So how can I figure out the number of bytes that were actually received from the server?
 
75% serious reply: take the content-length of the compressed data, and multiply by some reasonable estimate of the compression algorithm's efficiency
 
That's a lot of work for an inaccurate progress bar :P
 
4:19 PM
accurate progress bars are a myth :P
 
I worry that I'm misunderstanding the problem. If the server accurately reports at the beginning the number of bytes that it plans to send you, and within each packet it accurately reports the number of bytes the packet payload contains, then can't you calculate the progress from those?
If the server is using a magically good compressor, and sends 1 kb of data that happens to decompress into a 1GB file, then total network transfer progress should be in terms of the one kilobyte, not the one gigabyte
 
The problem is that aiohttp automatically decompresses the data for me. I don't know how I could access the original chunk of data. So if my response.content.readchunk() returns 1000 bytes, those 1000 bytes may have only been 900 before decompression
 
Ok, that makes sense.
I suspect there's a way to get the size of the data before automatic decompression. I've seen that feature in at least one HTTP lib.
 
Tbh I doubt there's a way to have the best of both worlds - have the data automatically decompressed and know how many bytes there were originally - but a man can dream
 
I will wander through the docs with maximum vigor until I find the answer, or until lunchtime
docs.aiohttp.org/en/stable/… can get "actual http chunks", but it sounds like 1) not all servers send chunks to begin with; 2) it won't magically decompress it for you afterwards
 
4:57 PM
@Kevin Oooh, I've actually been using readchunk... so either that still decompresses the data, or I got lucky up until now
I discovered the auto_decompress parameter, but that's for the entire Session :|
 
5:14 PM
just curious, are you writing a download manager?
 
5:31 PM
Not exactly. I'm writing something that can automatically download videos/music/etc to the correct location and also add metadata (like the artist, or the uploader, or the length) to the file name if desired
 
5:47 PM
A handful of answers at stackoverflow.com/questions/15644964/… calculate progress from total content-length, and the len of each chunk. I wonder if all the servers they tested against didn't use compression, or if requests doesn't decompress automatically for you, or if the discrepancy is too small for the upvoters to care, or what.
 
I guess servers usually only compress HTML and not files
 
Ooh, docs.python.org/3/library/… has a nice callback parameter. Too bad it's deprecated.
I guess it's plausible that servers usually don't compress files... If the file exists only for the user to download, then presumably the webmaster would compress it themselves ahead of time.
(disclaimer: I have zero concrete data, or even anecdotal experience, about compression of HTTP)
docs.python-requests.org/en/latest/user/quickstart/… confirms that requests won't decompress on your behalf if you use stream=True and read from response.raw
 
6:10 PM
You know what, I think I'll just move on the other problem I'm having, namely figuring out how to add progress reporting to my library so that I can hook up a progress bar to it
Surprisingly, there are no modules for progress reporting. Progress bars, yes, plenty. But what do you do if you're a library?
 
a bunch of log dumps to a file? an asynchronous hook for "check status"? that kind of deal?
actually, question. when you say progress, are you counting progress in terms of n tasks out of total tasks, or counting progress in terms of time remaining
 
Just count in Windows Time. Any moment between "now" and "heat death of the universe" is equivalent.
 
I suspect you can get pretty far just by putting a method in the API like register_progress_callback(func), and you periodically call func with nice diagnostic arguments every so often
register_callback is to progress reporting, as print is to logging
 
@ParitoshSingh The idea is that you report "I have X amount of work to do, and have currently completed Y", and how that information is displayed is entirely up to the application. If it wants to display an ETA or a "currently going at a speed of X tasks/sec", it basically has to calculate that on its own (although I'll probably provide helper functions for that)
 
gotcha, makes sense
 
6:22 PM
docs.microsoft.com/en-us/windows/win32/uxguide/progress-bars is actually a decent checklist for basic things to include/avoid in one's progress bar, in order to keep your users mostly sane
If I read it right, it suggested a double progress bar if you have to complete N heterogeneous tasks, and you can estimate the required time for each task as it starts, but can't easily estimate the total required time. Not a bad idea.
 
i think the issue is, how do you decouple that work, giving people the option to hook "into" making progress bars if they wanted
 
Current design idea: Something like this
 
I like it
I often warn help seekers not to conflate big O complexity with clock time, but I wonder if you could use the former to make a reasonable estimate of the latter...
If you have an algorithm that is quite precisely O(N^2) in all cases, then you can take the equation clock_time == a * N^2 + b*N + c, and solve for a/b/c by running a handful of test cases with varying Ns.
... Assuming that the true run time isn't actually a*N^2 + d*log(N) + e*N^-1, or something
"Surely it doesn't matter what the little terms are as long as you get the big term correct?", you hypothetically ask. Rather, it's the little values that matter the most. If the task gets to 99% completion and your bar says "1 minute remaining" for two minutes, you have failed.
 
6:42 PM
@Kevin There's some cruel irony in reading guidelines like "Users should never have to guess if progress is being made." for that one OS.
"Of course we know. We've found out through tears, pain and blood. Yours."
 
Haha, I was just thinking "every one of these bullet points is the result of a million suffering users"
It is said that throughout history, prisoners of war have been subjected to cruel experiments, and some of the resulting data is still used in modern science and engineering...
 
6:59 PM
The sample file I'm using to reverse-engineer a file format, has 500 zero bytes in a row and I don't know why
This seems like an inefficient use of space
 
Padding?
 
bitrot
 
The HDF5 and ROOT formats are a bit like micro file systems, and deleting content can leave zero byte sections as well.
 
The file was passed on over five generations using an SD card. You're the first person to notice the corruption. Now you must go to The Source to retrieve the missing information.
 
the section comes immediately after a series of null-terminated strings that look a lot like directory names, so it's definitely file system adjacent
@AndrasDeak I accept this quest
I'll need a magical object wieldable only by the chosen one, and a fun talking animal sidekick, and a mentor who will perish in act I, and at least two love interests
 
7:09 PM
good thing you don't need comic relief
 
Yeah the fun talking animal will be the exasperated bert to my chaotic ernie
 
So @Aran-Fey it seems that your style messes with SO main (which I don't want, I already have official dark mode there), but if I comment out the SO main part the chat part breaks too :'(
and I can't disable them separately
things like this are why I've been avoiding yet another something manager :P
 
7:33 PM
Perhaps it's possible to apply the style only to this specific url. github.com/openstyles/stylus/wiki/… uses @-moz-document, but support seems limited for it and its non-moz equivalent.
Greasemonkey has a similar metadata block, and it has pretty good url filtering capability, so maybe UserCSS has something like that too
 
the userstyle itself has a @-moz-document domain("stackoverflow.com") directive
in greasemonkey I'd just remove the url pattern and that would be it
 
What if you replace it with @document url("https://chat.stackoverflow.com/rooms/6/python")?
 
there's a block later that relates to /6
 
Hmm yes
 
I'm sure there's a simple way to disable it and I'll wait for Aran-Fey to tell me what that is :P
 
7:38 PM
That seems most efficient. I will return to my zeroes.
 
I mean I'll be very happy if you tell me the simple way, I just don't want you to waste time on something that I don't really need, I don't understand, and I was reluctant to get into in the first place.
and that Aran-Fey probably knows off the top of his head
 
I have a nonzero amount of curiosity about the problem, but (all other things being equal) the pull of the file format project is stronger
 
must be all that zeros pulling
 
Little black holes, each of them
 
7:56 PM
@AndrasDeak Click the Stylus icon, then the 3 little dots next to the style, and check "disable on this domain". Screenshot with horrible font colors because reasons
 
Perfectly hidden! Thanks :)
aaand it's working <3
now to try and apply it to chat.SE...
@Aran-Fey thanks again
 
00:00 - 20:0020:00 - 23:00

« first day (3901 days earlier)      last day (1038 days later) »