Are ‘share this’ buttons really effective?

On a lot of websites (especially blogs), we find ‘share it’ buttons like this –> alt text.

Personally, I never used one. If I want to share something online, I copy the link and manually share it through SNS or IM. Other people claim that they use it, though.

Overall, are ‘share this’ buttons really worth putting on websites? Yes, they usually consume only a small amount of screen space and bandwidth, but is it worth it? Aren’t they just adding to visual noise?

what is soln and code for this problem

given string s1 and s2, we have to transform s1 to palindrome such that s1 contain s2 as substring in minimum opeartion, where operation is we can convert any character to an other character . print -1 if not possible .

Ex. : s1 = arbcd, s2 = ar output : 2 s1 = aaaaa, s2 = bbb output : 3

youtube-dl: ERROR: This video is not available… Which video?

When using youtube-dl version 2019.07.16, if I run the following command:

$   youtube-dl --get-id 

I will sometimes get an output like this example:

dIJxA-_1MVM gE3xeJC_G_L ITll8zhfvwk ERROR: This video is not available. dQw4w9WgXcQ 

This will happen if the user or YouTube removes the video in question. The only issue is, this does not say which video this message is referring to.

Am I just missing one of youtube-dl’s many flags?

I need help debugging this Spotlight implementation

I’m hoping someone can help me debug this wacky implementation of a Spotlight done in Java LWJGL that I found online. Basically, I found the bug, but I cannot figure out how to fix it so that the math makes sense.

The bug is that the code takes an angle and converts it radians and takes the cosine TWICE before passing it to an Open GL fragment shader. The value that the shader gets for the spotlight’s cutoff angle is like 0.99991065.

The first part of the bug appears in this class on lines 93-94:

    float cutoff = (float) Math.cos(Math.toRadians(140));     SpotLight spotLight = new SpotLight(pointLight, coneDir, cutoff); 

The value being passed to with “cutoff” is -0.76604444. So that’s the cosine of 140 degrees in radians… so far I’m ok.

The second part of the bug is in the constructor of the Spotlight class itself:

public SpotLight(PointLight pointLight, Vector3f coneDirection, float cutOffAngle) {     this.pointLight = pointLight;     this.coneDirection = coneDirection;     setCutOffAngle(cutOffAngle); } 

Combined with its setCutOffAngle method:

public void setCutOff(float cutOff) {     this.cutOff = cutOff; }  public final void setCutOffAngle(float cutOffAngle) {     this.setCutOff((float)Math.cos(Math.toRadians(cutOffAngle))); } 

Do you see the wackiness I’m talking about??? It’s treating the radian angle like degrees, converting it to radians again, and then setting the actual cutoff value to the cosine of that! That value is like 0.99991065 and that is what is passed to the fragment shader’s code.

This is the code in the actual fragment shader that uses the resulting value(line 112):

vec4 calcSpotLight(SpotLight light, vec3 position, vec3 normal) {   vec3 light_direction = - position;   vec3 to_light_dir  = normalize(light_direction);   vec3 from_light_dir  = -to_light_dir;   float spot_alfa = dot(from_light_dir, normalize(light.conedir));    vec4 colour = vec4(0, 0, 0, 0);    if ( spot_alfa > light.cutoff )    {       colour = calcPointLight(, position, normal);       colour *= (1.0 - (1.0 - spot_alfa)/(1.0 - light.cutoff));   }   return colour;     } 

So I understand the concept of the Spotlight and it’s cutoff angle, but I’m not good at math or linear algebra. I’m hoping to learn how to use dot products and normalization from good examples. But this has got me totally confused. Yes, I can jury rig it to work by making my degree angle run through this bizarre double cosine(toRadians()) logic, but I’d rather do the math correctly…

Can anyone tell me how to fix this? This particular repository has been dormant for a couple years but it is still my top google search result and many people have recommended it online.

I really appreciate any expert help.

edit: maybe “bug” isn’t the right word for this. But I consider it a bug if the implementation intends for you to pass it an angle in degrees, but actually requires you to pass the value in radians…

Why is this expand/collapse all button not working in webpart?

I added a content editor webpart and added some code to it by linking it to an HTML file. I copied the code from It is a collapsible section web component with expand/collapse all buttons.

This code works when I test it in my Brackets software however, when I import it into SharePoint the menu keeps opening and closing immediately when i click the “expand all” button. It must stay open when clicked and close when I click the “collapse all” button.

Thank you in advance for your time and consideration!

