« first day (4498 days earlier)      last day (434 days later) » 

3:22 AM
you know... one of the main reasons I don't use an IDE is so I don't end up wanting to ask a question like stackoverflow.com/questions/75381043 x.x
 
yeah...
IDEs never worked for me
 
3:47 AM
(btw, I updated one of your duplicate links. you might want to add the canonical to your saves)
oh, that was like an hour ago, you presumably don't know what I'm talking about. stackoverflow.com/questions/12934190/… <- canonical replacing stackoverflow.com/questions/11185781/…, which I hammered
 
oh heh, thanks
 
 
2 hours later…
5:58 AM
@KarlKnechtel yes, for both static and classmethod one
@KarlKnechtel use text editor or vi or emacs ?
 
 
2 hours later…
7:42 AM
If you actually know what you're doing, IDEs make life soooo much easier
 
8:03 AM
@Chuu pointing out an active bug report for the issue is still a perfectly good answer
 
8:37 AM
FWIW, the next Full Moon is at 2023-Mar-07 12:40:21.864 UTC. I calculated that using my Python code here: astronomy.stackexchange.com/a/49781/16685 Also see astronomy.stackexchange.com/q/50940/16685
I also have code that calculates the times of all 4 major phases over a time period, but it's a bit inefficient because it makes all the Horizons request separately instead of using a parallel approach and batching them together. IIRC, you can make ~32,000 requests in a batch.
 
I'm working on a library for manipulating video and audio. I was planning to create some abstract base classes for video streams and audio streams like so:
class Stream:
    def __iter__(self): raise NotImplementedError

class AudioStream(Stream):
    def get_sample_rate(self): raise NotImplementedError

class VideoStream(Stream):
    def get_resolution(self): raise NotImplementedError
And operations that modify a stream (like cropping the video) would also be implemented as subclasses of these ABCs, for example:
class Crop(VideoStream):
    def __init__(self, stream: VideoStream):
        self.stream = stream

    def __iter__(self):
        for frame in self.stream:
            yield frame.crop(x, y, w, h)

    def get_resolution(self):
        return (w, h)
 
The Moon is actually rather dark. It's roughly the shade of old asphalt. From space, the Earth is much brighter, mostly because water is quite reflective.
 
The problem with this is that I don't know what to do with operations that can operate on both video and audio streams. Those would have to implement both get_sample_rate and get_resolution. Should I use multiple inheritance and inherit from AudioStream and VideoStream at the same time, or is there a better design?
Also, there'll probably be more types of streams in the future, like stereo audio or subtitles
 
8:56 AM
My opinion: I think I'd prefer composition to multiple inheritance. I want separate streams that have some kind of timestamp / frame counter so I can synchronize them, when necessary.
I suppose it could be helpful to study the organisation of FFmpeg. And then decide what stuff in that design you like, and what stuff you think could be done better. ;)
 
I don't see how composition would help? The operation still has to implement get_sample_rate and get_resolution. Not inheriting from AudioStream and VideoStream only makes my code duck-typed instead of statically typed
class Repeat(???):
    def __init__(self, stream: Stream):
        self.stream = stream

    def __iter__(self):
        yield from self.stream
        yield from self.stream

    def get_sample_rate(self):
        return self.stream.get_sample_rate()

    def get_resolution(self):
        return self.stream.get_resolution()
Essentially, my problem is that I have 2 kinds of operations: Those that change the stream's metadata (like Crop) and those that don't (like Repeat). The latter should be usable on any stream, which, with my current design, requires me to know about every kind of stream that exits (audio, video, subtitles, etc) and implement all of the abstract methods for that kind of stream
 
10:00 AM
The current setup with multiple inheritance can work if you think of the parents as mixins. Not sure that generalizes to stuff like "stereo audio".
 
That's really the problem, that it doesn't generalize. I shouldn't have to implement all these abstract methods. There's something fundamentally wrong with this abstraction, but I can't figure out how to fix it
 
10:32 AM
Do you actually need the "top-level" object to expose all of that itself? I'd probably go for a "multi-stream" object that contains an arbitrary number of video and audio stream.
 
@Aran-Fey wouldn't you want to inherit those operations from concrete subclasses?
 
what about one big class that implements everything, where things like crop/repeat/mono-or-stereo are settings that manipulate how __iter__ behaves?
 
@MisterMiyagi I do have some higher-level objects. We're at the lowest level of the abstraction here - where do I get the frames and the metadata from, and how do I manipulate them? In particular, how do I make "manipulators" that can operate on different kinds of streams?
 
