javascript – Is there any global variable i can use for mobile phone?

Im trying to prevent default on form refresh on mobile phone. It works fine for my mac laptop but on my laptop it still resubmits the form.

This code works for Mac because i can use the “window” global variable, is there a global variable or code that would work for my mobile phone? Anything that pertains to a mobile phone?

      if ( window.history.replaceState ) {

         window.history.replaceState( null, null, window.location.href );
     }

Using a shortcode with global $product multiple times within a WooCommerce product page

I’m trying to create shortcode for the SKU so I can use it to prefill a mailto link for enquiries from the product page. This means I need to use the shortcode twice on the same page (to put it in the email title and body).

Using the following code works perfectly if the (sv_sku) shortcode is only used once in a page.

function skyverge_echo_wc_sku() {
 global $product;
 return $product->get_sku();
}
add_shortcode( 'sv_sku', 'skyverge_echo_wc_sku' );

However, if I try and use the shortcode twice on the page, then I get a blank screen and in the error logs it says there was an error on the return line:

PHP message: PHP Fatal error: Uncaught Error: Call to a member
function get_sku() on null

I’m at a loss here. Is it to do with calling global $product multiple times? Or am I missing something more fundamental?

Thanks

Why is vscode’s python designed to be able to go to the global variables of other modules by go to declaration?

As far as I know, the global variables of other modules are not available, right?

theming – Using TWIG in views global custom text to test for a specific content type

I am filtering for two custom content types to display on a page in Drupal 9 Views: “Artwork Page” and “Cover Page”. I want to apply special html tags to “Cover Page”. I have researched and tried many field names for “Content Type” but to no avail. In this instance, Views’ replacement pattern for Content Type is {{ type }} but using this in the TWIG if statement doesn’t work. I’ve tried both the machine name (cover_page) and value (Cover Page).

{% if type == 'cover_page' %}
  <h1>THIS IS THE BEGINNING</h1>
{% endif %}

{% if type == 'Cover Page' %}
  <h1>THIS IS THE BEGINNING</h1>
{% endif %}

Neither of these worked.

Local And Global Scope Variables In Javascript

Global Variables − A global variable has a global scope which means it can be defined anywhere in your JavaScript code.
Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.

blockchain – Suppose crypto is adopted globaly, and 100 years pass. Where would 100 years worth of global transactions/smart contracts be stored?

(…) each computer has the entire chain downloaded onto the hard drive? Or do we merely query the chain from designated nodes?

Full-nodes (a node is a wallet etc) typically store a full copy of the transaction journal (blockchain) locally in non-volatile storage – typically a hard-disk. Not in memory (RAM).

Pruning nodes discard transaction data that has been processed and that they no longer need – this greatly reduces their storage needs. It does slightly hamper other new full-nodes processing the full transaction journal – they have to find other, non-pruning, sources for pruned blocks. They need to do this to independently and trustlessly determine the current state (the set of monetary amounts valid for use as inputs in future transactions)

Lightweight nodes, mostly those that use Simplified Payment Verification (SPV), trust other nodes to store the full transaction journal. They don’t store a permanent local copy of the transaction journal to any significant extent.

In future it may be that, in the next 100 years, SPV nodes will predominate or that non-volatile storage will be smaller, cheaper and higher capacity, or that changes to the network protocols etc will address this in novel ways.

❓ASK – Most of the global population have phones – Could this help crypto? | NewProxyLists

One of the major concerns when it comes to the use and implementation of cryptocurrency, apart from the security and usage concerns, is the infrastructure that is needed in order to be able to make use of these payment systems. However in a recent article it is shown that out of the 1.7 billion people worldwide that do not have access to any finances, over 65% of these people still have a cell phone. Do you think that this shows that they will still have the potential to make use of cryptocurrency?

nt.number theory – Artin L-series for non-geometric extensions of global function fields

There is a theorem of A. Weil on Artin L-series (Page 129 of Number Theory in Function Fields):

Let $L/K$ be a geometric, Galois extension of global function fields. Denote by $q$ the number of elements in the constant field. Let $L(s,chi)$ be a corresponding Artin L-series and assume that $chi$ is irreducible and non-trivial. Then $L(s,chi)$ is a polynomial in $q^{-s}$. In particular, this implies that $L(s,chi)$ has a holomorphic continuation to the whole complex plane. Moreover, denoting by $m$ the degree of $L(s,chi)$ in $q^{-s}$, we
have
$$L(s,chi)=prod_{i=1}^m(1-pi_i(chi)q^{-s}),$$
where for each $i$ with $1le ile m$, $|pi_i(chi)|=sqrt q$.

Here $L/K$ being geometric means the constant field of $L$ is the same as $K$. For the general case that $L/K$ is not geometric, I wonder if there is a similar formula for $L(s,chi)$, but I found no references. Any help will be appreciated.

c++ – Creating a threadsafe, mutable, global configuration struct wrapper with C++17

I’m trying to create a relatively simple class that stores global configuration in some serializable struct, and reads/writes from/to a file.

My main goal is to make this class easy to use correctly. While it’s not a public library, there will be a sizable team using it in many parts of the codebase and I want to make it obvious to use in new code.

