I am having a hard time with my second year modules in computer science, mainly Data structures and algorithms alongside with pure math

I am having a hard time with my second year modules in computer science, mainly Data structures and algorithms alongside with pure math – Software Engineering Stack Exchange

How do you transform this code into pure functional javascript?

var files = ();
for (const entry of Object.entries(collection)) {
    var folder = "";
    entry.forEach(item => {
        if (typeof item == "string") {
            folder = item;
        }

        if (typeof item == "object") {
            item.forEach(file => {
                files.push(folder + "/" + file); // append files only (recursive)      
            })
        }
        
    });
    // sometimes lists contain names of children directories. check with the top parent to exclude directory names
    files = files.filter(x => !Object.keys(collection).includes(x));
}
console.log(files);

There is a javascript object collection which is a collection of key-value pairs representing some directory.
Each key is the name of a subdirectory and its value is of type list, particularly a list of filenames only that are inside that directory.

This code works and it gets a list of absolute filepath names from the base directory recursively through some additional logic and concatenation.

I’m having a hard time rewriting this code to purely use .map(), .filter(), .find() or curry methods

Feedback appreciated

8 – How to add an autocomplete field with pure javascript

I’m implementing the javascript library Annotorious which allow to add annotations on an image. My goal is to be able to link content with part of the image select with Annotorious. When we select a zone, Annotorious open a form we can personalize to add information we want link with the zone. In my case, I added a fieldtext but I want it uses the autocomplete but I don’t know how to activate this behavior.

Regarding the code in core/lib/Drupal/Core/Render/Element/FormElement.php, the form element add the class ‘form-autocomplete’ and the attributes ‘data-autocomplete-path’ equals to the url of an autocomplete function on his input and inject the library core/drupal.autocomplete. Regarding this, I tried to reproduce the same behavior. But I guess something is missing because my field doesn’t query my endpoint when I typed in it but I don’t know why. I was also thinking this maybe doesn’t work because it’s add by javascript after the loading of the page but in this case, I don’t know how to solve this problem.

Here my code:

My widget field:

class ImagePinWidget extends ImageWidget {

  public static function process($element, FormStateInterface $form_state, $form) {
    $element = parent::process($element, $form_state, $form);

    $element('preview')('#attributes') = array('id' => array('my-image'));

    $element('#attached')('library')() = 'my_module/image-pin';
    $element('#theme') = 'image_pin_widget';

    return $element;
  }

}

My my_module.libraries.yml

recogito-annotorious:
  version: 1.x
  css:
    component:
      /libraries/annotorious/annotorious.min.css: { minified: true }
  js:
    /libraries/annotorious/annotorious.min.js: { minified: true }

annotorious-toolbar:
  version: 1.x
  js:
    https://cdn.jsdelivr.net/npm/@recogito/annotorious-toolbar@latest/dist/annotorious-toolbar.min.js: { type: external, minified: true }

image-pin:
  version: 1.0.0
  css:
    component:
      css/image-pin.css: {}
  js:
    js/image_pin.js: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/drupalSettings
    - my_module/recogito-annotorious
    - core/drupal.autocomplete
    - my_module/annotorious-toolbar

image_pin.js:

(function ($, Drupal, drupalSettings, Annotorious) {

  'use strict';

  Drupal.behaviors.redacto_form_image_pin = {
    attach: function (context) {
      var config = {
        image:'my-image',
        widgets: (
          Drupal.behaviors.my_module_image_pin.nodeSelectorWidget,
        ),
      };

      var anno = Annotorious.init(config);

      Annotorious.Toolbar(anno, document.getElementById('toolbar'));
    },

    /**
     * Dynamic behavior when the status changes.
     *
     * @param $status
     */
    nodeSelectorWidget: function (args) {

      // 4. This part renders the UI elements
      var createField = function() {
        var input = document.createElement('input');

        input.classList.add('form-autocomplete');
        input.setAttribute('data-autocomplete-path', '/fr/autocomplete/custom');

        return input;
      }

      var container = document.createElement('div');
      container.className = 'nodeselector-widget';

      container.appendChild(createField());

      return container;

    }

  };

})(jQuery, Drupal, drupalSettings, Annotorious);

I precise the path /fr/autocomplete/insects return correctly a json list of content and autocomplete create in a usual form works correctly with it. Example of autocomplete I do in an usual drupal form with this custom autocomplete:

$element('test_autocomplete') = (
     '#type' => 'textfield',
     '#title' => t('Autocomplete Articles'),
     '#autocomplete_route_name' => 'my_module.custom_autocomplete',
   );

Cheap Fully Managed KVM VPS Hosting – Pure SSD Space – DDoS Protected – 24×7 server monitor – 99.9% Uptime guarantee | NewProxyLists

Dreamwebhosts Offering unmanaged & managed VPS hosting And Dedicated servers with Linux or Windows. We make sure your website is fast, secure, and always up so that you stay focused on what you do best. We offer everything that you need to build, host, and manage a website. Our top priority is to provide the best website hosting experience to our clients at an affordable cost.

10% discounted price on a first quarterly, semi-annually, and annually billing.

VPS Features:-

KVM Linux Server
Complete Root/SSH Access
Multiple Operating Systems
Choose your own Control panel
99.9% Uptime
Server Monitor
PayPal, Credit & Debit Cards
24×7 Live Chat and Ticket Support

Below is the list of SSD VPS plans:-

VPS I:-
CPU 1 vCore
Memory 1 GB
Storage 25 GB SSD
Bandwidth 1 TB
>>>> Price: $5.99/- month – Buy Now

VPS II:-
CPU 2 vCore
Memory 2 GB
Storage 40 GB SSD
Bandwidth 2 TB
>>>> Price: $12.99/- month – Buy Now

VPS III:-
CPU 2 vCore
Memory 4 GB
Storage 60 GB SSD
Bandwidth 3 TB
>>>> Price: $22.99/- month – Buy Now

VPS IV:-
CPU 4 vCore
Memory 8 GB
Storage 100 GB SSD
Bandwidth 4 TB
>>>> Price: $44.99/- month – Buy Now

VPS V:-
CPU 6 vCore
Memory 16 GB
Storage 200 GB SSD
Bandwidth 5 TB
>>>> Price: $81.99/- month – Buy Now

Free Add-ons provided with all plans:

SSL Certificate

  • Sectigo Domain SSL – $7.80 /yr
  • Let’s Encrypt SSL – Free

Website Backup Service
Payment Methods: PayPal, Credit & Debit Cards
We even offer a 30-day money-back guarantee, and there are no contracts or hidden fees.
In case you have any questions, you can contact our sales department by initiating a chat or by dropping an email to sales@dreamwebhosts.com

Connect with DreamWebHosts

Facebook
Twitter
LinkedIn
Instagram

algorithms – Need help understanding Knuth’s proof that: The set of all pure words is well-ordered by the relation >

In the paper linked below by Knuth and Bendix, theorem 1:

The set of all pure words is well-ordered by the relation ‘$>$

has a proof that I can’t seem to follow despite staring at it all day. I can’t even decipher what the notation is trying to represent.

So, we have four fixed sequences:

  • An infinite sequence of variables $v_1, v_2, v_3, …$ etc. (not relevant for Theorem 1)
  • A finite sequence of operators $f_1, f_2, f_3, …, f_n$
  • A finite sequence of degrees $d_1, d_2, d_3, .., d_n$
    • (i.e. degree of $f_4 = d_4$)
  • and a finite sequence of weights $w_1, w_2, w_3, …, w_n$
    • (i.e. weight of $f_4 = w_4$)

A word is then defined inductively as either a variable alone or an operator followed by an appropriate number of other words depending on the degree of said operator.

A ‘pure word’ is a word with no variables and the weight of a pure word, $alpha$ is defined as follows:

  • $w(alpha) = sum_j w_jn(f_j , alpha)$ where $n(f_j, alpha)$ is the number of occurrences of $f_j$ in the word $alpha$

Finally the relation $>$ that orders all pure words that is proved to be well-ordered is defined as:

$ alpha > beta $ if and only if:

    1. $w(alpha) > w(beta) $
    • (I’m assuming the ‘$>$‘ here is strict integer inequality and not the same ‘$>$‘ that is being defined.)
    1. $w(alpha) = w(beta)$ and $alpha = f_jalpha_1 … alpha_{dj}$, $beta = f_kbeta_1 … beta_{dk}$, and either:
    • 2a) $ j > k$; or
    • 2b) $j = k$ and $alpha_1 = beta_1,…, alpha_{t-1} = beta_{t-1}, alpha_t > beta_t$, for some $t, 1 leq t leq d_j$

