Typescript : Adding types to a function that takes in a string and returns a different promise based on the string

The problem here is that the interface IAnimal is not what those apis return. You want to return that interface from your function, but those APIs should have their own interface representing the response data.

interface DogApiResponse {
  message: string
  status: string

interface FoxApiResponse {
  image: string

interface Animal {
  status: string
  image: string | null

To generalize the set of available animal types I propose to also add interface for the fetching part of individual APIs.

declare type RandomAnimalFactory = () => Promise<Animal>

Now we declare two factories – for dogs and foxes

const dogFactory: RandomAnimalFactory = async () => {
  const result: DogApiResponse = await fetch(dogApiUrl).then(data => data.json())
  if (result.status !== 'success') {
    throw new Error('Dog API railure')
  return {image: result.message, status: 'success'}

const foxFactory: RandomAnimalFactory = async () => {
  const result: FoxApiResponse = await fetch(foxApiUrl).then(data => data.json())
  return {image: result.image, status: 'success'}

The we can have the named animal factory work like this

declare type NamedAnimalFactory = (name: string) => Promise<Animal>

const createRandomNamedAnimalFactory = (randomFactories: {(key: string): RandomAnimalFactory}): NamedAnimalFactory => {
  return async (name) => {
    const factory = randomFactories(name.trim().toLowerCase())
    if (!factory) {
      return {image: null, status: 'failure'}

    try {
      return await factory()
    } catch {
      return {image: null, status: 'failure'}

const getAnimal: NamedAnimalFactory = createRandomNamedAnimalFactory({
  dog: dogFactory,
  fox: foxFactory,

plotting – Mathematica returns an empty plot for the real part of the eigenvalues

I have a 3*3 matrix. Using Mathematica I have found the eigenvalues in terms of “K”. The problem arises when I’m plotting the real part of eigenvalues against “k” (k is a positive number ranging from 0.02 to 0.05). Can someone guide me, why I’m getting empty?
enter image description here

(*Here is my Matrix*)

J1 = {{-v^2 - w^2 - F - D1*k^2, -2*u*v, -2*u*w}, {v^2, 
    2*u*v - (F + k1) - D2*k^2, 0}, {w^2, 0, 
    2*u*w - (F + k2) - D3*k^2}};

(*I have defined the eigen values as the function of the following 
{λ4(F_, D1_, D2_, D3_, k1_, k2_, u_, v_, 
    w_), λ5(F_, D1_, D2_, D3_, k1_, k2_, u_, v_, 
    w_), λ6(F_, D1_, D2_, D3_, k1_, k2_, u_, v_, w_)} = 

(*Here are the numerical values of the parameters*)
    290, 61.443, 11, 0.0043, 0.046, 0.381, 0.0767, 0.186), λ5(
   0.025, 290, 61.443, 11, 0.0043, 0.046, 0.381, 0.0767, 
   0.186), λ6(0.025, 290, 61.443, 11, 0.0043, 0.046, 0.381, 
   0.0767, 0.186)};

(*Plotting the real part of the eigen values against k*)
Plot({Re(λ1), Re(λ2), Re(λ3)}, {k, 0.01, 0.05}, 
 PlotStyle -> {{Thick, Red}, {Thick, Blue}}, Frame -> True, 
 FrameLabel -> {Style("k", 18), Style("Re(λ)", 18)})

html – Javascript Datatable returns no data

i can see items in datatable but first row is No Data in table ?

(document).ready(function () {
“ajax”: {
“type”: “GET”,
“url”: ‘/History/GetCallbackHistory’,
“data”: { UserId: document.getElementById(“callbackuserid”).value },
“dataSrc”: “”,
“success”: function (response) {
response.forEach(function (dt) {
$(“#tdata”).append(“” +
“” + dt.Id +”” +
“” + dt.DateCallback +”” +
“” + dt.DateEnd +”” +
“” + dt.Point +”” +
“” + dt.TaskId +”” +
“” + typecallback(dt.callbackId) +”” +
“” + dt.Task_name +”” +
“” + callbackStatus(dt.callbackStatus) +”” +
+”” );
// fillTable(getData());

sharepoint enterprise – Searching for anything besides ‘This Site’ returns error

We have SharePoint 2013 on-prem and I recently applied Windows security patches from October 2020. Since then, whenever we search on SharePoint for anything other than ‘this site’, this error is returned:

The base type ‘Microsoft.Office.Server.Search.Internal.UI.SearchResultsLayoutPage’ is not allowed for this page. The type Microsoft.Office.Server.Search.Internal.UI.SearchResultsLayoutPage, Microsoft.Office.Server.Search, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c could not be found or it is not registered as safe.

I’ve found posts about others with this issue and tried their attempted fixes, notably updating the web.config file on all SharePoint servers to include the above, however it still is not working.

Does anybody have a successful resolution of this?

mathematical optimization – Maximize returns unevaluated even though there is a global maximum

I was trying to calculate the maximum of a gaussian plus a line, but Maximize return unevaluated:

In(8):= Maximize(1/((Sigma)*Sqrt(2*Pi))*Exp(-1/2*(x-(Mu))^2/(Sigma)^2)+s*x,x )
Out(8)= Maximize(s x+E^(-((x-(Mu))^2/(2 (Sigma)^2)))/(Sqrt(2 (Pi)) (Sigma)),x)

enter image description here

So I thought maybe it doesn’t have an analytical form so I removed the line term but I still get no answer even though the answer is zero.

In(9):= Maximize(1/((Sigma)*Sqrt(2*Pi))*Exp(-1/2*(x-(Mu))^2/(Sigma)^2),x )
Out(9)= Maximize(E^(-((x-(Mu))^2/(2 (Sigma)^2)))/(Sqrt(2 (Pi)) (Sigma)),x)

enter image description here

I’m not really trained in Mathematica so I know I’m probably just doing something wrong, I just don’t know what…

Thanks a lot 🙂

Automated Trading System Start Earning Investment 13% Monthly Returns Previously Reserved For Wealthy

Reduced Size Image

Automated Trading System Start Earning Investment 13% Monthly Returns Previously Reserved For Wealthy

Act Now: The Fund Will Close Once We Reach $25M in Total Retail Deposits.🔒

Fully Verified Trading ✅
Highest Performing Strategies in all Markets.
Verified by FXStat, FXBlue, and more.
Program Audited by CPA

Join the World’s Most Profitable 💰
Private Managed Account Program 🔐
Fully Verified +19% Average Monthly Returns.​ 💵

Register FREE for Access to Private MyFxBook

Verification & Begin Profiting with Equitrade Today

More Details

Bitcoin-qt getnewaddress returns address starting with 2

I am expecting it starts with ‘3’ the the results below:

getnewaddress "" "p2sh-segwit"

Is this because I am running on a private block chain?

coinbase.com – Coinbase API create new address returns 404 “not found”

I am trying to create a new address for my Coinbase account to try putting some coins in it with my application.
I am using .Net core for accessing the Coinbase endpoint.
I have tried both creating requests manually and using the NuGet package “Coinbase”, for casual requests like fetching user data, changing user data (nickname) everything is working fine (so the error is not in bad request creation or similar) except when I want to create a new address for putting some crypto in it. It returns not found. Also I tried fetching the list of addresses and it also returns 404 (I have plenty of addresses when I check my account under Settings/Crypto Addresses).
Do I miss some configuration on my Coinbase account? I am using the API key and API secret and I granted all permissions to it. I have linked that account to Coinbase wallet on my phone.
Thanks for the help.

magento2 – Ajax add to cart popup: Product method sometimes returns null

Currently I’m experiencing issues with a third party ajax add to cart popup module. The issue is that, on very rare occasion the get product method will return null, and this causes the following error in the getProductCollection method, as the product collection will return null when the product is null:

report.ERROR: Warning: count(): Parameter must be an array or an object that implements Countable

If I protect against null values by passing an empty array (countable) when the product is null then I see the following error in the getImage method:

Uncaught TypeError: Argument 1 passed to Magento\Catalog\Block\Product\ImageBuilder::setProduct() must be an instance of Magento\Catalog\Model\Product, null given

It seems to be that the issue is that on rare occasion, the product will return null. The problem is that I’m unable to reproduce this issue. The related error might log once a day, or sometimes once a week. The only way I can reproduce is by explicitly setting the get product method to return null, or by deleting a product and then adding it to cart before refreshing the page. Otherwise, when testing the add to cart popup seems to work perfectly.

One option might be to only load the popup when the product is not null:

if ($this->getProduct() != null)

This prevents any unexpected errors when the product is null, but I’m not quite understanding why the get product method would return null in the first place. Is this normal, and the issue here is the lack of protection against null values?

The mentioned methods are as follows:

getProduct method:

public function getProduct()
    if(!$this->_product && $this->getProductId()) {
        $this->_product = $this->_initProduct($this->getProductId());
    return $this->_product;

getProductCollection method:

public function getProductCollection() {        
    if (!$this->_productCollection && $this->getProduct()) {
        $this->_productCollection = $this->_crosssellBlock->getItemCollection();
    return $this->_productCollection;

getImage method:

public function getImage($product, $imageId, $attributes = ()) {
        return $this->imageBuilder->setProduct($product)

Any help would be appreciated.


adb – Android device ro.crypto.state returns “encrypted”, but I can access the /data partition. How?

I have a OnePlus 3 with an unlocked bootloader and LineageOS. I forget the PIN and I am trying to recover access to it, and I have access to the recovery. The data is encrypted.

My understanding is that, if the device is using FBE, the value adb shell getprop ro.crypto.state will return encrypted, and the /data partition will be impossible to read.

Despite the fact that adb shell getprop ro.crypto.state returns encrypted, and despite the fact that I have not entered the PIN stored in the hardware keystore, I am able to browse and copy files from /data using adb shell.

So this seems to be in conflict: I should not be able to access /data if that returns encrypted. Is this true? If not, why is this not a conflict?

(I apologize if this has been asked before, I could not find any questions on this.)