Saturday, July 24, 2021

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


quanteda - calculating sparsity proportion of top n features

Posted: 24 Jul 2021 08:17 AM PDT

I'm trying to get the top n features of a corpus and then check the sparsity proportion of the top n features. However, my coding does not work well because sparsity work only with dfm objects, but if I put sparsity() after dfm_remove(stopwords("en")) I could not know the proportion of the top features. Could you please tell me some suggestions for my case?

Thank you in advance for your help!

  top_n_terms <- text %>%         tokens(remove_numbers = TRUE, remove_punct = TRUE, remove_symbols = TRUE) %>%         tokens_ngrams(n = 1:3) %>%         dfm() %>%         dfm_remove(stopwords("en")) %>%         topfeatures(n = 3000) %>%         sparsity()  

Find how many common missing (nan) values are in DataFrame columns

Posted: 24 Jul 2021 08:17 AM PDT

I have got DataFrame with about 20 columns and 50000 rows. Small part of this Pandas table is below:

enter image description here

I am looking for some way to count how many missing values are in the same positions (rows) in a few columns. When number of the columns is known simply code like these:

((df['HomeRemote'].isnull() & df['CompanySize'].isnull()).sum()  

probably is the answer, but unfortunately number of the columns to compare could be more than 2. I don't know it, because it depends on situation and that's why I looking for something like "universal" solution (working for any number of columns).

My idea is finding a way to "push" every df[col].isnull() into the FOR loop (where col is name of column), but I have a problem with put '&' between every df[col].isnull().

Maybe anyone here have some other possibility to consider?

If something is not clear enough, please let me know.

Can't build C++ program using Pistache.io due to link errors

Posted: 24 Jul 2021 08:16 AM PDT

I followed the instructions on the official website to build and install Pistache.io. Now, I'm trying to build this sample program from the official repository: https://github.com/pistacheio/pistache/blob/master/examples/hello_server.cc

However, I get the following error even though I've used the -lpistache flag:

g++ -Wall -Wextra -std=c++17  -lpistache  hellopis.cpp   -o hellopis  /usr/bin/ld: /tmp/ccuHXrLC.o: warning: relocation against `_ZTVN8Pistache3Tcp7HandlerE' in read-only section `.text._ZN8Pistache3Tcp7HandlerC2ERKS1_[_ZN8Pistache3Tcp7HandlerC5ERKS1_]'  /usr/bin/ld: /tmp/ccuHXrLC.o: in function `main':  hellopis.cpp:(.text+0x3b): undefined reference to `Pistache::Port::Port(unsigned short)'  /usr/bin/ld: hellopis.cpp:(.text+0x4a): undefined reference to `Pistache::IP::any()'  /usr/bin/ld: hellopis.cpp:(.text+0x9f): undefined reference to `Pistache::Address::Address(Pistache::IP, Pistache::Port)'  /usr/bin/ld: hellopis.cpp:(.text+0xb2): undefined reference to `Pistache::Http::Endpoint::options()'  /usr/bin/ld: hellopis.cpp:(.text+0xc6): undefined reference to `Pistache::Http::Endpoint::Options::threads(int)'  /usr/bin/ld: hellopis.cpp:(.text+0x103): undefined reference to `Pistache::Http::Endpoint::Endpoint(Pistache::Address const&)'  /usr/bin/ld: hellopis.cpp:(.text+0x11c): undefined reference to `Pistache::Http::Endpoint::init(Pistache::Http::Endpoint::Options const&)'  /usr/bin/ld: hellopis.cpp:(.text+0x151): undefined reference to `Pistache::Http::Endpoint::setHandler(std::shared_ptr<Pistache::Http::Handler> const&)'  /usr/bin/ld: hellopis.cpp:(.text+0x178): undefined reference to `Pistache::Http::Endpoint::serve()'  /usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Endpoint::~Endpoint()':  hellopis.cpp:(.text._ZN8Pistache4Http8EndpointD2Ev[_ZN8Pistache4Http8EndpointD5Ev]+0x3c): undefined reference to `Pistache::Tcp::Listener::~Listener()'  /usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Async::Promise<long> Pistache::Http::ResponseWriter::send<13ul>(Pistache::Http::Code, char const (&) [13ul], Pistache::Http::Mime::MediaType const&)':  hellopis.cpp:(.text._ZN8Pistache4Http14ResponseWriter4sendILm13EEENS_5Async7PromiseIlEENS0_4CodeERAT__KcRKNS0_4Mime9MediaTypeE[_ZN8Pistache4Http14ResponseWriter4sendILm13EEENS_5Async7PromiseIlEENS0_4CodeERAT__KcRKNS0_4Mime9MediaTypeE]+0x3b): undefined reference to `Pistache::Http::ResponseWriter::sendImpl(Pistache::Http::Code, char const*, unsigned long, Pistache::Http::Mime::MediaType const&)'  /usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Tcp::Handler::Handler(Pistache::Tcp::Handler const&)':  hellopis.cpp:(.text._ZN8Pistache3Tcp7HandlerC2ERKS1_[_ZN8Pistache3Tcp7HandlerC5ERKS1_]+0x26): undefined reference to `vtable for Pistache::Tcp::Handler'  /usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::Handler(Pistache::Http::Handler const&)':  hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2ERKS1_[_ZN8Pistache4Http7HandlerC5ERKS1_]+0x26): undefined reference to `vtable for Pistache::Http::Handler'  /usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::~Handler()':  hellopis.cpp:(.text._ZN8Pistache4Http7HandlerD2Ev[_ZN8Pistache4Http7HandlerD5Ev]+0xf): undefined reference to `vtable for Pistache::Http::Handler'  /usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerD2Ev[_ZN8Pistache4Http7HandlerD5Ev]+0x22): undefined reference to `Pistache::Tcp::Handler::~Handler()'  /usr/bin/ld: /tmp/ccuHXrLC.o: in function `Pistache::Http::Handler::Handler()':  hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x15): undefined reference to `Pistache::Tcp::Handler::Handler()'  /usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x1c): undefined reference to `vtable for Pistache::Http::Handler'  /usr/bin/ld: hellopis.cpp:(.text._ZN8Pistache4Http7HandlerC2Ev[_ZN8Pistache4Http7HandlerC5Ev]+0x7b): undefined reference to `Pistache::Tcp::Handler::~Handler()'  /usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x28): undefined reference to `Pistache::Http::Handler::onInput(char const*, unsigned long, std::shared_ptr<Pistache::Tcp::Peer> const&)'  /usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x30): undefined reference to `Pistache::Http::Handler::onConnection(std::shared_ptr<Pistache::Tcp::Peer> const&)'  /usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x38): undefined reference to `Pistache::Tcp::Handler::onDisconnection(std::shared_ptr<Pistache::Tcp::Peer> const&)'  /usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTV12HelloHandler[_ZTV12HelloHandler]+0x48): undefined reference to `Pistache::Http::Handler::onTimeout(Pistache::Http::Request const&, Pistache::Http::ResponseWriter)'  /usr/bin/ld: /tmp/ccuHXrLC.o:(.data.rel.ro._ZTI12HelloHandler[_ZTI12HelloHandler]+0x10): undefined reference to `typeinfo for Pistache::Http::Handler'  /usr/bin/ld: warning: creating DT_TEXTREL in a PIE  collect2: error: ld returned 1 exit status  make: *** [<builtin>: hellopis] Error 1  

What is this error and how can I resolve it?

get Y value given X value in AM Charts JS

Posted: 24 Jul 2021 08:16 AM PDT

I am using AMCharts for my project, what I want is to accomplish this:

given 1. data points:

const data = [{x: 23, y: 0},{x: 24, y: 0},{x: 25, y: 23},...,{x: 26, y: 24}]  

I want to extract any Y value given X value from the series...

Partial code I am using to create chart:

        this.chart = am4core.create(this.chartDiv, am4charts.XYChart);            this.title = this.chart.titles.create();            // chartData is just an array of x,y values          this.chart.data = this.props.chartData;            const X_AXIS = this.chart.xAxes.push(new am4charts.ValueAxis());          X_AXIS.title.text = "X VALUES";            const Y_AXIS = this.chart.yAxes.push(new am4charts.ValueAxis());          Y_AXIS.title.text = "Y VALUES";            this.series = this.chart.series.push(new am4charts.LineSeries());          this.series.dataFields.valueX = "xValue";          this.series.dataFields.valueY = "yValue";            // cursor          this.chart.cursor = new am4charts.XYCursor();          this.chart.cursor.xAxis = X_AXIS;          this.chart.cursor.yAxis = Y_AXIS;          this.chart.cursor.snapToSeries = this.series;  

How can I accomplish this? Say Y value for X = 24 in JS (something like this.series.get(25))

How to make condition to round down to next change variable using BigDecimal

Posted: 24 Jul 2021 08:16 AM PDT

everyone!

I am trying to make change on an application using quarters, dimes, and nickels. The problem is I have to use BigDecimal and I'm not familiar enough to proceed with this problem. This code here works fine if you're trying to buy something that is a multiple of 25 cents, but say you buy something that costs $6.95 it will only return your change in quarters at 27.80 quarters. I realize this is happening because the customerBalance is immediately subtracting in only quarters. My question is how do I have it return 27 quarters and 2 dimes for something that costs $6.95. I'm fairly new to coding so please be understanding. Thank you in advance!

} else if(choice.equals(FINISH_TRANSACTION)) {                  System.out.println(customerBalance);                  //This needs to go down line by line to distribute change accordingly                  //Need to return in whole integers                  BigDecimal quarter = BigDecimal.valueOf(4).multiply(customerBalance);                  customerBalance = customerBalance.subtract(customerBalance);                  BigDecimal dime = BigDecimal.valueOf(10).multiply(customerBalance);                  customerBalance = customerBalance.subtract(customerBalance);                  BigDecimal nickel = BigDecimal.valueOf(20).multiply(customerBalance);                  customerBalance = customerBalance.subtract(customerBalance);                    //This is currently printing in quarters only                  System.out.println("Your change is: " + quarter + " quarters, " + dime + " dimes, " + "and " +nickel + " nickels.");                  //Resets Customer Balance To Zero                  customerBalance = BigDecimal.valueOf(0.00);  

How do I push code from a new local folder to an existing Github repository's main branch and keep commit history?

Posted: 24 Jul 2021 08:18 AM PDT

I have an existing repository in which the main branch has several commits.

I have a local folder on my desktop that contains code that I wish to commit to the main branch and completely replaces all code in the previous commit. I wish to retain the commit history of the main branch.

How do I connect my local folder to the existing github repository, point it to the main branch, commit to this branch such that it replaces all code in the previous commit and yet keeps all the commit history up to this point?

I have done the following:  # Initialize the local directory as a Git repository.  git init    # Add files  git add .    # Commit your changes  git commit -m "First commit"    # Add remote origin  git remote add origin <Remote repository URL>  # <Remote repository URL> looks like: https://github.com/user/repo.git    # Verifies the new remote URL  git remote -v    # Push your changes to main  git push origin main  

But it says git error: failed to push some refs to remote

Cannot access csproj file when double clicking on it

Posted: 24 Jul 2021 08:18 AM PDT

I am new to programming, so I hope I am not missing anything.

I have several projects of .net framework 4.7.2 and I need to add something to .csproj file.

I know I can do it by navigating to the file path and clicking on the file and edit it on notepad for example, but this is not the issue.

I tried to open from my Visual Studio (2019) the .csproj file and figured out that some of my projects opens the file when double clicking on them and some are not. Why? Is it a bug or something causes it? I don't remember I did any special configuration for it.

Some facts that might be related:

  • My code is written in C#.
  • I have some library projects and a console project (all targets to .net framework 4.7.2 version).
  • The solution compiles properly.

Complete file path of multiple excels with Python

Posted: 24 Jul 2021 08:17 AM PDT

I have multiple excels open on my computer, which are in different instances. I am using below script to get complete path of all the files. With below code I can get only a list of file names. But I need full path.

import xlwings as xw  wb = xw.books  print (wb)  

Awk multiline non-greedy matching workaround

Posted: 24 Jul 2021 08:17 AM PDT

I'm trying to extract the contents of an HTML list using awk. Some list entries are multi-line.

Example input list:

<ul>      <li>          <b>2021-07-21:</b> Lorem ipsum       </li>      <li>          <b>2021-07-19:</b> Lorem ipsum       </li>      <li><b>2021-07-10:</b> Lorem ipsum</li>  </ul>  

Command I'm using:

awk -v RS="" '{match($0, /<li>(.+)<\/li>/, entry); print entry[1]}' file.html  

Current output:

        <b>2021-07-21:</b> Lorem ipsum       </li>      <li>          <b>2021-07-19:</b> Lorem ipsum       </li>      <li><b>2021-07-10:</b> Lorem ipsum  

Desired output:

        <b>2021-07-21:</b> Lorem ipsum           <b>2021-07-19:</b> Lorem ipsum       <b>2021-07-10:</b> Lorem ipsum    

I know the issue is because the list entries are not separated by empty lines. I thought of using non-greedy matching, but apparently Awk doesn't support it. Is there a possible workaround?

Firebase Web Push - Actions issues

Posted: 24 Jul 2021 08:17 AM PDT

I have some issues with Actions in web push notifications. I use similar code of showNotification in messaging.onMessage and messaging.setBackgroundMessageHandler

messaging.setBackgroundMessageHandler(function(payload) {      const notificationTitle = payload.notification.title;      const notificationOptions = {          body: payload.notification.body,          icon: payload.notification.icon,          tag: payload.notification.tag,          image: payload.notification.image,          requireInteraction: true,          actions: [              {                  action: 'click-action',                  title: 'Read more',                  icon: 'https://example.com/read-more-icon.png'              }          ]      };        return self.registration.showNotification(notificationTitle,          notificationOptions);  });  

firebasejs 7.14.0

  1. If I get the push in background - there is no action button at all.
  2. If I get the push in onmessage - I have the action button, but without icon and onclick handled by self.addEventListener('notificationclick', function(event) with empty "event"

Same code without "actions" works pretty fine in both cases.

Do you have any ideas about the reasons of this behavior and how to fix it?

Thanks!

How can I use the fastest method to group the dataframe and generate a column as a sequence of numbers?

Posted: 24 Jul 2021 08:16 AM PDT

How can I use the fastest method to group the dataframe and generate a column as a sequence of numbers? My code steps are as follows:

  1. First generate the date dataframe date
  2. Generate code dataframe
  3. Generate the Cartesian product df of date and code
  4. Delete redundant columns ['a','level_1','order']
  5. Group according to the date column, and generate an order column in the order of values within each group

my question:

  1. These steps feel too cumbersome, is there an easy way?
  2. How to avoid generation of level_1 and order columns in the fourth step
  3. How to optimize the code, it takes 5 seconds to execute it now

My code is as follows:

import pandas as pd  import numpy as np      def add_order(df):      df = df.reset_index(drop=True).reset_index()      df = df.rename(columns={'date': 'order'})      return df      def generate_data():      np.random.seed(202107)      date = pd.date_range(start='20150101', end='20210723', freq='D')      date = date.to_pydatetime()      date = np.vectorize(lambda s: s.strftime('%Y-%m-%d'))(date)      date = pd.DataFrame(date, columns=['date'])      date['a'] = 1        code = pd.DataFrame(range(50), columns=['code'])      code['a'] = 1        df = pd.merge(date, code, how='outer')      df['value'] = np.random.random(len(df)) * 1000        return df      def get_result(df):      df = df.sort_values(by='value', ascending=False)      df = df.groupby('date').apply(add_order)      df = df.reset_index().sort_values(by=['date', 'code']).reset_index(drop=True)      df = df.drop(columns=['a', 'level_1', 'order'])      df = df.rename(columns={'index': 'order'})      col = ['date', 'code', 'value', 'order']      df = df[col]      print(df)      return df      def main():      df = generate_data()      df = get_result(df)  
%timeit main()  5.25 s ± 130 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)  

The result is:

              date  order  code       value  0       2015-01-01     0  227.190649     39  1       2015-01-01     1  543.938036     26  2       2015-01-01     2  175.707748     43  3       2015-01-01     3  789.146427      9  4       2015-01-01     4  585.727841     24  ...            ...   ...         ...    ...  119795  2021-07-23    45   92.698866     43  119796  2021-07-23    46  111.500843     40  119797  2021-07-23    47  700.675634     12  119798  2021-07-23    48  933.134534      4  119799  2021-07-23    49  108.004811     42  

Algorithm sorting details, but without excluding

Posted: 24 Jul 2021 08:16 AM PDT

I have come across a problem. I'm not asking for help how to construct what I'm searching for, but only to guide me to what I'm looking for! 😊 The thing I want to create is some sort of 'Sorting Algorithm/Mechanism'.

Example: Imagine I have a database with over 1000 pictures of different vehicles. A person sees a vehicle, he now tries to get as much information and details about that vehicle, such as:

  • Shape
  • number of wheels
  • number and shape of windows
  • number and shape of light(s)
  • number and shape of exhaust(s)

Etc…

He then gives me all information about that vehicle he saw. BUT! Without telling me anything about: Make and model. … I will now take that information and tell my database to sort out every vehicle so that it arranges all 1000 vehicle by best match, based by the description it have been given. But it should NOT exclude any vehicle!

So…

If the person tells me that the vehicle only has 4 wheels, but in reality it has 5 (he might not have seen the fifth wheel) it should just get a bad score in the # of wheels. But if every other aspect matches that vehicle perfect it will still get a high score.

That way we don't exclude the vehicle that he has seen, and we still have a change to find the correct vehicle.

The whole aspect of this mechanism is to, as said, sort out the most, so instead of looking through 1000 vehicles we only need to sort through the best matches which is 10 to maybe 50 vehicles out of a 1000 (hopefully).

I tried to describe it the best I could in a language that isn't 'my father's tongue'. So bear with me.

Again, I'm not looking for anybody telling me how to make this algorithm, I'm pretty sure nobody even wants of have the time to do that for me, without getting paid somehow... But I just need to know where to look regarding learning and understanding how to create this mess of a mechanism.

Kind regards Gent!

I am having a problem in taking user input and conditional statements along with logical operators

Posted: 24 Jul 2021 08:16 AM PDT

Following is my code-
import java. until. Scanner
public class Rudra  {
public static void main  (String  [] args ){
Scanner sc = new Scanner  (System. in);
System. out. println  ("....... ");
System. out. println  ("Are you new to here?  ");

String answer = sc. nextLine  ();
System. out. println  ("Your name : ");
String subAnswer = sc. nextLine  ();
System. out. println  ("Your age: ");
int lastAnswer = sc. nextInt  ();

if ( subAnswer. equals ("Cat") && lastAnswer == 4 ) {
        System. out. println  (subAnswer + " -your cuteness is 23 percent " );
} else if ( subAnswer. equals ("Dog") && lastAnswer == 6 ) {
          System. out. println  ( subAnswer + " -your cuteness is 32 percent " );
} else if  ( subAnswer. equals ("Horse") && lastAnswer == 9 ) {
           System. out. println  ( subAnswer + " -your cuteness is 42 percent " );
}else if ( subAnswer. equals ("Hamster") && lastAnswer == 1 ) {
           System. out. println  ( subAnswer + " -your cuteness is 90  percent " );
} else if  ( subAnswer. equals ("mouse") && lastAnswer == 2 ) {
          System. out. println  ( subAnswer + " -your cuteness is 99  percent " );
}else  {
          System. out. println  ("No cuteness ");
}
}
}
When l enter the first two names that is cat and dog and their age, it tells it's cuteness percent but when l enter other animals like horse and all and their age, it shows "No cuteness ". Why so?  It should also tell their cuteness percent. Please help me..

GUI does not appears on Ubuntu 18.x [closed]

Posted: 24 Jul 2021 08:17 AM PDT

I have installed the GUI on Ubuntu server 18.x using the below commands.

  1. sudo apt-get update && sudo apt-get upgrade
  2. sudo apt-get install tasksel
  3. sudo apt-get install slim
  4. sudo apt-get install lightdm
  5. tasksel

All the steps were run successfully without any error, I have reboot the server, now when I run the below command.

sudo service display_manager start

It gives the below error.

Failed to start display_manager.service: Unit display_manager.service not found but didn't appear the GUI. Now It's give the below error.

Unable to deploy to heroku using the Wolfram Alpha API

Posted: 24 Jul 2021 08:18 AM PDT

I am developing a discord bot, to use on a server with my friends. One of the functions I wanted it to have is solving equations and giving responses through the Wolfram Alpha API. I used the Node.js package:

"dependencies": {      "wolfram-alpha-api": "https://products.wolframalpha.com/api/libraries/javascript/wolfram-alpha-api-1.0.0-rc.1.tgz"    }  

Running locally, it works perfectly, but when deploying to Heroku I get a:

Installing dependencies    Installing node modules    npm ERR! code EINTEGRITY    npm ERR! sha512-Ixpm2jwpZA6Q5n9LkLl7Sr42v6ycbM4uuY9BnyAp2J+j/m0QElINtiRMPy1GQUMhz9nDL3fcLganuOG5cFVaaQ== integrity checksum failed when using sha512: wanted sha512-Ixpm2jwpZA6Q5n9LkLl7Sr42v6ycbM4uuY9BnyAp2J+j/m0QElINtiRMPy1GQUMhz9nDL3fcLganuOG5cFVaaQ== but got sha512-yujgD6IWkQvCfiOw8K1xaLvVCSB3NstUZzcolEq5cKIRTbeyEo/1sipK0k0oFcIWX39X6t6fqDlphLCzFVgQCw==. (12482 bytes)    Build failed  

It said to specify the node version, so I did 15.x, but the problem was not solved. What could be the solution, having in mind that it was working (building and deploying) perfectly before installing the Wolfram Package?

Excel: How to calculate the sum product with multiple conditions?

Posted: 24 Jul 2021 08:16 AM PDT

My table looks like this 2 tables As you can see the there is a rate chart and distribution of Staff among different levels. What I need is a table with the total rate for each staff. For example, if you take staff C, you can see he is in Cat2 with 2 times in L1U and 3 times in L1L Cat2; also Cat1 for 3 times in L2L. So the total amount for C will be

Level&Cat    Rate    Count    Subtotal  L1U-Cat2      15      2          30  L1L-Cat2      17      3          51  L2L-Cat1      35      3          105  == Total = 105+51+30 =>186  

So the final output will be

Staff Name       Total  A              Need calculation  B              Need calculation  C                 186  D              Need calculation  ...                ....    

how can this be possible? Now I am using Count if but for each row and column so it is almost like 51 columns long for each level and category and the calculation threading gives a lot of lag because of this.

What formula can I use?

Could not get data from Ajax [closed]

Posted: 24 Jul 2021 08:16 AM PDT

I am calling my CodeIgniter controller function through ajax :

$.ajax({    type: 'POST',    url: 'getReferrals',    dataType: 'json',    data: 'useradd=' + uadd,    error: function(error) {            alert(error);    },    success: function (response) {      // Do smth with the response     alert(response);     console.log(response);    }   });  

CI Controller is returning back data but my success alert is blank and error alert is [object][object]

here is my php function

$uadd = $this->input->post('useradd', TRUE);            $getref = $this->referral_model->getref($uadd);      return $getref;  

OK, this is my html code:

<div class="input-item">      <input type="text" class="input-border-simple" id="useraddress"          name="useraddress" value="<?php echo $useraddress; ?>"          disabled>      <em class="fas fa-user"></em>  </div>  

which is getting it's value from PHP variable ajax code and controller is there in my question and my model is

public function getref($uadd)   {      $this->db->select('sponsor');      $this->db->from('referrals');      $this->db->where('smartchain', $uadd);      $query = $this->db->get();      $result = $query->result_array();      //print_r($result);      return $result;  }  

Hope it will help.

PowerShell safe expansion of non printing characters in arbitrary strings

Posted: 24 Jul 2021 08:18 AM PDT

I have data in an XML file, that will eventually be used as a Registry path, which MAY contain non printing characters (for example when copying the path from a web site into the XML). I want to validate the data and throw a specific error if non printing characters are found.

In Powershell, if I define a variable with non printing characters in single quotes and then test-Path it tests as a valid path as the non printing character is handled as a literal.

Test-Path 'HKEY_LOCAL_MACHINE\SOFTWARE\Test\`n@microsoft.com/GENUINE\@microsoft.com/GENUINE' -isValid  

The same thing with double quotes will "expand" the non printing characters and return false, which is what I need.

Test-Path "HKEY_LOCAL_MACHINE\SOFTWARE\Test\`n@microsoft.com/GENUINE\@microsoft.com/GENUINE" -isValid  

I have found reference to [string]::Format(() being used to expand the non printing characters, but

$invalidPath = 'HKEY_LOCAL_MACHINE\SOFTWARE\Test\`n@microsoft.com/GENUINE\@microsoft.com/GENUINE'  [string]::Format("{0}",$invalidPath)  

does not expand the non printing character as expected. I have also seen reference to using Invoke-Expression but that is NOT safe, and not an option.

Finally I found $ExecutionContext.InvokeCommand.ExpandString(), which seems to work,

$ExecutionContext.InvokeCommand.ExpandString('HKEY_LOCAL_MACHINE\SOFTWARE\Test\`n@microsoft.com/GENUINE\@microsoft.com/GENUINE')  

returns a multiline string to the console, while $ExecutionContext.InvokeCommand.ExpandString('Write-Host "Screwed"') returns the actual string to the console, rather than actually executing the Write-Host and only returning Screwed to the console.

Finally,

$invalidPath = 'HKEY_LOCAL_MACHINE\SOFTWARE\Test\`n@microsoft.com/GENUINE\@microsoft.com/GENUINE'  Test-Path ($ExecutionContext.InvokeCommand.ExpandString($invalidPath)) -isValid  

returns false as expected. Which has me thinking this is the correct approach to pursue, but given all the gotchas elsewhere, I want to be 100% sure there is no way for this approach to be used as a security weak point. Am I on the right track, or are there gotchas my Google-Fu hasn't turned up yet?

How to get a Workday Worker's web profile URL?

Posted: 24 Jul 2021 08:16 AM PDT

I wish to retrieve a Workday worker (aka employee) web profile URL via the Workday API. The use case is that I'm building a chatbot to retrieve user information and I want to be able to link to the worker (employee) web profile.

The issue is that I cannot do either of the following:

  1. get a web profile URL from the API
  2. create a web profile URL from data in the API

A web profile URL looks like the following. The userId looks like 1234 right before the .htmld extension as that is the only number that changes between employee profiles.

https://www.myworkday.com/{myCompany}/d/inst/autocompletesearch/247${1234}.htmld  

A worker API call is like the following with a 32 byte hexadecimal id.

https://services1.myworkday.com/ccx/api/api/v1/{myCompany}/workers/{workerId}  

The result does not have the web profile userId, e.g. 1234, any where in it, or a URL that can render a web page.

{    "id":"deadbeefdeadbeefdeadbeefdeadbeef",    "descriptor":"Joe Cool",    "href":"https://services1.myworkday.com/ccx/api/api/v1/example/workers/deadbeefdeadbeefdeadbeefdeadbeef",    "supervisoryOrganizationsManaged":"https://services1.myworkday.com/ccx/api/api/v1/example/workers/deadbeefdeadbeefdeadbeefdeadbeef/supervisoryOrganizationsManaged",    "yearsOfService":"1",    "primaryWorkEmail":"joe.cool@example.com",    "isManager":false,    "location":{      "descriptor":"Santa Rosa, California",      "id":"deadbeefdeadbeefdeadbeefdeadbeef"    },    "primarySupervisoryOrganization":{      "descriptor":"Peanuts (Charles 'Sparky' Schulz)",      "id":"deadbeefdeadbeefdeadbeefdeadbeef",      "href":"https://services1.myworkday.com/ccx/api/api/v1/example/supervisoryOrganizations/deadbeefdeadbeefdeadbeefdeadbeef"    },    "businessTitle":"beagle"  }  

Can anyone help provide info on how to get a web profile URL from the Workday API?

Using FontAwecome icon in Flask table

Posted: 24 Jul 2021 08:17 AM PDT

I have a pandas dataframe that I'm displaying as HTML in my Flask app and would like to add a Font Awesome icon as a column in that table and repeat it based on a count for each group. For example, in this scenario:

Group Count Icon
A 1
B 2

I want the icon to be repeated once for Group A and twice for Group B. I'm able display icons in my navbar after downloading the flask-fontawesome package. The unicode/<i> tag (not sure which one is needed) are:

  • &#xf091;
  • <i class="fa fa-trophy" aria-hidden="true"></i>

Combining Conditions in Access SQL Query

Posted: 24 Jul 2021 08:16 AM PDT

I need to create a SQL query in Access that picks a single value from a range of numbers based on a particular source value. But, there's a special logical quirk. If the table has numbers lower than the source value, the query should return the greatest number that's equal to or less than the source value. However, if the source value is lower than all the values in the table, the query should return the smallest value in the table. In other words, if the values in the table were

2000
1900
1800
1700

and the source value was 1975, the query should return 1900; but if the source value is 1632, the query should return 1700. The query should return only a single value that meets either the one condition, or the other if the first condition fails.
I'm not sure how I can combine the two conditions in Access SQL, and I haven't been able to find a similar question here. Thanks in advance for any help.

TIdTCPServer sharing of serial port

Posted: 24 Jul 2021 08:18 AM PDT

Recently I changed a program which acts as a TCP server to help share the traffic on a serial port connected to a device. Multiple clients connect and should have access to the Serial Port and act simultaneously.

Application is built using C++Builder, using TIdTCPServer in the server and TIdTCPClient in the client application.

Multiple clients need to connect and send commands to the serial port. The serial port will respond immediately after sending a command to it, as per the protocols of the device it is attached to.

There is also a background thread which occasionally accesses the serial port and updates a memory cache of data held in the server's memory. The commands for sending and receiving from the serial port have a mutex on them, so they are accessible from both the TIdTcpServer's OnExecute event and the background thread.

I'm having difficulty getting the TIdTCPServer's OnExecute event to work without overlapping.

It would be really nice if the OnExecute event were to execute fully without another request coming in from another client, causing the overlapping.

Here is the OnExecute event handler of the TIdTCPServer:

void __fastcall TfrmMain::IServerExecute(TIdContext *AContext)  {      int  i;      int Len;      TIdBytes TRB, TSB;      unsigned char ARB[BUFFERLENGTH];      int NumbSent, NumbReceived;        // Read the command from the client.  Send the length first then the actual data.      Len = AContext->Connection->Socket->ReadLongInt();      AContext->Connection->Socket->ReadBytes(TRB, Len, false);        memset(ARB,0,BUFFERLENGTH);      for(i=0;i<Len;i++) AOB[i]=TRB[i];        NumbSent=Len;          // Now send it out to the Serial port      ProcessSerialMessage(AOB, Len, ARB, &NumbReceived, false);        sending=false;        TSB.Length=NumbReceived;      for(i=0;i<TSB.Length;i++) TSB[i]=ARB[i];      AContext->Connection->Socket->Write(TSB.Length);      AContext->Connection->Socket->Write(TSB);        return;  }  

Here is the routine for sending the data out over the serial port:

int ProcessSerialMessage(unsigned char *SendBuf, int NumbSBytes, unsigned char *ReceiveBuf, int *NumbRBytes, bool CalledFromThread)  {        // MMUtex is a global TMutex Object      // Mutex required to help with the background thread trying to update memory cache.      MMutex->Acquire();          // Ok now send the data out over the serial port and receive it.      // These routines are standard serial port I/O routines and aren't explained here.      rawsend(SendBuf, NumbSBytes);      rawreceive(ReceiveBuf, NumbRBytes);        RetValue=*NumbRBytes;      MMutex->Release();        return(RetValue);  }  

Cumulative Count of Members by Month DPLYR

Posted: 24 Jul 2021 08:16 AM PDT

I have a list of members by signup month, what I'd like to do is create a data frame with total members by month.

Raw Data

month.list <- structure(c(18444, 18687, 18475, 18506, 18536, 18567, 18597,18718, 18659, 18628, 18779, 18748), class = "Date")   total.membership.working <- structure(list(`Mem Account` = c(26137295, 26139796, 26400007,26400455, 26402031, 26402078, 26402239, 1092287142, 1092295228,1092473120), Month = structure(c(18444, 18687, 18444, 18444,18475, 18475, 18444, 18779, 18779, 18779), class = "Date")), row.names = c(NA,-10L), groups = structure(list(`Mem Account` = c(26137295, 26139796,26400007, 26400455, 26402031, 26402078, 26402239, 1092287142,1092295228, 1092473120), .rows = structure(list(1L, 2L, 3L, 4L,5L, 6L, 7L, 8L, 9L, 10L), ptype = integer(0), class = c("vctrs_list_of","vctrs_vctr", "list"))), row.names = c(NA, -10L), class = c("tbl_df","tbl", "data.frame"), .drop = TRUE), class = c("grouped_df","tbl_df", "tbl", "data.frame"))     

I have written a for loop that will accomplish this, but I'm hoping to find a Tidy way to do it without the loop.

For Loop

total.membership <- data.frame()  for(i in 1:length(month.list)) {        foo <- total.membership.working %>%      ungroup() %>%      filter(Month <= month.list[i]) %>%      summarise(Month = max(Month),        total_membership = n_distinct(`Mem Account`))    total.membership <- total.membership %>%      bind_rows(foo)  }  

Desired Output

total.membership <- structure(list(Month = structure(c(18444, 18687, 18475, 18506,18536, 18567, 18597, 18628, 18779, 18748), class = "Date"), total_membership = c(45886L,58128L, 47878L, 49214L, 51119L, 53390L, 55200L, 56299L, 60503L,59583L)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 10L, 11L,12L), class = "data.frame")     > total.membership          Month total_membership  1  2020-07-01            45886  2  2021-03-01            58128  3  2020-08-01            47878  4  2020-09-01            49214  5  2020-10-01            51119  6  2020-11-01            53390  7  2020-12-01            55200  8  2021-04-01            58902  9  2021-02-01            57238  10 2021-01-01            56299  11 2021-06-01            60503  12 2021-05-01            59583  

GitHub Authentication Fails

Posted: 24 Jul 2021 08:15 AM PDT

I just created a new repo and setup the remote link to my repo on gitbash on windows 10. When I try to do a basic git push (git push origin main) from git bash: I get a popup windows for username and password. I don't get the username and password prompt on the Git bash shell, as documentation shows me to expect. Instead it give me a popup that asks for the userid and password. When I enter the userid and password it fails to authenticate. But gives me an authentication failed (invalid username or password).
But shows the url to the repo correctly (that I setup)
Even though I can use the same userid and password to login to GitHub web portal.
I don't 2FA setup.
What am I missing?

I only found help docs relating to authentication via Windows Desktop App. Which is not very helpful in my case.

JNA's equivalent to Windows EnableWindow?

Posted: 24 Jul 2021 08:17 AM PDT

I am in charge of porting Windows JNI code to Java, and have gone with JNA. Using the library is simple enough, as apparently it attempts to follow the structure and style of Windows' API (I do not know the API well, I follow the original JNI code).
I was able to find the JNA equivalent of most Windows API functions, but not EnableWindow.

This function is defined in winuser.h and logically, one should find it under com.sun.jna.platform.win32.WinUser, right? However there is no such function, and the only mention of EnableWindow is in the documentation of com.sun.jna.platform.win32.WinUser.WS_DISABLED:

[...] To change this after a window has been created, use the EnableWindow function.

That's it, no other reference, mention or indication towards the function. The rest of the documentation is equally terse and not very helpful when one does not know exactly what and where to look.

So where is JNA's EnableWindow, if it exists? And if it doesn't, what can be used in replacement?

Cloud Build: How to execute two CI jobs, in order?

Posted: 24 Jul 2021 08:17 AM PDT

I have set up a Cloud Build pipeline for deploying a Firebase web app.

The problem

The current script does unnecessary deployments. Even if backend files hadn't changed, it ends up testing and deploying the backend (takes 3 minutes; 4 minutes with backend tests).

Likewise for front-end (build and deploy only ~30s).

Context

GitHub / Cloud Build integration works so that Cloud Build is informed after the PR is already merged. That's fine.

I can make two separate CI jobs, filtered by the files that changed (this is available in Cloud Build console). The problem here is that if both change in the same commit, I would like the backend to be deployed first.

Come to think of it, I can bypass this by giving development guidance: if there are breaking changes (eg. a data model changes in the backend, or a new service such as Cloud Storage is added), those changes need to be deployed first in the backend. Making eg. two commits or deploying the backend manually.

What would you do??

I think the above side-thought is where I'm heading.

If you have experience with Cloud Build, how do you tackle this kind of cases?


Link changed to how the code was at the time of writing the question.

How can I customize the 2 warning text of required & pattern on the input field?

Posted: 24 Jul 2021 08:16 AM PDT

How can I customize the 2 warning text in 1 input field.

The 1 is for required/invalid and The 1 is for pattern (2 attributes for validation).


I search this including on the stackoverflow but I can't find any solution for this answer.

Because The only thing they asked & already answered was the 1 warning txt customization only.

Like this: changing the language of error message in required field in html5 contact form

and this one: How to change warning text when pattern is used in input?


I'm beginner in js, I only know some basics & I'm trying to find some clues on how can I do it, But i can't find any answer.

I try to do it, Please Help me, Correct my code, The codepen link is on the comment.


Thankyou so much in advance for your help & answers, I really appreciate it.

Is it possible to reliably run an ASCII text based video from cmd prompt?

Posted: 24 Jul 2021 08:15 AM PDT

Okay this one is a doozy

Let's start with what I have and what I have done then the issues I am having.


First I took a video and extracted the frames with FFMPEG which left me with a ton of frames. As we all know CMD can't do much with jpg files. So I used a program that allowed me to convert them to ASCII. With a little batch magic, I got something working to mass convert all of the images.


Code for that

JPEGCompiler.bat

@echo off  set /p video=Drag Video into Console (Currently Limited to C:/):   ffmpeg -i %video% -an -f image2 "output_%%05d.jpg"  

(This works with the help of FFMPEG )


I then had to create a list of the files for the next batch to grab. This wasn't super difficult.

Jpglist.bat


dir /B *.jpg >> JPEGList.txt  

And finally, a way of automating everything with an increasing variable.

JPEGCompiler.bat

@echo off  setlocal enableextensions enabledelayedexpansion  set cycles=0    cd> CD.txt    for /F "delims=" %%i in (CD.txt) do set "CD=%%i"  for /F "delims=" %%i in (CDD.txt) do set "CD=%%i"    type cd.txt | sed "s/C://">> CDD.txt    :startpoint  set "xprvar="  for /F "skip=%cycles% delims=" %%i in (JPEGList.txt) do if not defined xprvar set "xprvar=%%i"    set /a cycles=cycles+1  ascii-image-converter.exe %CDD%%xprvar% --save-txt .    goto startpoint  

Using what I learned previously with the increasing variable, I used the same method to grab all of the text files and order them into a list for CMD

Textlist.bat


dir /B *.txt >> TextList.txt  

That brings me to this point.

TEXTCompiler.bat


@echo off  color 02  set cycles=0    :startpoint      for /F "skip=%cycles% delims=" %%i in (TextList.txt) do set "xprvar=%%i"&goto nextline  :nextline    set /a cycles=cycles+1    type %xprvar%    call waitfor    goto startpoint  

(call waitfor is an attempt at using precise timing but it didn't really make a difference with or without it I get a little more control but the same issues are present)

enter image description here

The code runs fine but there are some issues. With the cls command its like it will clear the screen way too fast and the video gets slowly and occasionally eaten from the bottom up. However, without that cls, the ASCII art video scrolls like a boss.

There are also issues with sync from the original video. (bat plays fast or slow depending on how it's feeling?)

So my question is, is there a way to sync fps? What's the best way to go about this?

This playback can be seen here!

Playback without CLS

Low accuracy in the deep learning model

Posted: 24 Jul 2021 08:17 AM PDT

I am trying to build an image classification model to classify whether Thistle Caterpillar is present in an image or not. The classification is a single label classification. The dataset and the code for the same is attached below. The problem is that using the sequential model created I am getting a validation accuracy of zero.

DATASET LINK : https://www.kaggle.com/drravirsaxena/pest-identification

CODE

# Dimension of resized image  DEFAULT_IMAGE_SIZE = tuple((256, 256))    # Number of images used to train the model  N_IMAGES = 1000    # Path to the dataset folder  root_dir = '/content/drive/MyDrive/Thistle_Caterpillar '    train_dir = os.path.join(root_dir, 'train')  val_dir = os.path.join(root_dir, 'val')  
def convert_image_to_array(image_dir):      try:          image = cv2.imread(image_dir)          if image is not None:              image = cv2.resize(image, DEFAULT_IMAGE_SIZE)                 return img_to_array(image)          else:              return np.array([])      except Exception as e:          print(f"Error : {e}")          return None  
image_list, label_list = [], []    try:      print("[INFO] Loading images ...")      thistle_caterpillar_folder_list = listdir(train_dir)        for thistle_caterpillar_folder in thistle_caterpillar_folder_list:          print(f"[INFO] Processing {thistle_caterpillar_folder} ...")          thistle_caterpillar_image_list = listdir(f"{train_dir}/{thistle_caterpillar_folder}")            for image in thistle_caterpillar_image_list[:N_IMAGES]:              image_directory = f"{train_dir}/{thistle_caterpillar_folder}/{image}"              if image_directory.endswith(".jpeg")==True or image_directory.endswith(".JPEG")==True:                  image_list.append(convert_image_to_array(image_directory))                  label_list.append(thistle_caterpillar_folder)        print("[INFO] Image loading completed")    except Exception as e:      print(f"Error : {e}")    # Transform the loaded training image data into numpy array  np_image_list = np.array(image_list, dtype=np.float16) / 225.0  print()    # Check the number of images loaded for training  image_len = len(image_list)  print(f"Total number of images: {image_len}")  
label_binarizer = LabelBinarizer()  image_labels = label_binarizer.fit_transform(label_list)    pickle.dump(label_binarizer,open('/content/drive/MyDrive/Thistle_Caterpillar /thistle_caterpillar.pkl', 'wb'))  n_classes = len(label_binarizer.classes_)    print("Total number of classes: ", n_classes)  
augment = ImageDataGenerator(rotation_range=25, width_shift_range=0.1,                               height_shift_range=0.1, shear_range=0.2,                                zoom_range=0.2, horizontal_flip=True,                                fill_mode="nearest")  
print("[INFO] Splitting data to train and test...")  x_train, x_test, y_train, y_test = train_test_split(np_image_list, image_labels, test_size=0.2, random_state = 42)  
EPOCHS = 25  STEPS = 100  LR = 1e-3  BATCH_SIZE = 64  WIDTH = 256  HEIGHT = 256  DEPTH = 3  
model = Sequential()  inputShape = (HEIGHT, WIDTH, DEPTH)  chanDim = -1    if K.image_data_format() == "channels_first":      inputShape = (DEPTH, HEIGHT, WIDTH)      chanDim = 1    model.add(Conv2D(32, (3, 3), padding="same",input_shape=inputShape))  model.add(Activation("relu"))  model.add(BatchNormalization(axis=chanDim))  model.add(MaxPooling2D(pool_size=(3, 3)))  model.add(Dropout(0.25))  model.add(Conv2D(64, (3, 3), padding="same"))  model.add(Activation("relu"))  model.add(BatchNormalization(axis=chanDim))  model.add(Conv2D(64, (3, 3), padding="same"))  model.add(Activation("relu"))  model.add(BatchNormalization(axis=chanDim))  model.add(MaxPooling2D(pool_size=(2, 2)))  model.add(Dropout(0.25))  model.add(Conv2D(128, (3, 3), padding="same"))  model.add(Activation("relu"))  model.add(BatchNormalization(axis=chanDim))  model.add(Conv2D(128, (3, 3), padding="same"))  model.add(Activation("relu"))  model.add(BatchNormalization(axis=chanDim))  model.add(MaxPooling2D(pool_size=(2, 2)))  model.add(Dropout(0.25))  model.add(Flatten())  model.add(Dense(1024))  model.add(Activation("relu"))  model.add(BatchNormalization())  model.add(Dropout(0.5))  model.add(Dense(n_classes))  model.add(Activation("softmax"))    model.summary()  
# Initialize optimizer  opt = Adam(lr=LR, decay=LR / EPOCHS)    # Compile model  model.compile(loss="binary_crossentropy", optimizer=opt, metrics=["accuracy"])    # Train model  print("[INFO] Training network...")  history = model.fit_generator(augment.flow(x_train, y_train, batch_size=BATCH_SIZE),                                validation_data=(x_test, y_test),                                steps_per_epoch=len(x_train) // BATCH_SIZE,                                epochs=EPOCHS,                                 verbose=1)  

Error: Cannot find module 'webpack-cli/bin/config-yargs' with webpack-cli 4.2.0

Posted: 24 Jul 2021 08:16 AM PDT

When I try to run webpack-dev-server it gives the error.

Error: Cannot find module 'webpack-cli/bin/config-yargs'  

I looked around and found that you had to change the script to "webpack serve" and did that but then it gives me the following:

**[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.

  • configuration.devtool should match pattern "^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map$". BREAKING CHANGE since webpack 5: The devtool option is more strict. Please strictly follow the order of the keywords in the pattern.**

My system is Windows 10 Pro and the versions are the following:

  • webpack: 5.6.0
  • webpack-cli: 4.2.0
  • webpack-dev-server: 3.11.0

I've also tried including "inline: false" into the devServer object in webpack.config.js but to no avail.

No comments:

Post a Comment