Is creating a heterogeneous hierarchy in this way a bad way to use interfaces? What would a better design be?

So I’ve finally made some progress on the program which I’ve been discussing in some of my previous questions, but still have a variety of headscratchers related to “good coding” practices I’ve studied over a fair bit of time.

I have been making this program – basically, a kind of document editor – which uses an MVC-style, multi-layer architectural pattern for organizing and distilling the user interface and logic components, and one of the things I’m hung on is how to best use interfaces in the design. In particular, I have a problem that sounds very similar to the one here:

Is this bad design for a Shape interface?

Why avoid Java Inheritance “Extends”

(for the second question, I’m using C++, but it’s not unreasonable to say the same concern applies)

in that GUI elements – or “views” – can be dynamically created and destroyed, and thus there is a need to put them in some kind of common container, and following the lead of how this is typically done in most cases I use a hierarchy structure they can be added or removed from, like a tree. But each view is also quite different because it does different things and can emit different events, hence it needs a different interface, but also shares some functionality in common. And I’d ideally like to insulate the controllers from the specific GUI widget toolkit we are using (or even if we are using one at all, e.g. a text or web interface as in if you want to make a cloud program out of it). So what I have right now is a two-piece interface/implementation inheritance system which seems to go afoul of a number of “rules”, yet also seems to work.

In particular, all views derive their interfaces from:

class IMVCView {
public:
     virtual ~IMVCView() = default;

     virtual IMVCView *getParent() = 0;
     virtual IMVCView *getFirstChild() = 0;
     virtual IMVCView *getNextSibling() = 0;

     virtual IMVCView *addChildAtBeginning(std::unique_ptr<IMVCView> child) = 0;
     virtual IMVCView *addSiblingAfter(std::unique_ptr<IMVCView> sibling) = 0;
     
     virtual std::unique_ptr<IMVCView> removeChild(IMVCView *child) = 0;

     virtual void addController(std::unique_ptr<IMVCController> controller) = 0;
};

which isn’t quite so bad – however, it gets messy when it comes to actually creating the views. Namely, the problem is in the tree-handling methods. In particular, there is no reason to expect this code to vary between views, but it also isn’t “proper”, I don’t think, to inherit an implementation directly onto what would be supposed to be the extended interface to the parts that do actually vary. So it shares a lot of commonality with the issue described in the first link.

Moreover, in the second link, it is suggested that you should not inherit implementations as a means of code re-use at all, yet we have those tree methods there to befuddle us. Not only that, we need to execute a down-cast to do the actual node addition and removal anyways, which is what happens in the current setup as it stands. And to top it all off, though, I see interfaces like this in similar situations in “real life” code, which makes me think there isn’t really a vastly better way after all:

https://searchcode.com/file/73721724/fbopen/fbopen-libfbml/src/include/nsIDOMNode.h/

(here describing a document with multiple composed elements.)

I can think of some alternatives, but none seem entirely satisfactory. One possibility is to separate the nodes from the other parts of the view interface. Every view should derive from the node class and its own interface. But this then doesn’t really express nicely in the code that all views “are” views, but rather nodes. Another one is to forget the idea of expressing this with code and just keep it informal. Put an std::variant or similar into a generic tree container. But that doesn’t, of course, alleviate the casting.

Moreover, and perhaps more seriously, it ignores that in some cases the tree actually has deeper meaning on and thus more intimate connections to the backend, in that, depending on how the specific UI implementation works, it may actually compose the graphical details of those views together, such as putting a document window within the main editor. The way I address that problem right now is to define a “compositor” interface that would be implemented for each widget system, but then it involves type matching inside (casting and matching) to make sure that we aren’t trying to do an illegal composition like of views from two different, incompatible widget toolkits (which you shouldn’t do, but the seeming LSP rulebreaking smell is there).

That said, right now, the current setup seems to give rather limited boilerplate and it’s quick and easy to add and extend with views, but I’m not comfortable with it because it seems to run afoul of these various rules I’ve internalized, esp. in light of ominous warnings like these from the second link:

“It is easy to do and often seems like the right thing but it will make your code more difficult to maintain, test and evolve.”

After all, once it’s set and the program has evolved far enough, there won’t be much feasibility in changing it – so better do as much future-proofing now as you can.

So is there a better way?

iphone – Creating a copy of an ITunes backup using Apple ComputerMobile SyncBackup folder

