问:
How to Capture Websocket in Realtime with Wireshark or custom decode functions
I'm able to log all windows traffic by Wireshark and Chrome Inspector thru Network->WS.

Unfortunately I'm writing a web bot to interact with some websites automatically. I really need to go thru the data in websocket, not by HTML and some other methods that I have used before.

Chrome (and most probably Firefox) cannot save data in realtime. Chrome can save .har file with all the traffic, but even if I automate that, the file grows with every new packet, so it will result in performance issue very soon.

Wireshark can do that and even decrypt TLS (https) in realtime. It also supports saving file on every x packets or x seconds. But for some (maybe security) reason it saves encrypted pcap file. I don't know how to decrypt it.

On other hand I'm able to capture traffic with PcapDotNet. I'm also able to log IPs, ports and sequence and rebuild whole TLS frame from 2-3 separate TCP packets.

Till the moment in C# I tried logging the packets and try some decryption without any success:

```<code>            int index = -1;
            foreach (IpV4Datagram IPpack in IPPackets)
            {
                index += 1;
                string src = IPpack.Source.ToString();
                string dest = IPpack.Destination.ToString();
                string destPort = IPpack.Tcp.DestinationPort.ToString();
                string controlBits = IPpack.Tcp.ControlBits.ToString();
                int p1 = 0;
                if ((controlBits == "Acknowledgment")|(controlBits == "Push, Acknowledgment"))
                {
                    //Add
                    p1 = TCPCPackets.FindIndex(x => (x.SourceIP == src) & (x.DestinationIP == dest) & (x.DestinationPort == destPort));
                    if (p1 < 0)
                    {
                        TCPCombinedPacket newCP = new TCPCombinedPacket();
                        newCP.SourceIP = src;
                        newCP.DestinationIP = dest;
                        newCP.DestinationPort = destPort;
                        TCPCPackets.Add(newCP);

                        p1 = TCPCPackets.Count() - 1;
                    }

                    TCPCPackets[p1].Counter += 1;
                    int totcount = packets[index].Count();
                    int start = totcount - IPpack.Tcp.PayloadLength;
                    if (start < totcount)
                    {
                        for (int o = start; o < totcount; o++)
                        {
                            TCPCPackets[p1].bytedata.Add(packets[index][o]);
                        }
                    }

                }
                if (controlBits == "Push, Acknowledgment")
                {
                    //Finish
                    TCPWPackets.Add(TCPCPackets[p1]);
                    TCPCPackets.RemoveAt(p1);
                }
            }
</code>```

But I'm not able to find any single TLS decryption function. I tried with the integrated .net decryptor but with no success:

```<code>        public string DecryptString(byte[] key, byte[] buffer)
        {
            byte[] iv = new byte[16];
            //byte[] buffer = Convert.FromBase64String(cipherText);
            using (Aes aes = Aes.Create())
            {
                aes.Key = key;//Encoding.UTF8.GetBytes(key);
                aes.IV = iv;
                ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
                using (MemoryStream memoryStream = new MemoryStream(buffer))
                {
                    using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, decryptor, CryptoStreamMode.Read))
                    {
                        using (StreamReader streamReader = new StreamReader((Stream)cryptoStream))
                        {
                            return streamReader.ReadToEnd();
                        }
                    }
                }
            }
        }
</code>```

It seems TLS uses many types of encryptions and it's generally not exposed to C#, much more likely to driver level. I'm not able to find any TLS decryption code anywhere.

I have many CLIENT_HANDSHAKE_TRAFFIC_SECRET, SERVER_HANDSHAKE_TRAFFIC_SECRET, CLIENT_TRAFFIC_SECRET in the ssl.log file from the web browser as I already set SSLKEYLOGFILE environment variable.
My idea was to try with some decrypt function until I find working key and store the key per IP and port. Sorting this "try" list of keys by success rate, while outdated will go last. But obviously with packets in my variable but no TLS decryption function I can do nothing...

The last thing I tried is to run inspector over inspector and run the following Java scrypt. But it seems it's no longer supported. Also I found 1-2 third party extensions to capture WinSocket traffic for Chrome that are no longer available (and I even cannot find them, only history pages). Here is the JS code which I tried on older version chrome with no success (which returns errors, and actually I don't see the used sub-objects - maybe no longer supported):

```<code>// https://bgrins.github.io/devtools-snippets/#console-save
(function(console){
  console.save = function(data, filename){
    if(!data) {
      console.error('Console.save: No data')
      return;
    }

    if(!filename) filename = 'console.json'

    if(typeof data === "object"){
      data = JSON.stringify(data, undefined, 4)
    }

    var blob = new Blob([data], {type: 'text/json'}),
    e = document.createEvent('MouseEvents'),
    a = document.createElement('a')

    a.download = filename
    a.href = window.URL.createObjectURL(blob)
    a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
    a.dispatchEvent(e)
  }
})(console)

// Frame/Socket message counter + filename
var iter = 0;

// This replaces the browser's `webSocketFrameReceived` code with the original code
// and adds two lines, one to save the socket message and one to increment the counter.
SDK.NetworkDispatcher.prototype.webSocketFrameReceived = function (requestId, time, response) {
  var networkRequest = this._inflightRequestsById[requestId];
  if (!networkRequest) return;
  console.save(JSON.parse(response.payloadData), iter + ".json")
  iter++;
  networkRequest.addFrame(response, time, false);
  networkRequest.responseReceivedTime = time;
  this._updateNetworkRequest(networkRequest);
}
</code>```

The link is this one: How to save websocket frames in Chrome

Any idea how I can capture TLS encrypted WebSocket traffic in realtime with max delay of 1 second?

```<code></code>```

Body:
I'm able to log all windows traffic by Wireshark and Chrome Inspector thru Network->WS.

Unfortunately I'm writing a web bot to interact with some websites automatically. I really need to go thru the data in websocket, not by HTML and some other methods that I have used before.

Chrome (and most probably Firefox) cannot save data in realtime. Chrome can save .har file with all the traffic, but even if I automate that, the file grows with every new packet, so it will result in performance issue very soon.

Wireshark can do that and even decrypt TLS (https) in realtime. It also supports saving file on every x packets or x seconds. But for some (maybe security) reason it saves encrypted pcap file. I don't know how to decrypt it.

On other hand I'm able to capture traffic with PcapDotNet. I'm also able to log IPs, ports and sequence and rebuild whole TLS frame from 2-3 separate TCP packets.

Till the moment in C# I tried logging the packets and try some decryption without any success:

            int index = -1;
            foreach (IpV4Datagram IPpack in IPPackets)
            {
                index += 1;
                string src = IPpack.Source.ToString();
                string dest = IPpack.Destination.ToString();
                string destPort = IPpack.Tcp.DestinationPort.ToString();
                string controlBits = IPpack.Tcp.ControlBits.ToString();
                int p1 = 0;
                if ((controlBits == "Acknowledgment")|(controlBits == "Push, Acknowledgment"))
                {
                    //Add
                    p1 = TCPCPackets.FindIndex(x => (x.SourceIP == src) & (x.DestinationIP == dest) & (x.DestinationPort == destPort));
                    if (p1 < 0)
                    {
                        TCPCombinedPacket newCP = new TCPCombinedPacket();
                        newCP.SourceIP = src;
                        newCP.DestinationIP = dest;
                        newCP.DestinationPort = destPort;
                        TCPCPackets.Add(newCP);

                        p1 = TCPCPackets.Count() - 1;
                    }

                    TCPCPackets[p1].Counter += 1;
                    int totcount = packets[index].Count();
                    int start = totcount - IPpack.Tcp.PayloadLength;
                    if (start < totcount)
                    {
                        for (int o = start; o < totcount; o++)
                        {
                            TCPCPackets[p1].bytedata.Add(packets[index][o]);
                        }
                    }

                }
                if (controlBits == "Push, Acknowledgment")
                {
                    //Finish
                    TCPWPackets.Add(TCPCPackets[p1]);
                    TCPCPackets.RemoveAt(p1);
                }
            }