Finally on page 266, for the proof that $>$ is well-ordered the exposition states:

Now let $alpha$ be a pure word with $n_j$ symbols of degree $d_j$. It is easy to prove inductively that:

$n_0 + n_1 + n_2 + … = 1 + 0.n_0 + 1.n_1 + 2.n_2 + …,$

i.e. $n_0 = 1 + n_2 + 2n_3 + …$

I don’t know whether it really is ‘easy’ to prove the above because I don’t really know what the above is.

I’m fairly sure symbols are just operators in this context of pure words but if $n_0, n_1,$ etc. are symbols then how are they being summed? Does $n_0$ in the above actually represent $w(n_0)$. That doesn’t seem to provide any clarity as to what is going on with the proof.

I’ve reread the first four pages of the paper multiple times and nothing seems to be getting any clearer:

https://www.cs.tufts.edu/~nr/cs257/archive/don-knuth/knuth-bendix.pdf

Any insight would be appreciated.

architecture – Combining a pure ECS with a FSM scheduling system

Flat update loop

The multi-phase design may be the root of the problem, because it creates a dependency graph of its own, misaligned to ECS’s dependency graph. The most direct solution would be to express the phases as a single ECS update.

If certain update function needs to be called multiple times (i.e. in different phases) during the update loop, you can pass the phase argument to that function. Even better, you could tell it what exactly you want in terms more specific than a phase. Like this:

updateMovement(playerOnly = true);
//...
updateMovement(playerOnly = false);

To alternate between player’s turn and everyone else’s, it may be okay to keep phases, but just 2 of them as a simple if-else branch. Alternatively, you may think of an animation queue, that may be played once calculations are complete.

Entity tracking lists

The issue of update sparsity (i.e. updates are skipping lots or most of the entities) in ECS is solved with entity lists. Ideally, you are supposed to use the entity lists from very beginning, to track which entities are relevant to which update function. The lists must be updated every time entity is created, modified or destroyed.

This approach may be applied to other aspects, such an AI or animation state (those may be FSMs). Allocate a list for each possible state (non-enums must be compressed to enums with clever mapping) and move entities between lists according to their current state. You also want to encapsulate the state to automate the list transfers.


These were the core issues, everything below is tangential.


One of they key features of rogue-likes is non-modality: one control scheme is used for all gameplay interaction. Picking item from the shelves and interacting with the cash register to deposit the money is the canonical way of trading, while displaying separate UI is antithetical to that.

Not saying that it’s a silver bullet, but so far as a player I find that more enjoyable — partly because an “immersive” design promotes well-thought shopping list of really valuable items, while most shopping UIs welcomed me to the bottomless repositories of garbage.

Non-modality should also play well with the ECS design.

High Performance US VPS Hosting – High Storage & Bandwidth – Pure SSD & HDD. | NewProxyLists

Hostpoco has been providing quality unmanaged VPS, Dedicated servers, and advanced solutions. We’re focused on customers who are looking for premium quality hosting on a reliable platform that performs beyond their expectations. We are working very hard to make our customers satisfied. We provide the best high-quality web hosting to our customers at a cheap price. Our main priority is to provide our customers with secure & private hosting services at an affordable price to fulfill all their hosting demands.

Pick the best plan that suits your needs.

All plans include:
– VPS Type OpenVZ
– Free Setup
– 1 IPv4 included
– 99 % Uptime Guarantee
– 24/7 Live Support
– Root / SSH Access
– Easy to use control panel to self-manage

View all plans here: https://www.hostpoco.com/cheap-us-vps-hosting.php

*VPS Startup Plan
– 1024 MB Memory – 30 GB Raid 10 Storage – 2 TB Monthly Traffic – 1 IPv4 included – only $14.99 /m.

*VPS Pro Plan
– 2048 MB Memory – 60 GB Raid 10 Storage – 3 TB Monthly Traffic – 1 IPv4 included – only $24.99 /m.

*VPS Premium plan
– 4096 MB Memory – 120 GB Raid 10 Storage- 4 TB Monthly Traffic – 1 IPv4 included – only $44.99 /m.

*VPS Elite Plan
– 8192 MB Memory – 180 GB Raid 10 Storage – 8 TB Monthly Traffic – 1 IPv4 included – only $84.99 /m.

If you have any questions about our services please send us an email at sales@hostpoco.com
We also have a live chat link on our website.