Settings.h

#pragma once

#include <exception>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <shared_mutex>

/// Represents global configuration based on a struct.
/// Provides abilities to load/save to a file.
///
/// @param SettingsStruct The following global overloads must exist for
/// serialization to/from streams:
///
///   ostream& operator<<(ostream&, const SettingsStruct
///   istream& operator>>(istream&, SettingsStruct&);
///
template <typename SettingsStruct>
class Settings {
 private:
  SettingsStruct settings_;
  mutable std::shared_mutex mutex_;
  std::filesystem::path filename_;

 public:
  /// Attempts to open file and initialize in-memory settings.
  Settings(std::filesystem::path filename);

  /// @note Calls Commit() before destruction
  ~Settings() { Commit(); }

  Settings(const Settings &) = delete;
  Settings &operator=(const Settings &) = delete;
  Settings(Settings &&) = delete;
  Settings &operator=(Settings &&) = delete;

  /// Commits in-memory settings to a file
  void Commit() const;

  /// @return a copy of the current settings
  SettingsStruct Get() const {
    std::shared_lock lk(mutex_);
    return settings_;
  }

  /// Safely locks + mutates the current settings based on the given transform
  /// function.
  ///
  /// @return a copy of the mutated settings
  ///
  /// @example
  ///   settings.Mutate(()(auto old){ old.SomeGroup.Nested = 4.0; return old; }
  template <typename Func>
  SettingsStruct Mutate(const Func &transformFunction) {
    std::scoped_lock lk(mutex_);
    settings_ = transformFunction(settings_);
    return settings_;
  }
};

template <typename SettingsStruct>
Settings<SettingsStruct>::Settings(std::filesystem::path filename)
    : filename_(filename) {
  std::ifstream ifs(filename);
  if (ifs.is_open()) {
    ifs >> settings_;
  } else {
    std::cerr << "warning could not open settings file "
              << std::filesystem::absolute(filename);
  }
}

template <typename SettingsStruct>
void Settings<SettingsStruct>::Commit() const {
  std::scoped_lock lk(mutex_);
  std::ofstream ofs(filename_);
  ofs << settings_;
}

main.cpp

#include <fstream>
#include <future>
#include <iostream>

#include "Settings.h"

using namespace std;

struct SomeGroupedSettings {
  float Nested = 0.1;  // default
  string Address = "asdf";
};

struct MySettings {
  int Version = 1;

  SomeGroupedSettings SomeGroup = {};
};

ostream &operator<<(ostream &out, const MySettings &s) {
  out << s.Version << 'n'
      << s.SomeGroup.Nested << 'n'
      << s.SomeGroup.Address << 'n';
  return out;
}

istream &operator>>(istream &in, MySettings &s) {
  in >> s.Version;
  in >> s.SomeGroup.Nested;
  in >> s.SomeGroup.Address;
  return in;
}

int main(int argc, char **argv) {
  const auto filename = argc > 1 ? argv(1) : "config.txt";

  // clean file for testing
  {
    ofstream ofs(filename);
    if (! ofs.is_open()) return 1;
    ofs << "1n0.5nold_addressn";
  }

  Settings<MySettings> settings(filename);

  cout << "Loaded settings:n" << settings.Get() << endl;

  auto a = std::async(std::launch::async, ((&)() {
                        cout << "Changing address in other thread..." << endl;
                        settings.Mutate(()(auto old) {
                          old.SomeGroup.Address = "new_address";
                          return old;
                        });
                        cout << "Changed address in other thread:n"
                             << settings.Get() << endl;
                      }));

  cout << "Changing settings in other thread..." << endl;

  settings.Mutate(()(auto old) {
    old.SomeGroup.Nested = 101.3;
    old.Version = 3;
    // leave SomeGroup.Address alone
    return old;
  });

  cout << "Changed settings in main thread:n" << settings.Get() << endl;
}

Example output

Loaded settings:
1
0.5
old_address

Changing Nested in main thread...
Changing Address in other thread...
Changed Address in other thread:
3
101.3
new_address

Changed Nested in main thread:
3
101.3
new_address


With config.txt looking like:

3
101.3
new_address

Questions/not questions:

  • I will replace the <</>>-based serialization scheme with a parser based on Nlohmann’s JSON Library in the future. I’m not looking for feedback on this.

  • Get() will be called often, while Mutate will be called rarely.

  • Performance is not a massive concern, but obvious improvements are obviously welcome.

  • The pattern for Mutate that I came up with (passing a mutator as an argument) doesn’t seem widely used, or at least I’m not searching the right terms.

    • What are some better ways to handle mutation of shared classes?

    • Is the design of Mutate a terrible or particularly strange design? What are its pitfalls and why isn’t it more common? I can’t find much about it.

  • How could I add threadsafe move operations to this? It might be useful.

Any feedback, or examples of this sort of thing in the wild, is much appreciated.

Good Global CDN Providers that also Work in China

Hi,

I am looking for a good global CDN provider. I have checked lists such as the following:

1] https://www.cdnplanet.com/
… | Read the rest of https://www.webhostingtalk.com/showthread.php?t=1851245&goto=newpost