Jump to content

Ingolme

Moderator
  • Content Count

    14,058
  • Joined

  • Last visited

  • Days Won

    69

Posts posted by Ingolme


  1. Obfuscated (minified) code is shorter and takes less time to download. Usually they'll have two versions of the code: the minified version and the regular version. If you're doing debugging it's best to use the regular version of the code. Minified code usually has the extension .min.js.

    I checked FabricJS. Here's the unminified version of it: https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.js

     


  2. The code is obfuscated in order to make it hard to read. All of it is ordinary Javascript syntax but arranged in a deliberately confusing fashion.

    1. That's how you declare a function as a property of an object. A simple example is below:

    var obj = {
      doSomething : function(a) { alert(a); }
    };
    obj.doSomething();

    2. This line of code is doing a lot of operations at once, so I'll have to unpack it.

    // 1. Using || to choose a non-empty value.
    // The || operator returns the first value which evaluates to a boolean "true".
    // If "t" already exists, then assign "t" to itself.
    // Otherwise, assign an empty array.
    t = t || []; 
    
    // 2. The return value of the assignment operator is the assigned value.
    // In this example, a takes the value that was assigned to b, so a = 5.
    a = (b = 5);
    
    // 3. Since "t" is an array it has a length property, which we assign to "r".
    r = (t = t || []).length;
    
    // Same as:
    t = t || [];
    r = t.length;

    3. The "?" is the conditional operator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

    It is like an if...else block but shorter. It has the format condition ? expression : expression where if the condition is true, the first expression is executed and if it is false then the second expression is executed. In the block of code that you are looking at, the code is equivalent to the following:

    if(r) {
      // FIRST EXPRESSION
      t.forEach(function(i, r) {
        i && i.type ? fabric.util.getKlass(i.type, n).fromObject(i, function(t, e) {
          e || (o[r] = t),
          s && s(i, t, e),
          a()
        }) : a()
      })
    } else {
      // SECOND EXPRESSION
      e && e(o)
    }

    4. The && operator evaluates items from left to right until it finds that one of them returns a false value. It will not evaluate any of the other expressions once a false value has been found. In this example, they're using it so that the expression "i.type ? ... : ..." only gets executed if the variable "i" exists.

    5. The || operator behaves the opposite to the && operator. It evaluates expressions from left to right and stops at the first one that returns a true value. If "e" exists and evaluates to a true value then the || operator will stop there and not evaluate the (o[r] = t) expression, therefore preventing the assignment from happening. It is equivalent to the following code.

    if(!e) {
      o[r] = t;
    }

     

    It's good to know these things, but if you ask me, it's not usually worth trying to look into obfuscated code.


  3. From PHP's end, you would use the $_FILES array as in this tutorial: https://www.w3schools.com/php/php_file_upload.asp

    I'm not familiar with Python's libraries, but if you can't find a library to upload files you're going to have to manually build the body of a file upload HTTP request which is not that easy. An easier alternative is to send a POST request where one variable contains the file contents and another variable contains the name of the file.

    Whichever way you do it, you should do some validation on the PHP end to prevent people from using this as a gateway to hack into your server. If they manage to upload a PHP file or another kind of executable file then they can do anything.


  4. I'm not sure how Python is sending the data, but your PHP code will depend on the format of the data.

    Assuming that Python is sending a JSON string, you can read the string using file_get_contents('php://input') and transform it into an array or object using json_decode().

    <?php
    $input = file_get_contents('php://input');
    $data = json_decode($input, true);
    
    // Print out the structure for testing
    var_dump($data);
    
    ?>

     


  5. I suspect some margins may be escaping the container. The quick solution to that would be to add overflow: hidden to #container.

    Another possibility is that images are changing the height of the container. Since DOMContentLoaded usually fires before images have loaded, the images are not adding to the height of the container at the time that the event fired.


  6. By default, the browser decides how much space to reserve for the columns based on how much content is in each one. I'm not sure if the W3C specifies an algorithm for this or if each browser just does its own thing.

    You can manually set the width of a column by setting the width of one of its cells, however a cell will always be forced to be wide enough to fit its content without overflowing.


  7. If you have a Content Management System (CMS), you will have to find or create a plug-in for the CMS that does that. If you don't have a CMS and there's no system for dynamically creating pages on your site then the sitemap will have to be created manually. Without knowing more about your website's back end I can't give a clear answer.

    • Thanks 1

  8. The idea of a view-model is a slight alteration to the ordinary Model-View-Controller paradigm. First of all, to make things clear, there's no solid definition for what MVC is, it's just the idea of dedicating one of three different functions to each piece of your software.

    In the paradigms that contain a view-model component (I've seen the Model-View-ViewModel paradigm mentioned before), a view-model is a model that is attached to a view in such a way that an alteration to the model directly alters the view that it is connected to without the need for a controller to read the model and pass the data to the view.


  9. You probably should check the security settings of each of your browsers. Whenever the website makes a request for the location, the browser asks the user for permission. If this is not happening it's likely that the browser has been configured to reject all location permission requests. Each browser has its own permission setting, it is not shared across browsers.

×
×
  • Create New...