But I'm not able to find any single TLS decryption function. I tried with the integrated .net decryptor but with no success:

        public string DecryptString(byte[] key, byte[] buffer)
        {
            byte[] iv = new byte[16];
            //byte[] buffer = Convert.FromBase64String(cipherText);
            using (Aes aes = Aes.Create())
            {
                aes.Key = key;//Encoding.UTF8.GetBytes(key);
                aes.IV = iv;
                ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
                using (MemoryStream memoryStream = new MemoryStream(buffer))
                {
                    using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, decryptor, CryptoStreamMode.Read))
                    {
                        using (StreamReader streamReader = new StreamReader((Stream)cryptoStream))
                        {
                            return streamReader.ReadToEnd();
                        }
                    }
                }
            }
        }

It seems TLS uses many types of encryptions and it's generally not exposed to C#, much more likely to driver level. I'm not able to find any TLS decryption code anywhere.

I have many CLIENT_HANDSHAKE_TRAFFIC_SECRET, SERVER_HANDSHAKE_TRAFFIC_SECRET, CLIENT_TRAFFIC_SECRET in the ssl.log file from the web browser as I already set SSLKEYLOGFILE environment variable.
My idea was to try with some decrypt function until I find working key and store the key per IP and port. Sorting this "try" list of keys by success rate, while outdated will go last. But obviously with packets in my variable but no TLS decryption function I can do nothing...

The last thing I tried is to run inspector over inspector and run the following Java scrypt. But it seems it's no longer supported. Also I found 1-2 third party extensions to capture WinSocket traffic for Chrome that are no longer available (and I even cannot find them, only history pages). Here is the JS code which I tried on older version chrome with no success (which returns errors, and actually I don't see the used sub-objects - maybe no longer supported):

// https://bgrins.github.io/devtools-snippets/#console-save
(function(console){
  console.save = function(data, filename){
    if(!data) {
      console.error('Console.save: No data')
      return;
    }

    if(!filename) filename = 'console.json'

    if(typeof data === "object"){
      data = JSON.stringify(data, undefined, 4)
    }

    var blob = new Blob([data], {type: 'text/json'}),
    e = document.createEvent('MouseEvents'),
    a = document.createElement('a')

    a.download = filename
    a.href = window.URL.createObjectURL(blob)
    a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
    e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
    a.dispatchEvent(e)
  }
})(console)

// Frame/Socket message counter + filename
var iter = 0;

// This replaces the browser's `webSocketFrameReceived` code with the original code
// and adds two lines, one to save the socket message and one to increment the counter.
SDK.NetworkDispatcher.prototype.webSocketFrameReceived = function (requestId, time, response) {
  var networkRequest = this._inflightRequestsById[requestId];
  if (!networkRequest) return;
  console.save(JSON.parse(response.payloadData), iter + ".json")
  iter++;
  networkRequest.addFrame(response, time, false);
  networkRequest.responseReceivedTime = time;
  this._updateNetworkRequest(networkRequest);
}

The link is this one: How to save websocket frames in Chrome

Any idea how I can capture TLS encrypted WebSocket traffic in realtime with max delay of 1 second?


来源: stackexchange

问:
Passenger (+Apache) is not auto-detecting Rails application
We are setting up Rails applications on Ubuntu 22.04 and when I visit the application URL I get a listing of files from within the app's public directory. Does anyone have any thoughts as to why Phusion Passenger is not auto-detecting the Rails application?
Thank you
Chris

Passenger -v: 6.0.15

Apache -v: 2.4.52

I don't know if this will help anyone else but the below changes is what we did which then enabled Phusion Passenger to auto-detect the Rails application.

Server Admin removed the default 001-ssl.conf file which contained SSL statements and added them to the below .conf file.

Changed my symlink to eops -> /home/eops/app/eops/current. My symlink was found at /var/www/html/

My rails_apps.conf file to:

```<code><IfModule mod_ssl.c>
<VirtualHost mydomain.com:443>
    ServerName mydomain.com
    ServerAdmin my_email_address

    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn
    LogLevel debug

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    # Overall Rules For The DocumentRoot
    <Directory /var/www/html>
        # Relax Apache security settings
        AllowOverride all
        Require all granted
        # MultiViews must be turned off
        Options -MultiViews
    </Directory>

    # ------- Host apps below

    # Shib protected at Application Level
    <Directory /var/www/html/eops>
        Allow from all
        Options -MultiViews

        # Uncomment below line if you are on Apache > 2.4
        Require all granted
    </Directory>

    Alias /eops /home/eops/app/eops/current/public
    <Location /eops>
        # Require Shibboleth authentication
        AuthType shibboleth
        ShibRequestSetting requireSession 1
        require valid-user

        PassengerBaseURI "/eops"
        PassengerStartupFile config.ru
        PassengerAppType rack
        PassengerAppRoot /home/eops/app/eops/current
        RailsEnv staging
        PassengerRuby /home/eops/.rbenv/versions/2.1.6/bin/ruby
    </Location>

</VirtualHost>
</code>```

ContentLicense: CC BY-SA 4.0

Body:
We are setting up Rails applications on Ubuntu 22.04 and when I visit the application URL I get a listing of files from within the app's public directory. Does anyone have any thoughts as to why Phusion Passenger is not auto-detecting the Rails application?
Thank you
Chris

Passenger -v: 6.0.15

Apache -v: 2.4.52

I don't know if this will help anyone else but the below changes is what we did which then enabled Phusion Passenger to auto-detect the Rails application.

Server Admin removed the default 001-ssl.conf file which contained SSL statements and added them to the below .conf file.

Changed my symlink to eops -> /home/eops/app/eops/current. My symlink was found at /var/www/html/

My rails_apps.conf file to:

<IfModule mod_ssl.c>
<VirtualHost mydomain.com:443>
    ServerName mydomain.com
    ServerAdmin my_email_address

    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn
    LogLevel debug

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLCertificateFile /etc/letsencrypt/live/mydomain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mydomain.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf

    # Overall Rules For The DocumentRoot
    <Directory /var/www/html>
        # Relax Apache security settings
        AllowOverride all
        Require all granted
        # MultiViews must be turned off
        Options -MultiViews
    </Directory>

    # ------- Host apps below

    # Shib protected at Application Level
    <Directory /var/www/html/eops>
        Allow from all
        Options -MultiViews

        # Uncomment below line if you are on Apache > 2.4
        Require all granted
    </Directory>

    Alias /eops /home/eops/app/eops/current/public
    <Location /eops>
        # Require Shibboleth authentication
        AuthType shibboleth
        ShibRequestSetting requireSession 1
        require valid-user

        PassengerBaseURI "/eops"
        PassengerStartupFile config.ru
        PassengerAppType rack
        PassengerAppRoot /home/eops/app/eops/current
        RailsEnv staging
        PassengerRuby /home/eops/.rbenv/versions/2.1.6/bin/ruby
    </Location>

</VirtualHost>


问:
How to disable Chunked transfer in IIS?
I have two websites that basically use the same code base, lets called them A & B.  When I upload A and run, the site is not chunked.  When I debug and test B, the page is not Chunked but when it is run from the server, the pages become chunked.  Is there a setting in IIS or web.config that disables Chunking of the page.  Any ideas on how to identify why the page is chunking?</p>

Title: How to disable Chunked transfer in IIS?


Title: Trying to convert a 3 dimentional list into dataframe (Python)

Body:
I am fairly new to python and I was trying to convert the following list into a dataframe.

To start I applied the following to an existing dataframe:

df1b=[df1a.iloc[:,:n].pct_change()]
df1b
print(type(df1b))

and the result I got is:

[                      A             B             C              D  \
 Date
 2022-05-31           NaN           NaN           NaN           NaN
 2022-06-01     -0.004854     -0.006553     -0.002063      0.000000
 2022-06-06      0.001330      0.003958      0.015162     -0.000339
 2022-06-07      0.004872     -0.008541      0.008826     -0.003068
 2022-06-08      0.001322      0.001325     -0.008748     -0.007289
 ...                  ...           ...           ...           ...
 2022-12-07     -0.005360      0.000656      0.002903      0.006578
 2022-12-08     -0.003592     -0.003932      0.015195      0.004320
 2022-12-09      0.001352      0.003289     -0.012117     -0.004411
 2022-12-12     -0.003150     -0.005246      0.021645      0.002991
 2022-12-13      0.003160      0.001978      0.000000      0.000000

                        E              F            G
 Date
 2022-05-31           NaN           NaN           NaN
 2022-06-01      0.000000      0.000000      0.000000
 2022-06-06      0.004129      0.010404      0.002574
 2022-06-07      0.006773     -0.002818     -0.002243
 2022-06-08     -0.008411     -0.010415      0.005496
 ...                  ...           ...           ...
 2022-12-07     -0.000378     -0.003718     -0.006345
 2022-12-08      0.006671      0.002271      0.009224
 2022-12-09     -0.012664     -0.002914     -0.006248
 2022-12-12      0.017739      0.003564     -0.002653
 2022-12-13      0.000000      0.000000      0.000000

 [137 rows x 7 columns]]

