707 Matching Annotations
  1. Last 7 days
  2. Nov 2022
    1. js const { generateFragment } = await import('https://unpkg.com/text-fragments-polyfill/dist/fragment-generation-utils.js'); const result = generateFragment(window.getSelection()); if (result.status === 0) { let url = `${location.origin}${location.pathname}${location.search}`; const fragment = result.fragment; const prefix = fragment.prefix ? `${encodeURIComponent(fragment.prefix)}-,` : ''; const suffix = fragment.suffix ? `,-${encodeURIComponent(fragment.suffix)}` : ''; const textStart = encodeURIComponent(fragment.textStart); const textEnd = fragment.textEnd ? `,${encodeURIComponent(fragment.textEnd)}` : ''; url += `#:~:text=${prefix}${textStart}${textEnd}${suffix}`; console.log(url); }

  3. Oct 2022
  4. Sep 2022
    1. with careful screening and interviews.

      Hire Dedicated Angular JS Developers from iCoderz

      Do you want an AngularJS expert for your modern single-page app development needs? Hire dedicated Angular JS developers from India to develop secure and scalable web applications. We can help you build your Angular JS Development team with careful screening and interviews. https://bit.ly/3xLjhMl

    1. It works because in JavaScript, true && expression always evaluates to expression, and false && expression always evaluates to false. Therefore, if the condition is true, the element right after && will appear in the output. If it is false, React will ignore and skip it.

      Good example for the {var > 0 %% } type of expression.

    2. In JavaScript, class methods are not bound by default. If you forget to bind this.handleClick and pass it to onClick, this will be undefined when the function is actually called.

      Remember to BIND for Class Components or just USE arrow functions instead.

    3. You can put any valid JavaScript expression inside the curly braces in JSX. For example, 2 + 2, user.firstName, or formatName(user) are all valid JavaScript expressions.

      ANY JS!

  5. Aug 2022
    1. ```js const today = new Date(); today.setUTCHours(0,0,0,0); console.log("Today: ", today);

      const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); yesterday.setUTCHours(0,0,0,0); console.log("Yesterday: ", yesterday); ```

    1. ```js // Time of writing article = 14th January, 2022

      // ✅ Set date to Nearest Midnight in the Past const d1 = new Date(); d1.setHours(0, 0, 0, 0);

      console.log(d1); // Fri Jan 14 2022 00:00:00

      // ✅ Set date to Nearest Midnight in the future const d2 = new Date(); d2.setHours(24, 0, 0, 0);

      console.log(d2); // Sat Jan 15 2022 00:00:00 ```

    1. As other answers state, it's perfectly possible, because arrays in JavaScript are just objects. However, there is still the a question of whether it's a good idea or not. That's a "coding style" question, so it's hard to say objectively, but Douglas Crockford doesn't have a problem with it (at least in some cases). In JavaScript: The Good Parts, he actually uses the example of adding a "total" method to an array.

      Because an array is really an object, we can add methods directly to an individual array:

      ```js // Give the data array a total function

      data.total = function () {
          return this.reduce(add, 0);
      };
      
      total = data.total();    // total is 108
      

      ``` Since the string 'total' is not an integer, adding a total property to an array does not change its length.

    1. ```js let array = [1, 2, 3, 4, 5];

      for(let i = array.length - 1; i >= 1; i--) { let j = Math.floor(Math.random() * (i + 1)); // 0 <= j <= i let temp = array[j]; array[j] = array[i]; array[i] = temp; } ```

    1. The Widget API allows you to externally control the widget that is embedded on your website through javascript. You set the width and height of the widget to 0 and it hides the widget. I tinkered with this on codepen this week and I am pleased that I now have a working playlist ready to be utilized on my website.

      https://codepen.io/mdcrowcodes/pen/eYEMyzY

      ```js var iframeElement = document.querySelector('iframe'); var iframeElementID = iframeElement.id; var widget = SC.Widget(iframeElement); var x = document.getElementById("play");

      widget.bind(SC.Widget.Events.FINISH,function(){ widget.getCurrentSound(function(currentSound) { document.getElementById("currentTrack").innerHTML = currentSound.title; }); });

      function play(){<br /> if (x.innerHTML === "▶") { x.innerHTML = "||"; } else {x.innerHTML = "▶"; } widget.toggle(); };

      function next(){ x.innerHTML = "||"; widget.next(); widget.seekTo(0); widget.getCurrentSound(function(currentSound) { document.getElementById("currentTrack").innerHTML = currentSound.title; }); };

      function prev(){ x.innerHTML = "||"; widget.prev(); widget.seekTo(0); widget.getCurrentSound(function(currentSound) { document.getElementById("currentTrack").innerHTML = currentSound.title; }); };

      widget.bind(SC.Widget.Events.READY, function() { widget.getCurrentSound(function(currentSound) { document.getElementById("currentTrack").innerHTML = currentSound.title;

      widget.getSounds(function(tracks){ for (var i in tracks) {

         $('#tracklist').append("<li class='track-item' id='" + i + "'" + ">" + tracks[i].title + "</li>");
        }
      
       $(".track-item").click(function(){
         var s = this.id
         widget.seekTo(0);
      widget.skip(s);       
        x.innerHTML = "||" ;     widget.getCurrentSound(function(currentSound) {
      

      document.getElementById("currentTrack").innerHTML = currentSound.title; });

      });

      });

      }); }); ```

    1. ```js (function () { var html = document.documentElement.innerHTML;

      /** 
       * the iframe's onload event is triggered twice: once when appending it to the document, 
       * and once when the form finishes submitting and the new URL is loaded 
       */
      var loaded = 0;
      
      var iframe = document.createElement('iframe');
      
          // unique name, to make sure we don't create any conflicts with other elements on the page
          iframe.name = 'bookmarklet-' + Math.floor((Math.random() * 10000) + 1);
          iframe.style.display = 'none';
      
          iframe.onload = function () {
              // remove the iframe from the document on the second firing of the onload event
              if (++loaded == 1) {
                  return;
              }
      
              // you can also alert('Done!') here :)
              document.body.removeChild(iframe);
          };
      
      var form = document.createElement('form');
          form.method = "POST";
          form.action = "http://requestb.in/sbnc0lsb?nocache=" + Math.random();
          form.target = iframe.name;
      
      var textarea = document.createElement('textarea');
          textarea.name = 'source';
          textarea.value = html;
      
      form.appendChild(textarea);
      iframe.appendChild(form);
      
      document.body.appendChild(iframe);
      
      form.submit();
      

      })(); ```