Sunday, April 24, 2022

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


Is it common to have an android app behave entirely different when internal testing and downloaded from googly play directly?

Posted: 24 Apr 2022 07:00 PM PDT

I have not enabled obfuscation, nor am I requiring use of an API. All storage is local to the users device. The app behaves just fine on my development test phone, but crashes for my internal testers

word2vec + XGBoostRegressor - error Check failed: preds.Size() == info.labels_.Size() (1 vs. 70812) : labels are not correctly providedpreds.size=1

Posted: 24 Apr 2022 06:59 PM PDT

I am quite new to NLP. I am building a Regression model for predicting discrete values (like price). While I was Using xgboostRegressor + word2vec. It throws the below error when trying to fit the model.
My input to the word2vec is a list of words [![enter image description here][1]][1]

Tags [text, font , graphics, screenshot , gain]

from xgboost import XGBRegressor    xgb_model = XGBRegressor(          objective = 'reg:squarederror',          colsample_bytree = 0.5,          learning_rate = 0.05,          max_depth = 6,          min_child_weight = 1,          n_estimators = 1000,          subsample = 0.7)    %time xgb_model.fit(list(x_train), y_train, early_stopping_rounds=5, verbose=False)    y_pred_xgb = xgb_model.predict(x_test)  

XGBoostError Traceback (most recent call last) in () 10 subsample = 0.7) 11 ---> 12 get_ipython().magic('time xgb_model.fit(list(x_train), y_train, early_stopping_rounds=5, verbose=False)') 13 14 y_pred_xgb = xgb_model.predict(x_test)