Instructions found on internet says that I need to edit the:
“Info.plist” file.
Here is where the backup folder was found: “C:Users%username%AppDataRoamingApple ComputerMobileSyncBackup” folder, where “%username%” represents your Windows username

Proceeding with the instructions: 1) I copied and pasted a copy of the backup folder.
2) Renamed the copy with date, time and “nickname”.
3) opened the copied folder and found the Info.plist file.
4) Used Windows Notepad to open the Info.plist in order to edit it.
5) as directed went to the bottom of the file for the purpose of finding “Yourname’s iPhone” per this instruction: “Edit the last line, which should look similar to ” Yourname’s iPhone”. Change it to something like “Yourname’s iPhone – Dec 12, 2013″ so that you can easily identify the date of the backup.”
6) there was no such ‘last line’.

So my questions are: A) how can I edit the copied backup folder’s Info.plist since I did not find that line?
B)The instructions indicate that the purpose of changing the last line is to differentiate it from all other backup folders. However, in the Library listing where I found the original file, I did change the name of the copied file so from that I can differentiate it from all others. So the question is: do I really need to change the last (non-existant) line of the Info.plist file when I can easily differentiate the copied backup folder by the name change I performed?

Any help is, of course, gratefully appreciated.

magento2.4 – Why do some of my products not have a custome price check box when creating an order from the admin side? Magento 2.4

When creating an order in Magento 2.4, some of my products will have a custom price check box, and some of them won’t. The attributes for each are exactly the same. The only difference is the name. Is there a setting I’m missing that wouldn’t allow a product to have a custom price check box? There are no advanced pricing rules set up for either product.

missing custom price check box

8 – Creating an API via module routing files that includes csrf verification headers

I am working on migrating a custom API from D7 to D8 and am doing so by using module routing. I have a routing.yml file that looks like so:

ytp_user.api.login:
  path: "/api/v1/user/login"
  defaults:
    _title: "User API Login"
    _controller: 'Drupalytp_userControllerUserAPIController::login'
  methods: [POST]
  requirements:
    _csrf_request_header_token: "TRUE"
ytp_user.api.get_current_user:
  path: "/api/v2/user/me"
  defaults:
    _title: "User API Get Current User"
    _controller: 'Drupalytp_userControllerUserAPIController::getCurrentUser'
  methods: [GET]
  requirements:
    _custom_access: 'Drupalytp_userControllerUserAPIController::authorize'

In the first route, I am trying to validate a csrf token provided in the headers, via the requirement _csrf_request_header_token: "TRUE", however, this does absolutely nothing. It doesn’t validate or even check that the header exists as the documentation suggests it should.

I’ve tried replacing this with _csrf_token: 'TRUE' which at least checks that the token exists in the query, but I can’t get a valid token!!! If I grab a token from /session/token and then pass it along in the query as ?token=<token-from-session/token> then I just get an error saying the CSRF token is invalid.

Am I missing another step or is the documentation just straight up incorrect? I have been searching for hours and everything suggests that what I have should work, so why is the CSRF token not being validated properly?

Creating a regex to get multiple values and print

I'm looking for any help with the code below. Basically the ip:port string keeps changing and may contain more than one true value in str and i wonder if is possible to use a regex using the search function to get the all ip:port and print in demo.


<p id="demo"></p>

<script>
var str = "Please 127.0.0.1:80 locate where 127.0.0.2:80 occurs!";
var pos = str.search("b(?:(?:25(0-5)|2(0-4)(0-9)|(01)?(0-9)(0-9)?).){3}(?:25(0-5)|2(0-4)(0-9)|(01)?(0-9)(0-9)?):d{1,5}b");...
Code (markup):

Creating a regex to get multiple values and print

export – Creating a library of saved function values

I have a command of the form J[b,c,n] which outputs a list of complex numbers, obtained by using FindRoot. Some outputs take over 4 hours to compute and once computed I would like to be able to save the values obtained so if I switch computers or open a new notebook I can get the values without spending time computing again. I would also like, as I compute the function for different parameters, this file of outputs to automatically update, so it really is producing a library of saved outputs. This could then be distributed with the relevant notebook of code so other people using it can save time if they want to compute something previously computed.

I am aware of questions regarding DumpSave and ways to save outputs but I’m not sure if it can be used in the way I would like. Any pointers would be appreciated.

java – XStream deserializing simple XML keeps giving error saying no such field when it should be creating a collection

