Calling javascript in javascript works for some but not all scripts

The script loading is asyncronous, so when hljs.initHighlightingOnLoad() is called the scripts are not loaded yet.

Alternative 1

You can modify your loadScript() function to make it work with promises, which resolve when the script is loaded (taken from here):

function loadScript(url) {    
    return new Promise(function(resolve, reject) {
        var script = document.createElement("script");
        script.onload = resolve;
        script.onerror = reject;
        script.src = url;
        document.getElementsByTagName("head")(0).appendChild(script);
    });
}

Now you can call your code and be sure that all libraries are loaded before calling hljs.initHighlightingOnLoad():

(async function init() {
  await loadScript('https://polyfill.io/v3/polyfill.min.js?features=es6');
  await loadScript('https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js')
  await loadScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js')
  
  hljs.initHighlightingOnLoad();
})()

Alternative 2

You can modify your loadScript() function to make it load the scripts using defer and add an optional onload handler that you can use to call hljs.initHighlightingOnLoad():

function loadScript(url, onload)
{    
    var head = document.getElementsByTagName('head')(0);
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    script.async = false;
    script.onload = onload;
    head.appendChild(script);
}

loadScript('https://polyfill.io/v3/polyfill.min.js?features=es6')
loadScript('https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js')
loadScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js', () => {hljs.initHighlightingOnLoad()})

htaccess – How ExpiresByType and Header set Cache-Control works together?

ExpiresByType image/jpg "access 2 years"

First… to clarify, this should probably be image/jpeg, not image/jpg. image/jpeg is the official mime-type for JPEG files. Check the Content-Type HTTP response header associated with this response. For instance, if your server is sending JPEG files with a image/jpeg mime-type (as it should be), then the above directive is not doing anything.

Note that image/jpg has nothing to do with the file extension (eg. .jpg) that might be on the underlying filename. It refers to the mime-type the server is sending the resource as.

So, for the remainder of my answer, I assume this is the correct mime-type that your server is sending.

When will jpg files expire ? In 2 years or in one year (31536000 seconds) ?

The answer to this does depend on the type of request/response and what you are doing server-side. ie. Does the request map directly to a physical file or not? Since you mention “jpg files” then #1 below probably applies here (the most common scenario) and the “jpg file” will expire in 1 year.

1. Request maps directly to a physical .jpg file

The request maps directly to a physical JPEG file on disk (either directly or via an internal rewrite*1). eg. /myimage.jpg – which would indeed be the most common use case (ie. you are linking directly to your static resources) then the JPEG file will expire in 1 year, by the Header directive. This is because:

  1. <FilesMatch> (and <Files>) containers only match physical files.
  2. The Header directive is processed later and so will always override the Cache-Control header that mod_expires might otherwise set.

*1 Note that you could link to (ie. request) /get-image.php, but providing the request is internally rewritten directly to an underlying .jpg file on disk, eg. /some-image.jpg then the same applies.

2. Request does NOT map directly to a physical file

HOWEVER, if the request does not map to a physical file. For example, if either of the following scenarios is true (both are really the same):

  • You are linking to a PHP script that serves the JPEG image (either by creating it, or reading it from a different location, etc.) and there is no internal rewrite to a physical file.

    href="send-image.php?name=myimage.jpg&size=medium"
    
  • You are linking to a .jpg URL, eg. href="/myotherimage-medium.jpg" and you are internally rewriting this to a script (like above) that generates this image and returns it to the client.

Then the JPEG image will expire in 2 years since the <FilesMatch> directive will not apply, because the request does not map directly to a physical file.

