Wednesday, June 8, 2022

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


Network Images not showing in android Flutter

Posted: 07 Jun 2022 10:58 AM PDT

I am working on a recipe searching flutter app for android. I am using Edamam API. I am also using a dummy image of the user for now (because I haven't connected my application with Firebase so far). The images are loaded in the android emulator, but it doesn't load any photos when I run the app on my actual phone. Please have a look at my problem.

Emulator's Screenshot: Cookpad Emulator Screenshot Actual Phone's Screenshot: Cookpad Mobile Screenshot

This is the code for loading images from API.

image: DecorationImage(                    image:                        NetworkImage(query["hits"][index]["recipe"]["image"]),  

Meteor JS or a combination of other tools for a Minecraft control panel?

Posted: 07 Jun 2022 10:58 AM PDT

As a personal project, I'm looking to make a Minecraft server control panel, something like Pterodactyl or Multicraft (with fewer features, of course). I'm making a list of tools I'll use and am right now thinking about whether to use a stack of Meteor JS, Nuxt JS, and Bulma CSS framework. Would Meteor be a good idea for this kind of project (for the panel part)? I'll be using Nuxt and Bulma regardless of whether I choose Meteor JS or Express JS and some other tools.

How to run Bash Script on startup and keep monitoring the results on the terminal

Posted: 07 Jun 2022 10:58 AM PDT

I am very new to linux. Only using for a few months on and off as a server. Due to some issues I wont elaborate here to not waste time, I made a bash script which will ping google every 10 minutes and if there is a response it will keep the loop running and if not then the PC will restart. After a lot of hurdle I have been able to make the script and also make it start on bootup. However the issue is that i want to see the results on the terminal, meaning I want to keep monitoring it but the terminal does not open on bootup. But it does open if I run it as ./net.sh. The script is running on startup, that much I know because I use another script to open an application and it works flawlessly.

My system information

NAME="Linux Mint"  VERSION="18.3 (Sylvia)"  ID=linuxmint  ID_LIKE=ubuntu  PRETTY_NAME="Linux Mint 18.3"  VERSION_ID="18.3"  HOME_URL="http://www.linuxmint.com/"  SUPPORT_URL="http://forums.linuxmint.com/"  BUG_REPORT_URL="http://bugs.launchpad.net/linuxmint/"  VERSION_CODENAME=sylvia  UBUNTU_CODENAME=xenial  

The contents of my net.sh bash script are

#! /bin/bash    xfce4-terminal &    sleep 30    while true  do          ping -c1 google.com          if [ $? == 0 ]; then                  echo "Ping Sucessful. The Device will Continue Operating"                  sleep 600          else                  systemctl reboot          fi    done  

I have put the scripts in /usr/bin and inserted the scripts for startup at boot in /etc/rc.local

Special attention, I want to mention that there is also a similar thread but I went through it and didnt find the answer helpful. I am not a linux wiz and most of it flew over my head. So if someeone could help me as I am a newbie, I would be very glad

regex JS - replace single quotes with forward slash and double quotes

Posted: 07 Jun 2022 10:58 AM PDT

I have a string that looks like the following:

const string = "[{'name': 'Peter', 'age': '21'}]"  

I want to transform the string so the single quotes are replaced with a forward slash and double quotes.

const result = "[{\"name\": \"Peter\", "age": \"21\"}]"  

I have been able to do the following but it doesn't seem to work. Can anyone help or point me in the right direction?

string.replace((/'/g, '\"'))  

const string = "[{'name': 'Peter', 'age': '21'}]";  const result = string.replace((/'/g, '\"'));    console.log(result);

Map local application behind public subresource

Posted: 07 Jun 2022 10:58 AM PDT

I'm running Joplin Server on my Raspi4 under http://127.0.0.1:23000 and on the Raspi I can successfully access the web app.

Since I don't want to publish the port 23000, I want Joplin Server to be accessible via https://myRaspi/joplinServer. Therefore I'm using Nginx.

I tried at first with:

location /joplinServer {    proxy_pass http://127.0.0.1:22300;  }  

Now when calling https://myRaspi/joplinServer from any other machine, Nginx keeps the subresource /joplinServer, resulting in an "inner call" to http://127.0.0.1:22300/joplinServer - which does not exist, sure, because Joplin Server itself knows nothing about the subresource and seems to have troubles with handling it.

I also tried this:

location = /joplinServer {    rewrite ^/joplinServer?$ http://127.0.0.1:22300 break;  }  

But now every external requests to https://myRaspi/joplinServer ends up as http://127.0.0.1:22300 on my machine which does obviously not work.

So what do I have to configure on Nginx to make my setting work?

Thanks in advance!

How to remove strings which extends original string from JavaScript array?

Posted: 07 Jun 2022 10:57 AM PDT

I have the following array: ['total.color.violet', 'total.color.violet.truefont', 'total.color.red', 'total.color.red.circle', 'total.color.red.circle.elefant', 'total.color.blue', 'total.color.yellow', 'total.color.yellow.dotted']. As we can see all the strings have constant part total.color and the variable part. I need to get the next result: ['total.color.violet', 'total.color.red', 'total.color.blue', 'total.color.yellow'] - to remove strings which have more than 'third level' complexity and leave string only with 'second level' complexity. Please, look throw this algorithm and give me any tips, if it is possible.

Non deterministic behavior of native_ functions in OpenCL kernel

Posted: 07 Jun 2022 10:57 AM PDT

TL;DR: Using native_log2() produces non deterministic behavior in OpenCL kernel, while using log2() produces deterministic behavior. Why is this happening?

So I have this function below acting as a helper function for an OpenCL kernel, and I was using the native_ version of log2 (native_log2) to improve speed performance.

When I was comparing the results produced by the kernel and by the original program, I realized that in most of the cases the kernel is producing the right values, however, sometimes it produces an incorrect value (like 30 incorrect values in 500k function calls). VERY IMPORTANT: The errors are not always on the same computations. I am processing multiple input files, and the errors seem to occur randomly in different sets of files with different runs. That is, the results are non deterministic.

After some tests I narrowed the problem to the function below and found out that swapping the native_log2 by log2 produces the correct value 100% of the times. All those typecasts look ugly, but the log2() and floor() functions are only compatible with double/float, while my input/output must be integers.

My device is a NVIDIA GPU 940MX and only supports OpenCL 1.2. The OpenCL 1.2 documentation states that

A subset of functions from table 6.8 that are defined with the native_ prefix. These functions may map to one or more native device instructions and will typically have better performance compared to the corresponding functions (without the native__ prefix) described in table 6.8. The accuracy (and in some cases the input range(s)) of these functions is implementation-defined.

Clearly I am supposed to expect some errors when using native_ functions, but the documentation is not clear about the determinism of the errors I may be encountering.

Can someone give me directions on why I am facing this strange behavior?

int xGetExpGolombNumberOfBits(int value){      unsigned int uiLength2 = 1;      unsigned int uiTemp2 = select((unsigned int)( value << 1 ), ( (unsigned int)( -value ) << 1 ) + 1, value <= 0);            // These magic numbers (7 and 128) are substituting two constants for the sake of clarity      while( uiTemp2 > 128 )       {        uiLength2 += ( 7 << 1 );        uiTemp2  >>=   7;      }        return uiLength2 + (((int)floor(native_log2((float)uiTemp2))) << 1);  }  

Best Vue-Signature-Pad syntax for Vue3 <script setup lang="ts>?

Posted: 07 Jun 2022 10:57 AM PDT

I would be very grateful to understand how to use the save and clear methods of Vue-Signature-Pad in Vue 3's <script setup lang="ts"> syntax.

This doesn't do anything, in Dev Tools/Components:

//in template:  <VueSignaturePad     v-model="signatureInput"     @change="changeDetected"// change never fires    @input="inputDetected" // input never fires  />  //in script setup:  const signatureInput= ref(undefined);    

in Dev Tool modelValue is always undefined.

Seems like I should be trying capture an updated value like @change="event.target as Canvas" or @mouseDown="" but I can't get any updated values out.

I'm sure part of my confusion is, it doesn't really look like a standard component, does it? I have no idea what to do with this from the docs...

methods: {      undo() {        this.$refs.signaturePad.undoSignature();      },      save() {        const { isEmpty, data } = this.$refs.signaturePad.saveSignature();        console.log(isEmpty);        console.log(data);      }    }  

... because this.$refs.signaturePad... is not an applicable concept, right?

Any guidance would be appreciated.

uipickerView is displayed after click on textfield then uiview then agin the same textfielf

Posted: 07 Jun 2022 10:57 AM PDT

I have a problem with Xcode and Swift. In scenario, I have three uitextfields and one uipickerview, the data of uipickerviews change for each textfield, and that work fine, but the problem is that for display the first uipickerview i must click on the first uitextfield then on UIView then again on uitextfield for display a uipickerview, then for display the picker for second uitextfield, i had to click on the second uitextfield then on UIView then again on the second uitextfield for display uipickerview, and the same for the third uitextfield (uitextfield then UIView then uitextfield) for display the uipickerview, each uitextfield have its datasource of uipickerview different from the other.

This is the short code:

 var level =  [String]()  let pickerSchool = UIPickerView()  var lastPressedTextField: UITextField?  var currentIndex = 0  let toolBar = UIToolbar()    @IBOutlet weak var cityTextField: UITextField!  @IBOutlet weak var levelSchoolTextField: UITextField!  @IBOutlet weak var schoolTextField: UITextField!      override func viewDidLoad() {          super.viewDidLoad()  toolBar.sizeToFit()          let buttonDone = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(closePicker))          toolBar.setItems([buttonDone], animated: true)  }      @IBAction func textFieldDidBeginEditing(_ textField: UITextField) {          lastPressedTextField = textField          lastPressedTextField?.inputAccessoryView = toolBar          lastPressedTextField!.inputView = pickerSchool      }      override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {          view.endEditing(true)      }      func numberOfComponents(in pickerView: UIPickerView) -> Int {          return 1      }       func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {            if lastPressedTextField == cityTextField {          return RequestService.gettenCity[row]      } else if lastPressedTextField == levelSchoolTextField {          return  level[row]      } else if lastPressedTextField == schoolTextField {          return  RequestService.gettenSchool[row]      }      return ""  }      func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {          if lastPressedTextField == cityTextField {              return RequestService.gettenCity.count          } else if lastPressedTextField == levelSchoolTextField {              return   level.count          } else if lastPressedTextField == schoolTextField {              return  RequestService.gettenSchool.count          }          return 0      }        func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {          currentIndex = row          if lastPressedTextField == cityTextField {              self.cityTextField.text = RequestService.gettenCity[row]          }          else if lastPressedTextField == levelSchoolTextField {              self.levelSchoolTextField?.text = level[row]          }          else  {              self.schoolTextField.text = RequestService.gettenSchool[row]          }      }    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {          pickerSchool.isHidden = false          textField.inputView = pickerSchool;          return false      }      func textFieldDidEndEditing(_ textField: UITextField) {          pickerSchool.isHidden = true      }    @objc func closePicker(){          if lastPressedTextField == cityTextField {              lastPressedTextField?.text = RequestService.gettenCity[currentIndex]          } else if lastPressedTextField == levelSchoolTextField {              //  lastPressedTextField?.text = level[currentIndex]              //              let newParameters : Parameters = [                  "city": cityTextField.text!,                  "level" : levelSchoolTextField.text!              ]              api =  URL(string: "http://localhost/mesamies/getschools.php")              repository.schoolSelect(url: api!, method: .post, parameters: newParameters) { dataResponse in                  switch dataResponse {                  case .success(let schools):                      let school = schools.count                      for i in 0...school-1{                          RequestService.gettenSchool.append(schools[i].name!)                          RequestService.gettenSchoolId.append(Int(schools[i].id!)!)                      }                  case .failure(let error):                      print(error)                  }              } //          }          else if lastPressedTextField == schoolTextField {              schoolTextField?.text = RequestService.gettenSchool[currentIndex]          }          lastPressedTextField?.resignFirstResponder()          view.endEditing(true)      }  

If you want see all the code, this is the link on github:

https://github.com/mdolwan/Projet_12/blob/master/MesAmies/Controllers/SettingViewController.swift

I wrote a QT Tcp/ip Client Side C++ Program I want to send Buffer To Server.How Can I do that?

Posted: 07 Jun 2022 10:58 AM PDT

First of all, I connect to the server with the first ip I get from the user. I want to send a buffer to this ip address. On the server side, the code takes the information in this buffer and changes the ip. That's why I need to send the buffer with tcp. I shared the code below. I can connect to the ip. But since I can't send the buffer, the ip does not change on the server side. What am I doing wrong?

userpage.h

#define SF366_SYNC_WORD (0xAF0F00FF)    #pragma pack(push,1)    typedef enum{      TCP_MT_SET_IP_ADDRESS = 0x100,      TCP_MT_SET_OPERATION_MODE,      TCP_MT_GET_LOGS,  }TCP_MESSAGE_TYPE;    typedef enum{      OM_IDLE,      OM_AUTO,      OM_MANUAL,      OM_EMERGENCY_STOP,  }TCP_OPERATION_MODE;    typedef struct{      uint8_t ipAddr1;      uint8_t ipAddr2;      uint8_t ipAddr3;      uint8_t ipAddr4;        uint8_t gatawayIpAddr1;      uint8_t gatawayIpAddr2;      uint8_t gatawayIpAddr3;      uint8_t gatawayIpAddr4;  }SET_IP_ADDR_MESSAGE;    typedef struct{      uint8_t operationMode;  }SET_OPERATION_MODE_MESSAGE;      typedef struct{      // should be equal to SF366_SYNC_WORD      uint32_t syncWord;        //types defined in enum TCP_MESSAGE_TYPE      uint32_t tcpMessageType;        //length of the message including the TCP_MESSAGE_HEADER      uint32_t messageLength;  }TCP_MESSAGE_HEADER;      #pragma pack(pop)    namespace Ui {  class userpage;  }    class userpage : public QMainWindow  {      Q_OBJECT    public:      explicit userpage(QWidget *parent = nullptr);      ~userpage();      void keyPressEvent(QKeyEvent * event);    signals:        void showPageModGod();      public slots :      void showPageByPermission(QString  permission);  private slots:          void on_pushButton_chooseFile_clicked();        void on_systemControlButton_toggled(bool checked);        void on_pushButton_connect_clicked();        void on_pushButton_disconnect_clicked();      void readTcpData();        void on_lineEdit_ipaddress_returnPressed();        void on_pushButton_setIP_clicked();    private:      Ui::userpage *ui;      QMainWindow *main_page;      GmDialog *godmood_page;      QTcpSocket *socketTcp;  };    

No comments:

Post a Comment