问:
Selenium chrome hanging every other time
My selenium chrome script hangs every other time it is run, and it only does this when it is run with an extension, however I have no idea why.

I have recently, and what seems to be out of nowhere, encountered a problem that is seriously confusing me. I have a python selenium script run through Chrome that utilizes a proxy server, as it uses a username/password combination to authenticate and is not just authenticated through IP I have made a chrome extension that the driver loads before starting a new session.

Below is the script:

```<code>import selenium
import selenium.webdriver.common.proxy
import selenium.webdriver.common.desired_capabilities

chrome_options = selenium.webdriver.ChromeOptions()
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--ignore-ssl-errors')

prefs = {"profile.default_content_setting_values.notifications" : 2, "profile.managed_default_content_settings.images": 2, "profile.default_content_settings.images":2, 'disk-cache-size': 4096 }
chrome_options.add_experimental_option("prefs",prefs)

add_log_prefs = selenium.webdriver.common.desired_capabilities.DesiredCapabilities.CHROME
add_log_prefs['loggingPrefs'] = { 'browser':'ALL' }

chrome_options.add_argument('--load-extension='+proxy_extension_path)

driver = selenium.webdriver.Chrome(chrome_driver_path,
                                   options=chrome_options,
                                   desired_capabilities=add_log_prefs)

driver.set_window_size(window_size_w, window_size_h)

driver.get('https://www.google.com/')
</code>```

Below is the extension:

Manifest.json:

```<code>{
    "version": "1.0.0",
    "manifest_version": 1,
    "name": "Chrome Proxy",
    "permissions": [
        "proxy",
        "tabs",
        "unlimitedStorage",
        "storage",
        "<all_urls>",
        "webRequest",
        "webRequestBlocking"
    ],
    "background": {
        "scripts": ["background.js"]
    },
    "minimum_chrome_version":"1.0.0"
}
</code>```

background.js:

```<code>var config = {
        mode: "fixed_servers",
        rules: {
          singleProxy: {
            scheme: "http",
            host: "HOST",
            port: parseInt(PORT)
          },
          bypassList: ["localhost"]
        }
      };

chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

function callbackFn(details) {
    return {
        authCredentials: {
            username: "USERNAME",
            password: "PASSWORD"
        }
    };
}

chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ['blocking']
);
</code>```

The issue I am experiencing is that when i start the script and try to load a website through get e.g. driver.get("https://www.google.com/"), it will navigate to the website every other time i start the program and every other time it will timeout. When it times out, I can manually go in and navigate to the website myself, so it seems like it is just hanging there.

This happens even when I re-run the script and scrub it for any loaded variables etc., but the fact that it happens every other time to me indicates that there is somehow some left-over setting that gets cleaned after the script times out and then resat when after it manages to navigate to the webaddress.

Edit: Additionally I have tried to add a profile and alter that, however this does not help my case either. I thought about using the proxy server differently but I cant find any way to use a proxy server with password/name besides an extension.

I am completely at a loss and have been working on this problem for hours on end at this point, so any suggestions would be much appreciated.

答:
Using a custom chrome profile is one of the solutions that resolve this issue. Don't ask me how and why :-) still have to investigate on that part.

But for now, if you want to continue with your scripts then add the below line to your chrome options.

```<code> options.add_argument(r"--user-data-dir=path\to\chrome\user data\any_new_profile_name")
 # below is the sample
 options.add_argument(r"--user-data-dir=C:\Users\xxxx\AppData\Local\Google\Chrome\User Data\ChromeAutoProfile")
</code>```

You don't have to create the new chrome profile, script will create the profile first time if it does not exist.

Body:
My selenium chrome script hangs every other time it is run, and it only does this when it is run with an extension, however I have no idea why.

I have recently, and what seems to be out of nowhere, encountered a problem that is seriously confusing me. I have a python selenium script run through Chrome that utilizes a proxy server, as it uses a username/password combination to authenticate and is not just authenticated through IP I have made a chrome extension that the driver loads before starting a new session.

Below is the script:

import selenium
import selenium.webdriver.common.proxy
import selenium.webdriver.common.desired_capabilities

chrome_options = selenium.webdriver.ChromeOptions()
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--ignore-ssl-errors')

prefs = {"profile.default_content_setting_values.notifications" : 2, "profile.managed_default_content_settings.images": 2, "profile.default_content_settings.images":2, 'disk-cache-size': 4096 }
chrome_options.add_experimental_option("prefs",prefs)

add_log_prefs = selenium.webdriver.common.desired_capabilities.DesiredCapabilities.CHROME
add_log_prefs['loggingPrefs'] = { 'browser':'ALL' }

chrome_options.add_argument('--load-extension='+proxy_extension_path)

driver = selenium.webdriver.Chrome(chrome_driver_path,
                                   options=chrome_options,
                                   desired_capabilities=add_log_prefs)

driver.set_window_size(window_size_w, window_size_h)

driver.get('https://www.google.com/')

Below is the extension:

Manifest.json:

{
    "version": "1.0.0",
    "manifest_version": 1,
    "name": "Chrome Proxy",
    "permissions": [
        "proxy",
        "tabs",
        "unlimitedStorage",
        "storage",
        "<all_urls>",
        "webRequest",
        "webRequestBlocking"
    ],
    "background": {
        "scripts": ["background.js"]
    },
    "minimum_chrome_version":"1.0.0"
}

background.js:

var config = {
        mode: "fixed_servers",
        rules: {
          singleProxy: {
            scheme: "http",
            host: "HOST",
            port: parseInt(PORT)
          },
          bypassList: ["localhost"]
        }
      };

chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});

function callbackFn(details) {
    return {
        authCredentials: {
            username: "USERNAME",
            password: "PASSWORD"
        }
    };
}

chrome.webRequest.onAuthRequired.addListener(
            callbackFn,
            {urls: ["<all_urls>"]},
            ['blocking']
);

The issue I am experiencing is that when i start the script and try to load a website through get e.g. driver.get("https://www.google.com/"), it will navigate to the website every other time i start the program and every other time it will timeout. When it times out, I can manually go in and navigate to the website myself, so it seems like it is just hanging there.

This happens even when I re-run the script and scrub it for any loaded variables etc., but the fact that it happens every other time to me indicates that there is somehow some left-over setting that gets cleaned after the script times out and then resat when after it manages to navigate to the webaddress.

Edit: Additionally I have tried to add a profile and alter that, however this does not help my case either. I thought about using the proxy server differently but I cant find any way to use a proxy server with password/name besides an extension.

I am completely at a loss and have been working on this problem for hours on end at this point, so any suggestions would be much appreciated.

Body:
Using a custom chrome profile is one of the solutions that resolve this issue. Don't ask me how and why :-) still have to investigate on that part.

But for now, if you want to continue with your scripts then add the below line to your chrome options.

 options.add_argument(r"--user-data-dir=path\to\chrome\user data\any_new_profile_name")
 # below is the sample
 options.add_argument(r"--user-data-dir=C:\Users\xxxx\AppData\Local\Google\Chrome\User Data\ChromeAutoProfile")

You don't have to create the new chrome profile, script will create the profile first time if it does not exist.


来源: stackexchange

问:
Overlay Text on a Centered Image Which Is Smaller Than Its Containing Element
I have the following case:

Image which its width is less than the page width.

Image needs to be centered within its parent div (Which is wider).

Overlay text should be displayed on the image on one of its corners.

Image can not be stretched. Image will appear in its native size.

The image size can not be set in CSS as this template will be used for many images in different size.

So the code I came up with is given in https://jsfiddle.net/RoyiA/gdezys7j Or (Must be viewed in Full Screen so the image will be centered):

@font-face {font-family: "MammaGamma";
src: url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.eot");
src: url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.eot?#iefix") format("embedded-opentype"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.woff2") format("woff2"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.woff") format("woff"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.ttf") format("truetype"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.svg#MammaGamma") format("svg");
}

.image-container {
   position: relative;
   font-family: Arial;
}

.image-center{
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
}

