Java – how do I store different types of objects in the same container / list?


The easiest thing would be to put them on a list of Objetos::

ArrayList listaContenedor = new ArrayList();

And to pick them up by assigning them to their respective types:

Gato gato = (Gato)listaContenedor.get(0);
Perro perro = (Perro)listaContenedor.get(1);
Pulpo pulpo = (Pulpo)listaContenedor.get(2);

You can also create the list without "input":

ArrayList listaContenedor = new ArrayList();

Documentation: java.util.ArrayList


How to use the JSON You have to put it in the dependencies (the objects) JSON They are very common, so they never hurt you in a project. You import them wherever you use them.

You can save them in objects JSON,
In this way, you can create different structures that are better for you in some cases.


JSONArray of JSONs

In this example, I see more clearly a JSON of JSONs in which the JSON Father can be treated as a container and create one JSON for each object so that you can treat them as different objects.

JSONObject jsonContenedor = new JSONObject();

JSONObject jsonGato = new JSONObject();
JSONObject jsonPerro = new JSONObject();
JSONObject jsonPulpo = new JSONObject();

//Pones los atributos de cada objeto en el JSON
jsonGato.put("nombre", "Garfield");

//Almacenar los jsons en el contenedor
jsonContenedor.put("gato", jsonGato);
jsonContenedor.put("perro", jsonPerro);
jsonContenedor.put("pulpo", jsonPulpo);

Then to get it:

JSONObject gato = jsonContenedor.getJSONObject("gato");
String nombreGato = gato.getString("nombre");

c ++ class template, custom container

So I wrote that class template for a custom container. Basically, elements and their occurrences are saved. If an element is moved into the container and it already exists, it only increases its counter.

#pragma once


// Template class for a tocc, or Thing Occurence Counter Container
class tocc

    // Increments the count of that item or creates a new pair if it doesn't exist
    void push(const T& item)
        // If no the item isn't found, create new pair with a count of 1
        if(_tocc.find(item) == _tocc.end())
            _tocc.insert(std::pair(item, 1));

    // Decrements the count of that item and erases it if the count reaches 0
    void pop(const T& item)
        // If the item is found
        if(_tocc.find(item) != _tocc.end())
            ( <= 1) ? _tocc.erase(item) :;

        // Do nothing if the item isn't found

    // Gets the count of a particular item
    // Returns the count if the item exists, 0 otherwise
    long int getCount(const T& item)
        if(_tocc.find(item) == _tocc.end())
            return 0;

    // Returns true if the item is present in the map, false otherwise
    bool contains(const T& item)
        return _tocc.find(item) != _tocc.end();

    std::map _tocc;

Here I have put all of the code in one "file" for the sake of simplicity, although I know that the best practice is to separate files into headers and source files (which I usually do).

I would like to know what can be improved with this implementation.

css – What is the cleanest way to reduce Gutenberg blocks to the width of a container?

With Gutenberg, blocks can be set to different widths. For example, an image can fill the standard grid container with around 1200 pixels or use the full window width. I have tested the following four CSS methods and have had problems with each approach. Which method works in real pages?

Gutenberg width selection

The well-known standard theme has a content area with full width and sets all blocks to container width if no special width adjustment is specified.