Ultimately, if your system may include multiple streams your functions must be able to handle them.
So a "manipulator" would have to understand that it must peek into a "multi-stream".
TBH that sounds like a job for singledispatch. cue heroic music
 
I think you're expanding the scope of my problem here. I only operate on a single stream
Or at least, the output is a single stream. There'll be operations that overlay or mix multiple streams into one, but the output is always one stream
@Arne I don't think that's viable. There are so many different operations you can apply to a stream - and you can even apply them multiple times - that representing everything as a single class would be huge mess
Oh, I guess a critical part I forgot to mention is that my operations are lazy. If the user tells me to crop a stream, I don't actually do it until I have to (when saving the result to a file)
So if the user does something like stream.crop(0,0,5,5).repeat(3).slice(1,9).blend(other_stream).repeat(2), I need a way to represent that
Which is why I think it's a good idea to implement each operation as a separate class - turn that into something like [Crop(0,0,5,5), Repeat(3), Slice(1,9), Blend(other_stream), Repeat(2)]
 
@sahasrara62 that's "a meme", not related to python at all, and not even funny.
You should post these somewhere else. Like, the recycle bin.
 
11:41 AM
@AndrasDeak--СлаваУкраїні ok
 
12:03 PM
@Aran-Fey if the API is to chain each of those operations, don't you still have to add a method to the base class for each of them, even if each operation is a class? .crop is still acting on a VideoStream?
Also, I don't know what a Repeat is so can't you just use functions for this rather than heavy OOP?
I realise I'm not giving you an answer at all (I'm not sure, either) but it looks ripe to get caught in an OOP hole
I can't believe I'm saying this but pandas does handle a lot of chained operations rather well. Where it gets annoying is things like MultiIndex/Groupby object has no attribute X, which is what your Repeat object might end up emulating?
 
I will need a method for each operation, yes. But I can't do it without classes, because there are operations that modify both the content and the metadata. .slice() could be implemented as a function that simply returns a shorter iterator, but that doesn't work for .crop() (because it also has to change the resolution metadata)
 
would this change if metadata were properties on each frame?
 
12:20 PM
Yes, but it would make accessing the metadata a much more expensive operation. If you wanted to know the resolution of a video stream, I would have to go and decode the first frame in the stream, then apply all the effects to the image, and then return its resolution
Imagine a sequence of operations like stream1.blend(stream2).brightness(0.5).black_and_white().flip().crop(0,0,0,0).resolution. Everything before the .crop() is irrelevant for the resolution
 
hmm
if your operations were more lazy, it wouldn't be that expensive
 
Well, how would I make them more lazy? :D
 
.resolution would only need a single decoded frame, and if all operations would accept frame iterators instead of a fully decoded stream, it would be just a single iteration on all operations until you get that frame
that's how I prefer to write my data pipelines, as it finds bugs later in the chain a lot faster
 
Oh, that's what you mean. Sure, I only need to apply the operations to a single frame. But that can still be a very expensive operation. Who knows what all needs to happen for that one frame to be created? Maybe that one frame depends on the contents of 2 other video streams
 
well, if some operations need to fully exhaust the frame iteration then that's that. just wanted to throw the idea out there.
I still haven't completely grasped how you wanted to design it, but that ^ is more or less what I mean.
 
12:38 PM
Yeah, sorry, it's proven to be trickier to explain than I anticipated
Appreciate the input, I'll figure something out
 
12:49 PM
I wonder how ffmpeg does all this. It's a command-line tool that works on video, audio, static images, etc. There's no obvious OOP-y bits from the user's perspective, but maybe there's some in the inner workings.
 
I don't think ffmpeg has this problem... You can't ask ffmpeg "Hey, if I execute this filter graph, what will the resolution of the output stream be?" At least, I don't think you can
 
Yeah I'm uncertain of that myself
Here is their implementation of the Crop filter. It's in C, so there may not be much fancy OOP work.
 
The moral of the story is that it doesn't pay off to be lazy. Be eager, then you save yourself a bunch of problems
 