<html> <head>     <style>         .wrapper {            margin: 0 auto;            max-width: 50em;            min-width: 18.75em;                     }         header, main, footer {             display: block;             text-align: center         }          h1, h2, h3 {                 font-family: Verdana, serif;                 color: #545f1d;                 font-weight: lighter;                 }         h1 {                 font-size: 4em;                 }         h2 {                 font-size: 1.3em;                 text-align: left;                 }         p {                 text-align: justify;                 font: 12pt/1.5 Verdana, Arial, Helvetica, "Luxi Serif", sans-serif;                 color: #000;                 }         /* button styling */          .controls {          text-align: right;          margin-bottom: 1em;         }          .controls li {           display: inline;         }          button {           background: green;           color: #fff;           border: 0;           font-size: 0.85rem;           border-radius: 0.25rem;         }          /*         Custom elements are inline by default         */         toggle-section {           display: block;         }          /*         Only applies if script runs and          `role="region"` is added         */         toggle-section[role="region"] {           border-width: 2px 0;           border-style: solid;         }          toggle-section[role="region"] + toggle-section {           border-top: 0;         }             </style>          <main>             <div class="wrapper">       <toggle-section open="false">         <h2 id="section-1">Section 1</h2>         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non lectus sit amet nunc facilisis molestie. Praesent quis libero et mauris facilisis dignissim at sed nisi.</p>          <p>Nullam efficitur porttitor lectus, ac finibus nibh fermentum ac. Phasellus aliquam, nibh non efficitur pharetra, tellus diam posuere lectus, a consequat elit ex nec ligula.</p>       </toggle-section>       <toggle-section open="false">         <h2 id="section-2">Section 2</h2>         <p>Aliquam erat volutpat. Nulla facilisi. Nunc porttitor, elit non eleifend aliquam, est leo scelerisque nibh, nec faucibus odio urna ac nulla.</p>          <p>Maecenas laoreet in metus eget convallis. Vivamus at eleifend felis. Proin non vehicula neque. Etiam eleifend sapien ut nulla malesuada, ac condimentum nisl efficitur.</p>       </toggle-section>             </div>         </main>      <script type="text/javascript">         (function() {       // Check for <template> support       if ('content' in document.createElement('template')) {         const tmpl = document.createElement('template')          // Create the web component's template         // featuring a <slot> for the Light DOM content         tmpl.innerHTML = `           <h2>             <button aria-expanded="false">               <svg aria-hidden="true" focusable="false" viewBox="0 0 10 10">                 <rect class="vert" height="8" width="2" y="1" x="4"/>                 <rect height="2" width="8" y="4" x="1"/>               </svg>             </button>           </h2>           <div class="content" hidden>             <slot></slot>           </div>           <style>             h2 {               margin: 0;             }              h2 button {               all: inherit;               box-sizing: border-box;               display: flex;               justify-content: space-between;               width: 100%;               padding: 0.5em 0;             }              h2 button:focus svg {               outline: 2px solid;             }              button svg {               height: 1em;               margin-left: 0.5em;             }              [aria-expanded="true"] .vert {               display: none;             }              [aria-expanded] rect {               fill: currentColor;             }           </style>         `         // Check for latest Shadow DOM syntax support         if (document.head.attachShadow) {           class ToggleSection extends HTMLElement {             constructor() {               super()                // Make the host element a region               this.setAttribute('role', 'region')                // Create a `shadowRoot` and populate from template                this.attachShadow({ mode: 'open' })               this.shadowRoot.appendChild(tmpl.content.cloneNode(true))                // Assign the toggle button               this.btn = this.shadowRoot.querySelector('h2 button')                // Get the first element in Light DOM               const oldHeading = this.querySelector(':first-child')               // and cast its heading level (which should, but may not, exist)               let level = parseInt(oldHeading.tagName.substr(1))               // Then take its `id` (may be null)               let id =                // Get the Shadow DOM <h2>               this.heading = this.shadowRoot.querySelector('h2')                // If `id` exists, apply it               if (id) {        = id               }                // If there is no level, there is no heading.               // Add a warning.               if (!level) {                 console.warn('The first element inside each <toggle-section> should be a heading of an appropriate level.')               }                // If the level is a real integer but not 2               // set `aria-level` accordingly               if (level && level !== 2) {                 this.heading.setAttribute('aria-level', level)               }                // Add the Light DOM heading label to the innerHTML of the toggle button               // and remove the now unwanted Light DOM heading               this.btn.innerHTML = oldHeading.textContent + this.btn.innerHTML               oldHeading.parentNode.removeChild(oldHeading)                // The main state switching function               this.switchState = () => {                 let expanded = this.getAttribute('open') === 'true' || false                  // Toggle `aria-expanded`                 this.btn.setAttribute('aria-expanded', expanded)                 // Toggle the `.content` element's visibility                 this.shadowRoot.querySelector('.content').hidden = !expanded               }                this.btn.onclick = () => {                  // Change the component's `open` attribute value on click                 let open = this.getAttribute('open') === 'true' || false                 this.setAttribute('open', open ? 'false' : 'true')                  // Update the hash if the collapsible section's                  // heading has an `id` and we are opening, not closing                 if ( && !open) {                   history.pushState(null, null, '#' +                 }               }             }              connectedCallback() {               if (window.location.hash.substr(1) === {                 this.setAttribute('open', 'true')                 this.btn.focus()               }              }              // Identify just the `open` attribute as an observed attribute             static get observedAttributes() {               return ['open']             }              // When `open` changes value, execute switchState()             attributeChangedCallback(name) {               if (name === 'open') {                 this.switchState()               }             }           }            // Add our new custom element to the window for use           window.customElements.define('toggle-section', ToggleSection)             // Define the expand/collapse all template           const buttons = document.createElement('div')           buttons.innerHTML = `             <ul class="controls" aria-label="section controls">               <li><button id="expand">expand all</button></li>               <li><button id="collapse">collapse all</button></li>             </ul>             `            // Get the first `toggle-section` on the page           // and all toggle sections as a node list           const first = document.querySelector('toggle-section')           const all = document.querySelectorAll('toggle-section')            // Insert the button controls before the first <toggle-section>           first.parentNode.insertBefore(buttons, first)            // Place the click on the parent <ul>...           buttons.addEventListener('click', (e) => {             // ...then determine which button was the target              let expand = === 'expand' ? true : false              // Iterate over the toggle sections to switch             // each one's state uniformly   , (t) => {               t.setAttribute('open', expand)             })           })         }       }     })()         </script> 

Vue.js Two Way Communication Using Objects As Probs – Is this an Anti-Pattern?

Typically the way to communicate between parent <-> child component in Vue.js is to send the child a prop and emit an event from the child, which is listened to on the parent.

However, if you pass in an object to a child prop, updating the object in the child will update the object in the parent as objects are passed by reference, not copied.

This basically provides two-way communication in a much simpler way, however, I never see this method referenced in any official tutorials. This suggests it may be an anti-pattern (you arent suppose to modify props in the child) but if it is, why? It achieves what I want. What could be the consequences of communicating in this way?

Should this class be immutable?

Say I have a class that is used to monitor the size of a directory. Currently it can only monitor the size of a single directory:

public class DirectoryMonitor {      private final File absolutePathToDirectory;      public DirectoryMonitor(final File absolutePathToDirectory) {         this.absolutePathToDirectory = checkNotNull(absolutePathToDirectory);     }      public BigInteger getSizeOfDirectoryInBytes() {         return FileUtils.sizeOfDirectoryAsBigInteger(absolutePathToDirectory);     } } 

Would it be better to have it able to monitor the size of any directory?

public class DirectoryMonitor {     public BigInteger getSizeOfDirectoryInBytes(final File absolutePathToDirectory) {         return FileUtils.sizeOfDirectoryAsBigInteger(absolutePathToDirectory);     } } 

I prefer the first example since it’s immutable: an instance of DirectoryMonitor can only ever operate on one directory throughout the instance’s lifetime.

Is this variation of the assignment problem NP-hard, and does it have a name?

I’m trying to solve a problem very similar to the assignment problem, with a few twists.

The problem has a certain amount of workers, and a certain amount of tasks – workers is always >= tasks. Each agent has a cost to perform each task. The goal is to assign workers to tasks such that the total cost is minimized. However, there are far more workers than tasks, and multiple workers can be assigned to a task. A task has a “capacity” of how many people can be working on it. Thus far, what I have described can still be considered the assignment problem and the constraint of multiple workers to a task can be solved with the Hungarian Algorithm by cloning tasks to the amount of workers that can perform them at once. However, there’s one last constraint that breaks pretty much everything: workers have a type and only workers of the same type can work on the same task. Tasks do not have types, but the workers who work on them must all have the same type. I suspect this problem is NP-hard and has to be solved with probabilistic optimization algorithms.