Trying to convert the following xml to java objects…

<?xml version="1.0" encoding="utf-8"?>
<layertypes>
  <layertype id="layer_1" label="first" />
  <layertype id="layer_2" label="Second" />
</layertypes>

with these classes:

@XStreamAlias("layertype")
public class LayerType {

    @XStreamAsAttribute
    private String id;

    @XStreamAsAttribute
    private String label;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getLabel() {
        return label;
    }
    public void setLabel(String label) {
        this.label = label;
    }
}

and

@XStreamAlias("layertypes")
public class LayerTypes {

    @XStreamImplicit(itemFieldName = "layertype")
    private List<LayerType> layertypes = new ArrayList<>();
    public List<LayerType> getLayertypes() {
        return layertypes;
    }
    public void setLayertypes(List<LayerType> layertypes) {
        this.layertypes = layertypes;
    }
}

and these classes and xstream are called from here:

        XStream xstream = new XStream();
        xstream.processAnnotations(LayerType.class);
        xstream.processAnnotations(LayerTypes.class);
        LayerTypes layerTypes = (LayerTypes) xstream.fromXML(inputStream);

and I get this:

com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field xbeans.LayerTypes.layertype
---- Debugging information ----
message             : No such field  xbeans.LayerTypes.layertype
field               : layertype
class               : xbeans.LayerTypes
required-type       : xbeans.LayerTypes
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /layertypes/layertype
line number         : 3
version             : 1.4.15
-------------------------------

Any clue what I’m doing wrong? Stepping through the debugger it’s like Xstream just can’t find or doesn’t have a mapper for the implicit collection. This seems like it should be so simple and I’ve tried following all the tutorials I’ve found. Yet always this error.

Creating a gma950 Kext in Xcode 6.2

I am trying to create a kext for the gma 950 graphics chip on my MacBook2,1. I have created kexts before, but I have never done anything this big. Do you know where I could get started, like source code from older drivers.

unity – Creating the Vertices and Triangle Indices for Voxel Generated Mesh

I am running into a problem with a compute shader I am writing to generate the vertices and triangle indices for a voxel generated mesh.

Currently, I am creating an AppendStructuredBuffer of triangle structs which just have the three vertices of a triangle and reading from the AppendStructuredBuffer to the CPU. When read to the CPU, I then read from the buffer and set it in a RWStructuredBuffer in the GPU. Following that, I run a compute shader kernel to parse the triangle buffer.

Obviously if I can do this all on the GPU I should since reading and writing between the CPU and GPU is expensive.

When trying to put it all in one kernel I run into problems however. Each voxel has a range of possible triangles (0-5) that can form in it. Because of that, I can’t simply use the dispatch id to put it in a RWStructuredBuffer (at least I don’t think so). That’s why using an AppendStructuredBuffer seems natural; it allows for the variable amount of triangles.

After getting the array of triangle vertices and array of triangle vertex indices, I bring them back to the CPU and set them to a mesh and render it. In the future I want to use a geometry shader to render the mesh since that is most likely more efficient, but I’m trying to take this one step at a time, and geometry shaders are a whole ‘nother beast I know nothing about.

javascript – Google meet is not creating admission message when the tab is not active

I was making an extension for google meet which will make a popup window of that message and keep message top of all windows. But for some reasons the admission request is not being created while the tab is not active or window is minimized. I use qt frame work for popup window and WebSockets and MutationObservers for real time data transaction.

var socket = new WebSocket("ws://localhost:<my port number>")
var observer = new MutationObserver(function(mutation){
    for(var i in mutations){
        if(mutation.type == "childList"){
            if(mutation.target == document.querySelector(<path to parent element were admission boxes are being created>)){
                socket.send("yeah message is now created")
            }
        }
    }
})
observer.observe(document.body, {childList:true, subtree:true})

I am clear with the qt part. The only problem is with google meet that it is not creating any admission box nodes when it is not active. I tried these things

  • setting an interval to change document.title to show that the page is still active.
  • dispatching “mouseover” event to document.body continuously
  • calling function window.focus()

I also tried to set the tab active by extension api function tabs.update(highlighted:true). But it didn’t work when the browser window is minimized. It there any way to make tabs stay focused even if browser windows are minimized.

This is what I mean by admission box of google meet. I don’t know which property is read by google before appending this element to the parent node.

enter image description here