.entry-content > *:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.is-style-wide) {
  max-width: 58rem;
  width: calc(100% - 4rem);

Pro: Works with all blocks.

Con: Very stubborn CSS selector.

The content area is full width and is filled by all blocks. There is a special group block that reduces the blocks contained to the container width. This is the approach of the Elementor section block.

Pro: Works with all blocks, simple CSS

Con: Almost everything has to be wrapped up in this section block

The content area is full width. The Gutenberg blocks contain an element that shrinks to grid size.

lorem ipsum

Pro: Very simple CSS with explicit selectors

Con: Every single Gutenberg block has to be rewritten, as it normally doesn't have this element.

This is the approach of most topics. The content element has that at around 1200px. Each block that is wider gets a special CSS that grows above the parent block.

.entry-content .alignfull {
  margin-left: calc(-100vw/2 + 100%/2);
  margin-right: calc(-100vw/2 + 100%/2);
  max-width: 100vw;
  width: auto;

Con: Wrong width than 100vw contains the scroll bar, hacky CSS

Pros: none. It doesn't even work.

The Docker start does not go into the container

I cannot start my container. I always have to restart my PC to be able to upload it again. I would like to know what I'm doing wrong so that I can climb again in the event of a fall without restarting the PC. The commands below have been listed in the print below.

In short, I was wondering how to start a "dead" container.

CMD pressure

I have given the command:

Docker restart dbtest

and the return was:

Daemon error response: Container dbtest cannot be restarted: Driver could not program the external connectivity on the endpoint dbtest (af1a00ef5c1fb2653d64f5dd5fe028108d71288daa2e3c3edf6a37ba5eee80bc): Error when starting the Userland / proxy / exponent: Unforeseen / ported / exponented / ported

Disk Utility – What is the command to remove a container and reclaim space?

I tried to boot my Mac, but half of it failed and left me with a 50 GB container that I cannot delete. It's just one that I don't touch. I know there are commands to delete containers, but I don't know how to format them.
Here is the discussion list:

/ dev / disk0 (internal, physical):
0: GUID_partition_scheme * 500.3 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_APFS container disk2 443.0 GB disk0s2
3: Apple_APFS container disk1 49.1 GB disk0s3

/ dev / disk1 (synthesized):
0: APFS container scheme – +49.1 GB disk1
Physical Store disk0s3
1: APFS Volume Recovery 1.0 MB disk1s1

/ dev / disk2 (synthesized):
0: APFS container scheme – +443.0 GB disk2
Physical Store disk0s2
1: APFS Volume Macintosh HD 384.2 GB disk2s1
2: APFS Volume Preboot 42.2 MB disk2s2
3: APFS Volume Recovery 1.0 GB disk2s3
4: APFS Volume VM 2.1 GB disk2s4

ubuntu – Nginx error in Docker container: (111: Connection refused) when connecting to the upstream client

I run a Django app with Nginx in a Docker container and everything went fine until I rebuilt the container. Suddenly I get a 502 (Bad Gateway) error and the logs say

(111: Connection refused) during the connection to the upstream, client:

I have no idea what has changed, to be honest, and I'm new to Nginx. The Django / Python code should not have changed. I'm pulling the latest Nginx image, so there may have been a change that doesn't work well with my configuration. But I also tried older versions and get the same error. Maybe my app crashes because there is no port it is listening on? (see the screenshot)

I tried to customize ALLOWED_HOSTS ('*')Set SSL_NO_VERIFY to True and False, still the same error. I have no more options … I don't know how to debug it better. The app works well on site, so setting the debug to True didn't help me.

I just do not know. I deploy my app on an EC2 instance with nginx in a Docker container.

Here are my configurations and my build file:

server {

    listen 443 ssl;
    client_max_body_size 0;
    charset utf-8;
    ssl_stapling off;
    ssl_stapling_verify off;

    ssl_certificate            /etc/letsencrypt/live/;
    ssl_certificate_key       /etc/letsencrypt/live/;

    set $my_host $http_host;
    if ($http_host = "") {
          set $my_host "";

    location / {
        proxy_pass http://django:5000;
        proxy_set_header Host $my_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


server {
        listen 80 ;
        return 301$request_uri;
server {
        listen 80 ;
        return 301$request_uri;
server {
        listen 443 ;
        return 301$request_uri;
        ssl_stapling off;
        ssl_stapling_verify off;

        ssl_certificate           /etc/letsencrypt/live/;
        ssl_certificate_key       /etc/letsencrypt/live/;

version: '3'

      context: .
      dockerfile: ./compose/production/django/Dockerfile
    image: my_website_production_django
      - ./.envs/.production/.django
      - ./.envs/.production/.postgres
    command: /start

    container_name: 'nginx'
    image: nginx:latest
      - "80:80"
      - "443:443"
    volumes: ##The following files are found on AWS EC2 instance.
       - /home/ubuntu/nginx-conf/my.conf:/etc/nginx/conf.d/default.conf
       - /etc/letsencrypt/live/
       - /etc/letsencrypt/live/
      - django

    image: redis:5.0

You are welcome to provide further information or code if required. Really desperate and grateful for help. Thank you very much.

Development environment Python Flask, react with node and webpack and load it into a Docker container during operation

Is there a general guideline I could follow to set up a Python bottle development environment, node.js – webpack – react.js, in a Docker container that supports hot reload?

I followed a few instructions online, but couldn't set up a working environment because I want it to work.

Ideally, every change in the piston back end and in the reaction front end triggers a reload of the component and reflects the changes. All of this is in a Docker container that can be started with docker-compose. The best way to build a production build is with a separate command to deploy the app to a production environment from within the Docker container.

I am not choosing a ready-made solution from one of you, but a policy that should be followed. I also wonder how to structure the project in relation to the folder tree.

I am grateful for any information in any direction.


PHP – DI container with automatic wiring

For this reason, I have decided to write my own DI container for educational purposes and would like to receive feedback on how I can improve the quality of my code.

I am not sure about the documentation because I have most of my experience with closed source personal code. Therefore I would like to have some feedback.

Another area is where I use exit(), maybe an exception would be better? Although my experience here may be minimal Exception or RuntimeException?

I would also prefer answers to common best practices to personal preferences.

objects(get_class($object)) = $object;

     * Fetch a cached object from the container.
     * @param string $objectName
     * @return object
    public function fetch(string $objectName) : object {
        if (array_key_exists($objectName, $this->objects)) {
            return $this->objects($objectName);

        return $this->make($objectName);

     * Creates an object from its name and auto-wires constructor arguments.
     * @param string $objectName
     * @return object
     * @throws ReflectionException
    private function make(string $objectName) : object {
        $reflection = new ReflectionClass($objectName);

        if (!$reflection->isInstantiable()) {
            exit($reflection->getName() . ' can't be instantiated.');

        $arguments = $this->resolveArguments($reflection);

        if (count($arguments) < 1) {
            return $reflection->newInstance();
        else {
            return $reflection->newInstanceArgs($arguments);

     * Creates an array of arguments from a reflection class.
     * Uses default value if there is one, auto-wires the object if not.
     * @param $reflection
     * @return array
    private function resolveArguments($reflection) : array {
        $constructor = $reflection->getConstructor();
        $parameters = $constructor->getParameters();

        if (!$parameters) {
            return $reflection->newInstance();

        $arguments = ();

        foreach ($parameters as $parameter) {
            if ($parameter->isDefaultValueAvailable()) {
                $arguments() = $parameter->getDefaultValue();

            if ($parameter->getClass() == null) {
                exit($parameter->name . ' on ' . $reflection->getName() . ' needs a default value');

            $arguments() = $this->fetch($parameter->getClass()->getName());

        return $arguments;

layout – Should a box shadow be used on a container?

Is there a rule about where / when / how to use box shadows?

Short answer: No. In general, a box shadow is just a visual element, just like a background color or a border.

Long answer

Box shadows are known to work very well

– Levitation on boxes / modals to get the user's attention:

Enter image description here

– Introduction of visual depth as an indicator of the clickability of elements and containers

Enter image description here

And lately in dashboards:

– As a layout element to highlight action dashboard areas

Enter image description here

Depending on how many visual elements are already used in your dashboard and how much a shadow on your container fits into this composition, you can use it.

Ease of use – Should a container overflow the viewport?

I have a page that I am redesigning for my company and that is only used for the search. Pagination is used so that more and more results are loaded when the page is scrolled.

I wanted to use a container (white part) with rounded edges, but I wasn't sure if using a container is a bad practice if the viewport overflows for an indefinite number of scrolls. Is this bad practice?

I also tried setting a maximum height for the container and adding a scroll bar, but I think this will affect the user experience.

Am I worried too much, or is that okay?

Enter image description here