<class 'list'>

when I applied the following to convert the list into a dataframe it says:

Prices = ['A','B','C','D','E','F','G']

df = pd.DataFrame(df1b, columns =['Prices'], dtype = float)

Error Message:

Must pass 2-d input. shape=(1, 137, 7)

Can anybody help?


问:
While training a DNN with pretrained model, and tried to fine tune it, did it change the weights of downloaded pretrained model in my computer?
I do not know if the fine tuning of the pretrained model changes the weights value in the downloaded pretrained model or it changes the model weights of my network only.

I design a DNN with the help of ResNet50 pretrained model ... and I tried to fine tune it, so I turned the trainable into true ... did it change the weights of the downloaded ResNet model in my computer or these changes is local to my model?


问:
is JWT access token/refresh token flow ONLY the backend/server side bad?
Is refreshing JWT access token ONLY on the backend/server side bad?

I've read everywhere to use separate /refresh endpoint to obtain new access token when first request returns 401/403 error, but let's say both resource server and authentication server are just basic monolith app, and we can obtain new access token on the same backend.

Refresh endpoint called on the client side:

vs. obtaining new access token on the server side/backend only:

I've seen this sort of answer:

If however your application is one big monolith, where every endpoint is hosted by the same server and therefore is capable of checking refresh tokens and issuing access tokens, then there is absolutely no reason for you to be using access tokens or JWTs in general. You should just use refresh tokens, which, in this case, would be better called a session token.

There is still a reason to use JWT just to reduce e.g. database calls needed to check validity of refresh token.

So why is it mostly done on the client side and is there anything wrong with doing it ONLY on the backend side.


问:
"django.db.utils.OperationalError: no such function: lwgeom_version" Django Version 3.2.16, Spatialite Version 4.2.0 on Windows 10
I have a Django application that uses some geographic information. I have installed GDAL and installed Spatialite by downloading the windows binaries and placing them in my python directory (conda environment in my case) as detailed in this post. That was the only way I was able to get it to work without throwing an error.

My database is set in settings.py as

```<code>    DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        'ENGINE': 'django.contrib.gis.db.backends.spatialite',
        'NAME': BASE_DIR / 'db.sqlite3',
        }

    }
</code>```

When I try to test a query based on geographic coordinates such as

```<code>loc = Point(location['lng'], location['lat'])
radius = D(mi=20)

queryset = BusinessProfile.objects.filter(businessAddress__coordinates__dwithin=(loc, 2.0)) \
            .filter(businessAddress__coordinates__distance_lte=(loc, radius)) \
            .annotate(distance=Distance("businessAddress__coordinates", loc)) \
            .order_by("distance")
</code>```

I get the following error:

```<code>django.db.utils.OperationalError: no such function: lwgeom_version
</code>```

I have already installed GDAL and spatialite, can anyone help me figure out what the problem could be here?

Body:
I have a Django application that uses some geographic information. I have installed GDAL and installed Spatialite by downloading the windows binaries and placing them in my python directory (conda environment in my case) as detailed in this post. That was the only way I was able to get it to work without throwing an error.

My database is set in settings.py as

    DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        'ENGINE': 'django.contrib.gis.db.backends.spatialite',
        'NAME': BASE_DIR / 'db.sqlite3',
        }

    }

When I try to test a query based on geographic coordinates such as

loc = Point(location['lng'], location['lat'])
radius = D(mi=20)

queryset = BusinessProfile.objects.filter(businessAddress__coordinates__dwithin=(loc, 2.0)) \
            .filter(businessAddress__coordinates__distance_lte=(loc, radius)) \
            .annotate(distance=Distance("businessAddress__coordinates", loc)) \
            .order_by("distance")

I get the following error:

django.db.utils.OperationalError: no such function: lwgeom_version

I have already installed GDAL and spatialite, can anyone help me figure out what the problem could be here?


问:
Importing python variable from a file in directory to main file
I have project:

```<code>/app
     main.py
     __init__.py
    /directory1
        a.py
        b.py
        __init__.py

    /directory2
        c.py
        d.py
        __init__.py

</code>```

/x - folder x

This is my code in order to import

```<code>from directory2 import c
new_var = c.variable
</code>```

If it's important, I'am using FastApi
And I need variable from directory2, c.py file import to main.py. What should I do? I would need a clear answer: do this (and it will work). Thank you in advice!

An Error:
File "C:\Users\Admin\PycharmProjects\app\main.py", line 3, in
from directory2 import c

Body:
I have project:

/app
     main.py
     __init__.py
    /directory1
        a.py
        b.py
        __init__.py

    /directory2
        c.py
        d.py
        __init__.py

/x - folder x

This is my code in order to import

from directory2 import c
new_var = c.variable

If it's important, I'am using FastApi
And I need variable from directory2, c.py file import to main.py. What should I do? I would need a clear answer: do this (and it will work). Thank you in advice!

An Error:
File "C:\Users\Admin\PycharmProjects\app\main.py", line 3, in
from directory2 import c


问:
How do I create a pivot/crosstab query in SQL Server when I don't know the column names in advance?
I am querying some sales figures in SQL Server to determine sales by customer by year. This is easy in Access:

TRANSFORM Sum(dbo_HISTORY.NET_SALES) AS SumOfNET_SALES
SELECT dbo_HISTORY.CUSTOMER_NAME
FROM dbo_HISTORY
GROUP BY dbo_HISTORY.CUSTOMER_NAME
PIVOT dbo_HISTORY.YEAR;
```
<p>In SQL Server, I can add things easily enough:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT [SPEC_MIS].DBO.HISTORY.CUSTOMER_NAME,[SPEC_MIS].DBO.HISTORY.YEAR,sum([SPEC_MIS].DBO.HISTORY.NET_SALES) AS SALES
FROM [SPEC_MIS].DBO.HISTORY
GROUP BY CUSTOMER_NAME,YEAR
ORDER BY CUSTOMER_NAME,YEAR
</code>```

But I can't work out how to get the pivot to work. Note that I need this query to work on any arrangement of years, I don't want to have to rewrite this query every year.

Body:
I am querying some sales figures in SQL Server to determine sales by customer by year. This is easy in Access:

TRANSFORM Sum(dbo_HISTORY.NET_SALES) AS SumOfNET_SALES
SELECT dbo_HISTORY.CUSTOMER_NAME
FROM dbo_HISTORY
GROUP BY dbo_HISTORY.CUSTOMER_NAME
PIVOT dbo_HISTORY.YEAR;

In SQL Server, I can add things easily enough:

SELECT [SPEC_MIS].DBO.HISTORY.CUSTOMER_NAME,[SPEC_MIS].DBO.HISTORY.YEAR,sum([SPEC_MIS].DBO.HISTORY.NET_SALES) AS SALES
FROM [SPEC_MIS].DBO.HISTORY
GROUP BY CUSTOMER_NAME,YEAR
ORDER BY CUSTOMER_NAME,YEAR

But I can't work out how to get the pivot to work. Note that I need this query to work on any arrangement of years, I don't want to have to rewrite this query every year.


问:
In Electron, how to I call a JavaScript function when the index.html page loads?
I am using Electron to create a desktop app for my students. The purpose of the app is to help them prepare for a final examination. My app will have four learning modules. Each module will contain some original information about a certain topic, links to outside resources, and a quiz at the end of each module. It will also contain a link to a comprehensive test, to be taken only after completing all four modules. The app's main window will have five buttons: four buttons that link to a learning module and one button that links to the comprehensive test.

I would like to set up the app to track my students' progress through the modules and keep them from advancing to the next module until they have completed the one before it. For example, when a student opens the app for the first time, only the button for the first learning module will be enabled; all the other buttons will be disabled. When they pass the first module, only the button for the second learning module will be enabled; all the others will be disabled. And so on until they finish the comprehensive test.

What I need is: a way that each time the app is opened, a JavaScript function is called that will check the value of a "student progress variable" (possible values: 0 to 5) that is stored in the app. That value will determine which buttons are enabled and disabled when the app launches. The value will start at 0 and increase by 1 when a student completes a learning module.