8 frames  <decorator-gen-53> in time(self, line, cell, local_ns)    <timed eval> in <module>()    /usr/local/lib/python3.7/dist-packages/xgboost/core.py in _check_call(ret)      174     """      175     if ret != 0:  --> 176         raise XGBoostError(py_str(_LIB.XGBGetLastError()))      177       178     XGBoostError: [01:43:27] /workspace/src/objective/regression_obj.cu:65: Check failed: preds.Size() == info.labels_.Size() (1 vs. 70812) : labels are not correctly providedpreds.size=1, label.size=70812  Stack trace:    [bt] (0) /usr/local/lib/python3.7/dist-packages/xgboost/./lib/libxgboost.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x24) [0x7f45763dfcb4]    [bt] (1) /usr/local/lib/python3.7/dist-packages/xgboost/./lib/libxgboost.so(xgboost::obj::RegLossObj<xgboost::obj::LinearSquareLoss>::GetGradient(xgboost::HostDeviceVector<float> const&, xgboost::MetaInfo const&, int, xgboost::HostDeviceVector<xgboost::detail::GradientPairInternal<float> >*)+0x21e) [0x7f45765ea84e]    [bt] (2) /usr/local/lib/python3.7/dist-packages/xgboost/./lib/libxgboost.so(xgboost::LearnerImpl::UpdateOneIter(int, xgboost::DMatrix*)+0x345) [0x7f4576479505]    [bt] (3) /usr/local/lib/python3.7/dist-packages/xgboost/./lib/libxgboost.so(XGBoosterUpdateOneIter+0x35) [0x7f45763dcaa5]    [bt] (4) /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call_unix64+0x4c) [0x7f45d2a66dae]    [bt] (5) /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call+0x22f) [0x7f45d2a6671f]    [bt] (6) /usr/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so(_ctypes_callproc+0x28c) [0x7f45d2c7a5dc]    [bt] (7) /usr/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so(+0x109e3) [0x7f45d2c799e3]    [bt] (8) /usr/bin/python3(_PyObject_FastCallKeywords+0x92) [0x5559ff072902]        [1]: https://i.stack.imgur.com/JcTKs.png  

Flutter Hive getting double of an item in a list after app restart

Posted: 24 Apr 2022 06:58 PM PDT

I am building a simple budgeting app in flutter and I am using Hive for local data storage. I have a list of weeks, that gets loaded from a hive box when the app starts:

class WeekList extends ChangeNotifier {    WeekList() {      int boxLength = box.length;      for (var i = 0; i < boxLength; i++) {        listOfWeeks.add(box.getAt(i));      }    }  

The problem I am seeing is if I start a new week, and then quickly restart the app it loads with two of the last week. Adding a new week runs this code:

  void addWeek({      required double budget,    }) {      Week newWeek = Week(        budget: budget,      );        listOfWeeks.add(newWeek);      box.add(newWeek);      notifyListeners();    }  

The odd part is if I add a new week, and edit a value in the week then when I restart the app it does not create double of the last week on load...

Updating a value in the week looks like this:

  //updateSundayValue    void updateSunday(        {required double newValue, required int index, required Week week}) {      listOfWeeks[index].sunday = twoDecimalPlaces(newValue, 2);      listOfWeeks[index].sundayDisplayValue =          twoDecimalPlaces(newValue, 2).toString();      box.putAt(index, week);      notifyListeners();    }  

its odd to me that it will repeat the last week added to the list on load if I dont edit the new week I just added....

I need help passing the parameters of onclick to a function in Javascript

Posted: 24 Apr 2022 06:58 PM PDT

This is for a school project, I'm still super new to JS. I'm trying to create a slideshow that replaces the main image and loops through different 5 image arrays depending on what button you click. The arrays are supposed to be passed to the one function displayPics. I am also very confused about how to group all the arrays to run the count through... It is a total mess but I know it is failing at passing the parameter. My HTML and Javascript:

  <img      id="mainImg"      style=" "      src="barn.jpeg"      alt="barn" >    <button onclick="displayPics('Goats');" >Goats</button>  <button onclick="displayPics('Cows');" >Cows</button>  <button oneclick="displayPics('Donkeys');">Donkey</button>        <script >  var mainImg = document.getElementById('mainImg');  var imageIndex = 0;    function displayPics(x){      var pictures = ['goats1.jpeg','goats2.jpeg','goats3.jpeg','goats4.jpeg','goats5.jpeg'];      var pictures2 = ['cows1.jpeg','cows2.jpeg','cows3.jpeg','cows4.jpeg','cows5.jpeg'];          for (var count = 0; count < pictures.length; count++) {      task(count);        function task(count){        setTimeout(function(){          if ("displayPics()" == "displayPics('Goats')"){              pictures = pictures[0];}            }                    else if ("displayPics()" == "displayPics('Cows')"){    pictures = pictures2[0]; }      }      }      }      </script>  

How to find the first child that has a certain class in a DOM subtree?

Posted: 24 Apr 2022 06:58 PM PDT

Is there any DOM method to find the first element that has a certain class

<div class="parent">     <div>        <div></div>        <p class="paragraph"></p>    </div>  </div>    

what if i have multiple p elements in the page and i need only to find the p element that is anywhere in the subtree starting from .parent.

regex: How to ensure all the candidate strings can be matched

Posted: 24 Apr 2022 06:58 PM PDT

When constructing a regular expression for matching a list of candidate strings, how to ensure all the strings can be matched? For example,

This regular expression (?:O|SO|S|OH|OS)(?:\s?[-+*°.1-9]){0,4} can match all the examples below

O 4 2 -  O 2 -   SO 4 * - 2   S 2-   

However, if I swap S and SO, the resulting regular expression (?:O|S|SO|OH|OS)(?:\s?[-+*°.1-9]){0,4} failed to match the SO 4 * - 2 in the example above.

So my confusion is how to order the list of candidate strings in the regular expression, so that all of them can be safely and uniquely matched? Since the actual list of candidate strings in my project is a bit more complicated than the example, is there a sorting algorithm that can achieve this?

I want to make R codes with this SAS loop codes

Posted: 24 Apr 2022 06:57 PM PDT

I am doing big data analysis, and I want to add up each individual's physical activity. Moderate or more physical activity is defined as 'in the past week, 20 minutes or more per day and 3 days a week or more' is defined as The SAS codes for this are as follows.

if 0<=pha_05z1 <=24 and pha_06z1=. then do;   ph_a0100=pha_05z1*60;  end;  if a<=pha_05z1<=24 and 0<=pha_06z1 <=59 then do;   ph_a0100=(pha_05z1*60)+pha_06z1;  end;  if pha_05z1=. and 0<=pha_06z1<=59 then do;   ph_a0100=pha_06z1;  end;  if pha_04z1 in (0:2) the ph_a0200=0;  else if pha_04z1 in (3:7) then do;   if ph_a0100=. then ph_a0200=.;   else if 0<=ph_a0100<=19 then ph_a0200=0;   else if 20<=ph_a0100 then ph_a0200=1;  end;  -----  (Abstinence from vigorous physical activity)  -----  if ph_a0200=1 or ph_a0400=1 then ph_a0500=1;  else if ph_a0200=0 and ph_a0400=0 then ph_a0500=0;  

Below is what I made in R code.

if (pha_05z1<=24 & pha_05z1>=0 & pha_06z1==88)  {    ch2020_$ph_a0100 <- pha_05z1*60  }  if (pha_05z1<=24 & pha_05z1>=0 & pha_06z1<=59 & pha_06z1>=0)  {    ch2020_$ph_a0100 <- pha_05z1*60 + pha_06z1  }  if (pha_05z1==88 & pha_06z1<=59 & pha_06z1>=0)  {    ch2020_$ph_a0100 <- pha_06z1  }  ch2020_$ph_a0200 <-     ifelse(pha_04z1%in%c(0,1,2),0,            ifelse(pha_04z1>=3 & ch2020_$ph_a0100==NA),NA,            ifelse(ch2020_$ph_a0100<=19 & ch2020_$ph_a0100 >=0),0,1)  

This code doesn't work. How can I solve this? Thank you in advance. Please help.

how to use python requests to upload file?

Posted: 24 Apr 2022 06:56 PM PDT

import requests    cookies = {      'root_session_id': 'something',      'visid_incap_987752': 'something',          '_gid': 'something',       #there are more cookies but I dont wanna post all of them for safety reasons and I changed        #the values for the above cookies, I changed to something for safety reasons for stackoverflow, however they        #are proper values     }    headers = {      'authority': 'www.coursehero.com',      'accept': 'application/json, text/plain, */*',      'accept-language': 'en-US,en;q=0.9',      'cache-control': 'no-cache',      'content-type': 'multipart/form-data; boundary=----WebKitFormBoundarykw7irLeGtukpiiD6',      # Requests sorts cookies= alphabetically        'origin': 'https://www.coursehero.com',      'pragma': 'no-cache',      'referer': 'https://www.coursehero.com/upload/',      'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',      'sec-ch-ua-mobile': '?0',      'sec-ch-ua-platform': '"Windows"',      'sec-fetch-dest': 'empty',      'sec-fetch-mode': 'cors',      'sec-fetch-site': 'same-origin',      'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36',      'x-newrelic-id': 'Ug8CUVVbGwIDUlVUBgkGVg==',  }    data = '------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="method"\r\n\r\nregular\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="source"\r\n\r\nDrag & Drop\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="course_id"\r\n\r\n10122614\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="school_id"\r\n\r\n2658\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="is_mandatory_tagging"\r\n\r\ntrue\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="data"\r\n\r\n{"submitted":true,"document_submission_id":30234005}\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="files"; filename="screencapture-us13-proxysite-process-php-2022-04-19-18_33_18.png"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="hash"\r\n\r\nb9290fc1a94abb6a1706f57a3a2b254119fe248f\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="upload_application_name"\r\n\r\nflu\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY\r\nContent-Disposition: form-data; name="upload_application_version"\r\n\r\nupld_flu_breakpoint_test_v4_0\r\n------WebKitFormBoundaryMxmgytoOe4GjAGyY--\r\n'  files = {    'file': open('testfile.txt', 'rb')}        response = requests.post('https://www.coursehero.com/api/v1/uploads/', cookies=cookies,   files=files,  headers=headers, data=data )  with open('b.html',"w") as f:        f.write(response.text)   

error I get is data cant be a string

Traceback (most recent call last):    File "main.py", line 41, in <module>      response = requests.post('https://www.coursehero.com/api/v1/uploads/', cookies=cookies,  files=files, headers=headers,  data=data )    File "/home/runner/WorstRecentLaw/venv/lib/python3.8/site-packages/requests/api.py", line 117, in post      return request('post', url, data=data, json=json, **kwargs)    File "/home/runner/WorstRecentLaw/venv/lib/python3.8/site-packages/requests/api.py", line 61, in request      return session.request(method=method, url=url, **kwargs)    File "/home/runner/WorstRecentLaw/venv/lib/python3.8/site-packages/requests/sessions.py", line 515, in request      prep = self.prepare_request(req)    File "/home/runner/WorstRecentLaw/venv/lib/python3.8/site-packages/requests/sessions.py", line 443, in prepare_request      p.prepare(    File "/home/runner/WorstRecentLaw/venv/lib/python3.8/site-packages/requests/models.py", line 321, in prepare      self.prepare_body(data, files, json)    File "/home/runner/WorstRecentLaw/venv/lib/python3.8/site-packages/requests/models.py", line 514, in prepare_body      (body, content_type) = self._encode_files(files, data)    File "/home/runner/WorstRecentLaw/venv/lib/python3.8/site-packages/requests/models.py", line 124, in _encode_files      raise ValueError("Data must not be a string.")  ValueError: Data must not be a string.  

https://www.coursehero.com/upload/ is the website you can take and look and see the requests when I click on upload file or when I try to drag and drop a file. u can log in using this account email: stackkkyoverflow@hotmail.com password: stackkkyoverflow and then go to the website https://www.coursehero.com/upload/ or you can easily create a free account and then go to the upload website above incase someone changes the password.
I want to upload a file using python requests to that website, idk if I have the correct request as well. Also I copied the network request using cmd bash and converted it to python requests using the online converter so I don't miss out on anything

Implementing flood fill BFS

Posted: 24 Apr 2022 07:00 PM PDT

I'm trying to find if a certain area is reachable within a set of moves using a flood fill breadth first search algorithm, but I'm having trouble implementing the algorithm. I have a grid here

        let map = [              [0, 0, 0, 0, 0, 0, 0],              [0, 0, 0, 0, 0, 0, 0],              [0, 0, 0, 0, -1, 0, 0],              [0, 0, -1, 1, -1, 0, 0],              [0, 0, -1, 0, 0, 0, 0],              [0, 0, -1, 0, 0, 0, 0],              [0, 0, 0, 0, 0, 0, 0],          ]  

Where 1 is my starting position and -1 represents blocked or inaccessible tiles.

From what I understand of flood fill BFS is your first node is the starting position, in my case it's where my map is [y,x]==1 and push this into your que. You then iterate through each element of your que. Then find the neighbors for each element, then you check each neighbor if it's accessible or its visited. And if it's not visited, you append it to the visited list and lastly append it to your list of reachable tiles.

I'm lost on the algorithm and can't implement it properly. Here's my attempt at the algorithm

<html>    <head>    </head>    <body>      <canvas id="canvas" width="640" height="480"></canvas>  </body>    <script>      document.addEventListener("DOMContentLoaded", e => {          let canvas = document.getElementById("canvas");          let ctx = canvas.getContext("2d");          let mapwidth = 7;          let mapheight = 7;          let map = [              [0, 0, 0, 0, 0, 0, 0],              [0, 0, 0, 0, 0, 0, 0],              [0, 0, 0, 0, -1, 0, 0],              [0, 0, -1, 1, -1, 0, 0],              [0, 0, -1, 0, 0, 0, 0],              [0, 0, -1, 0, 0, 0, 0],              [0, 0, 0, 0, 0, 0, 0],          ]          let tw = 25;          let th = 25;          function drawgridlines() {              for (var n = 0; n < mapheight; ++n) {                  for (var m = 0; m < mapwidth; ++m) {                      ctx.strokeRect(m * th, n * tw, th, tw);                  }              }          }          function fillgrid() {                for (var n = 0; n < mapheight; ++n) {                  for (var m = 0; m < mapwidth; ++m) {                      if (map[m][n] == 1) {                          ctx.fillStyle = "red";                          ctx.fillRect(m * th, n * tw, th, tw);                      } else if (map[m][n] == -1) {                          ctx.fillStyle = "black";                          ctx.fillRect(m * th, n * tw, th, tw);                      }                  }              }          }          function filltile(k) {                let m = k[0];              let n = k[1];              ctx.fillStyle = "blue";              ctx.fillRect(m * th, n * tw, th, tw);          }          function inbounds(k) {              let m = k[0];              let n = k[1];              return (m >= 0 && m < mapheight && n >= 0 && n < mapwidth);          }          function isblocked(k) {              let m = k[0];              let n = k[1];              if (map[m][n] == -1) {                  return true;              }              return false;          }          function contains(v, k) {              v.forEach(element => {                  if (element[0] == k[0] && element[1] == k[1]) {                      return true;                  }              });              return false;          }          function getneighbors(start) {              let m = start[0];              let n = start[1];              let neighbors = [];              if (inbounds([m - 1, n])) {                  neighbors.push([m - 1, n]);              }              if (inbounds([m, n - 1])) {                  neighbors.push([m, n - 1]);              }              if (inbounds([m + 1, n])) {                  neighbors.push([m + 1, n]);              }              if (inbounds([m, n + 1])) {                  neighbors.push([m, n + 1]);              }              return neighbors;          }          function findstart() {              for (var m = 0; m < mapheight; ++m) {                  for (var n = 0; n < mapwidth; ++n) {                      if (map[m][n] == 1) {                          return [m, n];                      }                  }              }              return undefined;          }              ////HELP :(          function floodfillreachable(start, moves) {              let que = [];              let visited = [];              let flood = [];              que.unshift(start);              for (var k = 1; k <= moves; ++k) {                  while (que.length > 0) {                      let current = que.pop();                      let n = getneighbors(current);                      n.forEach(element => {                          if (!isblocked(element)) {                              if (!contains(visited, element)) {                                  visited.push(element);                                  flood.push(element);                              }                          }                      });                  }              }              return flood;          }            function draw(time) {              ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);              ctx.strokeStyle = "black";              drawgridlines();              fillgrid();                let start = findstart();              let flood = floodfillreachable(start, 4);              flood.forEach(element => {                  filltile(element);              });              requestAnimationFrame(draw);          }          requestAnimationFrame(draw);      });  </script>    </html>

Loop through array and creating new arrays based on object properties

Posted: 24 Apr 2022 06:56 PM PDT

I have an array filled with mixed user Inventory objects.
the objects have an object.name attribute. when I iterate through the array it will already be sorted by name. if we looked at obj.name in the array it would have this structure
[ball,ball,monkey,monkey,sausage]

  1. I would like to loop through the array.

  2. get all elements with common name attribute and create a new array out of those elements.

any suggestions there? bonus points if we can name the array the object.name attribute. I am using Kotlin.

Here is the code/thoughts I have to start, any other suggestions are appreciated if this is not doable

private fun sortElements(){          val temp = userstuff[0].name //but what if they only have 1 of these names.. doesnt work          userstuff.forEach { element ->              if(temp == element.name)               we have another item with same name put in appropriate array               else{                    new array                     loop          }  

is there a faster way to create a pixel on the screen, other than multithreading? [closed]

Posted: 24 Apr 2022 07:01 PM PDT

some code I want to speed up specifically the drawing pixel part so that I don't have to multithread (the code makes a cube (not 3d) that is randomly colored) (also, the code to say what its doing in the beginning is just for show) (the number pain is a joke, and killme is a joke too, but both are still useful (yes, the code is supposed to run forever, or until I shut it down))or is multithreading the way to go?

pixel drawing part I want to speed up:

HDC hdc = GetDC(GetConsoleWindow());  for (int x = xx; x < endx; ++x)      for (int y = yy; y < endy; ++y)          SetPixel(hdc, x, y, RGB(dist6(rng), dist7(rg),   

full code:

  #include <windows.h>      #include <random>      #include <thread>      #include <iostream>      using std::thread;      using std::endl;      int i;      int killme = 62.5;      int aa = killme / 2;      int a = killme + aa;      int aaa = aa + a;      int pain = 1000;      void thread1(int xx, int yy, int endx, int endy)      {          pain++;          std::random_device dev;          std::mt19937 rng(dev());          std::uniform_int_distribution<std::mt19937::result_type> dist6(100, 255);          std::random_device de;          std::mt19937 rg(de());          std::uniform_int_distribution<std::mt19937::result_type> dist7(100, 255);          std::random_device e;          std::mt19937 g(e());          std::uniform_int_distribution<std::mt19937::result_type> dist8(100, 255);          HDC hdc = GetDC(GetConsoleWindow());          for (int x = xx; x < endx; ++x)              for (int y = yy; y < endy; ++y)                  SetPixel(hdc, x, y, RGB(dist6(rng), dist7(rg), dist8(g)));      }      int main()      {          std::cout << "initializing program";          std::cout << "\n#include <windows.h>\n#include <random>\n#include <thread>\n#include <iostream>\nusing std::thread;\nusing std::cout;\nstd::endl;\nint i;\nint killme = 62.5;\nint a = killme * 2;\nint aaa = a + a;\nvoid thread1(int xx, int yy, int endx, int endy)\n{\nstd::random_device dev;\nstd::mt19937 rng(dev());\nstd::uniform_int_distribution<std::mt19937::result_type> dist6(100, 255);\n" << endl << "thread t1(thread1,1,10,aa,aa);" << endl << "thread t2(thread1, aa, 10, killme, aa);" << endl << "thread t3(thread1,1,aa,aa,killme);" << endl << "thread t4(thread1, killme, killme, a, a); " << endl << "t1.join(); " << endl << "t2.join(); " << endl << "t3.join(); " << endl << "t4.join(); " << endl;          Sleep(1);          system("cls");          while (pain != 100)          {              thread t1(thread1,10,10,aa,aa);               thread t2(thread1,aa,10,killme, aa);              thread t3(thread1,10,aa,aa,killme);              thread t4(thread1,killme,killme,a,a);              thread t5(thread1,aa,aa,killme,killme);              t1.join();              t2.join();              t3.join();              t4.join();              t5.join();                        }              return 0;      }  

"undefined reference to main" when generating 64bits shared library via gcc

Posted: 24 Apr 2022 06:57 PM PDT

i was trying to assemble codes below to shared library via gcc.

.section .text    .global S_0x400607  .type S_0x400607, @function  S_0x400607:  push %rbp  mov %rsp,%rbp  sub $0x10,%rsp  mov %edi,-0x4(%rbp)  mov -0x4(%rbp),%eax  mov %eax,%esi  lea S_0x400724(%rip),%rdi  mov $0x0,%eax  callq printf  nop  leaveq  retq      .section .rodata    S_0x400724:  .byte 0x25  .byte 0x64  .byte 0x0a  .byte 0x00  

i used command below in terminal and got errors.

$ gcc zzz_out.s -shared -fPIC  -o libzzz.so  /usr/bin/ld: /tmp/ccq8FvIT.o: relocation R_X86_64_PC32 against symbol `printf@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC  /usr/bin/ld: final link failed: Bad value  collect2: error: ld returned 1 exit status  

Then i googled the question and got a seemingly feasible answer in undefined-reference-to-main-for-shared-library. Then i added option -no-pie, used commands below and got another error.

$ gcc zzz_out.s -shared -fPIC -no-pie  -o libzzz.so  /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crt1.o: In function `_start':  (.text+0x20): undefined reference to `main'  collect2: error: ld returned 1 exit status  

It seems that the order of options matters. But i used codes in 32-bits like this.

.section .text    .globl S_0x8048506  .type  S_0x8048506, @function  S_0x8048506:  push %ebp  mov %esp,%ebp  push %ebx  sub $0x4,%esp  call S_0x80485CC  add $_GLOBAL_OFFSET_TABLE_,%eax  sub $0x8,%esp  pushl 0x8(%ebp)  lea S_0x8048670,%edx  push %edx  mov %eax,%ebx  call printf  add $0x10,%esp  nop  mov -0x4(%ebp),%ebx  leave  ret    S_0x80485CC:  mov (%esp),%eax  ret    .section .rodata  S_0x8048670:  .byte 0x25  .byte 0x64  .byte 0x0a  .byte 0x00  

gcc works perfectly and libzzz.so generated in current directory. Sorry if i asked a simple question. I'm totally new in this region.

Extract data from text/javascript using python

Posted: 24 Apr 2022 06:56 PM PDT

How to extract 'https://www.example.com/get_file/4/b315c8e0d6fad43d89445378b5292eed6981a999ba/174000/174469/174469.mp4/?br=707' & using 'video_url'

[<script src="https://www.example.com/player/kt_player.js?v=5.5.1" type="text/javascript"></script>, <script type="text/javascript">                              /* <![CDATA[ */                                                              function getEmbed(width, height) {                                      if (width && height) {                                          return '<iframe width="' + width + '" height="' + height + '" src="https://www.example.com/embed/174469" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>';                                      }                                      return '<iframe width="852" height="480" src="https://www.example.com/embed/174469" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>';                                  }                                                            var flashvars = {                                                                      video_id: '174469',                                                                     video_categories: 'example_category1', 'example_category2',                                                                     video_tags: 'example_tag1', 'example_tag2',                                                                     license_code: '$603825119921245',                                                                   rnd: '1650848189',                                                                  video_url: 'https://www.example.com/get_file/4/b315c8e0d6fad43d89445378b5292eed6981a999ba/174000/174469/174469.mp4/?br=707',                                                                    postfix: '.mp4',                                                                    video_url_text: '480p',                                                                     video_alt_url: 'https://www.example.com/get_file/4/ffafbe6913656c2250c34bf20fd945a5f86898d749/174000/174469/174469_720p.mp4/?br=1290',                                                                  video_alt_url_text: '720p',                                                                     video_alt_url_hd: '1',                                                                  video_alt_url2: 'https://www.example.com/get_file/4/66c8876a9fd8cd3d823d06880c1797b1424f3200df/174000/174469/174469_1080p.mp4/?br=2559',                                                                    video_alt_url2_text: '1080p',                                                                   video_alt_url2_hd: '1',                                                                     preview_url: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview.jpg',                                                                   preview_url1: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview.mp4.jpg',                                                                  preview_height1: '480',                                                                     preview_url2: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview_720p.mp4.jpg',                                                                     preview_height2: '720',                                                                     preview_url3: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview_1080p.mp4.jpg',                                                                    preview_height3: '1080',                                                                    skin: 'youtube.css',                                                                    logo_position: '0,0',                                                                   logo_anchor: 'topleft',                                                                     hide_controlbar: '1',                                                                   hide_style: 'fade',                                                                     volume: '1',                                                                    related_src: 'https://www.example.com/related_videos_html/174469/',                                                                     adv_pre_vast: 'https://twinrdsrv.com/preroll.engine?id=613eb379-62dd-49ef-8299-db2b5b2af4d7&zid=12861&cvs={ClientVideoSupport}&time={TimeOffset}&stdtime={StdTimeOffset}&abr={IsAdblockRequest}&pageurl={PageUrl}&tid={TrackingId}&res={Resolution}&bw={BrowserWidth}&bh={BrowserHeight}&kw={Keywords}&referrerUrl={ReferrerUrl}&pw={PlayerWidth}&ph={PlayerHeight}',                                                                   adv_pre_skip_duration: '5',                                                                     adv_pre_skip_text_time: 'Skip ad in %time',                                                                     adv_pre_skip_text: 'Skip ad',                                                                   adv_post_vast: 'https://twinrdsrv.com/preroll.engine?id=613eb379-62dd-49ef-8299-db2b5b2af4d7&zid=12861&cvs={ClientVideoSupport}&time={TimeOffset}&stdtime={StdTimeOffset}&abr={IsAdblockRequest}&pageurl={PageUrl}&tid={TrackingId}&res={Resolution}&bw={BrowserWidth}&bh={BrowserHeight}&kw={Keywords}&referrerUrl={ReferrerUrl}&pw={PlayerWidth}&ph={PlayerHeight}',                                                                  adv_post_skip_duration: '5',                                                                    adv_post_skip_text_time: 'Skip ad in %time',                                                                    adv_post_skip_text: 'Skip ad',                                                                  lrcv: '1651572296480833989009946',                                                                  vast_timeout1: '10',                                                                    player_width: '882',                                                                    player_height: '496.9014084507',                                                                    embed: '1'                                                          };                                                          var player_obj = kt_player('kt_player', 'https://www.example.com/player/kt_player.swf?v=5.5.1', '100%', '100%', flashvars);                                                                  window.onload = function() {                                          $('.pop-adv .btn').click(function(e) {                                              player_obj.play();                                          });                                      };  /* ]]> */                          </script>]  

I tried;

import json    script= """[<script src="https://www.example.com/player/kt_player.js?v=5.5.1" type="text/javascript"></script>, <script type="text/javascript">                              /* <![CDATA[ */                                                              function getEmbed(width, height) {                                      if (width && height) {                                          return '<iframe width="' + width + '" height="' + height + '" src="https://www.example.com/embed/174469" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>';                                      }                                      return '<iframe width="852" height="480" src="https://www.example.com/embed/174469" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>';                                  }                                                            var flashvars = {                                                                      video_id: '174469',                                                                     video_categories: 'example_category1, example_category2',                                                                   video_tags: 'example_tag1, esample_tag2',                                                                   license_code: '$603825119921245',                                                                   rnd: '1650848189',                                                                  video_url: 'https://www.example.com/get_file/4/b315c8e0d6fad43d89445378b5292eed6981a999ba/174000/174469/174469.mp4/?br=707',                                                                    postfix: '.mp4',                                                                    video_url_text: '480p',                                                                     video_alt_url: 'https://www.example.com/get_file/4/ffafbe6913656c2250c34bf20fd945a5f86898d749/174000/174469/174469_720p.mp4/?br=1290',                                                                  video_alt_url_text: '720p',                                                                     video_alt_url_hd: '1',                                                                  video_alt_url2: 'https://www.example.com/get_file/4/66c8876a9fd8cd3d823d06880c1797b1424f3200df/174000/174469/174469_1080p.mp4/?br=2559',                                                                    video_alt_url2_text: '1080p',                                                                   video_alt_url2_hd: '1',                                                                     preview_url: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview.jpg',                                                                   preview_url1: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview.mp4.jpg',                                                                  preview_height1: '480',                                                                     preview_url2: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview_720p.mp4.jpg',                                                                     preview_height2: '720',                                                                     preview_url3: 'https://www.example.com/contents/videos_screenshots/174000/174469/preview_1080p.mp4.jpg',                                                                    preview_height3: '1080',                                                                    skin: 'youtube.css',                                                                    logo_position: '0,0',                                                                   logo_anchor: 'topleft',                                                                     hide_controlbar: '1',                                                                   hide_style: 'fade',                                                                     volume: '1',                                                                    related_src: 'https://www.example.com/related_videos_html/174469/',                                                                     adv_pre_vast: 'https://twinrdsrv.com/preroll.engine?id=613eb379-62dd-49ef-8299-db2b5b2af4d7&zid=12861&cvs={ClientVideoSupport}&time={TimeOffset}&stdtime={StdTimeOffset}&abr={IsAdblockRequest}&pageurl={PageUrl}&tid={TrackingId}&res={Resolution}&bw={BrowserWidth}&bh={BrowserHeight}&kw={Keywords}&referrerUrl={ReferrerUrl}&pw={PlayerWidth}&ph={PlayerHeight}',                                                                   adv_pre_skip_duration: '5',                                                                     adv_pre_skip_text_time: 'Skip ad in %time',                                                                     adv_pre_skip_text: 'Skip ad',                                                                   adv_post_vast: 'https://twinrdsrv.com/preroll.engine?id=613eb379-62dd-49ef-8299-db2b5b2af4d7&zid=12861&cvs={ClientVideoSupport}&time={TimeOffset}&stdtime={StdTimeOffset}&abr={IsAdblockRequest}&pageurl={PageUrl}&tid={TrackingId}&res={Resolution}&bw={BrowserWidth}&bh={BrowserHeight}&kw={Keywords}&referrerUrl={ReferrerUrl}&pw={PlayerWidth}&ph={PlayerHeight}',                                                                  adv_post_skip_duration: '5',                                                                    adv_post_skip_text_time: 'Skip ad in %time',                                                                    adv_post_skip_text: 'Skip ad',                                                                  lrcv: '1651572296480833989009946',                                                                  vast_timeout1: '10',                                                                    player_width: '882',                                                                    player_height: '496.9014084507',                                                                    embed: '1'                                                          };                                                          var player_obj = kt_player('kt_player', 'https://www.example.com/player/kt_player.swf?v=5.5.1', '100%', '100%', flashvars);                                                                  window.onload = function() {                                          $('.pop-adv .btn').click(function(e) {                                              player_obj.play();                                          });                                      };  /* ]]> */                          </script>]"""    json_data= json.loads(script)  print(json_data['video_url'])  

and got this error,

json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)

Can I programmatically interact with an "installer" (ie. ./install.sh)

Posted: 24 Apr 2022 06:57 PM PDT

I need to run a fairly complicated installer.sh script that, when ran, asks you all kinds of questions via dialog command which involve typing, multiple choice, checkboxes.

I need to run this installer on many, many, many machines. I'm trying to think of a way to write a simple ruby script to SSH into a server, run the command, but then use code to programmatically answer the questions when "prompted". I would write/handle what answers to put in my ruby code.

Is this possible?

The only caveat I can think of is it does 4 minutes of installing before asking for prompts. Ideally the script could detect 'am I being prompted?' and then answer right away so my ruby code would be systematic like...

1. <up><enter>  2. password<enter>  3. <space><enter>  

I am also open to other methods of doing it...

I can't really "unwrap" the installer as it is just so complicated, I really just have to go through the prompts.

I have thought about provisioning images like in AWS... but the host I must use does not support images.

Tuning ranking in search result

Posted: 24 Apr 2022 06:59 PM PDT

doc1 = {"id":1,"text":"tonight"}  doc2 = {"id":2,"text":"tonight tonight"}  doc3 = {"id":3,"text":"tonight tonight tonight"}  doc4 = {"id":4,"text":"tonight and something else"}  doc5 = {"id":5,"text":"tonight and you"}    es.index(index="tonight", document=doc1)  es.index(index="tonight", document=doc2)  es.index(index="tonight", document=doc3)  es.index(index="tonight", document=doc4)  es.index(index="tonight", document=doc5)  

Suppose I have the above documents indexed. When I use the below query:

data = json.dumps({      "query":{           "bool":{              "should":[                  {                      "match":{                          "text": "tonight"                      }                  }              ]          }      }  })  

The hits returned in the order of "tonight tonight tonight", "tonight tonight","tonight", "tonight and you" and "tonight and something else".

May I ask if there is a way to make "tonight" as the first hit returned with highest _score?

In my real life use case, I am conducting iterating throught the whole index to find out the most relevant text other than itself, and the document being searched should be returned as the first hit (most matched) if possible.

Could someone please give me some ideas on how to query?

Thank you!!!

Would it be possible to draw this stacked bar chart in R?

Posted: 24 Apr 2022 07:00 PM PDT

I have a data frame named act_df like this: Average sedentary hours, average lightly active hours, average fairly active hours, average very active hours per a person

int_by_id<-group_by(daily_intensity_minutes,Id)  act_df <- summarise(int_by_id,avg_sd_hr=round(mean(SedentaryMinutes)/60),    avg_light_actv_hr=round(mean(LightlyActiveMinutes)/60),     avg_fairly_actv_hr=round(mean(FairlyActiveMinutes)/60),    avg_very_actv_hr=round(mean(VeryActiveMinutes)/60))  

I manipulated data by using group by and summarize function to see average activity per person.

And I want draw bar chart in this way: Id on Y-axis and the each bar is filled with other columns like average sedentary hours, average lightly active hours

Would it be possible to visualize this in R?

I am asking this because I don't know what to write down in the blank after fill while using ggplot2.( fill='___') Usually, in the blank, one of columns in it. However, for my case, all the columns except 'Id' are filling the bars.

Intercepting Fetch function - Request Headers

Posted: 24 Apr 2022 06:59 PM PDT

I am intercepting already intercepted fetch and I cannot read final request data (specifically request headers).

By intercepting I mean wrapping original window.fetch()

See comments below.

// this was already wrapped before me...  // so it's NOT pure window.fetch  const originalFetch = window.fetch;     window.fetch = function() {            // this will be added to the request      arguments[1].headers.append("X-Security-A", 1);            // After apply() below, the arguments are changed using      // other external functions, which also intercept the fetch      // and they will add additional headers;      // I don't have access to these functions.            // I cannot change the resource URL, because the external      // functions check it.            // I need to read the new headers, but the [arguments]      // remain unchanged. They are changed somewhere within this apply()      var promise = originalFetch.apply(this, arguments);            // this will be added, but will NOT be added to actual      // request, which already happened      arguments[1].headers.append("X-Security-B", 1);            promise.then((response) => {                        // Here I will get the results, but the request headers              // are still NOT here;              // only the ones I added              // If I look in Chrome Console the sent request              // contains all the headers I need to see.                            // HOW CAN I GET THE REQUEST HEADERS HERE?                console.log('XXX Promise', promise);              console.log('XXX Headers ', Array.from(arguments[1].headers.entries()));              console.log('XXX Response', response);              return response;          });        return promise;  }  

How to map and filter through array based on a value?

Posted: 24 Apr 2022 07:00 PM PDT

How do i filter the data based on the id? Example if i wanted to filter id= "24". So it will filter out the object that is matching.

[    {      "id": "Sheet1",      "data": [        {          "id": "24",          "title": "Title of article",          "date_time": "11/05/2022",          "description": "Description of Article"        },        {          "id": "25",          "title": "Title of article 2",          "date_time": "15/05/2022",          "description": "Description of Article 2"        }      ]    }  ]    

Output:

"data": [        {          "id": "24",          "title": "Title of article",          "date_time": "11/05/2022",          "description": "Description of Article"        }      ]      

sklearn TimeSeries cross-validation and recalculating sample weights dynamically on each fit/fold

Posted: 24 Apr 2022 06:56 PM PDT

I have a pretty simple little model in a Pipeline which I want to weight the samples for and do cross-validation on:

from lightgbm import LGBMClassifier  from category_encoders import OneHotEncoder, OrdinalEncoder  from sklearn.pipeline import FeatureUnion, Pipeline  from sklearn.base import TransformerMixin  from sklearn.model_selection import cross_validate  from sklearn.model_selection import TimeSeriesSplit  import pandas as pd    categorical_columns = ['time_zone']  ordinal_columns = ['distance_miles']  date_column = ['date_of_entry']    class ColumnExtractor(TransformerMixin):        def __init__(self, features,  cast_as=None):            self.features = features          self.cast_as = cast_as        def get_feature_names_out(self, features):          return self.features        def fit(self, *args, **kwargs):          return self        def transform(self, X, **transform_params):          return X[self.features].astype(self.cast_as)    def exp_decay_weighted_obs(obs, decay_rate=0.01):      total_rows = len(obs)      i = 1      weights = []      while (i <= total_rows):          curr_weight = pow((1 - decay_rate), (total_rows - i))          weights.append(curr_weight)          i = i + 1      return (weights)      #generate weights over all days in the range of our obs  def temporal_exp_decay_weighted_obs(dates, decay_rate=0.01):      first_date = dates[0]      last_date = dates[len(dates) - 1]        days_arr = pd.date_range(start=first_date, end=last_date, closed=None)      weights = exp_decay_weighted_obs(obs=days_arr, decay_rate=decay_rate)      return (dict(zip(days_arr, weights)))    def reshape_weights(rows, weight_index_field, weights):      w = []      for idx, row in rows.iterrows():          w.append(weights[row[weight_index_field].to_pydatetime()])      return w    #some fake data..our obs are one week apart, but could be any dates, sorted asc  x_data = {'time_zone':['ET', 'PT', 'PT', 'MT', 'ET', 'ET'],            'distance_miles':[200, 21, 1900, 18, 56, 100]}  y_train = [0, 1, 1, 0, 1, 0]  X_train = pd.DataFrame(x_data)  X_train['date_of_entry'] = pd.date_range('1/1/2022', periods = 6, freq ='W')  dates_x = X_train['date_of_entry'].unique()    #get weights for each day in our range, exponentially decayed from first date by DAY  weights = temporal_exp_decay_weighted_obs(dates_x, decay_rate=0.01)  weights_x = reshape_weights(X_train, 'date_of_entry', weights)    mlpl = Pipeline([      ('features', FeatureUnion([          ('categoricals', Pipeline([              ('extract', ColumnExtractor(categorical_columns, str)),              ('encoder', OneHotEncoder())          ])),          ('ordinals', Pipeline([              ('extract', ColumnExtractor(ordinal_columns, int)),              ('encoder', OrdinalEncoder())          ]))      ])),      ('classifier', LGBMClassifier())  ])    #we can use our weights in fit..like so  mlpl.fit(X=X_train, y=y_train, classifier__sample_weight=weights_x)    # but how might we calculate the weights again in a TimeseriesSplit?  #the values of the temporal exp decay rates would/should be different  #use fit_param?  scores = cross_validate(mlpl, X_train, y_train, cv=TimeSeriesSplit(n_splits=2), scoring='balanced_accuracy')  

So, i have devised a sort of exponential decay based upon the date of the observation ("date of entry" --as you move further back in time, the observations are weighted less based upon the day and the decay rate.

I can calculate this beforehand and supply it to the fit() on the Pipeline with no issue at all-and this is done in the code snippet.

But I want to cross validate using a timeSeries split (to keep the order of the observations), but the weights would NOT be correct for each of the splits because I want them weighted to the date range of the split, not the date range of the entire data set. basically I need to be able to dynamically generate those weights per each call to fit().

How would I best do this? some fit_param magic on the cross-validate() call? some superclass on the LGBMClassifier which recalcs them on the data passed in (but how do I make those date obs NOT be a part of the X data?)? Thoughts?

Creating dynamic keys values in json array in google apps script

Posted: 24 Apr 2022 06:56 PM PDT

I have this workbook of data - dataset

Now, the actual dataset will probably have duplicates of the same company and my end goal is to create a timeline of activities, but that's for another question.

What I'm trying to accomplish here is by converting the data here, which is contact centric (meaning that each row represents a new contact, not a new company) into a company centric JSON array.

This is represented in the code below

var companies = {    'names':[]  };  function organiseLeads() {        const leads = leadSheet.getDataRange().getValues();      leads.splice(0,1);      try {      for (var i in leads) {        var data = leads[i];        var companyName = data[3];          var exists = companies.names.some(function (company) {          return company === companyName;        });  Logger.log(exists);        if (exists == false) {          companies.names[companyName] = {            'region': data[4],            'type': data[5],            'createDate': data[9],            'ids': {              'opportunityId': data[8],              'accountId': data[7],              'leadId': data[0]            },            'activities': [{              'type': 'Lead Created',              'date': data[9],              'detail': data[2]            }]          }        } else if (exists == true && data[9].valueOf() < companies[companyName].createDate) {          companies.names[companyName].createDate = data[9];          companies.names[companyName].activities.push({ 'type': 'Lead Created', 'date': data[9], 'detail': data[2] });        } else if (exists == true && data[9].valueOf() > companies[companyName].createDate) {          companies.names[companyName].activities.push({ 'type': 'Lead Created', 'date': data[9], 'detail': data[2] });        }      }    } catch(e) {      Logger.log(e);      Logger.log(exists);       Logger.log(data);        Logger.log(companyName);         Logger.log(companies.names);    }  }  

In this context leadSheet refers to the dataset mentioned here. It's defined in Google Script elsewhere.

I've also tried using companies.names.push([companyName = {}]) (with all the additional data there), but nothing happens.

What's supposed to happen is that it checks to see if the company already exists, in this array. If it doesn't, it will create it as multi-dimensional array use the company name as the primary key and then have the details as the nested key values pairs.

If the company already exists, it just makes some minor changes to that company record, and then returns the entire json array.

However, what happens is nothing. It doesn't set anything in the JSON array at all. And when i've tried to flatten the companies array, I get the error companies.some is not a function and the exists variable, which checks to see if company already exists, always returns false.

How do I make sure that the data gets properly pushed into the JSON array? Keep in mind that the key for the company name is dynamically generated and not a static key.

How overwriting is implemented based on append-only storage layer in Cloud, like azure? [closed]

Posted: 24 Apr 2022 06:57 PM PDT

Background

Azure/Alicloud IAAS use append-only storage layer for data replication, and provide block/filesystem/object store in upper layer. Distributed file system under this architecture must have different implementation comparing to traditional one like CEPH.

Question

How overwrite of file and change of directory is implemented under this architecture, index + gc?

Can you give me some paper or article?

Is there a smarter method to create series with different intervalls for count within a query?

Posted: 24 Apr 2022 06:59 PM PDT

I want to create different intervalls:

  • 0 to 10 steps 1
  • 10 to 100 steps 10
  • 100 to 1.000 steps 100
  • 1.000 to 10.000 steps 1.000

to query a table for count the items.

with "series" as (                      (SELECT generate_series(0, 10, 1) AS r_from)                          union                        (select generate_series(10, 90, 10) as r_from)                          union                       (select generate_series(100, 900, 100) as r_from)                          union                       (select generate_series(1000, 9000, 1000) as r_from)                          order by r_from                  )  , "range" as    ( select r_from                      ,   case                               when r_from < 10    then r_from + 1                               when r_from < 100   then r_from + 10                              when r_from < 1000  then r_from + 100                                                  else r_from + 1000                           end as r_to                  from series)  select r_from, r_to,(SELECT count(*) FROM "my_table" WHERE "my_value" BETWEEN r_from AND r_to) as "Anz."  FROM "range";  

Insert tab character into SlateJS text editor

Posted: 24 Apr 2022 07:00 PM PDT

How to insert tab characters into SlateJS?

So inserting &emsp; is a tab character, however, when inserting this as text, it appears as the literal characters &emsp; not the text with a tab spacing.

// Don't work, inserts literal characters  const insertText = (editor, format) => {      Editor.insertText(editor, `&emsp;')  }  

Is there any simple way to insert a &emsp; and have Slatejs recognise it as the html, not as pure text?

Based on my rough understanding, it might be I'll need to serialise and deserialise html before inserting it. Maybe even inserting <pre> </pre> blocks with the spacing included.

How to get specific chunks from stream node js

Posted: 24 Apr 2022 06:59 PM PDT

I'm trying to make a server that are used like a "CDN proxy".

We have

  • S1: main server that has all media
  • S2 CDN proxy
  • client

The aim is:

  1. obtain a stream from server1 (S1) (I'm using this follow link as placeholder, the effective link could be a temp link)
axios.get(link, { responseType: "stream", adapter: httpAdapter })      .then((axiosResponse: any) => { ... })   
  1. since I have a stream, I don't need to proxy the entire media to the client, but just a chunk (specified from the client)

I don't know how to retrieve a specific chunk without download all chunks up to the desired chunk.

This is a scratch:

import express, { Request, Response } from 'express';  import expressAsyncHandler from 'express-async-handler';  import * as http from 'http';  const axios = require("axios");  const httpAdapter = require("axios/lib/adapters/http");        const app = express();  const HTTP_PORT = 3000;  var server = http.createServer(app);      const link = 'https://images.all-free-download.com/footage_preview/mp4/city_panorama_6891675.mp4';    app.get('/video.mp4', expressAsyncHandler(async (req: Request, res: Response) => {    axios.get(link, { responseType: "stream", adapter: httpAdapter })      .then((axiosResponse: any) => {        let stream = axiosResponse?.data;          const fileSize = axiosResponse["headers"]["content-length"];        const range = req.headers.range        if (range) {          const parts = range.replace(/bytes=/, "").split("-")          const start = parseInt(parts[0], 10)          const end = parts[1]            ? parseInt(parts[1], 10)            : fileSize - 1          const chunksize = (end - start) + 1            /*******************************/          const streamChunk = /* GET CHUNCK FROM STREAM WITHOUT OVERHEAD */ null;          /*******************************/            const head = {            'Content-Range': `bytes ${start}-${end}/${fileSize}`,            'Accept-Ranges': 'bytes',            'Content-Length': chunksize,            'Content-Type': 'video/mp4',          }          res.writeHead(206, head);          streamChunk.pipe(res);        } else {          const head = {            'Content-Length': fileSize,            'Content-Type': 'video/mp4',          }          res.writeHead(200, head)          stream.pipe(res)        }      })  }));    server.listen(HTTP_PORT, () => {    console.log("Running on port: " + HTTP_PORT);  });  

I hope someone can help me.

Thanks in advice :)

UPDATE Follow code works on VLC

import express, { Request, Response } from 'express';  import expressAsyncHandler from 'express-async-handler';  import * as http from 'http';  import * as https from 'https';  const axios = require("axios");  const httpAdapter = require("axios/lib/adapters/http");    const app = express();  const HTTP_PORT = 3000;  var server = http.createServer(app);    /************************************************/  // PREVENT EXCEPTION CLOSURE  process.on('uncaughtException', function (err) {    console.error(err);    console.log("Node NOT Exiting...");  });  /************************************************/    const link = 'https://samplelib.com/lib/preview/mp4/sample-30s.mp4';      app.get('/video.mp4', expressAsyncHandler(async (req: Request, res: Response) => {    if (req.socket.destroyed) {      return;    }      delete req.headers.referer;      let head;    let status;    const range = req.headers.range    const axiosResponseHead = await axios.head(link)    const fileSize = axiosResponseHead["headers"]["content-length"];      const agent = new https.Agent({      rejectUnauthorized: false    });        console.log(range)      if (range) {      req.headers.host = new URL(link).hostname;        const parts = range?.replace(/bytes=/, "")?.split("-")      const start = parseInt(parts[0], 10)      const end = parts[1]        ? parseInt(parts[1], 10)        : fileSize - 1      const chunksize = (end - start) + 1      head = {        'Content-Range': `bytes ${start}-${end}/${fileSize}`,        'range': `bytes=${start}-${end}`,        'Accept-Ranges': 'bytes',        'Content-Length': chunksize,        'Content-Type': 'video/mp4',      }      status = 206;      req.headers.range = head.range    } else {      head = {        'Content-Length': fileSize,        'Content-Type': 'video/mp4',      }      status = 200;    }        console.log(req.headers)    console.log(head)    console.log("==================================")        let axiosResponse: any    let stream: any;      res.on('close', function () {      stream?.destroy();    });      let instance = axios.create();    axiosResponse = await instance.get(link, {      responseType: "stream", adapter: httpAdapter, headers: req.headers, httpsAgent: agent    })    stream = axiosResponse?.data;    res.writeHead(status, head)    stream.pipe(res, { end: true });  }));      server.listen(HTTP_PORT, () => {    console.log("Running on port: " + HTTP_PORT);  });    function sleep(ms: number) {    return new Promise(resolve => setTimeout(resolve, ms));  }  

Import web3 not found... in solana web3.js

Posted: 24 Apr 2022 07:01 PM PDT

I npm installed everything, yet only web3 is not working? Is this a bug or is there an alternative to this solution?

 import React,{useEffect, useState}from 'react';      import { Connection, PublicKey,Account } from '@solana/web3.js';      import { MintLayout, TOKEN_PROGRAM_ID, Token } from '@solana/spl-token';      import { Program, Provider } from '@project-serum/anchor';            import { sendTransactions } from './connection';      import './CandyMachine.css';  

Error message below

export 'web3' (imported as 'web3') was not found in '@solana/web3.js' (possible exports: Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction)  

Dynamic instruction trace for Android Apps

Posted: 24 Apr 2022 07:00 PM PDT

I want to generate the dynamic instruction trace of Android Apps (Just like for a basic hello world C program, I am able to generate the instruction trace using the tools like Dynamorio, pintool).

I want to know at runtime, what are the address of the instruction which are getting executed? Is anyone aware of any existing tool which can help me in this?

I found out that there are existing tools like Dynamorio (support for Linux, Windows is there but for Android's ART environment, they are not), Pin tool (the last Android version they were supporting is the Icecream).

I also tried using https://perfetto.dev/ but they seem to capture the device activity.

In that, if I want to generate the dynamic instruction trace of Android Apps, I am unable to do so.

Is anyone aware of any tool which seems to generate the dynamic instruction trace for Android Apps?

Any response from your side will be highly appreciated and will help in my project.

Axios response.data return HTML instead of an object

Posted: 24 Apr 2022 07:01 PM PDT

I need help about Axios. I develop a SPA webapp on Laravel 6 (with package SPARK) and VueJS (version 2).

On a Vue component, I want to retrieve datas from my bdd. So, I use Axios to make a get request on an API uri. But, when I call Axios request, data field in Response object is a HTML code.

This is my code :

routes/web.php

Route::get('/', function(){      return view('welcome');  });    Route::middleware('auth')->get('/{any?}', function (){      return view('documents');  })->where('any', '[\/\w\.-]*');  

The "welcome" view is a blade page where redirect on "/login" if user is not authenticate. Otherwise, it redirect on "/home". The link "/home" is define on vue-router in app.js. The other route is the unique way to display the webapp (it's a single page application). The Vue instanciation is in "passeport" view.

resources/js/app.js

import 'es6-promise/auto'    require('spark-bootstrap');  require('./components/bootstrap');    window.Vue = require('vue');    import VueRouter from 'vue-router';  Vue.use(VueRouter);    import VueAxios from 'vue-axios';  import axios from 'axios';  Vue.use(VueAxios, axios);    Vue.component('index', require('./components/pages/index').default);    import Dashboard from './components/pages/dashboard.vue';  ...    const routes = [       {          name: 'dashboard',          path: '/home',          component: Dashboard,      },      {...}  ]    const router = new VueRouter({       history: true,      mode: 'history',       routes: routes  });    var app = new Vue({      mixins: [require('spark')],      router,  });  

router package is added in Vue instanciation. it is in the same context than spark component (identify by the #spark-app element)

resources/views/documents.blade.php

@extends('spark::layouts.app')    @section('content')      <div id="app">          <index :user="user"></index>      </div>  @endsection  

It is the view returned for any path. In the spark::layout.app, there is only a div with id="spark-app" and the @yield('content').

resouces/js/components/pages/index.vue

<template>      <transition name="fade">        <Component :is="layout" :user="user">          <router-view :layout.sync="layout" :user="user"></router-view>        </Component>      </transition>  </template>  .  .  <script>      const default_layout = "default";        export default{        props: ['user'],          data(){          return{            layout: 'div',          }        },      }  </script>  

It's just the vue component with the router-view configure with a layout.

resources/js/components/pages/dashboard.vue

<template>  ...  </template>    <script>  import Default from './../layouts/Default.vue'      export default {          props: ['user'],            data: function () {              return {                  documents: []              }          },          created() {               this.$emit('update:layout', Default);          },          mounted(){              // extract passeports's informations              this.axios.get('/api/documentslist').then(response => {                  console.log(response);                  this.documents= response.data.data;              });          }      }  </script>  

Here, I call the documentslist API define in routes/api.php.

routes/api.php

Route::middleware('auth:api')->group(function () {      Route::get('/user', function (Request $request) {          return $request->user();      });      Route::get('/documentslist', 'DocumentController@list');  });  

app/http/Controllers/DocumentController.php

...  public function list(Request $request){     return DocumentCollection(Document::all());  }  ...  

When I go to "/home", I verified "documents" data in Vue (or in the javascript console log), and response.data = "\r\n\r\n\r\n (...) v-if=\"notification.creator\" :src=\"notification.creator.photo_url\" class=... (10024 total length)"

But, list method in DocumentController have to return a list of documents, and not a HTML code.

Furthermore, I use Passport Laravel to unified authentication by login and the API token. And the Axios request work in the same project without SPA structure.

I hope I'm clear in the problem explanation, and that I forget any detail to understand.

Thanks.

Python argparse error: error: argument count: invalid int value

Posted: 24 Apr 2022 07:01 PM PDT

I am trying to run below code in jupyter notebook.

import argparse  parser = argparse.ArgumentParser(description='Example with non-optional arguments')  parser.add_argument('count', action="store", type=int)  parser.add_argument('units', action="store")  print(parser.parse_args())  

but this gives this gives below error

usage: ipykernel_launcher.py [-h] count units  ipykernel_launcher.py: error: argument count: invalid int value: 'C:\\Users\\Kwan Lee\\AppData\\Roaming\\jupyter\\runtime\\kernel-76bf5bb5-ea74-42d5-8164-5c56b75bfafc.json'  An exception has occurred, use %tb to see the full traceback.    SystemExit: 2      c:\users\kwan lee\anaconda2\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py:2971: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.    warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)  

I am just trying to learn what argparse is but I don't get this error.

Set value in a datagridview cell programmatically

Posted: 24 Apr 2022 07:01 PM PDT

I'm new in C# and I have a problem with setting the value of a cell programmatically.

I've created a column and added it to the DataGridView:

  DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();    column.Name = "DeclaredBy";    column.HeaderText = "DeclaredBy";    TaskDataGridView.Columns.Add(column);  

The column shows up correctly. But when I want to set a value in any cell of this column, nothing happens, the cell is still empty:

TaskDataGridView.Rows[i].Cells["DeclaredBy"].Value = "test";  

Avada Wordpress Theme, cannot resize logo ( using cafe demo content )

Posted: 24 Apr 2022 07:01 PM PDT

I'm using the Avada Wordpress theme and have installed the Cafe Site Demo Content. I went into Appearance > Theme Options > Logo and uploaded my image logo file but it seems to lock it to a tiny size in that top left menu corner. I remade the logo image at double the size and re uploaded it and it still is the same small size on the website, I cannot find an option to allow me to increase the logo size. Does anyone have any ideas?

No comments:

Post a Comment