Wednesday, June 16, 2021

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


What is the mistake here in this C# code?

Posted: 16 Jun 2021 09:02 AM PDT

using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  using System.Threading.Tasks;    namespace Repeating2  {      class Program      {          static void Main(string[] args)          {              int[] tal = new tal[3];              int tal2 = { 2, 6, 5, 2, 35 };              string str = { "hej", "på", "dig" };          }      }  }    is there any wrong with this code ??  

// Error CS0029 Cannot implicitly convert type 'tal[]' to 'int[]' Repeating2

// Error CS0118 'tal' is a variable but is used like a type Repeating2

// Error CS0622 Can only use array initializer expressions to assign to array types.

//Error CS0622  Can only use array initializer expressions to assign to array types.  

Adding children to StackLayout inside for loop causes this error "Layout cycle detected. Layout could not complete." in Xamarin Form UWP

Posted: 16 Jun 2021 09:02 AM PDT

foreach (var equipment in EquipmentCollection)  {    var control = new EquipmentControl(equipment);                   MyStackLayout.Children.Add(control);                 }  

I am getting this error only in UWP but not in Android. Even in UWP if the list size is small it is working fine.

I have tried few work arounds but still I couldn't able to make it work.

Since there is no UpdateLayout() method for xamarin-forms controls so I tried to use custom renderer for stacklayout and raised a child added event and called UpdateLayout() inside it but still got the crash.

[assembly: ExportRenderer(typeof(CustomStackLayout), typeof(CustomStackLayoutRenderer))]  namespace FO4.UWP.Controls  {      public class CustomStackLayoutRenderer : ViewRenderer<StackLayout, StackPanel>      {          StackPanel stkPanel;                     protected override void OnElementChanged(ElementChangedEventArgs<StackLayout> e)          {              base.OnElementChanged(e);                                                      if (e.NewElement != null)              {                  CustomStackLayout stkLayout = (CustomStackLayout)e.NewElement;                  stkLayout.ChildAdded += StkLayout_ChildAdded;                                }                if (e.OldElement != null)              {                  CustomStackLayout stkLayout = (CustomStackLayout)e.NewElement;                  stkLayout.ChildAdded -= StkLayout_ChildAdded;                              }            }            private void StkLayout_ChildAdded(object sender, ElementEventArgs e)          {                         this.UpdateLayout();          }                }  }  

HereMaps Javascript MemoryLeak?

Posted: 16 Jun 2021 09:02 AM PDT

I am currently trying to find some potential memory leaks in my angular application and found something which should regard to the hereMap, that I am using in one component. This is the situation:

I have an Angular 12 SPA with two components:

ComponentA - completely empty angular component - just for routing away from component B

ComponentB - the component that is using the hereMap.

When switching routes from Component A to B to A I would expect the garbage collector to remove most of the allocated memory after going back to A after a certain amount of time or when clicking "Collect garbage" in DevTools.

Here is what drives me crazy:

Every time when I go to the route with ComponentB, it seems like mapsjs-core.js adds a new TileManager that stays in memory forever and holds an enormous amount of objects and Arrays (3.5k Arrays and 10k Objects each time) which adds up to like 3-5mb memory each time.

Heap Snapshot

Those objects include textures, meshes, shields, etc in multiple instances of TileManagers (TileManager_0, TileManager_1, TileManager_2 after 3 times of creating a new instance of ComponentB).

After ngOnDestroy of ComponentB got called, ComponentB is no longer part of the memory, so disposing the map seems to work as expected.

Here is how the components look like:

import { Component, OnInit } from '@angular/core';    @Component({    selector: 'app-component-a',    templateUrl: './component-a.component.html',    styleUrls: ['./component-a.component.styl']  })  export class ComponentAComponent implements OnInit {      constructor() { }      ngOnInit(): void {    }    }