Note that in both cases (scenario #1 and #2 above), the ExpiresByType directive will apply, but the Header directive will always override this if it is applied.

Actually, there is a further complication here… mod_expires sets 2 response headers Cache-Control: max-age and Expires. Expires is only for old browsers, all modern browsers prioritise the Cache-Control: max-age header. So, in case #1 above, where the request maps directly to a physical file then you’ll have a conflict of headers… Cache-Control: max-age will state that it expires in 1 year (overridden by the Header directive), whereas the Expires header will state that it expires in 2 years (set my mod_expires).

So, unless you have specific caching requirements*2 then use mod_expires only.

*2 mod_expires only sets the max-age directive on the Cache-Control header. If you need to set other directives, eg. no-store or must-revalidate etc. then you will need to use the Header directive instead (or as well as).

Reference:

android – Kotlin: setText not works

I’m trying change some text after load a fragment. It will be location tracker in future. So I’m testing change of the text.

build.gradle module:

android {
      buildFeatures{
        dataBinding = true
        viewBinding = true
    }
}

start.xml:

    <TextView
        android:id="@+id/location"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:text="Current GPS Location"
        android:textColor="#FF0000"
        android:textSize="30sp"
        android:textStyle="bold" />

Start.kt:

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil.setContentView
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.example.basic.databinding.StartBinding

import android.util.Log


class Start : Fragment() {

    private lateinit var binding: StartBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = StartBinding.inflate(layoutInflater)
        binding.location.setText("Hello World")
    }

}

Application runs without problem but setText Not works. Do you know why?

8 – REST API Guzzle POST gives timeout but the same call works if I run it on the server cli

I have Drupal running in a docker container and nginx running in another container.

When I do the login call through postman or directly on the webserver cli it works perfectly.
But when I do call from within my application I get a timeout after 30 seconds.

From server:

wodby@php.container:/var/www/html $ curl -X POST
‘http://api.swappr.localhost/user/login?_format=json’
-H ‘Postman-Token: a9c80844-ed69-4d24-b205-6475b7e469dc’
-H ‘cache-control: no-cache’
-d ‘{“name”:”logintest2@gmail.com”, “pass”:”password”}’
{“current_user”:{“uid”:”21″,”name”:”logintest2@gmail.com”},”csrf_token”:”yf5YBYyY4YvXCcufLyTWeKnvbhq5sdcZHpgmsVDeSRY”,”logout_token”:”PEarVS7vPi5idARarGQzrrXAYcJL9YkiXmoHw_a7yJE”}

In code:

$response = Drupal::httpClient()->post(
            'http://api.swappr.localhost/user/login?_format=hal_json',
            ('name' => 'logintest2@gmail.com', 'pass' => 'password')
        );

cURL error 28: Operation timed out after 30001 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Anyone knows what could cause this problem?

camera shutter works only with live view shooting

i have a canon EOS 550D but when it’s time to use it, the shutter stopped clicking. but when i used the live view shooting, the shutter works. did i clicked on something? or do i need some settings to reset?

How does magento product image caching works?

I uploaded some images to my products and they were visible fine on frontend. I then went and deleted those images from pub/media/catalog/product folder and also deleted pub/media/catalog/product/cache folder. When I open the media cache link of product I now see the default placeholder image. The path I use in my browser is media/catalog/product/cache/ca230af9a56e172d8d63e4842d175bbe/k/a/kars.jpg This is no way the path for the placeholder image. So now the question is:

  1. How is magento replacing the deleted image with placeholder image, instead of showing 404?
  2. How is the path not showing 404 since I had deleted those folders?

Thank you for your help.

video – Apple says the VP9 codec no longer works on Catalina. I want this codec for my older OS. Where can I find it?

Apple has a page listing “Media formats affected by the transition to 64-bit technology”:

In macOS versions up to and including macOS Mojave, third-party software has extended the QuickTime 7 framework to support many incompatible media formats. In macOS Catalina, the QuickTime 7 framework will no longer be available, so incompatible formats won’t be supported in Final Cut Pro, Motion and Compressor.

Here are examples of media formats affected by this transition:

The second item on the list of affected formats reads:

AV1 / VP9

I am on an older version of macOS, and I would very much like to have native support for VP9 in QuickTime! Unfortunately, I am not aware of any QuickTime components that add compatibility with VP9. Perian, which is listed seperately, only ever supported up to VP8.

Was there ever a VP9 codec, and if not, what is Apple’s page referring to?

dnd 5e – is the requirement of being in a lightly obscured area to gain the benefit of the Nature’s Mantle works in a heavily obscured area?

RAW, no, you cannot use the bonus action hide when heavily obscured, but it probably isn’t a problem to allow it.