My question is: in Electron, how do I call a JavaScript function when the index.html page loads? Code examples would be ideal. Thanks!

I have tried the onload event handler in the  tag with no luck. I have all of the button clicks working fine, I just can't figure out how to call a function when the index.html page loads.


问:
How to scraping lazy loading webpage? C#, HtmlAgilityPack
I'm trying to parse a music playlist from a website. It's now takes only 15 items (regardless of whether I scroll down or up) but needs to be 50. Is it possible to force the load of lazyloading website?

I'm using Selenium WebDriver to run js


问:
Saving richtext format to firebase
I am doing project to post a project idea(good analogy to the project is this stackoverflow post your quation form) to firebase realtime or firestore database which uses rich text editor in my case TinyMCE but I can't do so even if I search many websites.

I try to upload the whole html markup to Firebase(I have considered security issues) ,then to retrieve the markup(styles) in to my front end Angular app,but I can't.

is there anyone who help me ?

Title: Saving richtext format to firebase


问:
There is a widget to copy and get images from clipboard?
Goal: Copy an image from HDD and get it(by pasting it) on my Flutter web app

What I tried:

Clipboard doesn't support image type.

Pasteboard works if I add images manually (from the app), but I need to add images from the desktop by copying it and for this it doesn't work. In particular the error is that image type is not supported.

Manually doing it using Javascript APIs and the result is the same of pasteboard.

I hope that my answer is clear. Thank you!

Example code using Pasteboard:

```<code>import 'package:flutter/material.dart';
import 'package:pasteboard/pasteboard.dart';

class TestPage extends StatefulWidget {
  const TestPage({super.key});

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          width: 500,
          height: 500,
          color: Colors.red,
        ),
        TextButton(
          onPressed: () async {

            // works if you copy text
            var text = await Pasteboard.text;
            print("text: $text");

            // works if you copy text, returns null if you copy an image
            var html = await Pasteboard.html;
            print("text: $html");

            // Returns always null
            var image = await Pasteboard.image;
            print(image);
          },
          child: const Text('Click me', style: TextStyle(fontSize: 20)),
        ),
      ],
    );
  }
}
</code>```

Body:
Goal: Copy an image from HDD and get it(by pasting it) on my Flutter web app

What I tried:

Clipboard doesn't support image type.

Pasteboard works if I add images manually (from the app), but I need to add images from the desktop by copying it and for this it doesn't work. In particular the error is that image type is not supported.

Manually doing it using Javascript APIs and the result is the same of pasteboard.

I hope that my answer is clear. Thank you!

Example code using Pasteboard:

import 'package:flutter/material.dart';
import 'package:pasteboard/pasteboard.dart';

class TestPage extends StatefulWidget {
  const TestPage({super.key});

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          width: 500,
          height: 500,
          color: Colors.red,
        ),
        TextButton(
          onPressed: () async {

            // works if you copy text
            var text = await Pasteboard.text;
            print("text: $text");

            // works if you copy text, returns null if you copy an image
            var html = await Pasteboard.html;
            print("text: $html");

            // Returns always null
            var image = await Pasteboard.image;
            print(image);
          },
          child: const Text('Click me', style: TextStyle(fontSize: 20)),
        ),
      ],
    );
  }
}


问:
Remove all falsy values from an array
This code is ok

```<code>function bouncer(arr) {
  const filteredArr = [];
  for (let i = 0; i < arr.length; i++) {
   if (arr[i]) filteredArr.push(arr[i]);
  }
  return filteredArr;
}

console.log(bouncer([7, "ate", "", false, 9]));
console.log(bouncer([false, null, 0, NaN, undefined, ""]));
console.log(bouncer([null, NaN, 1, 2, undefined]));
</code>```

Output:

```<code>[ 7, 'ate', 9 ]
[]
[ 1, 2 ]
</code>```

But if this is

(arr[i]) filteredArr.push(arr[i])

replaced by it

if (arr[i] != false && arr[i] != null && arr[i] != NaN && arr[i] != "" && arr[i] != 0 && arr[i] != undefined) filteredArr.push(arr[i]);

i have this in output:

```<code>[ 7, 'ate', 9 ]
[ NaN ]
[ NaN, 1, 2 ]
</code>```

I try to understand how this is work, but i can't.

p.s. sorry for my bad english.

Title: Remove all falsy values from an array

Body:
This code is ok

function bouncer(arr) {
  const filteredArr = [];
  for (let i = 0; i < arr.length; i++) {
   if (arr[i]) filteredArr.push(arr[i]);
  }
  return filteredArr;
}

console.log(bouncer([7, "ate", "", false, 9]));
console.log(bouncer([false, null, 0, NaN, undefined, ""]));
console.log(bouncer([null, NaN, 1, 2, undefined]));

Output:

[ 7, 'ate', 9 ]
[]
[ 1, 2 ]

But if this is

(arr[i]) filteredArr.push(arr[i])

replaced by it

if (arr[i] != false && arr[i] != null && arr[i] != NaN && arr[i] != "" && arr[i] != 0 && arr[i] != undefined) filteredArr.push(arr[i]);

i have this in output:

[ 7, 'ate', 9 ]
[ NaN ]
[ NaN, 1, 2 ]

I try to understand how this is work, but i can't.

p.s. sorry for my bad english.