.image-text-block {
   position: absolute;
display: block;
   top: 100px;
   left: 10px;
   background-color: rgba(100, 100, 100, 0.5);
   color: white;
   padding-left: 10px;
   padding-right: 10px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><h2>Image Text Blocks</h2>
<p>How to place text blocks over an image:</p>

<div class="image-container">
 <img class="image-center" src="https://i.imgur.com/0s8kLb7.png" alt="Nature">
   <div class="image-text-block">
     <h3>Created with <span style="font-family:MammaGamma; color:rgb(239, 74, 74)">Photoshop</span></h3>
     <p>Image: Jane by Mireille Lannoo</p>
   </div>
</div></code>```

The problem I'm having is that the text div is relative to the position of its parent div while the image is centered. How can address that?

答:
Just a couple of changes like so.</p>

```<code>.image-center {
    position: relative;
    display: block;
    margin-left: auto;
    margin-right: auto;
    object-fit: cover;
    width: 100vw;
    height: 100vh;
}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have the following case:

Image which its width is less than the page width.

Image needs to be centered within its parent div (Which is wider).

Overlay text should be displayed on the image on one of its corners.

Image can not be stretched. Image will appear in its native size.

The image size can not be set in CSS as this template will be used for many images in different size.

So the code I came up with is given in https://jsfiddle.net/RoyiA/gdezys7j Or (Must be viewed in Full Screen so the image will be centered):

@font-face {font-family: "MammaGamma";
src: url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.eot");
src: url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.eot?#iefix") format("embedded-opentype"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.woff2") format("woff2"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.woff") format("woff"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.ttf") format("truetype"),
url("//db.onlinewebfonts.com/t/1d8209e6e1d626b5657d1a5b99ea9572.svg#MammaGamma") format("svg");
}

.image-container {
   position: relative;
   font-family: Arial;
}

.image-center{
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
}

.image-text-block {
   position: absolute;
display: block;
   top: 100px;
   left: 10px;
   background-color: rgba(100, 100, 100, 0.5);
   color: white;
   padding-left: 10px;
   padding-right: 10px;
}

Image Text Blocks

How to place text blocks over an image:

Created with Photoshop

Image: Jane by Mireille Lannoo

The problem I'm having is that the text div is relative to the position of its parent div while the image is centered. How can address that?

Body:
Just a couple of changes like so.

.image-center {
    position: relative;
    display: block;
    margin-left: auto;
    margin-right: auto;
    object-fit: cover;
    width: 100vw;
    height: 100vh;
}


问:
How do I bind a style to my v-for loop in this example?
What am I doing wrong here?  There is no error - but there is also no style being applied when I look via dev tools.

```<code><!-- Template -->
<td v-for="steps in item.steps" v-bind:style="steps.name">
 {{ steps.name }}
</td>

// Component definition
computed: {
  endstage() {
    return {
      'background-color': '#f9f9f9',
    };
  }
}
</code>```

steps.name prints and if I bind class to steps.name that works - so not sure what I'm doing wrong with trying to bind style.

update:

In my template, I also am using this example which works fine:

```<code><!-- Template -->
<table :style="tableStyle">

// Component definition
computed: {
  tableStyle() {
    return {
      'background-color': '#f9f9f9',
      'border-color': '#C0C0C0',
      'padding': '8px',
      'color': 'red',
      'width': '100%',
      'display': 'table',
      'border': '1px solid #ddd',
    };
  }
}
</code>```

So why can I not do the same for td using steps.name which in this example results in 'endstage'?

答:
The output of your template will be something like this:

  endstage

```

<p>I'm assuming that isn't what you want as <code>endstage</code> is not a valid value for the <code>style</code> attribute. Note that the computed property isn't being used at all here. It is just trying to set the style to the string <code>'endstage'</code>.</p>

<p>I guess what you're trying to do is this?</p>

<pre class="lang-html prettyprint-override"><code><td v-for="steps in item.steps" :style="this[steps.name]">
</code>```

Assuming steps.name is 'endstage', this will use the object returned by the computed property endstage as the style. this[steps.name] evaluates as this['endstage'], which is just this.endstage.

It's not a great strategy though as it assumes that all names will have their own computed properties.

If endstage is the only name you care about then you could do something like this:

```

<p>If there are others then it'd be better to use a method:</p>

<pre class="lang-html prettyprint-override"><code><td v-for="steps in item.steps" :style="getStyle(steps.name)">
</code>```

with:

methods: {
  getStyle (name) {
    switch (name) {
      case 'endstage':
        return {'background-color': '#f9f9f9'}
      // Other cases here
    }
  }
}
```

Body:
What am I doing wrong here?  There is no error - but there is also no style being applied when I look via dev tools.

 {{ steps.name }}

// Component definition
computed: {
  endstage() {
    return {
      'background-color': '#f9f9f9',
    };
  }
}

steps.name prints and if I bind class to steps.name that works - so not sure what I'm doing wrong with trying to bind style.

update:

In my template, I also am using this example which works fine:

// Component definition
computed: {
  tableStyle() {
    return {
      'background-color': '#f9f9f9',
      'border-color': '#C0C0C0',
      'padding': '8px',
      'color': 'red',
      'width': '100%',
      'display': 'table',
      'border': '1px solid #ddd',
    };
  }
}

So why can I not do the same for td using steps.name which in this example results in 'endstage'?

Body:
The output of your template will be something like this:

<td style="endstage">
  endstage
</td>

I'm assuming that isn't what you want as endstage is not a valid value for the style attribute. Note that the computed property isn't being used at all here. It is just trying to set the style to the string 'endstage'.

I guess what you're trying to do is this?

<td v-for="steps in item.steps" :style="this[steps.name]">

Assuming steps.name is 'endstage', this will use the object returned by the computed property endstage as the style. this[steps.name] evaluates as this['endstage'], which is just this.endstage.

It's not a great strategy though as it assumes that all names will have their own computed properties.

If endstage is the only name you care about then you could do something like this:

<td v-for="steps in item.steps" :style="steps.name === 'endstage' ? endstage : null">

If there are others then it'd be better to use a method:

<td v-for="steps in item.steps" :style="getStyle(steps.name)">

with:

methods: {
  getStyle (name) {
    switch (name) {
      case 'endstage':
        return {'background-color': '#f9f9f9'}
      // Other cases here
    }
  }
}


问:
IntelliJ interactive rebase failing
Hello I can do rebase with current branch onto the selected but when I try to do interactive rebase from VCS/git/rebase this is what I am getting:

18:42   Rebase Failed
            cannot spawn sh: No such file or directory
            unable to start editor '"C:/Development/JetBrains/IntelliJ IDEA Community Edition 2018.3.4/jre64/bin/java" -cp "C:/Development/JetBrains/IntelliJ IDEA Community Edition 2018.3.4/plugins/git4idea/lib/git4idea.jar;C:/Development/JetBrains/IntelliJ IDEA Community Edition 2018.3.4/lib/xmlrpc-2.0.1.jar;C:/Development/JetBrains/IntelliJ IDEA Community Edition 2018.3.4/lib/commons-codec-1.10.jar" git4idea.rebase.GitRebaseEditorMain 63342'
            Retry

Does anyone know a solution to this?

答:
I just hit the same error; word for word. (Aside from being the commercial version and installed in Program Files instead of Development.) The odd part is I was running 2019.1.3, so there's no way it should have been running anything in 2018.3.4.

It appears to have been an issue with the in-place upgrade. I uninstalled 2019.1.3 (which interestingly was installed in C:/Program Files/JetBrains/IntelliJ IDEA 2018.3.4/), reinstalled, and now VCS > Git > Rebase works fine.

Title: IntelliJ interactive rebase failing


问:
has_many through associations where and select results
So I'm trying to filter results using WHERE condition but it's not working.

```<code>class Physician < ApplicationRecord
  has_many :appointments
  has_many :patients, through: :appointments
 end

class Appointment < ApplicationRecord
  belongs_to :physician
  belongs_to :patient
 end

class Patient < ApplicationRecord
  has_many :appointments
  has_many :physicians, through: :appointments
end
</code>```

and what I'm doing here is:

```<code>patients = Patient.joins(:physicians).includes(:physicians).where(:appointments => {:sick => true })
</code>```

However, what I'm getting is the following:

```<code>"results": {
  "patient": {
    "id": 2,
    "patient_name": "Rob"
   },
   "physicians": [
    {
      "id": 4,
      "physicians_name":...
      "sick":false
    ... ,
    {
      "id": 7,
     "physicians_name":...
     "sick":true
     ...
     ... ,
      {
      "id": 7,
      "physicians_name":...
      "sick":false
     ...
     ]
    }
</code>```

So as you noticed, I'm NOT getting only physicians with sick=true. any suggestions?

Update:
This is my serializer

```<code>class PatientSerializer < ActiveModel::Serializer
  attributes :records

 def records
    { info: records_info }
 end

 def records_info
  object.appointments.map do |a|
  a.attributes.merge(a.physician.attributes)
 end
</code>```

end
end

答: I believe includes(:physicians) is causing an eager loading, which makes the where clause not work as expected. Can you take it out and see if it fixes it? you can stick it at the end and see if it helps too.

Body:
So I'm trying to filter results using WHERE condition but it's not working.

class Physician < ApplicationRecord
  has_many :appointments
  has_many :patients, through: :appointments
 end

class Appointment < ApplicationRecord
  belongs_to :physician
  belongs_to :patient
 end

class Patient < ApplicationRecord
  has_many :appointments
  has_many :physicians, through: :appointments
end

and what I'm doing here is:

patients = Patient.joins(:physicians).includes(:physicians).where(:appointments => {:sick => true })

However, what I'm getting is the following:

"results": {
  "patient": {
    "id": 2,
    "patient_name": "Rob"
   },
   "physicians": [
    {
      "id": 4,
      "physicians_name":...
      "sick":false
    ... ,
    {
      "id": 7,
     "physicians_name":...
     "sick":true
     ...
     ... ,
      {
      "id": 7,
      "physicians_name":...
      "sick":false
     ...
     ]
    }

So as you noticed, I'm NOT getting only physicians with sick=true. any suggestions?

Update:
This is my serializer

class PatientSerializer < ActiveModel::Serializer
  attributes :records

 def records
    { info: records_info }
 end

 def records_info
  object.appointments.map do |a|
  a.attributes.merge(a.physician.attributes)
 end

end
end


问:
find empty cells with support for mixed datatypes of lists and sets and ints and str
Consider the following dataframe.

```<code>import pandas as pd
my_df = pd.DataFrame(columns =['A','B','C'])
my_df.at[0,'A'] = 1234
my_df.at[0,'C'] = ['5','6','7']
my_df.at[1,'A'] = set([8,9,10])
my_df.at[1,'B'] = 'my_hat'
</code>```

Then I want to find all the cells that are nan.

```<code>for row_index, row_data in my_df.iterrows():
   for cell in row_data:
      if pd.isnull(cell):
          print("found one")
</code>```

The pd.isnull, pd.isna, pd.notnull all cannot handle the mix of lists/sets with ints/str.

Please note this is a much simplified example, I need to test each cell with an if statement, detecting nans.

答:
Edit:

If you really need to check each cell for NaN, you may do it on my_df.isna() such as

```<code>for row_index, row_data in my_df.isna().iterrows():
   for cell in row_data:
      if cell:
          print("found one")
</code>```

Try this to see the output of your for loops. I took out the if line to show all values of cell from for loop:

```<code>for row_index, row_data in my_df.iterrows():
    for cell in row_data:
        print(cell)

Output:

1234
nan
['5', '6', '7']
{8, 9, 10}
my_hat
nan
</code>```

Now try:

```<code>pd.isnull(['5', '6', '7'])

Out[3183]: array([False, False, False])
</code>```

pd.isnull accepts scalar or array-like and returns bool or array-like of bool. One of your cell is array so it returns an array of bool values. Compare truthful of an array of bool values is ambiguous, so pandas just throws error.

If you want to check 'NaN' in df, call isna or isnull directly on df

```<code>my_df.isna()
</code>```

Or you need to call pd.isnull on the whole df

```<code>pd.isnull(my_df)

Out[3181]:
       A      B      C
0  False   True  False
1  False  False   True
</code>```

Body:
Consider the following dataframe.

import pandas as pd
my_df = pd.DataFrame(columns =['A','B','C'])
my_df.at[0,'A'] = 1234
my_df.at[0,'C'] = ['5','6','7']
my_df.at[1,'A'] = set([8,9,10])
my_df.at[1,'B'] = 'my_hat'

Then I want to find all the cells that are nan.

for row_index, row_data in my_df.iterrows():
   for cell in row_data:
      if pd.isnull(cell):
          print("found one")

The pd.isnull, pd.isna, pd.notnull all cannot handle the mix of lists/sets with ints/str.

Please note this is a much simplified example, I need to test each cell with an if statement, detecting nans.

Body:
Edit:

If you really need to check each cell for NaN, you may do it on my_df.isna() such as

for row_index, row_data in my_df.isna().iterrows():
   for cell in row_data:
      if cell:
          print("found one")

Try this to see the output of your for loops. I took out the if line to show all values of cell from for loop:

for row_index, row_data in my_df.iterrows():
    for cell in row_data:
        print(cell)

Output:

1234
nan
['5', '6', '7']
{8, 9, 10}
my_hat
nan

Now try:

pd.isnull(['5', '6', '7'])

Out[3183]: array([False, False, False])

pd.isnull accepts scalar or array-like and returns bool or array-like of bool. One of your cell is array so it returns an array of bool values. Compare truthful of an array of bool values is ambiguous, so pandas just throws error.

If you want to check 'NaN' in df, call isna or isnull directly on df

my_df.isna()

Or you need to call pd.isnull on the whole df

pd.isnull(my_df)

Out[3181]:
       A      B      C
0  False   True  False
1  False  False   True


问:
Laravel PDF-to-image: ImagickException: not authorized
if i upload a image in my tool and click on next step then following error occurs:

```<code>ImagickException: not authorized `/tmp/comcard_NEgyzR.pdf' @ error/constitute.c/ReadImage/412
/vendor/spatie/pdf-to-image/src/Pdf.php in line 169
</code>```

Any idea. This happend from one moment to another.

答:
I have face this issue solution change file path correctly  change base path to FCPATH of the file where is the saving

[PHP ImagickException: not authorized][1]

Complete Solution link  [1]: PHP ImagickException: not authorized

Body:
if i upload a image in my tool and click on next step then following error occurs:

ImagickException: not authorized `/tmp/comcard_NEgyzR.pdf' @ error/constitute.c/ReadImage/412
/vendor/spatie/pdf-to-image/src/Pdf.php in line 169

Any idea. This happend from one moment to another.


问:
HDFStore get column names
I have some problems with pandas' HDFStore being far to slow and unfortunately I'm unable to put together a satisfying solution from other questions here.

Situation

I have a big DataFrame, containing mostly floats and sometimes integer columns which goes through multiple processing steps (renaming, removing bad entries, aggregating by 30min). Each row has a timestamp associated to it. I would like to save some middle steps to a HDF file, so that the user can do a single step iteratively without starting from scratch each time.

Additionally the user should be able to plot certain column from these saves in order to select bad data. Therefore I would like to retrieve only the column names without reading the data in the HDFStore.
Concretely the user should get a list of all columns of all dataframes stored in the HDF then they should select which columns they would like to see whereafter I use matplotlib to present them the corresponding data.

Data

shape == (5730000, 339) does not seem large at all, that's why I'm confused... (Might get far more rows over time, columns should stay fixed)
In the first step I append iteratively rows and columns (that runs okay), but once that's done I always process the entire DataFrame at once, only grouping or removing data.

My approach

I do all manipulations in memory since pandas seems to be rather fast and I/O is slower (HDF is on different physical server, I think)

I use datetime index and automatically selected float or integer columns

I save the steps with hdf.put('/name', df, format='fixed') since hdf.put('/name'.format(grp), df, format='table', data_columns=True) seemed to be far too slow.

I use e.g. df.groupby(df.index).first() and df.groupby(pd.Grouper(freq='30Min')).agg(agg_dict) to process the data, where agg_dict is a dictonary with one function per column. This is incredibly slow as well.

For plotting, I have to read-in the entire dataframe and then get the columns: hdfstore.get('/name').columns

Question

How can I retrieve all columns without reading any data from the HDFStore?

What would be the most efficient way of storing my data? Is HDF the right option? Table or fixed?

Does it matter in term of efficiency if the index is a datetime index? Does there exists a more efficient format in general (e.g. all columns the same, fixed dtype?)

Is there a faster way to aggregate instead of groupby (df.groupby(pd.Grouper(freq='30Min')).agg(agg_dict))

similar questions

How to access single columns using .select
I see that I can use this to retrieve only certain columns but only after I know the column names, I think.

Thank you for any advice!

答:
You may simply load 0 rows of the DataFrame by specifying same start and stop attributes. And leave all internal index/column processing for pandas itself:

idx = pd.MultiIndex.from_product([('A', 'B'), range(2)], names=('Alpha', 'Int'))
df = pd.DataFrame(np.random.randn(len(idx), 3), index=idx, columns=('I', 'II', 'III'))
df

>>>                 I           II          III
>>> Alpha   Int
>>>     A     0     -0.472412    0.436486    0.354592
>>>           1     -0.095776   -0.598585   -0.847514
>>>     B     0      0.107897    1.236039   -0.196927
>>>           1     -0.154014    0.821511    0.092220
```

<p>Following works both for <code>fixed</code> an <code>table</code> formats:</p>

<pre class="lang-py prettyprint-override"><code>with pd.HDFStore('test.h5') as store:
    store.put('df', df, format='f')
    meta = store.select('df', start=1, stop=1)
    meta
    meta.index
    meta.columns

>>>               I     II    III
>>> Alpha   Int
>>>
>>> MultiIndex(levels=[[], []],
>>>            codes=[[], []],
>>>            names=['Alpha', 'Int'])
>>>
>>> Index(['I', 'II', 'III'], dtype='object')
</code>```

As for others question:

As long as your data is mostly homogeneous (almost float columns as you mentioned) and you are able to store it in single file without need to distribute data across machines - HDF is the first thing to try.

If you need to append/delete/query data - you must use table format. If you only need to write once and read many - fixed will improve performance.

As for datetime index, i think here we may use same idea as in 1 clause. If u are able to convert all data into single type it should increase your performance.

Nothing else that proposed in comment to your question comes to mind.

ContentLicense: CC BY-SA 3.0

Title: HDFStore get column names

Body:
You may simply load 0 rows of the DataFrame by specifying same start and stop attributes. And leave all internal index/column processing for pandas itself:

idx = pd.MultiIndex.from_product([('A', 'B'), range(2)], names=('Alpha', 'Int'))
df = pd.DataFrame(np.random.randn(len(idx), 3), index=idx, columns=('I', 'II', 'III'))
df

>>>                 I           II          III
>>> Alpha   Int
>>>     A     0     -0.472412    0.436486    0.354592
>>>           1     -0.095776   -0.598585   -0.847514
>>>     B     0      0.107897    1.236039   -0.196927
>>>           1     -0.154014    0.821511    0.092220

Following works both for fixed an table formats:

with pd.HDFStore('test.h5') as store:
    store.put('df', df, format='f')
    meta = store.select('df', start=1, stop=1)
    meta
    meta.index
    meta.columns

>>>               I     II    III
>>> Alpha   Int
>>>
>>> MultiIndex(levels=[[], []],
>>>            codes=[[], []],
>>>            names=['Alpha', 'Int'])
>>>
>>> Index(['I', 'II', 'III'], dtype='object')

As for others question:

As long as your data is mostly homogeneous (almost float columns as you mentioned) and you are able to store it in single file without need to distribute data across machines - HDF is the first thing to try.

If you need to append/delete/query data - you must use table format. If you only need to write once and read many - fixed will improve performance.

As for datetime index, i think here we may use same idea as in 1 clause. If u are able to convert all data into single type it should increase your performance.

Nothing else that proposed in comment to your question comes to mind.


问:
Tabulate XML file adding the relation of parent nodes number in Python
I have the following code trying to parse a XML file and convert to table form.

```<code>import xml.etree.ElementTree as ET
tree = ET.parse('smp.xml')
root = tree.getroot()

for text in root.iter('text'):
    print(text.attrib)

for text in root.iter('text'):
    print(text.text)
</code>```

Below is the output I'm getting so far but is far from my desired output, since I´m new to python and
I don't know how to organize these output to show tabulated them and additionally add the columns to the left for page, row and column parent elements
corresponding to each text/attribute.:

```<code>>>> import xml.etree.ElementTree as ET
>>> tree = ET.parse('smp.xml')
>>> root = tree.getroot()
>>>
>>> for text in root.iter('text'):
...     print(text.attrib)
...
{'width': '71.04', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '83.42', 'x': '121.10', 'height': '12.00'}
{'width': '101.07', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '124.82', 'x': '121.10', 'height': '12.00'}
{'width': '140.31', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '207.65', 'x': '121.10', 'height': '12.00'}
{'width': '24.36', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '69.62', 'x': '85.10', 'height': '12.00'}
{'width': '95.42', 'fontName': 'Arial', 'fontStyle': 'Bold', 'fontSize': '12.0', 'y': '239.45', 'x': '276.29', 'height': '12.00'}
{'width': '229.57', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '266.81', 'x': '121.10', 'height': '12.00'}
{'width': '155.71', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '266.81', 'x': '353.94', 'height': '12.00'}
{'width': '165.10', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '294.41', 'x': '85.10', 'height': '12.00'}
{'width': '14.39', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '294.41', 'x': '253.43', 'height': '12.00'}
{'width': '255.64', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '294.41', 'x': '271.04', 'height': '12.00'}
{'width': '432.97', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '501.43', 'x': '85.10', 'height': '12.00'}
{'width': '363.44', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '69.62', 'x': '85.10', 'height': '12.00'}
{'width': '382.36', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '83.42', 'x': '85.10', 'height': '12.00'}

>>> for text in root.iter('text'):
...     print(text.text)
...
achene
capsule
caryopsis
cypsela
fibrous drupe
follicle
legume
loment
nut
samara
schizocarp
silicle
utricle
</code>```

This is my expected output:

```<code>╔══════╦═══════╦═════╦════════╦════════════╦══════════╦══════════╦════════╦════════╦════════╦════════╦═══════════╗
║ page ║ index ║ row ║ column ║    text    ║ fontName ║ fontSize ║   x    ║   y    ║ width  ║ height ║ fontStyle ║
╠══════╬═══════╬═════╬════════╬════════════╬══════════╬══════════╬════════╬════════╬════════╬════════╬═══════════╣
║    0 ║     0 ║     ║        ║            ║          ║          ║        ║        ║        ║        ║           ║
║    1 ║     1 ║   0 ║      0 ║ achene     ║ Arial    ║       12 ║  121.1 ║  83.42 ║  71.04 ║     12 ║           ║
║    1 ║     1 ║   1 ║      0 ║ capsule    ║ Arial    ║       12 ║  121.1 ║ 124.82 ║ 101.07 ║     12 ║           ║
║    1 ║     1 ║   2 ║      0 ║ caryopsis  ║ Arial    ║       12 ║  121.1 ║ 207.65 ║ 140.31 ║     12 ║           ║
║    2 ║     2 ║   0 ║      0 ║ cypsela    ║ Arial    ║       12 ║   85.1 ║  69.62 ║  24.36 ║     12 ║           ║
║    3 ║     3 ║     ║        ║            ║          ║          ║        ║        ║        ║        ║           ║
║    4 ║     4 ║   0 ║      0 ║ fibrous    ║ Arial    ║       12 ║ 276.29 ║ 239.45 ║  95.42 ║     12 ║ Bold      ║
║    4 ║     4 ║   1 ║      1 ║ follicle   ║ Arial    ║       12 ║  121.1 ║ 266.81 ║ 229.57 ║     12 ║           ║
║    4 ║     4 ║   1 ║      1 ║ legume     ║ Arial    ║       12 ║ 353.94 ║ 266.81 ║ 155.71 ║     12 ║           ║
║    4 ║     4 ║   2 ║      2 ║ loment     ║ Arial    ║       12 ║   85.1 ║ 294.41 ║  165.1 ║     12 ║           ║
║    4 ║     4 ║   2 ║      2 ║ nut        ║ Arial    ║       12 ║ 253.43 ║ 294.41 ║  14.39 ║     12 ║           ║
║    4 ║     4 ║   2 ║      2 ║ samara     ║ Arial    ║       12 ║ 271.04 ║ 294.41 ║ 255.64 ║     12 ║           ║
║    4 ║     4 ║   3 ║      0 ║ schizocarp ║ Arial    ║       12 ║   85.1 ║ 501.43 ║ 432.97 ║     12 ║           ║
║    5 ║     5 ║   0 ║      0 ║ silicle    ║ Arial    ║       12 ║   85.1 ║  69.62 ║ 363.44 ║     12 ║           ║
║    5 ║     5 ║   1 ║      1 ║ utricle    ║ Arial    ║       12 ║   85.1 ║  83.42 ║ 382.36 ║     12 ║           ║
║    6 ║     6 ║     ║        ║            ║          ║          ║        ║        ║        ║        ║           ║
╚══════╩═══════╩═════╩════════╩════════════╩══════════╩══════════╩════════╩════════╩════════╩════════╩═══════════╝
</code>```

This is the xml file:

```<code><document>
    <page index="0"/>
    <page index="1">
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="83.42" width="71.04" height="12.00">achene</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="124.82" width="101.07" height="12.00">capsule</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="207.65" width="140.31" height="12.00">caryopsis</text></column></row>
    </page>
    <page index="2">
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="69.62" width="24.36" height="12.00">cypsela</text></column></row>
    </page>
    <page index="3"/>
    <page index="4">
        <row><column><text fontName="Arial" fontSize="12.0" fontStyle="Bold" x="276.29" y="239.45" width="95.42" height="12.00">fibrous drupe</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="266.81" width="229.57" height="12.00">follicle</text></column>
             <column><text fontName="Arial" fontSize="12.0" x="353.94" y="266.81" width="155.71" height="12.00">legume</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="294.41" width="165.10" height="12.00">loment – a type of indehiscent legume</text></column>
             <column><text fontName="Arial" fontSize="12.0" x="253.43" y="294.41" width="14.39" height="12.00">nut</text></column>
             <column><text fontName="Arial" fontSize="12.0" x="271.04" y="294.41" width="255.64" height="12.00">samara</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="501.43" width="432.97" height="12.00">schizocarp</text></column></row>
    </page>
    <page index="5">
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="69.62" width="363.44" height="12.00">silicle</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="83.42" width="382.36" height="12.00">utricle</text></column></row>
    </page>
    <page index="6"/>
</document>
</code>```

Thanks in advance for any help.

答:
This should get you close enough:

```<code>import pandas as pd
import xml.etree.ElementTree as ET

etree = ET.fromstring(xml_string)

df = pd.DataFrame()

for j in etree.iter('page'):
    for i in  j.iter('text'):
        dfcols = ['index','text','fontName','fontSize','x','y','width','height','fontStyle']
        df = df.append(pd.Series([j.get('index'),i.text,i.get('fontName'),i.get('fontSize'),i.get('x'),i.get('y'),i.get('width'),i.get('height'),i.get('fontStyle')],index=dfcols), ignore_index=True)

df = df[dfcols]
df.head()
</code>```

Output:

```<code> index  text          fontName fontSize x       y      width    height  fontStyle
0   1   achene         Arial    12.0    121.10  83.42   71.04   12.00   None
1   1   capsule        Arial    12.0    121.10  124.82  101.07  12.00   None
2   1   caryopsis      Arial    12.0    121.10  207.65  140.31  12.00   None
3   2   cypsela        Arial    12.0    85.10   69.62   24.36   12.00   None
4   4   fibrous drupe  Arial    12.0    276.29  239.45  95.42   12.00   Bold
</code>```

Body:
I have the following code trying to parse a XML file and convert to table form.

import xml.etree.ElementTree as ET
tree = ET.parse('smp.xml')
root = tree.getroot()

for text in root.iter('text'):
    print(text.attrib)

for text in root.iter('text'):
    print(text.text)

Below is the output I'm getting so far but is far from my desired output, since I´m new to python and
I don't know how to organize these output to show tabulated them and additionally add the columns to the left for page, row and column parent elements
corresponding to each text/attribute.:

>>> import xml.etree.ElementTree as ET
>>> tree = ET.parse('smp.xml')
>>> root = tree.getroot()
>>>
>>> for text in root.iter('text'):
...     print(text.attrib)
...
{'width': '71.04', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '83.42', 'x': '121.10', 'height': '12.00'}
{'width': '101.07', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '124.82', 'x': '121.10', 'height': '12.00'}
{'width': '140.31', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '207.65', 'x': '121.10', 'height': '12.00'}
{'width': '24.36', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '69.62', 'x': '85.10', 'height': '12.00'}
{'width': '95.42', 'fontName': 'Arial', 'fontStyle': 'Bold', 'fontSize': '12.0', 'y': '239.45', 'x': '276.29', 'height': '12.00'}
{'width': '229.57', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '266.81', 'x': '121.10', 'height': '12.00'}
{'width': '155.71', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '266.81', 'x': '353.94', 'height': '12.00'}
{'width': '165.10', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '294.41', 'x': '85.10', 'height': '12.00'}
{'width': '14.39', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '294.41', 'x': '253.43', 'height': '12.00'}
{'width': '255.64', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '294.41', 'x': '271.04', 'height': '12.00'}
{'width': '432.97', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '501.43', 'x': '85.10', 'height': '12.00'}
{'width': '363.44', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '69.62', 'x': '85.10', 'height': '12.00'}
{'width': '382.36', 'fontName': 'Arial', 'fontSize': '12.0', 'y': '83.42', 'x': '85.10', 'height': '12.00'}

>>> for text in root.iter('text'):
...     print(text.text)
...
achene
capsule
caryopsis
cypsela
fibrous drupe
follicle
legume
loment
nut
samara
schizocarp
silicle
utricle

This is my expected output:

╔══════╦═══════╦═════╦════════╦════════════╦══════════╦══════════╦════════╦════════╦════════╦════════╦═══════════╗
║ page ║ index ║ row ║ column ║    text    ║ fontName ║ fontSize ║   x    ║   y    ║ width  ║ height ║ fontStyle ║
╠══════╬═══════╬═════╬════════╬════════════╬══════════╬══════════╬════════╬════════╬════════╬════════╬═══════════╣
║    0 ║     0 ║     ║        ║            ║          ║          ║        ║        ║        ║        ║           ║
║    1 ║     1 ║   0 ║      0 ║ achene     ║ Arial    ║       12 ║  121.1 ║  83.42 ║  71.04 ║     12 ║           ║
║    1 ║     1 ║   1 ║      0 ║ capsule    ║ Arial    ║       12 ║  121.1 ║ 124.82 ║ 101.07 ║     12 ║           ║
║    1 ║     1 ║   2 ║      0 ║ caryopsis  ║ Arial    ║       12 ║  121.1 ║ 207.65 ║ 140.31 ║     12 ║           ║
║    2 ║     2 ║   0 ║      0 ║ cypsela    ║ Arial    ║       12 ║   85.1 ║  69.62 ║  24.36 ║     12 ║           ║
║    3 ║     3 ║     ║        ║            ║          ║          ║        ║        ║        ║        ║           ║
║    4 ║     4 ║   0 ║      0 ║ fibrous    ║ Arial    ║       12 ║ 276.29 ║ 239.45 ║  95.42 ║     12 ║ Bold      ║
║    4 ║     4 ║   1 ║      1 ║ follicle   ║ Arial    ║       12 ║  121.1 ║ 266.81 ║ 229.57 ║     12 ║           ║
║    4 ║     4 ║   1 ║      1 ║ legume     ║ Arial    ║       12 ║ 353.94 ║ 266.81 ║ 155.71 ║     12 ║           ║
║    4 ║     4 ║   2 ║      2 ║ loment     ║ Arial    ║       12 ║   85.1 ║ 294.41 ║  165.1 ║     12 ║           ║
║    4 ║     4 ║   2 ║      2 ║ nut        ║ Arial    ║       12 ║ 253.43 ║ 294.41 ║  14.39 ║     12 ║           ║
║    4 ║     4 ║   2 ║      2 ║ samara     ║ Arial    ║       12 ║ 271.04 ║ 294.41 ║ 255.64 ║     12 ║           ║
║    4 ║     4 ║   3 ║      0 ║ schizocarp ║ Arial    ║       12 ║   85.1 ║ 501.43 ║ 432.97 ║     12 ║           ║
║    5 ║     5 ║   0 ║      0 ║ silicle    ║ Arial    ║       12 ║   85.1 ║  69.62 ║ 363.44 ║     12 ║           ║
║    5 ║     5 ║   1 ║      1 ║ utricle    ║ Arial    ║       12 ║   85.1 ║  83.42 ║ 382.36 ║     12 ║           ║
║    6 ║     6 ║     ║        ║            ║          ║          ║        ║        ║        ║        ║           ║
╚══════╩═══════╩═════╩════════╩════════════╩══════════╩══════════╩════════╩════════╩════════╩════════╩═══════════╝

This is the xml file:

<document>
    <page index="0"/>
    <page index="1">
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="83.42" width="71.04" height="12.00">achene</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="124.82" width="101.07" height="12.00">capsule</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="207.65" width="140.31" height="12.00">caryopsis</text></column></row>
    </page>
    <page index="2">
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="69.62" width="24.36" height="12.00">cypsela</text></column></row>
    </page>
    <page index="3"/>
    <page index="4">
        <row><column><text fontName="Arial" fontSize="12.0" fontStyle="Bold" x="276.29" y="239.45" width="95.42" height="12.00">fibrous drupe</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="121.10" y="266.81" width="229.57" height="12.00">follicle</text></column>
             <column><text fontName="Arial" fontSize="12.0" x="353.94" y="266.81" width="155.71" height="12.00">legume</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="294.41" width="165.10" height="12.00">loment – a type of indehiscent legume</text></column>
             <column><text fontName="Arial" fontSize="12.0" x="253.43" y="294.41" width="14.39" height="12.00">nut</text></column>
             <column><text fontName="Arial" fontSize="12.0" x="271.04" y="294.41" width="255.64" height="12.00">samara</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="501.43" width="432.97" height="12.00">schizocarp</text></column></row>
    </page>
    <page index="5">
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="69.62" width="363.44" height="12.00">silicle</text></column></row>
        <row><column><text fontName="Arial" fontSize="12.0" x="85.10" y="83.42" width="382.36" height="12.00">utricle</text></column></row>
    </page>
    <page index="6"/>
</document>

Thanks in advance for any help.

Body:
This should get you close enough:

import pandas as pd
import xml.etree.ElementTree as ET

etree = ET.fromstring(xml_string)

df = pd.DataFrame()

for j in etree.iter('page'):
    for i in  j.iter('text'):
        dfcols = ['index','text','fontName','fontSize','x','y','width','height','fontStyle']
        df = df.append(pd.Series([j.get('index'),i.text,i.get('fontName'),i.get('fontSize'),i.get('x'),i.get('y'),i.get('width'),i.get('height'),i.get('fontStyle')],index=dfcols), ignore_index=True)

df = df[dfcols]
df.head()

Output:

 index  text          fontName fontSize x       y      width    height  fontStyle
0   1   achene         Arial    12.0    121.10  83.42   71.04   12.00   None
1   1   capsule        Arial    12.0    121.10  124.82  101.07  12.00   None
2   1   caryopsis      Arial    12.0    121.10  207.65  140.31  12.00   None
3   2   cypsela        Arial    12.0    85.10   69.62   24.36   12.00   None
4   4   fibrous drupe  Arial    12.0    276.29  239.45  95.42   12.00   Bold


问:
Change variable naming style for C++ in CLion
In CLion, the default naming style for local variables is camelCase. The C++ codebase that I'm working in has a convention of using snake_case for this. Is there any way to change the naming style for categories of symbols (local variables, instance variables, etc.)?

I would expect such a setting to appear in Settings > Editor > Code Style > C/C++ > Code Generation, but no such luck.

 Editor > Code Style > C/C++">

答:
Settings > Editor > Code Style > C/C++ > Naming Convention

This is a new feature in CLion as of release 2019.1.


问:
how to save the index and title of a segmented control in core data
I have a dozen segmented controls. I save the selected index for each one in Core Data. My entity is called Worksheet and each index is saved as an Int. That part works great.

The problem is that I want to display the selected titles in a different view. But I obviously can't just grab the index from Core Data. My new view has no idea what those numbers stand for. I know that CoreData can't save tuples, though, that would make things much easier.

I have tried creating a transformable attribute, and a custom managed object, but the first won't work for tuples, and I can't seem to wrap my head around the second. The title and the index don't seem like they should be separated.

答:
Put the titles in some sort of data model. You don't want to store the titles in Core Data. That makes localizing your app really difficult. Use your data model to convert the indexes into strings for display on the segmented controls and on other views.

This way your data model can load a set of strings for whatever languages your app supports (now or in the future) and the indexes can return the proper strings in the proper language. And the data model can be used by any number of views in your app.


问:
How to iterate through smaller chunks of data in API response
I am running into a limitation with an API I am working with. At the moment the max rows it can return is 10000. The goal is to access a month worth of data which sometimes can be up 200000 rows. This API allows filtering by start_at_row and row_limit. It also returns row_count in the response. I will need to make multiple requests in order to capture all 200000 rows. I'm stuck on figuring out how to trigger the next request after the first 10000 rows and how to pick at exactly at 10001 and run the next 10000 rows. Is there a common method used for this problem? Any advice is welcome. Let me know which pieces of information from my code I can provide that can be useful.</p>

答:
Update, I was able to figure this out on my own after a little trial and error and more research on Google.

I added start_at_row and row_limit as global variables that equal to 1 and 2 respectively.

From there I added a while loop(start_at_row <= row_limit), I then captured the row_count from the response given by the API and made it equal to role_limit.

To break the loop I made and an if statement with start_at_row > row_limit


问:
how do I compare textarea enter character
When I try to get the character from a textarea text it comes between quotes but when I evaluate him on console it appears like '↵'
how to compare those values?

variable evaluated on console

comparison with '↵' character

how it appears before evaluation

答:
You can execute a bit of a trick to compare the values. Check for the character and replace it with the character code if found.

See snippet example:

var vltest = document.getElementById("test1").innerHTML;

var newString = vltest.replace(/↵/g, '↵');

alert("Old: " + vltest +  " New: " + newString); //you can comment this out, just for demo purposes to show before/after

if (newString.indexOf('↵') > -1) { //check if found
  alert("Found it!")
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><textarea id="test1">↵</textarea></code>```

The 'downward left' arrow also has codes of  ↵ and ↵ - just a piece of trivia. Feasibly you could replace the arrow with something else (other than the afore-mentioned codes), for instance a  tag or a non-breaking space, and then check for the index of it, but this way works..

Hope this helps

Body:
You can execute a bit of a trick to compare the values. Check for the character and replace it with the character code if found.

See snippet example:

var vltest = document.getElementById("test1").innerHTML;

var newString = vltest.replace(/↵/g, '&#8629;');

alert("Old: " + vltest +  " New: " + newString); //you can comment this out, just for demo purposes to show before/after

if (newString.indexOf('&#8629;') > -1) { //check if found
  alert("Found it!")
}

<textarea id="test1">↵</textarea>

The 'downward left' arrow also has codes of  &#x21B5; and &crarr; - just a piece of trivia. Feasibly you could replace the arrow with something else (other than the afore-mentioned codes), for instance a <span> tag or a non-breaking space, and then check for the index of it, but this way works..

Hope this helps


问:
In the Haskell `System.Console.GetOpt` module, when are option explanations used?
I have a question about the System.Console.GetOpt module in the base package.

The OptDescr data type has a field for a String explanation of the command line option.

Where is there ever an opportunity to use this field? Idiomatic Haskell uses a list of options passed into getOpt. This means there is no way to access the option from the list in O(1) time. You'd have to iterate through the list to find the option you want. The returned tuple doen't include the explanations. This suggests that the explanations are never used.

All I can think of is that the explanations would appear in error messages, but I shouldn't have to use trial and error to determine this myself. The documentation only uses the word "explanation" once, and does not have an... explanation of what the explanations are used for.

```<code>data OptDescr a

    Each OptDescr describes a single option.
    The arguments to Option are:

        - list of short option characters
        - list of long option strings (without "--")
        - argument descriptor
        - explanation of option for user

    Constructors:

        Option [Char] [String] (ArgDescr a) String
</code>```

答: They are printed when you call usageInfo with the same list of options.

Body:
I have a question about the System.Console.GetOpt module in the base package.

The OptDescr data type has a field for a String explanation of the command line option.

Where is there ever an opportunity to use this field? Idiomatic Haskell uses a list of options passed into getOpt. This means there is no way to access the option from the list in O(1) time. You'd have to iterate through the list to find the option you want. The returned tuple doen't include the explanations. This suggests that the explanations are never used.

All I can think of is that the explanations would appear in error messages, but I shouldn't have to use trial and error to determine this myself. The documentation only uses the word "explanation" once, and does not have an... explanation of what the explanations are used for.

data OptDescr a

    Each OptDescr describes a single option.
    The arguments to Option are:

        - list of short option characters
        - list of long option strings (without "--")
        - argument descriptor
        - explanation of option for user

    Constructors:

        Option [Char] [String] (ArgDescr a) String


问:
Is checking the existence of file or folder blocking or non-blocking?
Is checking the existence of file or folder blocking or non-blocking?

```<code>access( fname, F_OK ) // blocking ?
</code>```

Is opening dir / file blocking or non-blocking?

```<code>opendir(dir); // blocking?
open(fd..); // blocking?
</code>```

Is list dir blocking or non-blocking?

```<code>readdir // blocking?
</code>```

By block, I mean take a long time to return.

答:
(I assume that you mean "block" in the sense that it's usually used in Unix manpages and related documentation: that is, you are asking whether these operations can involve the calling process waiting for an extended period for I/O to complete.  If this is not what you mean please edit your question to clarify.)

The short answer is that all of these system calls can potentially block.

The long answer:

checking for the existence of a file or folder: never do this, it introduces a TOCTOU race condition into your program.  In 20 years of Unix system programming I have literally never encountered a situation where the access system call was the right thing to use.  Instead just go ahead and attempt to open the file, enter the directory, whatever, and check whether that failed.

Having said that, access, stat, and lstat can block for the same reasons open can (discussed below).  fstat is not guaranteed not to block but usually it's ok to assume it won't.

open and opendir can block, even if you use O_NONBLOCK.  The most common case where this happens is when the file or directory you're trying to open is on a remote file system, so finding out whether the file exists and you're allowed to access it involves sending packets over the network.

There isn't any way around this within the POSIX API because there's no way to represent an in-progress open operation.  The networking API separates the creation of a socket (socket, which can't block) from the request to connect it to a remote peer (connect, which can), so when connect returns −1 with errno set to EINPROGRESS, you already know the socket descriptor number and you can select on it.  If open were to give you EINPROGRESS you wouldn't have a file descriptor to select on.

readdir can block for all the same reasons plain old read can block.  Again, the most common case where you'd notice is when the directory is on a remote file system.  The problem in this case is the DIR abstraction gets in the way of requesting non-blocking I/O in the normal fashion.

Body:
Is checking the existence of file or folder blocking or non-blocking?

access( fname, F_OK ) // blocking ?

Is opening dir / file blocking or non-blocking?

opendir(dir); // blocking?
open(fd..); // blocking?

Is list dir blocking or non-blocking?

readdir // blocking?

By block, I mean take a long time to return.


问:
LINQ: Select where object does not contain items from list
I'm struggling with LINQ syntax here...thought I'd toss it out here. I cant find exactly what I'm looking for anywhere else.

OK, say I've got this:

```<code>public class Bar
{
   public int BarId { get; set; }
}

public class Foo
{
   public List<Bar> BarList { get; set; }
}

List<Foo> fooBunch = GetABunchOfFoos(); //let's just assume I'm getting more than one
List<Foo> fooSelect = new List<Foo>;
List<Bar> filterBars = GetAFewBars(); //assume I'm getting like 2 or 3

fooSelect = (from f in fooBunch
             where !(from b in f.BarList select b.BarId).Contains(ITEM FROM filterBars.BarId)
             select f).ToList();
</code>```

So, long story short I want to use LINQ to filter out my list of objects based on objects from another list. I hope this makes sense. I think I'm just lost on the Contains portion...I don't know how to write that.

答:
I have not tried this, so I am not guarantueeing anything, however</p>

```<code>foreach Bar f in filterBars
{
     search(f)
}
Foo search(Bar b)
{
    fooSelect = (from f in fooBunch
                 where !(from b in f.BarList select b.BarId).Contains(b.ID)
                 select f).ToList();

    return fooSelect;
}
</code>```

Body:
I'm struggling with LINQ syntax here...thought I'd toss it out here. I cant find exactly what I'm looking for anywhere else.

OK, say I've got this:

public class Bar
{
   public int BarId { get; set; }
}

public class Foo
{
   public List<Bar> BarList { get; set; }
}

List<Foo> fooBunch = GetABunchOfFoos(); //let's just assume I'm getting more than one
List<Foo> fooSelect = new List<Foo>;
List<Bar> filterBars = GetAFewBars(); //assume I'm getting like 2 or 3

fooSelect = (from f in fooBunch
             where !(from b in f.BarList select b.BarId).Contains(ITEM FROM filterBars.BarId)
             select f).ToList();

So, long story short I want to use LINQ to filter out my list of objects based on objects from another list. I hope this makes sense. I think I'm just lost on the Contains portion...I don't know how to write that.

Body:
I have not tried this, so I am not guarantueeing anything, however

foreach Bar f in filterBars
{
     search(f)
}
Foo search(Bar b)
{
    fooSelect = (from f in fooBunch
                 where !(from b in f.BarList select b.BarId).Contains(b.ID)
                 select f).ToList();

    return fooSelect;
}


问:
How to draw a circular shape in PyBox2D
I have a code which draws a figure consisting of few polygon shapes using pyBox2D and PyGame. Ihave defined bodies and joints, it works well, it does what it is supposed to do, but problem occures when I want to change the head from polygon to circle shape, but I cannot draw it because I use for drawing vertices and circle shape has no vertices.

The problem occurs in this part of code (final drawing):

```<code>for body in world.bodies: #(ground_body, dynamic_body):  # or: world.bodies
    # The body gives us the position and angle of its shapes
    for fixture in body.fixtures:

        shape = fixture.shape

        vertices = [(body.transform * v) * PPM for v in shape.vertices]

        vertices = [(v[0], SCREEN_HEIGHT - v[1]) for v in vertices]

        pygame.draw.polygon(screen, colors[body.type], vertices)
</code>```

As I said above, the problem is that box2D. b2circleShape does not have vertices. How can i draw a circle or ad vertices to that shape?
Thank you very much

EDIT: The "duplicate" does not answer my question, could you please show me how to define circular body I tried this

```<code>import Box2D  # The main library
# Box2D.b2 maps Box2D.b2Vec2 to vec2 (and so on)
from Box2D.b2 import (world, polygonShape, staticBody, dynamicBody, circleShape)
from Box2D import (b2FixtureDef, b2PolygonShape, b2CircleShape)

chest_body = world.CreateDynamicBody(
        position=(10, 6.5),
        fixtures=b2FixtureDef(
                shape=b2PolygonShape(box=(0.5, 1.5)), density=120),
        angle=0) # This is a rectangular body which is defined correctly

circle = world.CreateDynamicBody(
    position=(10, 6.5),
    fixtures=b2FixtureDef(
            shape=b2CircleShape(0.5),
    angle=0)) # I tried this after checking your manual, this does not work
</code>```

The problem may be caused (and probably is caused) by the fact that i do not know how to run IntelliSense for pyBox2D or whether there is intellisense at all. That means that I do not know which parameters are needed
Any help appreciated

答:
There is a manual for python too. Check this

circle = b2CircleShape(pos=(1, 2), radius=0.5)
```

Title: How to draw a circular shape in PyBox2D

Body:
I have a code which draws a figure consisting of few polygon shapes using pyBox2D and PyGame. Ihave defined bodies and joints, it works well, it does what it is supposed to do, but problem occures when I want to change the head from polygon to circle shape, but I cannot draw it because I use for drawing vertices and circle shape has no vertices.

The problem occurs in this part of code (final drawing):

for body in world.bodies: #(ground_body, dynamic_body):  # or: world.bodies
    # The body gives us the position and angle of its shapes
    for fixture in body.fixtures:

        shape = fixture.shape

        vertices = [(body.transform * v) * PPM for v in shape.vertices]

        vertices = [(v[0], SCREEN_HEIGHT - v[1]) for v in vertices]

        pygame.draw.polygon(screen, colors[body.type], vertices)

As I said above, the problem is that box2D. b2circleShape does not have vertices. How can i draw a circle or ad vertices to that shape?
Thank you very much

EDIT: The "duplicate" does not answer my question, could you please show me how to define circular body I tried this

import Box2D  # The main library
# Box2D.b2 maps Box2D.b2Vec2 to vec2 (and so on)
from Box2D.b2 import (world, polygonShape, staticBody, dynamicBody, circleShape)
from Box2D import (b2FixtureDef, b2PolygonShape, b2CircleShape)

chest_body = world.CreateDynamicBody(
        position=(10, 6.5),
        fixtures=b2FixtureDef(
                shape=b2PolygonShape(box=(0.5, 1.5)), density=120),
        angle=0) # This is a rectangular body which is defined correctly

circle = world.CreateDynamicBody(
    position=(10, 6.5),
    fixtures=b2FixtureDef(
            shape=b2CircleShape(0.5),
    angle=0)) # I tried this after checking your manual, this does not work

The problem may be caused (and probably is caused) by the fact that i do not know how to run IntelliSense for pyBox2D or whether there is intellisense at all. That means that I do not know which parameters are needed
Any help appreciated


问:
iOS 9.0, Xamarin Studio, "waiting for debugger to connect..."
I have been using Xamarin.iOS platform with iPad with iOS 8.3 simulator successfully until I have updated Xcode 7 with iOS 9.0. When I select the simulator and run it, it keeps showing

waiting for debugger to connect...

nothing comes out at the end. Any solution?

By the way, why I cannot able to see ios 8 simulator options in the Xamarin after I updated the Xcode?

答:
Make sure that you have added a provisioning profile to you project.

Info.plist -> Signing -> Automatic Provisioning -> Select yours

I had the same problem and it was solved with this.


问:
Attempting to create JSONObject from String with Java (Android Studio)
I have run into an issue where I try to parse a serialised json string to a JSONObject to later retrieve key values for another object, PetFedInfo.  I make the called from my android app to an ASP.NET web API and the string returns successfully.

Here is the code where I parse the result from the asp.net api server:

```<code>    JSONObject jsonObj = new JSONObject();
    try {

        String stringFromServer =  PostHTTP(Constants.POST_PET_GETFEDINFO,jObj);
        Log.v("stringFromServer",stringFromServer);
        Log.v("directCallResult",PostHTTP(Constants.POST_PET_GETFEDINFO,jObj));
        Log.v("actualString","{\"petName\":\"nn\",\"lastFedTime\":\"\"}");

        jsonObj = new JSONObject("{\"petName\":\"nn\",\"lastFedTime\":\"\"}");
        Log.v("jsonObjFromManualString",jsonObj.toString());
        jsonObj = new JSONObject(PostHTTP(Constants.POST_PET_GETFEDINFO,jObj));
        Log.v("jsonObjFromDirectCall",jsonObj.toString());

    } catch (JSONException e) {
        e.printStackTrace();
    }
</code>```

After I run the app in debug mode, the string from the instance 'stringFromServer' (Logged as 'stringFromServer') throws an error when I attempt to create a JSONObject:

```<code>org.json.JSONException: Value {"petName":"mm","lastFedTime":""} of type java.lang.String cannot be converted to JSONObject
        at org.json.JSON.typeMismatch(JSON.java:112)
W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:168)
        at org.json.JSONObject.<init>(JSONObject.java:181)
        at com.FeedMyPet.helper.WebRequestManager$2.run(WebRequestManager.java:102)
</code>```

Whereas the string where I manually enter (logged as 'actualString') successfully creates the JSON object.  I have printed out all string values to the console using Log.v and they almost have the same output

```<code>V/stringFromServer: "{\"petName\":\"v\",\"lastFedTime\":\"\"}"
V/directCallResult: "{\"petName\":\"v\",\"lastFedTime\":\"\"}"
V/actualString: {"petName":"nn","lastFedTime":""}
</code>```

I have reviewed the construction for JSONObject and it accepts a String:

```<code>    public JSONObject(String json) throws JSONException {
        this(new JSONTokener(json));
    }
</code>```

I'm a little lost as to why the serialised object using quotation marks (no object?) successfully creates the object, and a String instance cannot.  How can I get the String object to match the result of 'actualString'?

Can someone please point me in the right direction?

答:
Try to clean the string received from the server. There might be some hidden characters added to it.

Have a you look at this link https://stackoverflow.com/a/15469907/578855

You can also try to replace the double quotes with this

json=json.replace("\\\"","'");

Body:
I have run into an issue where I try to parse a serialised json string to a JSONObject to later retrieve key values for another object, PetFedInfo.  I make the called from my android app to an ASP.NET web API and the string returns successfully.

Here is the code where I parse the result from the asp.net api server:

    JSONObject jsonObj = new JSONObject();
    try {

        String stringFromServer =  PostHTTP(Constants.POST_PET_GETFEDINFO,jObj);
        Log.v("stringFromServer",stringFromServer);
        Log.v("directCallResult",PostHTTP(Constants.POST_PET_GETFEDINFO,jObj));
        Log.v("actualString","{\"petName\":\"nn\",\"lastFedTime\":\"\"}");

        jsonObj = new JSONObject("{\"petName\":\"nn\",\"lastFedTime\":\"\"}");
        Log.v("jsonObjFromManualString",jsonObj.toString());
        jsonObj = new JSONObject(PostHTTP(Constants.POST_PET_GETFEDINFO,jObj));
        Log.v("jsonObjFromDirectCall",jsonObj.toString());

    } catch (JSONException e) {
        e.printStackTrace();
    }

After I run the app in debug mode, the string from the instance 'stringFromServer' (Logged as 'stringFromServer') throws an error when I attempt to create a JSONObject:

org.json.JSONException: Value {"petName":"mm","lastFedTime":""} of type java.lang.String cannot be converted to JSONObject
        at org.json.JSON.typeMismatch(JSON.java:112)
W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:168)
        at org.json.JSONObject.<init>(JSONObject.java:181)
        at com.FeedMyPet.helper.WebRequestManager$2.run(WebRequestManager.java:102)

Whereas the string where I manually enter (logged as 'actualString') successfully creates the JSON object.  I have printed out all string values to the console using Log.v and they almost have the same output

V/stringFromServer: "{\"petName\":\"v\",\"lastFedTime\":\"\"}"
V/directCallResult: "{\"petName\":\"v\",\"lastFedTime\":\"\"}"
V/actualString: {"petName":"nn","lastFedTime":""}

I have reviewed the construction for JSONObject and it accepts a String:

    public JSONObject(String json) throws JSONException {
        this(new JSONTokener(json));
    }

I'm a little lost as to why the serialised object using quotation marks (no object?) successfully creates the object, and a String instance cannot.  How can I get the String object to match the result of 'actualString'?

Can someone please point me in the right direction?


问:
How to create a switching function in Python?
I'm having difficulty creating a program that switches between string "X" and "O" every time the function is ran.

So for example, the first time switcher() is ran, it prints "x," and the next time it runs, it prints "o," and third it prints "x," and so forth

I've been able to achieve this without a function and just using an if else loop, but I can't do it using a function

```<code>def switch(value):
    if value == 0:
        x = value
        x + 1
        print("value: " + str(x) + " | turn: x")
        return x
    else:
        print("o")
        return 0

x = 0
for i in range(4):
    switch(x)
</code>```

it outputs:

```<code>value: 0 | turn: x
value: 0 | turn: x
value: 0 | turn: x
value: 0 | turn: x
</code>```

In order to achieve this, I make it so that when x = 0, it prints "X" and when it's 1 it prints "O," and then resets back to 0. It stays as 0 and only gives me x.

答:
You can define an Boolean attribute for the function, toggle it each time the function is called:</p>

```<code>def switch(value):
    if switch.state:
        print ('x')
    else:
        print('o')
    switch.state = not switch.state

switch.state = False
for x in range(4):
    switch(x)
</code>```

Body:
I'm having difficulty creating a program that switches between string "X" and "O" every time the function is ran.

So for example, the first time switcher() is ran, it prints "x," and the next time it runs, it prints "o," and third it prints "x," and so forth

I've been able to achieve this without a function and just using an if else loop, but I can't do it using a function

def switch(value):
    if value == 0:
        x = value
        x + 1
        print("value: " + str(x) + " | turn: x")
        return x
    else:
        print("o")
        return 0

x = 0
for i in range(4):
    switch(x)

it outputs:

value: 0 | turn: x
value: 0 | turn: x
value: 0 | turn: x
value: 0 | turn: x

In order to achieve this, I make it so that when x = 0, it prints "X" and when it's 1 it prints "O," and then resets back to 0. It stays as 0 and only gives me x.

Body:
You can define an Boolean attribute for the function, toggle it each time the function is called:

def switch(value):
    if switch.state:
        print ('x')
    else:
        print('o')
    switch.state = not switch.state

switch.state = False
for x in range(4):
    switch(x)


问:
BAT Multiple For-loops to further filter results
I'm setting up a bat script that lists all postgres installations by port used (5432, 5433, etc) and lets the user choose installation. I netstat into a txt and then read it with a for loop to filter results

So far so good, but the problem is I cannot narrow the results to my liking. I would want the list generated to be like this:

```<code>5432
5433
5434
etc
</code>```

This is what im using:

```<code>netstat -bnf -p tcp | findstr "127.0.0.1 post" > C:\anbo.txt 2>&1

for /f "usebackq tokens=2 delims=[:]" %%p in ("C:\anbo.txt") do (echo %%p )
</code>```

This is the raw output of the "netstat":

```<code>  TCP    127.0.0.1:5432         127.0.0.1:51725        ESTABLISHED
 [postgres.exe]
  TCP    127.0.0.1:5432         127.0.0.1:56261        ESTABLISHED
 [postgres.exe]
  TCP    127.0.0.1:5939         127.0.0.1:49833        ESTABLISHED
  TCP    127.0.0.1:49680        127.0.0.1:54677        ESTABLISHED
  TCP    127.0.0.1:49680        127.0.0.1:57445        ESTABLISHED
</code>```

This is the netstat filtered by the for loop:

```<code>5432         127.0.0.1
postgres.exe
5432         127.0.0.1
postgres.exe
5939         127.0.0.1
49680        127.0.0.1
49680        127.0.0.1
</code>```

I'm stumped on how to further filter the results. I am generating the netstat with "-b" because i want to know which ports are being used by what .exe.

Is it possible to loop for loops? A for within a for, so i could further narrow down results?
If i could for example run this for:

```<code>for /f "usebackq tokens=1 delims=. " %%s in ("F:\lop.txt") do (echo %%s)
</code>```

Being that lop.txt has the output of the previous for, i would end up with:

```<code>5432
postgres
5432
postgres
5939
49680
49680
</code>```

Which would be much closer to what i want. I would just need to "somehow" filter out the results which have no "postgres" on the line below them and find a way to ignore repeated values, like not listing two 5432s. Any idea how can I accomplish this?

答:
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "filename1=%sourcedir%\q56399294.txt"

:: remove variables starting #
FOR  /F "delims==" %%a In ('set # 2^>Nul') DO SET "%%a="

FOR /f "usebackq tokens=1,3 delims=[:] " %%p IN ("%filename1%") DO (
 IF "%%p"=="postgres.exe" (CALL :record) ELSE (SET "candidate=%%q")
)

FOR  /F "delims=#=" %%a In ('set # 2^>Nul') DO ECHO %%a

GOTO :EOF

:record
SET "#%candidate%=Y"
GOTO :eof
```

I used a file named q56399294.txt containing your netstat data for my testing.

First, clear any variables starting # Then analyse the netstat output (I've assumed every line starts with a space, as posted) and choose the first and third token (note DELIMS has been changed to include space). The port should be assigned to %%q and thence to candidate unless the first token is postgres.exe, when the port from the previous line is recorded as #port. Finally, report any #ports that are set.

Body:
I'm setting up a bat script that lists all postgres installations by port used (5432, 5433, etc) and lets the user choose installation. I netstat into a txt and then read it with a for loop to filter results

So far so good, but the problem is I cannot narrow the results to my liking. I would want the list generated to be like this:

5432
5433
5434
etc

This is what im using:

netstat -bnf -p tcp | findstr "127.0.0.1 post" > C:\anbo.txt 2>&1

for /f "usebackq tokens=2 delims=[:]" %%p in ("C:\anbo.txt") do (echo %%p )

This is the raw output of the "netstat":

  TCP    127.0.0.1:5432         127.0.0.1:51725        ESTABLISHED
 [postgres.exe]
  TCP    127.0.0.1:5432         127.0.0.1:56261        ESTABLISHED
 [postgres.exe]
  TCP    127.0.0.1:5939         127.0.0.1:49833        ESTABLISHED
  TCP    127.0.0.1:49680        127.0.0.1:54677        ESTABLISHED
  TCP    127.0.0.1:49680        127.0.0.1:57445        ESTABLISHED

This is the netstat filtered by the for loop:

5432         127.0.0.1
postgres.exe
5432         127.0.0.1
postgres.exe
5939         127.0.0.1
49680        127.0.0.1
49680        127.0.0.1

I'm stumped on how to further filter the results. I am generating the netstat with "-b" because i want to know which ports are being used by what .exe.

Is it possible to loop for loops? A for within a for, so i could further narrow down results?
If i could for example run this for:

for /f "usebackq tokens=1 delims=. " %%s in ("F:\lop.txt") do (echo %%s)

Being that lop.txt has the output of the previous for, i would end up with:

5432
postgres
5432
postgres
5939
49680
49680

Which would be much closer to what i want. I would just need to "somehow" filter out the results which have no "postgres" on the line below them and find a way to ignore repeated values, like not listing two 5432s. Any idea how can I accomplish this?

Body:
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "filename1=%sourcedir%\q56399294.txt"

:: remove variables starting #
FOR  /F "delims==" %%a In ('set # 2^>Nul') DO SET "%%a="

FOR /f "usebackq tokens=1,3 delims=[:] " %%p IN ("%filename1%") DO (
 IF "%%p"=="postgres.exe" (CALL :record) ELSE (SET "candidate=%%q")
)

FOR  /F "delims=#=" %%a In ('set # 2^>Nul') DO ECHO %%a

GOTO :EOF

:record
SET "#%candidate%=Y"
GOTO :eof

I used a file named q56399294.txt containing your netstat data for my testing.

First, clear any variables starting # Then analyse the netstat output (I've assumed every line starts with a space, as posted) and choose the first and third token (note DELIMS has been changed to include space). The port should be assigned to %%q and thence to candidate unless the first token is postgres.exe, when the port from the previous line is recorded as #port. Finally, report any #ports that are set.


问:
Calculating different tariff-periods for a call in SQL Server
For a call-rating system, I'm trying to split a telephone call duration into sub-durations for different tariff-periods. The calls are stored in a SQL Server database and have a starttime and total duration. Rates are different for night (0000 - 0800), peak (0800 - 1900) and offpeak (1900-235959) periods.

For example:
A call starts at 18:50:00 and has a duration of 1000 seconds. This would make the call end at 19:06:40, making it 10 minutes / 600 seconds in the peak-tariff and 400 seconds in the off-peak tariff.

Obviously, a call can wrap over an unlimited number of periods (we do not enforce a maximum call duration). A call lasting > 24 h can wrap all 3 periods, starting in peak, going through off-peak, night and back into peak tariff.

Currently, we are calculating the different tariff-periods using recursion in VB. We calculate how much of the call goes in the same tariff-period the call starts in, change the starttime and duration of the call accordingly and repeat this process till the full duration of the call has been reach (peakDuration + offpeakDuration + nightDuration == callDuration).

Regarding this issue, I have 2 questions:

Is it possible to do this effectively in a SQL Server statement? (I can think of subqueries or lots of coding in stored procedures, but that would not generate any performance improvement)

Will SQL Server be able to do such calculations in a way more resource-effective than the current VB scripts are doing it?

答:
```<code>kar_vasile(id,vid,datein,timein,timeout,bikari,tozihat)
{
--- the bikari field is unemployment time  you can delete any where
select
            id,
            vid,
            datein,
            timein,
            timeout,
            bikari,
            hourwork =
            case when
            timein <= timeout
            then
                SUM
            (abs(DATEDIFF(mi, timein, timeout)) - bikari)/60 --
            calculate Hour
        else
            SUM(abs(DATEDIFF(mi, timein, '23:59:00:00') + DATEDIFF(mi, '00:00:00', timeout) + 1) - bikari)/60 --
            calculate
            minute
                end
                ,
                minwork =
            case when
            timein <= timeout
            then
                SUM
            (abs(DATEDIFF(MI, timein, timeout)) - bikari)%60  --
            calclate Hour
            starttime is later
            than endtime
        else
            SUM(abs(DATEDIFF(mi, timein, '23:59:00:00') + DATEDIFF(mi, '00:00:00', timeout) + 1) - bikari)%60--
            calculate minute
            starttime is later
            than
            endtime
                end, tozihat

            from kar_vasile
            group
            by id, vid, datein, timein, timeout, tozihat, bikari
}
</code>```

OwnerDisplayName: Jasper F

LastEditorDisplayName: Jonathan Leffler

ContentLicense: CC BY-SA 2.5


问:
How to install python package from git repo that has git-lfs content with pip?
I have migrated large files in my git repository to git-lfs. The repository contains the source code of a custom python library. I was able to install it with pip:

```<code>pip install git+https://gitserver.com/myrepo.git@branch
</code>```

Currently (after migration), large files that are stored at lfs, obviously, are out of the installation (there are only links). I have installed git-lfs package from PyPI in the environment but it does not help.

Is there any way to tell pip to fetch git-lfs files while cloning the repo?

答:
If you have your per-user or system configuration settings properly set, then Git will automatically invoke Git LFS when cloning a repository that uses Git LFS.

The easiest way to do this is to run git lfs install --skip-repo, which will modify your .gitconfig to contain the proper entries. You can verify that your configuration is correct by running git lfs env and making sure that the last three git config options printed are non-empty.

Once that's set up, any time you clone a new repository using Git LFS, the LFS files will be automatically fetched and filled in. If you have an existing repository, you can use git lfs checkout to check out the files manually.

Body:
I have migrated large files in my git repository to git-lfs. The repository contains the source code of a custom python library. I was able to install it with pip:

pip install git+https://gitserver.com/myrepo.git@branch

Currently (after migration), large files that are stored at lfs, obviously, are out of the installation (there are only links). I have installed git-lfs package from PyPI in the environment but it does not help.

Is there any way to tell pip to fetch git-lfs files while cloning the repo?


问:
404 error when query string contains com1 for WebApi hosted on IIS 10
I have a simple WebApi solution hosted on IIS10.

I have a ProductController class that inherits ApiController. This class has a method GetProduct

```<code> [HttpGet]
    [Route("api/product/{productName}")]
    public object GetProduct(string productName)
    {
        return "abc";
    }
</code>```

When I try to hit the following api through postman

http://localhost:10000/api/product/com1?query=test

I get a 404 error, Tried to create a folder by the same name (com1) but got an error as well. Then found out that I cannot have the following values in my api
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.

I tried adding the following entries in IIS
under Request Filtering

Am I missing out on anything?

答: the blog suggested by Željko Huber worked for me. blog post</p>

Body:
I have a simple WebApi solution hosted on IIS10.

I have a ProductController class that inherits ApiController. This class has a method GetProduct

 [HttpGet]
    [Route("api/product/{productName}")]
    public object GetProduct(string productName)
    {
        return "abc";
    }

When I try to hit the following api through postman

http://localhost:10000/api/product/com1?query=test

I get a 404 error, Tried to create a folder by the same name (com1) but got an error as well. Then found out that I cannot have the following values in my api
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9.

I tried adding the following entries in IIS
under Request Filtering

Am I missing out on anything?


问:
Composition and Mixins with JavaScript
I am learning about compositions in Javascript. So I want to ask if this is correct way of doing things.

I made some exercises that look like this:

```<code>    class Animal {
    // constructor() {
    // }
    eat = () => {
        console.log("this creature is eating");
    }
}

const AnimalsWithWings = superclass => class extends superclass {
    constructor(Feathers, ...args) {
        super(...args);
        Object.assign(this, { Feathers });
    }
}

const CanDive = superclass => class extends superclass {
    // constructor( ...args) {
    //     super(...args);
    // }
    dive = () => {
        console.log("Can Dive");
    }
}

class Duck extends AnimalsWithWings(CanDive(Animal)) {
    constructor(eats, ...args) {
        super(...args);
        Object.assign(this, { eats });
    }
}

const duffy = new Duck("watermelon", true);
console.log(duffy);

duffy.dive();
duffy.eat()
</code>```

I am still in learning process so I just need some pointers.

答:
Did it do more or less what you expected?  Then, sure, it's a correct way to do it, whatever "correct" means here.

It looks to me like it does what it was meant to do when I pop it into the console.  I can't really say much more on your code specifically because I'm not sure what concrete domain it's trying to model, aside from maybe breaking down Ducks into atomic pieces.

If you're going to do it this way, though, I'd personally prefer to use a params object instead of just changing the constructor signature like that with AnimalsWithWings.  That way, the order of extra parametrizations doesn't depend on the order in which the mixins were applied, which I would consider a Surprise.  Surprises are bad.

```<code>const AnimalsWithWings = superclass => class extends superclass {
    // Everyone receives the same `params` object.
    // They only take what they know about, and ignore the rest.
    constructor(params) {
        super(params);
        Object.assign(this, { Feathers: params.Feathers });
    }
}
</code>```

Even more personal opiniony, I'd name them WithDiving and WithWings instead, just to keep a somewhat consistent naming scheme, and to better imply that these are modifiers, not "real" base classes.

Your code does saddle every Duck with a prototype chain 4 prototypes long, but eh, whatever.  If it somehow becomes a performance problem then you can create a utility function to optimize the mixin process or something.  Flatten the prototypes, maybe.

Your code does also let you call super.method() in methods, though it's debatable whether you should ever use that in a mixin at all.  I'd say you shouldn't, unless you want your mixins to implicitly depend on each other, which is a Surprise.

There are plenty of other ways of doing mixins, too.

You could create a utility function to flatten all the prototypes into a single new one and return a base class from that which you extend. (Just be sure to iterate property descriptors rather than just using Object.assign() when doing that flattening, if you want to properly handle things like get/set accessors, etc.)

You could eschew Classes and just directly create prototype objects and use Object.create() to create instances. (same thing about iterating property descriptors.)

You could create a Duck prototype using a bunch of iterative calls to Object.create() instead of iteratively extending base classes.

You could control the additional behaviors with helper Controller Classes instead of composing behavior directly into the base.

You could deal just in plain objects with data, and pass the objects to functions that expect the object to have certain properties on it in order to do things. (Amusingly, called "duck typing")  I'll grant that's not really mixins, just calling functions, but if it accomplishes the same thing in effect...

Probably a bunch others I can't really think about at the moment.  It's all sticking sets of behaviors onto some base thing.

Title: Composition and Mixins with JavaScript

Body:
I am learning about compositions in Javascript. So I want to ask if this is correct way of doing things.

I made some exercises that look like this:

    class Animal {
    // constructor() {
    // }
    eat = () => {
        console.log("this creature is eating");
    }
}

const AnimalsWithWings = superclass => class extends superclass {
    constructor(Feathers, ...args) {
        super(...args);
        Object.assign(this, { Feathers });
    }
}

const CanDive = superclass => class extends superclass {
    // constructor( ...args) {
    //     super(...args);
    // }
    dive = () => {
        console.log("Can Dive");
    }
}

class Duck extends AnimalsWithWings(CanDive(Animal)) {
    constructor(eats, ...args) {
        super(...args);
        Object.assign(this, { eats });
    }
}

const duffy = new Duck("watermelon", true);
console.log(duffy);

duffy.dive();
duffy.eat()

I am still in learning process so I just need some pointers.

Body:
Did it do more or less what you expected?  Then, sure, it's a correct way to do it, whatever "correct" means here.

It looks to me like it does what it was meant to do when I pop it into the console.  I can't really say much more on your code specifically because I'm not sure what concrete domain it's trying to model, aside from maybe breaking down Ducks into atomic pieces.

If you're going to do it this way, though, I'd personally prefer to use a params object instead of just changing the constructor signature like that with AnimalsWithWings.  That way, the order of extra parametrizations doesn't depend on the order in which the mixins were applied, which I would consider a Surprise.  Surprises are bad.

const AnimalsWithWings = superclass => class extends superclass {
    // Everyone receives the same `params` object.
    // They only take what they know about, and ignore the rest.
    constructor(params) {
        super(params);
        Object.assign(this, { Feathers: params.Feathers });
    }
}

Even more personal opiniony, I'd name them WithDiving and WithWings instead, just to keep a somewhat consistent naming scheme, and to better imply that these are modifiers, not "real" base classes.

Your code does saddle every Duck with a prototype chain 4 prototypes long, but eh, whatever.  If it somehow becomes a performance problem then you can create a utility function to optimize the mixin process or something.  Flatten the prototypes, maybe.

Your code does also let you call super.method() in methods, though it's debatable whether you should ever use that in a mixin at all.  I'd say you shouldn't, unless you want your mixins to implicitly depend on each other, which is a Surprise.

There are plenty of other ways of doing mixins, too.

You could create a utility function to flatten all the prototypes into a single new one and return a base class from that which you extend. (Just be sure to iterate property descriptors rather than just using Object.assign() when doing that flattening, if you want to properly handle things like get/set accessors, etc.)

You could eschew Classes and just directly create prototype objects and use Object.create() to create instances. (same thing about iterating property descriptors.)

You could create a Duck prototype using a bunch of iterative calls to Object.create() instead of iteratively extending base classes.

You could control the additional behaviors with helper Controller Classes instead of composing behavior directly into the base.

You could deal just in plain objects with data, and pass the objects to functions that expect the object to have certain properties on it in order to do things. (Amusingly, called "duck typing")  I'll grant that's not really mixins, just calling functions, but if it accomplishes the same thing in effect...

Probably a bunch others I can't really think about at the moment.  It's all sticking sets of behaviors onto some base thing.


问:
Multiple search in list
i am trying to search a list with multiple parameter but the parameters i enter are returning an empty list</p>

```<code>public ActionResult Index(string accountNo, string bookingDate, string productType)
        {
            DataModel db = new DataModel();
            var kIRDates = from m in db.KIRDates
                           where m.Verbund.ToString() == accountNo.ToString() || accountNo.ToString() == null || accountNo.ToString() == ""
                           where m.Belegdatum.ToString() == bookingDate.ToString() || bookingDate.ToString() == null || bookingDate.ToString() == ""

                           where m.Sparte == productType || productType == null || productType == ""
                           select m;
            Session["kIRDates"] = kIRDates.ToList<KIRDate>();
            return View(kIRDates);
        }
</code>```

```<code>@using (Html.BeginForm("Index", "KIRData", FormMethod.Get))
{

    @Html.TextBox("accountNo")
    @Html.TextBox("bookingDate")
    @Html.TextBox("productType")
    <input type="submit" value="Search" />

}
</code>```

答:
Its difficult to tell what you're looking for based on the amount of detail in your question, but you could try the code below.</p>

```<code>    public ActionResult Index(string accountNo, string bookingDate, string productType)
    {
        DataModel db = new DataModel();
        var kIRDates = db.KIRDates.Where(m => m.Verbund.ToString() == accountNo || m.Belegdatum.ToString() == bookingDate || m.Sparte.ToString() == productType);

        Session["kIRDates"] = kIRDates.ToList<KIRDate>();
        return View(kIRDates);
    }
</code>```

Title: Multiple search in list

Body:
i am trying to search a list with multiple parameter but the parameters i enter are returning an empty list

public ActionResult Index(string accountNo, string bookingDate, string productType)
        {
            DataModel db = new DataModel();
            var kIRDates = from m in db.KIRDates
                           where m.Verbund.ToString() == accountNo.ToString() || accountNo.ToString() == null || accountNo.ToString() == ""
                           where m.Belegdatum.ToString() == bookingDate.ToString() || bookingDate.ToString() == null || bookingDate.ToString() == ""

                           where m.Sparte == productType || productType == null || productType == ""
                           select m;
            Session["kIRDates"] = kIRDates.ToList<KIRDate>();
            return View(kIRDates);
        }

@using (Html.BeginForm("Index", "KIRData", FormMethod.Get))
{

    @Html.TextBox("accountNo")
    @Html.TextBox("bookingDate")
    @Html.TextBox("productType")
    <input type="submit" value="Search" />

}

Body:
Its difficult to tell what you're looking for based on the amount of detail in your question, but you could try the code below.

    public ActionResult Index(string accountNo, string bookingDate, string productType)
    {
        DataModel db = new DataModel();
        var kIRDates = db.KIRDates.Where(m => m.Verbund.ToString() == accountNo || m.Belegdatum.ToString() == bookingDate || m.Sparte.ToString() == productType);

        Session["kIRDates"] = kIRDates.ToList<KIRDate>();
        return View(kIRDates);
    }


问:
Write-Only access (no read, no list, no delete) to Azure Storage
I am developing an application that must have write-only access to an Azure Storage Blob container. If I just go with key-based access, the application will be capable of interacting way more than it is supposed to. All I need is Write-Only access permission to the container. In other words, the account used by the application must not expose the ability to read, list, or delete blobs; only write is allowed.

Is there any way to facilitate fine-tuned access using Role Based Access Control using either built in roles or Azure AD?

答:
How about using SAS with w permission only (sp=w).

https://learn.microsoft.com/en-us/rest/api/storageservices/Constructing-an-Account-SAS?redirectedfrom=MSDN

Read (r): Valid for all signed resources types (Service, Container, and Object). Permits read permissions to the specified resource type.

Write (w): Valid for all signed resources types (Service, Container, and Object). Permits write permissions to the specified resource type.

Delete (d): Valid for Container and Object resource types, except for queue messages.

List (l): Valid for Service and Container resource types only.

Add (a): Valid for the following Object resource types only: queue messages, table entities, and append blobs.

Create (c): Valid for the following Object resource types only: blobs and files. Users can create new blobs or files, but may not
  overwrite existing blobs or files.

Update (u): Valid for the following Object resource types only: queue messages and table entities.

Process (p): Valid for the following Object resource type only: queue messages.