Developer secret: simplify your class design by using a language that doesn't have classes
Ah, spoke too soon. Behold, a class:
typedef struct CropContext {
    const AVClass *class;
 
1:30 PM
Hmm, I was hoping that en.wikipedia.org/wiki/Filter_graph would have more discussion of design considerations
 
2:05 PM
I've got an idea... whether it'll work remains to be seen
 
2:54 PM
Actually, it's not
 
 
2 hours later…
5:24 PM
Welp, I'm parsing HTML with regex today
Or more specifically, I'm parsing aspx, which is 90% html and 10% fiddly template strings
 
If performance is not super-critical, pyparsing includes some HTML expressions that take care of a lot of HTML variability that are a pain to represent in regex.
It also allows you to target specific bits of a larger doc, if you are just trying to pull some individual pieces and ignore the rest.
 
5:47 PM
There isn't too much variability. I'm looking for any tag that resembles <asp:Label runat="server" Text="<%=KevinResources.Welcome %>" />. I need to replace %=KevinResources.Welcome with $KevinResourceString:Welcome.
Apparently "<%" style tags can embed text almost anywhere inside an aspx file. Inside an "asp:whatever" tag, however, you need "<$" style tags. And of course you can't use "<$" tags outside of an asp:whatever tag, so I can't just do a naive find/replace.
So the bright side is that the thing I'm searching for has no recursive elements. I only care about the attributes of a tag, and you can't embed an html tag inside an html tag's attribute. The contents of the "<%" tag can technically contain any arbitrarily complex C# expression (I think?), but I happen to know that all of mine only contain "KevinResources.whatever"
 
6:08 PM
Remember, there's a difference between "parsing" and "extracting information"
 
@Kevin I was struggling for hours today to try and make a non-interactive powershell shell pass a script with a Pause inside
I ended up changing the script...
 
We must embrace pain and use it as fuel on our journey
 
I remember you saying that once Kevin hmm
anyway, only time I ever played with powershell was when I did this: gist.github.com/secemp9/b54a4d3c66adf735d7b11a31f325d2cf
 
6:24 PM
I've cobbled together a regexy thing that does 95% of what I want. I still need to manually review matches, because Text="<%=KevinResources.Welcome %>" can also appear inside a JavaScript block. But I'd be reviewing the results manually even if I had a bulletproof solution, so it's fine
 
6:35 PM
You could parse the HTML... :P
 
7:05 PM
sample = """
<script>
</script>
<asp:Label runat="server" Text="<%=KevinResources.Welcome %>" />
"""

import pyparsing as pp
asp_label = pp.make_html_tags("asp:Label")[0]
asp_label.add_parse_action(pp.with_attribute(runat="server"))
print(asp_label.search_string(sample)[0].dump())
 
 
2 hours later…
8:38 PM
If anyone's curious, this is the design I ended up with. Streams have a Source from which they get data and metadata, and VideoStreams additionally have a video_metadata_source that they only use to get video metadata (like the resolution)
 
Cool, what program do you want to do?
 
It's essentially my own implementation of moviepy - manipulating videos and audio
 
Cool, what improvements do you intend to incorporate?
 
Documentation.
I'm half joking. Moviepy is an old mess, and semi-unmaintained. Heck, probably more than semi. But the main reason for why I'm creating this is... because it's surprisingly easy. It took me a few days to realize that I'm reimplementing moviepy, but then I was already half-finished so... might as well finish it now
 
8:57 PM
Nice, congrats!
pypi.org/project/moviepy: "Maintainers wanted!"
"As there are more and more people seeking support (320 open issues as of Sept. 2019!) and all the MoviePy maintainers seem busy, we’d love to hear about developers interested in giving a hand and solving some of the issues (especially the ones that affect you) or reviewing pull requests. Open an issue or contact us directly if you are interested. Thanks!"
 
Let it die, I say
 
Hehehe
 
I found a similar note earlier today about memory-profiler. I had spent 10 minutes trying to track down where an undefined profile name was coming from, to eventually figure out that I wasn't going crazy and it was memory-profiler injecting the name's import when you ran it on a module. Ew.
 
Huh. Weird... bug? Feature? I don't even know
 
feature for sure
I mean, intended feature :P
to make the best of that 10 wasted minutes I added a comment explaining this...
 
9:04 PM
If authors knew how much we get paid to write a few words, they'd be jealous!
Then again, no code has ever become a bestseller. Authors 1 - Programmers 1
 
The other fun thing I found today was in the release notes for conda 4.9.0:
> Bug fixes:

Stop env remove --dry-run from actually removing environments (#10261)
 
Ouch. That's one heck of an oversight
 
Hehe, yes. The fix had something like a 3-line diff, moving an rm_rf() call into an if :D
I'm somewhat surprised this was fixed in a new minor version, I'd have expected this to be fixed in a patch release when found. But I didn't bother looking up the history for the timeline.
 
Maybe one day the robots like ChatGPT will make software better than humans
 
9:17 PM
You do not believe?
 
Unless we blow up the Earth first, it's definitely going to happen
 
Ah, good to know I'm not the only one who thinks so, as currently the SO doesn't like the answers given by ChatGPT, for example.
It's certainly made by humans, but perhaps there will come a day when robots themselves will make AI software.
 

« first day (4498 days earlier)      last day (434 days later) »