Follow us on Twitter: https://twitter.com/HostPoco
Find us on Facebook: https://www.facebook.com/HostPoco/

 

Cheap Fully Managed KVM VPS Hosting – Pure SSD Space – DDoS Protected – 24×7 server monitor – 99.9% Uptime guarantee | NewProxyLists

Dreamwebhosts Offering unmanaged & managed VPS hosting And Dedicated servers with Linux or Windows. We make sure your website is fast, secure, and always up so that you stay focused on what you do best. We offer everything that you need to build, host, and manage a website. Our top priority is to provide the best website hosting experience to our clients at an affordable cost.

10% discounted price on a first quarterly, semi-annually, and annually billing.


Features:-

KVM Linux Server
Complete Root/SSH Access
Multiple Operating Systems
Control panel (Virtualmin)
99.9% Uptime
Server Monitor
PayPal, Credit & Debit Cards
24×7 Live Chat and Ticket Support

Below is the list of SSD VPS plans:-

VPS I:-
CPU 1 vCore
Memory 1 GB
Storage 25 GB SSD
Bandwidth 1 TB
>>>> Price: $5.99/monthBuy Now

VPS II:-
CPU 2 vCore
Memory 2 GB
Storage 40 GB SSD
Bandwidth 2 TB
>>>> Price: $12.99/monthBuy Now

VPS III:-
CPU 2 vCore
Memory 4 GB
Storage 60 GB SSD
Bandwidth 3 TB
>>>> Price: $22.99/monthBuy Now

VPS IV:-
CPU 4 vCore
Memory 8 GB
Storage 100 GB SSD
Bandwidth 4 TB
>>>> Price: $44.99/monthBuy Now

VPS V:-
CPU 6 vCore
Memory 16 GB
Storage 200 GB SSD
Bandwidth 5 TB
>>>> Price: $81.99/monthBuy Now

Free Add-ons provided with all plans:

SSL Certificate

  • Sectigo Domain SSL – $7.80 /yr
  • Let’s Encrypt SSL – Free

Website Backup Service
Payment Methods: PayPal, Credit & Debit Cards
We even offer a 30-day money-back guarantee, and there are no contracts or hidden fees.
In case you have any questions, you can contact our sales department by initiating a chat or by dropping an email to sales@dreamwebhosts.com

Connect with DreamWebHosts

Facebook
Twitter
LinkedIn
Instagram

dynamic – pure function assignment

The second slides shows the value of $1-x$. When the slider position is changed, Dynamic attempts to update its argument (1 - x) with the new value from the slider. The problem is, however, that a value cannot be assigned directly to the expression 1 - x (it is not a symbol), so the the update would fail.

Instead, in the second argument of Dynamic we have to provide a function that does that update by carrying out an assignment to the appropriate symbol whose value is being tracked, I.e. x. So we need a function that, given the new position of the slider as input (I.e. the new value of $1-x$), calculates the new value of $x$ and assigns it to that symbol.

In this case, the second slides tracks $y=1-x$. Moving the slider gives a new value of $y$. What is the corresponding new value of $x$? It is, of course, $1-y$. So, given $y$, we have to calculate this new value and assign it to $x$.

We could use Function({y}, 1 - y) or, with slots, 1 - # &. The function must also do the assignment to $x$, so we add that too: (x = 1 - #)&. Note that we need the parentheses because, without them, the expression would be interpreted as x = (1 - #&), i.e. “assign this pure function to x”.

In short, you should read the second argument of Dynamic as providing the following information: “given the new value of the tracked expression, what variable should I update? And to what value should I updated it?”

Is a pure white background generally better (if the user preference is “light mode” that is)? Over say something with a lower color temperature

I asked this in context of eBay which originally had a garish yellow background that was just straining on my eyes as well when I saw how the old site looked like. And I know their strategy was to make the change subtle. However, was there any reason for the change aside from the designer-of-the-day’s preference?

However, in the end they became fully white. Is a pure white background generally better (if the user preference is “light mode” that is)? Over say something with a “slightly” lower color temperature.

Most night-shift like filters just reduce the blue level ending up with a yellowish screen. Contrast ratio wise, it’s not as high as black and white (i.e. 21:1) but it can still be well above 7:1 which is AAA compliant.

For example in this palette where I scaled the luminosity from -100% to 100%
The 90% color #f6f3e7 is at 18.89 contrast ratio with black text.

enter image description here

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123