Rules-as-written, the mantle only allows you to bonus action hide when lightly obscured, and lightly obscured is not the same thing as heavily obscured.

But it probably won’t break anything to allow this to work. First, it makes sense that heavily obscured would be a subset of lightly obscured, even though that relationship is not defined in the rules. Second, it only makes the Nature’s Mantle slightly more versatile – this does not seem like a balance breaking improvement to make. As explained below, the mechanical combat benefits of being hidden are already had without taking the hide action when heavily obscured.

You don’t have to hide if you are heavily obscured, unless you want to be unheard also.

Taking the hide action allows you to be unseen:

When you take the Hide action, you make a Dexterity (Stealth) check in an attempt to hide, following the rules for hiding. If you succeed, you gain certain benefits, as described in the “Unseen Attackers and Targets” section later in this section.

These benefits are:

When you attack a target that you can’t see, you have disadvantage on the attack roll. This is true whether you’re guessing the target’s location or you’re targeting a creature you can hear but not see. If the target isn’t in the location you targeted, you automatically miss, but the DM typically just says that the attack missed, not whether you guessed the target’s location correctly.

When a creature can’t see you, you have advantage on attack rolls against it.

So hiding lets you be unseen. But if you are in a heavily obscured area, you are already unseen:

A heavily obscured area–such as darkness, opaque fog, or dense foliage–blocks vision entirely. A creature effectively suffers from the blinded condition when trying to see something in that area.

So being in an area of heavy obscurity affords you all of the mechanical benefits in combat of hiding, that is, disadvantage on attack rolls against you, and advantage on attack rolls against targets that can’t see you.

If you want to be totally hidden, you still have to take the hide action, since heavy obscurity doesn’t do anything for sound.

c++ – Direct State Access (DSA) is Failing, but pre 4.3 OpenGL works

I currently have an OpenGL project in which I am using GLFW for the window and context creation, and GLAD for loading OpenGL functions. The GLAD version I am using is OpenGL 4.6, compatibility profile, with all extensions (including ARB_direct_state_access).

My current graphics card settings are

OpenGL Version: 4.6.0 NVIDIA 457.09
GLSL Version: 4.60 NVIDIA
Renderer: GeForce GTX 970/PCIe/SSE2
Vendor: NVIDIA Corporation

When I run the following non-DSA code, it works fine.

// Create vertex array object and bind it
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

// Create an index buffer object and use the data in the indices vector
GLuint ibo;
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicies.size()*sizeof(GLint), indicies.data(), GL_STATIC_DRAW);

// Create a array buffer object and use the positional data which has x,y,z components
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, positions.size()*sizeof(GLfloat), positions.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);

However when I try to translate this code to a DSA format and run it, the program opens a window and then terminates without and useful debug information.

GLuint vao;
glGenVertexArrays(1, &vao);

GLuint vbo;
glCreateBuffers(1, &vbo);
glNamedBufferStorage(vbo, positions.size()*sizeof(GLfloat), positions.data(), GL_DYNAMIC_STORAGE_BIT);
glVertexArrayVertexBuffer(vao, 0, vbo, 0, 0);
glEnableVertexArrayAttrib(vao, 0);
glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, 0);
glVertexArrayAttribBinding(vao, 0, 0);

GLuint ibo;
glCreateBuffers(1, &ibo);
glNamedBufferStorage(ibo, sizeof(GLint)*indicies.size(), indicies.data(), GL_DYNAMIC_STORAGE_BIT);
glVertexArrayElementBuffer(vao, ibo);

In both cases I bind the Vertex Array Object before drawing like so

glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, indicies.size(), GL_UNSIGNED_INT, 0);

Why is my DSA like code not working?

Trackpad works but it is not detected in System Preferences

about a month ago I spilled juice on the keyboard. I took my MacBook Air for a diagnostic and they told me it worked but the battery had gone bad. The battery repair cost is approximately 14000MXN or 700.94USD. It was very slow so I installed macOS Mojave on it and I can’t change the trackpad settings.
P.S.: The battery is included in the logic board and that’s why is so expensive.
Device: MacBook Air 2017
-José