import { Component, OnInit } from '@angular/core';    @Component({    selector: 'app-component-b',    templateUrl: './component-b.component.html',    styleUrls: ['./component-b.component.styl']  })  export class ComponentBComponent implements OnInit, AfterViewInit, OnDestroy {    @ViewChild('map') public mapElement: ElementRef;    private map: H.Map;    private platform: H.service.Platform;    constructor() { }        ngOnInit(): void {          this.platform = new H.service.Platform({            apikey: myKey        });      }          ngAfterViewInit() {          const defaultLayers = this.platform.createDefaultLayers();          // Set min and max zoom level          defaultLayers.vector.normal.map.setMax(16);          defaultLayers.vector.normal.map.setMin(2);            // Initialize the map          this.map = new H.Map(              this.mapElement.nativeElement,              defaultLayers.vector.normal.map,              {                  zoom: ZoomLevels.ZOOM_MIN_SINGLE_MAP              }          );      }            public ngOnDestroy(): void {          this.map.dispose();      }    }

Getting error : -Missing ATOMIC_ATTRIBUTE in pair_string_ATOMIC_ATTRIBUTE when using basic-usage/00_browser.md #962

Posted: 16 Jun 2021 09:01 AM PDT

Version of EOSJS eosjs@16.0.9/lib/eos.min.js

Describe the bug

This piece of code throwing below error :

const result = await eos.transaction({                  actions: [{                      account: 'atomicassets',                      name: 'transfer',                      authorization: [{                          actor: user.accountName,                          permission: 'active',                      }],                      data: formData,                  }]              }, {                  blocksBehind: 3,                  expireSeconds: 30,              });  

Got Following Error when trying to hit

Caught exception: Error: [      "Unrecognized type or struct ATOMIC_ATTRIBUTE.variant_int8_int16_int32_int64_uint8_uint16_uint32_uint64_float32_float64_string_INT8_VEC_INT16_VEC_INT32_VEC_INT64_VEC_UINT8_VEC_UINT16_VEC_UINT32_VEC_UINT64_VEC_FLOAT_VEC_DOUBLE_VEC_STRING_VEC",      "Missing ATOMIC_ATTRIBUTE in pair_string_ATOMIC_ATTRIBUTE.fields.value"  ]  

To Reproduce Simply referred this https://github.com/EOSIO/eosjs/blob/master/docs/basic-usage/00_browser.md

Expected behavior It should work and do the transfer token.

You can refer to this github link https://github.com/EOSIO/eosjs/issues/962

Thanks in advance for your help.

Hacer un post y abrir la respuesta html en el navegador predeterminado o viceversa (Tampoco entiendo bien como seria lo que quiero hacer) JAVA

Posted: 16 Jun 2021 09:01 AM PDT

Estoy realizando una app de escritorio en java que analiza la pc del usuario, todos estos datos después quiero que sean desplazados a una landing de mi empresa y que a la vez esta misma se abra en el navegador predeterminado.

He encontrado códigos como el siguiente:

Desktop.getDesktop().browse(new URI("http://www.codigosparadesarrolladores.blogspot.com"));

¿Pero se podría plantear el post sobre ese new URI?

how we can retain the response from request.get() using concurrent.futures.threadpoolexecutor?

Posted: 16 Jun 2021 09:01 AM PDT

I have a python function to get some data from a url. The issue is that when I'm using the function with a simple loop its working fine, with a threadpoolexecutor() it is missing the data. here is the code:

ses = requests.session()  session = 'session_id' # Token_id used in url    def get_url(id,ses,session):   try:      headers = {              'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',              'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',              'Accept-Language': 'en-US,en;q=0.9'}            url = 'some URL'      response = ses.get(url, headers = headers,)      html1 = response.content      soup = BeautifulSoup(html1, "lxml")      try:          p_url = re.compile("(http://www.XZY.com/.*?.html)").findall(str(soup))[0].replace('http','https')      except:          p_url = None                return [id,p_url]    except:      return None  

When I run a simple for loop over certain_ids its gives correct result as:[[1,'The url for 1'],[2, 'the url for 2'],[3, 'the url for 3'],[4, 'the url for 4']]

but with ThreadPoolExecutor() I get:[[1,'The url for 1'],[2, None],[3, None],[4, 'the url for 4']]

Means randomly getting None value from a function.

How to overcome with this.

Performing a custom SQL query

Posted: 16 Jun 2021 09:03 AM PDT

I want to select all those rows in table A where column x's value is present in table B's column y.

I am new to writing SQL queries have have tried using different combinations of SELECT statement, COUNT function and WHERE clause since are a really long time, but was unable to do so.

Is it possible to do this using plain SQL queries or is something complex like procedure needed?

Rasberry Pi SSH connection

Posted: 16 Jun 2021 09:01 AM PDT

Even though there are many questions about the SSH connection with RasPi, I could not find a solution to my problem.

I am in the network of my university. The RasPi is connected to the LAN network of one department, "a". When I connect to the same network "a" with my laptop, I can access the Pi via SSH.

Now, when I am in the network of a different department "b", I can still ping the Pi, but SSH is not working: Network error: connection timed out. The firewall in department "a" is opened for the IP of the Pi.

interface enxc83ea701f2ce  static ip_address=10.162.80.186/24  .#static ip6_address=fd51:42f8:caae:d92e::ff/64  static routers=10.162.80.1  static domain_name_servers=10.162.80.1  

SSH is enabled. We tried to set up a static IP as well as the dynamic IP

Why is my R session crashing while using rcpp and OpenMP?

Posted: 16 Jun 2021 09:01 AM PDT

I am trying to optimize the performance of my code by utilizing both RcppArmadillo and OpenMP, however, my R session crashes when I run the code with ncores > 1.

// [[Rcpp::depends(RcppArmadillo)]]  // [[Rcpp::plugins(openmp)]]    #include <RcppArmadillo.h>  #include <iostream>  #include<algorithm>  #include <R.h>  #include <Rinternals.h>    using namespace std;  using namespace Rcpp;    // [[Rcpp::export]]  List A_hj_Comp(const arma::mat& X, int h, int j, double v, double u, int ncores=1){      arma::mat dat = X.rows(find(X.col(2)==h));      arma::mat ts = dat.rows( find(dat.col(3) == j && (dat.col(3) != dat.col(2))) );      arma::vec ts1 = ts.col(5);      arma::vec ts_1 = sort(unique(ts1));      arma::vec ts2 = ts_1.elem( find(ts_1 > v && ts_1 <= u) );            arma::mat temp1; arma::mat temp2; arma::mat temp2a;      int nn=ts2.size();      arma::vec res1(ts2.size());       arma::vec res2(ts2.size());      arma::vec A = arma::zeros<arma::vec>(nn+1);       double t;            // Added an omp pragma directive to parallelize the loop with ncores      #if defined(_OPENMP)          #pragma omp parallel for num_threads(ncores)      

No comments:

Post a Comment