问:
Do I need to have a separate installation of conda for each server with a different Centos version?
I would like to use my conda environment on different machines that all access the same file system. Currently, I have conda installed on this file system and I have created an environment on one of the machines which runs Centos 7. When I try to activate my environment on a machine running Centos 6 I receive an error (version `GLIBC_2.17' not found). Is it safe to create a new conda environment on this Centos 6 machine, or is it best to have a separate install of conda entirely to avoid these errors?</p>


问:
jquery rails 5 - uncaught TypeError: elems.sortable is not a function
We updated our rails app from rails 4.2.6 to 5.2.5 and ruby from 2.3.0 to 2.6.6. After the update, we start getting errors in the browser console (look at the image below). We tried updating the below gems and imports in the required files.

Also, didn't know what are we missing so tried added all packages of juery ui.

Before,

```<code># Use jquery as the JavaScript library
gem 'jquery-rails'

# Use the jquery ui widgets
gem 'jquery-ui-rails', '5.0.5'
</code>```

After,

```<code># Use jquery as the JavaScript library
gem 'jquery-rails', '~> 4.3.3'

# Use the jquery ui widgets
gem 'jquery-ui-rails', '~> 6.0.1'
</code>```

application.js

```<code>//= require jquery
//= require jquery_ujs

//= require jquery-ui/core
//= require jquery-ui/widget
//= require jquery-ui/position
//= require jquery-ui/widgets/mouse
//= require jquery-ui/widgets/draggable
//= require jquery-ui/widgets/droppable
//= require jquery-ui/widgets/resizable
//= require jquery-ui/widgets/selectable
//= require jquery-ui/widgets/sortable

//= require jquery-ui/widgets/accordion
//= require jquery-ui/widgets/autocomplete
//= require jquery-ui/widgets/button
//= require jquery-ui/widgets/datepicker
//= require jquery-ui/widgets/dialog
//= require jquery-ui/widgets/menu
//= require jquery-ui/widgets/progressbar
//= require jquery-ui/widgets/selectmenu
//= require jquery-ui/widgets/slider
//= require jquery-ui/widgets/spinner
//= require jquery-ui/widgets/tabs
//= require jquery-ui/widgets/tooltip

//= require jquery-ui/widgets/autocomplete
//= require select2

//= require react
//= require react_ujs

//= require vendor/cropper

//= require_tree .
</code>```

application.scss

```<code>// Import any jQuery plugins
@import "jquery-ui/autocomplete.css";
@import "select2";

@import "jquery-ui/core.css";
@import "jquery-ui/theme.css";

@import "jquery-ui/draggable.css";
@import "jquery-ui/resizable.css";
@import "jquery-ui/selectable.css";
@import "jquery-ui/sortable.css";

@import "jquery-ui/accordion.css";
@import "jquery-ui/autocomplete.css";
@import "jquery-ui/button.css";
@import "jquery-ui/datepicker.css";
@import "jquery-ui/dialog.css";
@import "jquery-ui/menu.css";
@import "jquery-ui/progressbar.css";
@import "jquery-ui/selectmenu.css";
@import "jquery-ui/slider.css";
@import "jquery-ui/spinner.css";
@import "jquery-ui/tabs.css";
@import "jquery-ui/tooltip.css";

// Import any vendor styles
@import "vendor/jquery.slick";
@import "vendor/cropper";
</code>```

active_admin.js.coffee

```<code>#= require active_admin/base

#= require select2
#= require jquery-ui/widgets/sortable
#= require jquery.minicolors
#= require cocoon

#= require vendor/cropper

#= require_tree ./admin
</code>```

active_admin.scss

```<code>// Import 3rd party librarys
@import "select2";
@import "font-awesome-sprockets";
@import "font-awesome";
@import "jquery-ui/sortable";
@import "active_admin/editor/wysiwyg";
@import "vendor/cropper";
@import "jquery.minicolors";
</code>```

Also, we were using cropper.js present in app/assets/javascripts/vendor/cropper.js, which also not seems to be working.

Would appreciate any kind of help!

Thank you

Body:
We updated our rails app from rails 4.2.6 to 5.2.5 and ruby from 2.3.0 to 2.6.6. After the update, we start getting errors in the browser console (look at the image below). We tried updating the below gems and imports in the required files.

Also, didn't know what are we missing so tried added all packages of juery ui.

Before,

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Use the jquery ui widgets
gem 'jquery-ui-rails', '5.0.5'

After,

# Use jquery as the JavaScript library
gem 'jquery-rails', '~> 4.3.3'

# Use the jquery ui widgets
gem 'jquery-ui-rails', '~> 6.0.1'

application.js

//= require jquery
//= require jquery_ujs

//= require jquery-ui/core
//= require jquery-ui/widget
//= require jquery-ui/position
//= require jquery-ui/widgets/mouse
//= require jquery-ui/widgets/draggable
//= require jquery-ui/widgets/droppable
//= require jquery-ui/widgets/resizable
//= require jquery-ui/widgets/selectable
//= require jquery-ui/widgets/sortable

//= require jquery-ui/widgets/accordion
//= require jquery-ui/widgets/autocomplete
//= require jquery-ui/widgets/button
//= require jquery-ui/widgets/datepicker
//= require jquery-ui/widgets/dialog
//= require jquery-ui/widgets/menu
//= require jquery-ui/widgets/progressbar
//= require jquery-ui/widgets/selectmenu
//= require jquery-ui/widgets/slider
//= require jquery-ui/widgets/spinner
//= require jquery-ui/widgets/tabs
//= require jquery-ui/widgets/tooltip

//= require jquery-ui/widgets/autocomplete
//= require select2

//= require react
//= require react_ujs

//= require vendor/cropper

//= require_tree .

application.scss

// Import any jQuery plugins
@import "jquery-ui/autocomplete.css";
@import "select2";

@import "jquery-ui/core.css";
@import "jquery-ui/theme.css";

@import "jquery-ui/draggable.css";
@import "jquery-ui/resizable.css";
@import "jquery-ui/selectable.css";
@import "jquery-ui/sortable.css";

@import "jquery-ui/accordion.css";
@import "jquery-ui/autocomplete.css";
@import "jquery-ui/button.css";
@import "jquery-ui/datepicker.css";
@import "jquery-ui/dialog.css";
@import "jquery-ui/menu.css";
@import "jquery-ui/progressbar.css";
@import "jquery-ui/selectmenu.css";
@import "jquery-ui/slider.css";
@import "jquery-ui/spinner.css";
@import "jquery-ui/tabs.css";
@import "jquery-ui/tooltip.css";

// Import any vendor styles
@import "vendor/jquery.slick";
@import "vendor/cropper";

active_admin.js.coffee

#= require active_admin/base

#= require select2
#= require jquery-ui/widgets/sortable
#= require jquery.minicolors
#= require cocoon

#= require vendor/cropper

#= require_tree ./admin

active_admin.scss

// Import 3rd party librarys
@import "select2";
@import "font-awesome-sprockets";
@import "font-awesome";
@import "jquery-ui/sortable";
@import "active_admin/editor/wysiwyg";
@import "vendor/cropper";
@import "jquery.minicolors";

Also, we were using cropper.js present in app/assets/javascripts/vendor/cropper.js, which also not seems to be working.

Would appreciate any kind of help!

Thank you


问:
Fix "unbalanced grouping command" Doxygen warnings
Our Doxygen build in ITK is raising a number of "unbalanced grouping commands" warnings:
https://open.cdash.org/viewBuildError.php?type=1&buildid=8335387

Following the warning description I am guessing that these might be due to a potential improper use of "\ingroup" commands in our files, or the impossibility to correctly interpret them the way we define our groups.

Besides the code modules that we parse as groups, we define a number of other groups.

That give rise (using a GitHub actions workflow) to the modules shown in:
https://itk.org/Doxygen/html/modules.html

Despite the warnings, many of these filters seem to display the modules/groups they belong to correctly in the header of the file, e.g.

Data Processing Objects » FunctionsData Processing Objects » Functions » Image Functions » | Image InterpolatorsGroup Core » | Module ITKCommon

https://itk.org/Doxygen/html/classitk_1_1BSplineInterpolationWeightFunction.html

However, we would like to remove the warnings and get a clean build, so I am wondering how to fix the warnings.

We have an ITK issue that may be useful for anyone trying to help.

Thanks.

Code inspection to locate grouping commands that are not properly closed.


问:
My Website Layout Is Broken But I Never Made Any Changes To It

The Problem

I have a webpage with multiple files, local images, and external style sheets. Today I started my Local Host like normal with Live Server and run the page on Google Chrome 108.0.5359.99 (Official Build) (64-bit) (cohort: Stable). And the website layout was broken. Most notable is position, margin, and padding.

Specific problems with the website:

Position: sticky is working on all of the pages expect index.html  file

Changing the margin, padding, and position values in the styles.css file does nothing but changing values like color does work

The network tab says 200, ok for styles.css

Intended Results

This image shows a block of content that is working as intended:
This image shows a block of content that is working as intended

And this image shows the content not loading properly:
And this image shows the content not loading properly

Here's the website URL https://creative-daffodil-2c8447.netlify.app/ As well as a Github repository: https://github.com/tech-world-code/website-test


问:
I get Nan Instead of an actual value after updating an excel file
I’m currently working on a bot that assigns tickets to users.
Once the ticket is assigned it updates an excel file and the volume of tickets for each user is saved using a formula. Once the file gets updated with upcoming tickets for the next run of the bot, python stops reading the actual value but gets NaN for each cell. Any ideas how to fix that?

I use pandas to open and read the file.

that's how it reads the file and turns the column into a list:

```<code>import pandas as pd
volume_table = pd.read_excel(
    r"<file_location>",
    sheet_name='VolumeCheck')

count_of_tickets_list = list(volume_table['Count Of tickets'])
</code>```

then it applies the changes and saves the file:

```<code>excel_report = openpyxl.load_workbook(InitialVariables.reporting_file_path)
    worksheets_available = excel_report.sheetnames
    sheet = excel_report[worksheets_available[0]]
    sheet.cell(column=1, row=sheet.max_row + 1, value=incident_number)
    sheet.cell(column=2, row=sheet.max_row, value=selected_agent)
    sheet.cell(column=3, row=sheet.max_row, value=report_date)
    sheet.cell(column=4, row=sheet.max_row, value=report_current_datetime)
    excel_report.save(InitialVariables.reporting_file_path)
    time.sleep(2)
    excel_report.close()
</code>```

Tried saving the file manually and that solved it but that’s not the point.

tried data_only:

```<code># Import the openpyxl module
import openpyxl

# Open the Excel file
wb = openpyxl.load_workbook("file-name", data_only=True)

# Get the sheet named "VolumeCheck"
ws = wb['VolumeCheck']

# Define the list of cells to apply the formula to
cells = [
    ws['C2'].value,
    ws['C3'].value,
    ws['C4'].value,
    ws['C5'].value,
    ws['C6'].value,
    ws['C7'].value,
    ws['C8'].value,
    ws['C9'].value,
    ws['C10'].value,
    ws['C11'].value,
    ws['C12'].value,
    ws['C13'].value,
    ws['C14'].value,
    ws['C15'].value,
]

print(cells)
</code>```

and the results is :

```<code>[None, None, None, None, None, None, None, None, None, None, None, None, None, None]
</code>```

Body:
I’m currently working on a bot that assigns tickets to users.
Once the ticket is assigned it updates an excel file and the volume of tickets for each user is saved using a formula. Once the file gets updated with upcoming tickets for the next run of the bot, python stops reading the actual value but gets NaN for each cell. Any ideas how to fix that?

I use pandas to open and read the file.

that's how it reads the file and turns the column into a list:

import pandas as pd
volume_table = pd.read_excel(
    r"<file_location>",
    sheet_name='VolumeCheck')

count_of_tickets_list = list(volume_table['Count Of tickets'])

then it applies the changes and saves the file:

excel_report = openpyxl.load_workbook(InitialVariables.reporting_file_path)
    worksheets_available = excel_report.sheetnames
    sheet = excel_report[worksheets_available[0]]
    sheet.cell(column=1, row=sheet.max_row + 1, value=incident_number)
    sheet.cell(column=2, row=sheet.max_row, value=selected_agent)
    sheet.cell(column=3, row=sheet.max_row, value=report_date)
    sheet.cell(column=4, row=sheet.max_row, value=report_current_datetime)
    excel_report.save(InitialVariables.reporting_file_path)
    time.sleep(2)
    excel_report.close()

Tried saving the file manually and that solved it but that’s not the point.

tried data_only:

# Import the openpyxl module
import openpyxl

# Open the Excel file
wb = openpyxl.load_workbook("file-name", data_only=True)

# Get the sheet named "VolumeCheck"
ws = wb['VolumeCheck']

# Define the list of cells to apply the formula to
cells = [
    ws['C2'].value,
    ws['C3'].value,
    ws['C4'].value,
    ws['C5'].value,
    ws['C6'].value,
    ws['C7'].value,
    ws['C8'].value,
    ws['C9'].value,
    ws['C10'].value,
    ws['C11'].value,
    ws['C12'].value,
    ws['C13'].value,
    ws['C14'].value,
    ws['C15'].value,
]

print(cells)

and the results is :

[None, None, None, None, None, None, None, None, None, None, None, None, None, None]


问:
cmdlet Get-Content at command pipeline position 1
I am trying to recursively find references of Constants.cs of an any other .cs files in a directory containing files with Paths. Name of the files are stored procedures and they  have the references(Paths) for that stored procedure.

This is PowerShell Script that i have written.

```<code>[CmdletBinding()]
param(
    [Parameter(Position=0, Mandatory=$true)]
    [string]$ProceduresFile,
    [Parameter(Position=1, Mandatory=$true)]
    [string]$ReferencesDir,
    [Parameter(Position=2, Mandatory=$true)]
    [string]$Project,
    [Parameter(Position=3, Mandatory=$false)]
    [string]$OutputPath = "."
)

$ErrorActionPreference = "Stop"
$storedProcFromFile = [IO.File]::ReadAllLines($ProceduresFile)

function Search-PSfile
{
    param(
        [string] $ReferencesDir,
        [string] $Project,
        [string] $file
    )

    $procedureName = $file.Split(".")[0].ToLower()
    $textName = "${procedureName}.txt"
    $pattern = "\b${Project}\.\b"

    #check for Constant.cs files in project directory-- returs true if present
    $isConstantFile = [bool](Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
            Get-Content |
            Select-String -Pattern "\bConstants.cs\b" |
            Select-String -Pattern $pattern -Quiet)

    #check for .cs files in project directory besides Constants.cs .. returs true if present
    $isOtherCsFile = [bool](Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
                    Get-Content |
                    Select-String -Pattern "\b.cs\b" |
                    Select-String -Pattern "\bConstants.cs\b" -NotMatch |
                    Select-String -Pattern $pattern  -Quiet)

    $filePattern = "\b${procedureName}\b"
    #check for .sql files other than itself.. returs true if present
    $isUsedSql = [bool](Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
                Get-Content |
                Select-String -Pattern "\.sql" |
                Select-String -Pattern $filePattern -NotMatch -Quiet)

    # if there are no constant files and no .sql file and no there .cs files then SP is not used
    If(!$isConstantFile -and !$isUsedSql -and !$isOtherCsFile)
    {
       return $false
    }
    # If there are Constants.cs then write SP name in Used.txt end function
    Elseif ($isConstantFile)
    {
        return $true
    }
    # If there are other .cs files then check if SP is commented out if yes then 'not used' else 'used'
    Elseif ($isOtherCsFile)
    {
        Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
        Get-Content |
        Select-String -Pattern "\b.cs\b" |
        Select-String -Pattern "\bConstants.cs\b" -NotMatch |
        Select-String -Pattern $pattern |
        ForEach-Object{
            $isUnCommented = [bool](Get-Content |
                                    Select-String -Pattern $filePattern |
                                    Select-String -Pattern "\/\/" -NotMatch -Quiet)

            if($isUnCommented)
            {
                return $true
            }
            else
            {
                return $false
            }
        }
    }
    # if there are no .cs files only .sql files then do a recusion and check for that .sql file
    Elseif ($isUsedSql)
    {
        Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
        Get-Content |
        Select-String -Pattern "\.sql" |
        Select-String -Pattern $filePattern -NotMatch |
        ForEach-Object{
            $sqlFile = (Get-Item $_).Name
            Search-PSfile -ReferencesDir $ReferencesDir -Project $Project -file $sqlFile -OutputPath $OutputPath
        }
    }
}

function Write-PSfile
{
    param(
        [string]$OutputPath,
        [string]$File,
        [string]$FileName,
        [string]$Text
    )

    $fileExist = Test-Path "${OutputPath}\${FileName}"
    if(!$fileExist)
    {
        $line = "${File} | ${Text}"
        New-Item -Path $OutputPath -Name $FileName -ItemType "file" -Value $line
    }
    else {
        $line = "${File} | ${Text}"
        $path = "${OutputPath}\${FileName}"
        Add-Content -Path $path -Value $line
    }
}

$storedProcFromFile | ForEach-Object{
    $isUsed = Search-PSfile -ReferencesDir $ReferencesDir -Project $Project -file $_ -OutputPath $OutputPath

    if($isUsed)
    {
        Write-PSfile -OutputPath $OutputPath -File $_ -FileName "Used.txt" -Text "Used"

    }
    else
    {
        Write-PSfile -OutputPath $OutputPath -File $_ -FileName "NotUsed.txt" -Text "Not Used"

    }
}

Write-Host "Script Ran Successfully"
</code>```

I am not sure why I am getting cmdlet Get-Content at command pipeline position 1 for second elseif Elseif ($isOtherCsFile)statement but others are working fine. Any Suggestion is welcome. Thankyou.

Body:
I am trying to recursively find references of Constants.cs of an any other .cs files in a directory containing files with Paths. Name of the files are stored procedures and they  have the references(Paths) for that stored procedure.

This is PowerShell Script that i have written.

[CmdletBinding()]
param(
    [Parameter(Position=0, Mandatory=$true)]
    [string]$ProceduresFile,
    [Parameter(Position=1, Mandatory=$true)]
    [string]$ReferencesDir,
    [Parameter(Position=2, Mandatory=$true)]
    [string]$Project,
    [Parameter(Position=3, Mandatory=$false)]
    [string]$OutputPath = "."
)

$ErrorActionPreference = "Stop"
$storedProcFromFile = [IO.File]::ReadAllLines($ProceduresFile)

function Search-PSfile
{
    param(
        [string] $ReferencesDir,
        [string] $Project,
        [string] $file
    )

    $procedureName = $file.Split(".")[0].ToLower()
    $textName = "${procedureName}.txt"
    $pattern = "\b${Project}\.\b"

    #check for Constant.cs files in project directory-- returs true if present
    $isConstantFile = [bool](Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
            Get-Content |
            Select-String -Pattern "\bConstants.cs\b" |
            Select-String -Pattern $pattern -Quiet)

    #check for .cs files in project directory besides Constants.cs .. returs true if present
    $isOtherCsFile = [bool](Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
                    Get-Content |
                    Select-String -Pattern "\b.cs\b" |
                    Select-String -Pattern "\bConstants.cs\b" -NotMatch |
                    Select-String -Pattern $pattern  -Quiet)

    $filePattern = "\b${procedureName}\b"
    #check for .sql files other than itself.. returs true if present
    $isUsedSql = [bool](Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
                Get-Content |
                Select-String -Pattern "\.sql" |
                Select-String -Pattern $filePattern -NotMatch -Quiet)

    # if there are no constant files and no .sql file and no there .cs files then SP is not used
    If(!$isConstantFile -and !$isUsedSql -and !$isOtherCsFile)
    {
       return $false
    }
    # If there are Constants.cs then write SP name in Used.txt end function
    Elseif ($isConstantFile)
    {
        return $true
    }
    # If there are other .cs files then check if SP is commented out if yes then 'not used' else 'used'
    Elseif ($isOtherCsFile)
    {
        Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
        Get-Content |
        Select-String -Pattern "\b.cs\b" |
        Select-String -Pattern "\bConstants.cs\b" -NotMatch |
        Select-String -Pattern $pattern |
        ForEach-Object{
            $isUnCommented = [bool](Get-Content |
                                    Select-String -Pattern $filePattern |
                                    Select-String -Pattern "\/\/" -NotMatch -Quiet)

            if($isUnCommented)
            {
                return $true
            }
            else
            {
                return $false
            }
        }
    }
    # if there are no .cs files only .sql files then do a recusion and check for that .sql file
    Elseif ($isUsedSql)
    {
        Get-ChildItem -Path $ReferencesDir -Filter $textName -Recurse |
        Get-Content |
        Select-String -Pattern "\.sql" |
        Select-String -Pattern $filePattern -NotMatch |
        ForEach-Object{
            $sqlFile = (Get-Item $_).Name
            Search-PSfile -ReferencesDir $ReferencesDir -Project $Project -file $sqlFile -OutputPath $OutputPath
        }
    }
}

function Write-PSfile
{
    param(
        [string]$OutputPath,
        [string]$File,
        [string]$FileName,
        [string]$Text
    )

    $fileExist = Test-Path "${OutputPath}\${FileName}"
    if(!$fileExist)
    {
        $line = "${File} | ${Text}"
        New-Item -Path $OutputPath -Name $FileName -ItemType "file" -Value $line
    }
    else {
        $line = "${File} | ${Text}"
        $path = "${OutputPath}\${FileName}"
        Add-Content -Path $path -Value $line
    }
}

$storedProcFromFile | ForEach-Object{
    $isUsed = Search-PSfile -ReferencesDir $ReferencesDir -Project $Project -file $_ -OutputPath $OutputPath

    if($isUsed)
    {
        Write-PSfile -OutputPath $OutputPath -File $_ -FileName "Used.txt" -Text "Used"

    }
    else
    {
        Write-PSfile -OutputPath $OutputPath -File $_ -FileName "NotUsed.txt" -Text "Not Used"

    }
}

Write-Host "Script Ran Successfully"

I am not sure why I am getting cmdlet Get-Content at command pipeline position 1 for second elseif Elseif ($isOtherCsFile)statement but others are working fine. Any Suggestion is welcome. Thankyou.


问:
How do I handle the data while writing to Kafka producer with Keys efficiently?
In SAP data Intelligence, We are receiving a source records as a batch of 100 MB packet from SAP and when written to Kafka topic we see the keys are blank. Since the incoming data is transactional in nature, the sequence is important. We are using Kafka producer that SAP delivers out of the box in SAP data intelligence cloud.

we had added a python script below in Data intelligence pipeline to pass the keys to the Key attribute of the message by reading one record at a time from the source packet and passing it to Kafka producer. This performs very slow ( 4 recs/ sec).

Is there an efficient way to writing to Kafka topic while still passing the keys than record by record?

```<code>
if(data):
        if(batchcounter == 0):
            #Set data_available flag when there is data available to fetch
            data_available = True

            #Getting the columns names from Header into col
            tbl_info = api.type_context.get_vtype(tbl.type_ref)
            col = list(tbl_info.columns.keys())

            #Getting the key columns from Header into col_def
            key = list(tbl_info.keys)

        df = pd.DataFrame(data, columns=col, dtype = 'str')
        df = data_profiling(df)

        for cnt in range(len(df)):
            keycontent = ""
            attr_kafka = {}
            new_header = {}
            for j in range(len(key)):
                keycontent += str(df[key[j]][cnt])
            new_header['com.sap.headers.kafka'] = ['',0,0,keycontent,'',"",[]]
            content = json.loads(df.iloc[[cnt]].to_json(orient = "records"))[0]
            content_json = json.dumps(content)
            api.outputs.outKafka.publish(content_json,-1, header=new_header)

api.set_port_callback("inSourcedata", on_input)

</code>```

Body:
In SAP data Intelligence, We are receiving a source records as a batch of 100 MB packet from SAP and when written to Kafka topic we see the keys are blank. Since the incoming data is transactional in nature, the sequence is important. We are using Kafka producer that SAP delivers out of the box in SAP data intelligence cloud.

we had added a python script below in Data intelligence pipeline to pass the keys to the Key attribute of the message by reading one record at a time from the source packet and passing it to Kafka producer. This performs very slow ( 4 recs/ sec).

Is there an efficient way to writing to Kafka topic while still passing the keys than record by record?

if(data):
        if(batchcounter == 0):
            #Set data_available flag when there is data available to fetch
            data_available = True

            #Getting the columns names from Header into col
            tbl_info = api.type_context.get_vtype(tbl.type_ref)
            col = list(tbl_info.columns.keys())

            #Getting the key columns from Header into col_def
            key = list(tbl_info.keys)

        df = pd.DataFrame(data, columns=col, dtype = 'str')
        df = data_profiling(df)

        for cnt in range(len(df)):
            keycontent = ""
            attr_kafka = {}
            new_header = {}
            for j in range(len(key)):
                keycontent += str(df[key[j]][cnt])
            new_header['com.sap.headers.kafka'] = ['',0,0,keycontent,'',"",[]]
            content = json.loads(df.iloc[[cnt]].to_json(orient = "records"))[0]
            content_json = json.dumps(content)
            api.outputs.outKafka.publish(content_json,-1, header=new_header)

api.set_port_callback("inSourcedata", on_input)


问:
Linking against dependent C libraries
Suppose I have static C libraries lib1 and lib2 where functions in lib2 call functions in lib1.  I've made crates lib1-sys and lib2-sys which simply list the extern functions exposed by each library, lib2-sys depends on lib1-sys.  The Cargo.toml file for each lists the corresponding library in its link field and the build.rs for each just gives cargo:rustc-link-search and cargo:rustc-link-lib.

My issue is that when I try and build a binary depending on lib2-sys (either as a separate crate or just building tests for lib2-sys), cargo doesn't link against lib1 so I get unresolved symbol errors from the functions in lib2 which call out to lib1.  That is, depending on lib1-sys apparently isn't enough to guarantee linking against lib1.  Is that expected behaviour?  I found two fixes which seem to work, which is prefered or is there anything better?

I can put extern crate lib1-sys; at the top of lib2-sys/lib.rs.

I can add cargo:rustc-link-lib=lib1 to lib2-sys/build.rs.

Title: Linking against dependent C libraries


问:
Vue JS: How to make two Vue Instances to work together on the same page?
I created a recipe website, you can find it here https://hungry-vegetarian.com/.
The tab on the index page is a vue instance. I'm trying to create a search bar that is also a vue instance.

The problem occurs when I try to display searched recipes on the index page. It just shows the search result on top of the search bar.

Ideally, only searched recipes should appear on the tab just like they are now but without any indications on top of the tab like Breakfast, Salad, Bakery, etc.

I don't know how to make two objects work together. For now, they work separately without communicating with each other.

SEARCH

```<code><div id="search">
        <div class="main-search">
          <h1 class="search-question">What  are you in the mood for?</h1>
          <div class="search-box">
                <input type="text" v-model="searchQuery" class="input-search" placeholder="Bread">
              <button class="btn-search"><i class="fa fa-search"></i></button>
            </div>
        </div>
        <div class="container">
          <div class="recipe" v-for="post in filteredList">
            <div v-if="searchQuery">
              <a v-bind:href="post.url" class="recipe-card__card-link" target="_blank">
                <img v-bind:src="post.image" alt="" class="recipe-card__image"/>
                <div class="recipe-card__text-wrapper">
                  <h2 class="recipe-card__title">{{post.name}}</h2>
                  <div class="recipe-card__details-wrapper">
                    <p class="recipe-card__excerpt">{{post.body}}</p>
                    <a v-bind:href="post.url" class="recipe-card__read-more">Read more <i class="fa fa-arrow-right"></i></a>
                  </div>
                </div>
              </a>
            </div>
          </div>
        </div>
      </div>
    </div>
</code>```

tab

```<code><main id="tab">
      <header>
        <nav>
          <ul>
            <div id="arrow">
              <span></span>
              <span></span>
              <span></span>
            </div>
            <li v-for="(tab, tabName) in tabs" :key="tabName">
              <button class="tab" @click="setTabActive(tabName)" :class="{'active': tabName === activeTab}">
                <span class="tab-copy">{{ tabName }}</span>
                <span class="tab-background">
                </span>
              </button>
            </li>
          </ul>
        </nav>
      </header>
      <article>
        <div class="container">
          <transition name="fade" mode="out-in" appear :duration="500">
            <tab-content v-for="(tabContent, t) in tabs" :data="tabContent" :key="'content'+t" v-if="t === activeTab" inline-template>
              <div class="content-wrapper">
                <div class="recipes" v-for="(recipe, i) in data.recipes" :key="i">
                  <a v-bind:href="recipe.url" class="recipe-card__card-link"></a>
                  <img :src="recipe.image" alt="" class="recipe-card__image">
                  <div class="recipe-card__text-wrapper">
                    <h2 class="recipe-card__title">{{recipe.name}}</h2>
                    <div class="recipe-card__details-wrapper">
                      <p class="recipe-card__excerpt">{{recipe.body}}</p>
                      <a v-bind:href="recipe.url" class="recipe-card__read-more">Read more <i class="fa fa-arrow-right"></i></a>
                    </div>
                  </div>
                </div>
              </div>
            </tab-content>
          </transition>
        </div>
      </article>
    </main>
</code>```

I tried to combine instances search and tab into just one instance tab, but it always gives me a Vue warning:

[Vue warn]: Property or method "searchQuery" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for  class-based components, by initializing the property.

Also, I feel like I can have just the wrong approach to this problem I am trying to solve. Please, any suggestions are welcome. I am stuck.

Body:
I created a recipe website, you can find it here https://hungry-vegetarian.com/.
The tab on the index page is a vue instance. I'm trying to create a search bar that is also a vue instance.

The problem occurs when I try to display searched recipes on the index page. It just shows the search result on top of the search bar.

Ideally, only searched recipes should appear on the tab just like they are now but without any indications on top of the tab like Breakfast, Salad, Bakery, etc.

I don't know how to make two objects work together. For now, they work separately without communicating with each other.

SEARCH

What  are you in the mood for?

                <input type="text" v-model="searchQuery" class="input-search" placeholder="Bread">
              <button class="btn-search"></button>

{{post.name}}

{{post.body}}

                    Read more

tab

              <button class="tab" @click="setTabActive(tabName)" :class="{'active': tabName === activeTab}">
                {{ tabName }}

              </button>

          <transition name="fade" mode="out-in" appear :duration="500">
            <tab-content v-for="(tabContent, t) in tabs" :data="tabContent" :key="'content'+t" v-if="t === activeTab" inline-template>

{{recipe.name}}

{{recipe.body}}

                      Read more

            </tab-content>
          </transition>

I tried to combine instances search and tab into just one instance tab, but it always gives me a Vue warning:

[Vue warn]: Property or method "searchQuery" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for  class-based components, by initializing the property.

Also, I feel like I can have just the wrong approach to this problem I am trying to solve. Please, any suggestions are welcome. I am stuck.


问:
How to use return statement properly
I want the terminal to return to the loop until the answer is 'OK'

Tried adding return to make the statement return into the lopp until the answer is desired

```<code>while true:
   agreement = str(input("Answer only in Yes or No OK? \n write 'OK' if you agree \n"))
   if agreement == str("OK"):
      print("Thanks")
   else:
      print("You can't move ahead without writing 'OK'")
       return agreement

itworking = str(input("Are you living?\n"))

if itworking == str ("yes"):
   print("You are living dude!")
else:
   print("You are dead hehe")

</code>```

Title: How to use return statement properly

Body:
I want the terminal to return to the loop until the answer is 'OK'

Tried adding return to make the statement return into the lopp until the answer is desired

while true:
   agreement = str(input("Answer only in Yes or No OK? \n write 'OK' if you agree \n"))
   if agreement == str("OK"):
      print("Thanks")
   else:
      print("You can't move ahead without writing 'OK'")
       return agreement

itworking = str(input("Are you living?\n"))

if itworking == str ("yes"):
   print("You are living dude!")
else:
   print("You are dead hehe")


问:
How can I convert raw pixel data to base64?
I want to load raw pixel data and convert it into base64 data image.

For example I have a matrix with this structure:

```<code>[[0, 0, 124, 255, ....], ....]
</code>```

And I want to convert it to base64 with this structure:

```<code>"data:image/webp;base64,AA...."
</code>```

Right now I'm using sharp, like that:

```<code>sharp(Buffer.from(data), {
        raw: {
          width: displayWidth,
          height: displayHeight,
          channels: 1,
        },
      })
        .webp({ quality: 100 })
        .toBuffer()
        .then((data) => {
          const base64 = `data:image/webp;base64,${data.toString("base64")}`;
          const img = base64.replace(/^data:image\/png;base64,/, "");
          scanImageStore.setImage(base64);
          console.timeEnd(`image-${id}`);
        });
</code>```

but it works very slow (around 500ms per conversion). I'm searching for a faster way to do so because the image getting loaded alot of times in a short duration.

Body:
I want to load raw pixel data and convert it into base64 data image.

For example I have a matrix with this structure:

[[0, 0, 124, 255, ....], ....]

And I want to convert it to base64 with this structure:

"data:image/webp;base64,AA...."

Right now I'm using sharp, like that:

sharp(Buffer.from(data), {
        raw: {
          width: displayWidth,
          height: displayHeight,
          channels: 1,
        },
      })
        .webp({ quality: 100 })
        .toBuffer()
        .then((data) => {
          const base64 = `data:image/webp;base64,${data.toString("base64")}`;
          const img = base64.replace(/^data:image\/png;base64,/, "");
          scanImageStore.setImage(base64);
          console.timeEnd(`image-${id}`);
        });

but it works very slow (around 500ms per conversion). I'm searching for a faster way to do so because the image getting loaded alot of times in a short duration.


问:
How to pick an individual based on the latest date
I have a dataset where some individuals are listed twice because they have received one or more degrees. I am wanting to only get the latest graduation date for each individual. Below are examples of what is currently happening and the desired output.</p>
```<code>People |  g_date  |
PersonA|2019-01-01|
PersonA|2020-01-01|
PersonB|2010-05-01|
PersonB|2015-01-01|
PersonC|2010-06-01|

People |  g_date  |
PersonA|2020-01-01|
PersonB|2015-01-01|
Personc|2010-06-01|
</code>```

Body:
I have a dataset where some individuals are listed twice because they have received one or more degrees. I am wanting to only get the latest graduation date for each individual. Below are examples of what is currently happening and the desired output.

People |  g_date  |
PersonA|2019-01-01|
PersonA|2020-01-01|
PersonB|2010-05-01|
PersonB|2015-01-01|
PersonC|2010-06-01|

People |  g_date  |
PersonA|2020-01-01|
PersonB|2015-01-01|
Personc|2010-06-01|


问:
I need to derive a function that depend on sample and parameters in R
I have a random variable which gets the parameters alpha and beta. but they're unknown and I need to estimate them. Can I create a function dependent on alpha and beta (without having them), and to derive the function in R?

i tried to define the function but without using an actual alpha and beta (but WITH the variables of the sample!), and by using the function expression it doesn't look like the actual calculations of the sample are accure. I don't get how to derive them according to alpha and beta.

I have a sample of X,Y, and with those I need to estimate alpha and beta.
[]

(https://i.stack.imgur.com/iWcoJ.png)

thanx!!!


问:
Expected End of Statement Highlighting WHERE
I am attempting to delete records from a table based on a listbox selection in my form. The table is DailyLog & UserLoggedOn where username is a variable based on user. The listbox is Me.lstRespLBPers. The field is the table is RespLBPerson. I keep getting "Expected end of Statement" error message with the word WHERE highlighted. What am I doing wrong. Code is listed below:

sql = "DELETE * FROM DailyLog_" & UserLoggedOn WHERE  [RespLBPerson] <> Me.LstRespLBPers

I tried the code and expected the records to be deleted from the table but got the error message.