问:
How do I make perfectly lined text to always fir the end of the line?
I'm trying to create a column where the text perfectly fits the end of the line but I can't seem to get it working. I've also tried searching for it and found no solutions to this problem.

I need the text to end at the end of the column just like this webpage has :

https://www.realitnitrznice.cz/blog/4

I was trying to achieve this effect by setting max width :

```<code>.article-maxwidth{
  max-width: 40vw;
}
</code>```

but it's extrememely inaccurate. I've also tried setting the w-75 for example which again showed to be very inaccurate. I've noticed that the webpage has it set with spaces somehow. If the text isn't long enough the page will fill in bigger spaces to somehow push the text to the end of the column.

Here's my current code that I'm trying to line :

```<code><div class="wrapper container-fluid shorter">
        <div class="blog-body article-maxwidth">

            <h5 class="main-title">Jak postavit dům levně aneb proč jsou typové domy tak levné</h5>
            <p class="author"><i class="fas fa-pen-fancy"></i> Realitní tržnice</p>

            <p>Velmi často, když s někým řeším cenu stavby dochází na druhé straně k zděšení, jak je možné, že domy co navrhujeme jsou tak drahé. Ano všichni jsou často nadopovaní marketingovými steroidy, které na ně firmy prodávající typové projekty nebo typové domy chrlí.</p>

            <div class="image">
                <a href="images/5.jpg" data-rel="lightcase">
                    <img src="images/5.jpg" alt="Exotická kuchyně">
                </a>
                <span class="title">Exotická kuchyně</span>
            </div>

            <h2>Dlouhá cesta do ráje</h2>
            <p>Letiště v Bangkoku je krokem z komfortní zóny pro všechny, kdo se bojí sednout do letadla. Let do vysněného ráje trvá kolem 12 hodin s minimálně jedním přestupem v některé z evropských metropolí.    O přímé lince z Prahy do Bangkoku se    zatím pouze mluví, ale zdá se, že bychom se jí mohli v dohledné dočkat. Aby byla trasa pro letecké společnosti zajímavá z finančního hlediska, je nutné, aby ji využilo alespoň 30 000 cestujících    ročně, a to naše republika s přehledem    splňuje.</p>

            <div class="image">
                <a href="images/2.jpg" data-rel="lightcase">
                    <img src="images/2.jpg" alt="Thajské pláže">
                </a>
                <span class="title">Thajské pláže</span>
            </div>

            <h2>Svobodně dýchejte</h2>
            <p>Kdysi se tahle země jmenovala Siam, což v překladu znamená „svoboda“. A svobodně se tu budete cítit i dnes. Své si tu najde milovník pulsujících velkoměst, který zaplesá nad svítícím a rušným    Bangkokem, ale i obdivovatelé panenské    přírody, národních parků s pralesy a vodopády nebo sněhobílých pláží. A až se unavíte sledováním okolních krás, pohodlně se usaďte a nechte si naservírovat cokoliv ze zdejší kuchyně. Vyhlášená je    po celém světě, ale můžeme vám    zaručit, že takové dobroty jako tady mimo území Thajska neochutnáte.</p>

            <!--<div class="image"><a href="blog/4/3.jpg" data-rel="lightcase"><img src="blog/4/6.jpg" alt="Taxi"></a></div>  <span class="title">Taxi</span> -->

            <h2>Kde složit hlavu</h2>
            <p>Zvlášť v hlavní sezóně, která trvá od listopadu do března, je radno domluvit si ubytování předem. Jestli toužíte po komfortu a hýčkání, zaměřte se na čtyřhvězdičkové rezorty. Za noc v nich    zaplatíte řádově méně než u nás a můžete se    spolehnout, že servis bude perfektní. Ubytování dokážete najít i na místě, ale obrňte se trpělivostí.</p>

            <div class="image">
                <a href="images/4.jpg" data-rel="lightcase">
                    <img src="images/4.jpg" alt="Noční ulice">
                </a>
                <span class="title">Noční ulice</span>
            </div>

            <h2>Vzpomínky na celý život</h2>
            <p>Ať zvolíte jakýkoliv typ svého pobytu v Thajsku, můžete se spolehnout, že vás ve všech ohledech nadchne. Výstražný prst bychom zvedli jen v jednom případě, a to jsou drogy. Jejich držení a    užívání je trestné a cizinci bývají snadným    terčem jak drogové mafie, tak policie.</p>

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

Does anyone happen to know how can I achieve this? Any documentation that explains this issue in depth? Thanks for any suggestions.

答:
You could add text-align: justify to make the text break at the place

.article {
  display: block;
  width: 40%;
  height: auto;
  padding: 10px;
  background-color: lightgray;
  color: black;
  text-align: justify;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="article">
  <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil molestiae voluptatum sunt nostrum eos maxime in temporibus accusamus, a vero laudantium sapiente? Officiis minima animi magnam sequi recusandae reiciendis libero!</p>
</div> </code>```

Body:
I'm trying to create a column where the text perfectly fits the end of the line but I can't seem to get it working. I've also tried searching for it and found no solutions to this problem.

I need the text to end at the end of the column just like this webpage has :

https://www.realitnitrznice.cz/blog/4

I was trying to achieve this effect by setting max width :

.article-maxwidth{
  max-width: 40vw;
}

but it's extrememely inaccurate. I've also tried setting the w-75 for example which again showed to be very inaccurate. I've noticed that the webpage has it set with spaces somehow. If the text isn't long enough the page will fill in bigger spaces to somehow push the text to the end of the column.

Here's my current code that I'm trying to line :

Jak postavit dům levně aneb proč jsou typové domy tak levné

 Realitní tržnice

Velmi často, když s někým řeším cenu stavby dochází na druhé straně k zděšení, jak je možné, že domy co navrhujeme jsou tak drahé. Ano všichni jsou často nadopovaní marketingovými steroidy, které na ně firmy prodávající typové projekty nebo typové domy chrlí.

                Exotická kuchyně

Dlouhá cesta do ráje

Letiště v Bangkoku je krokem z komfortní zóny pro všechny, kdo se bojí sednout do letadla. Let do vysněného ráje trvá kolem 12 hodin s minimálně jedním přestupem v některé z evropských metropolí.    O přímé lince z Prahy do Bangkoku se    zatím pouze mluví, ale zdá se, že bychom se jí mohli v dohledné dočkat. Aby byla trasa pro letecké společnosti zajímavá z finančního hlediska, je nutné, aby ji využilo alespoň 30 000 cestujících    ročně, a to naše republika s přehledem    splňuje.

                Thajské pláže

Svobodně dýchejte

Kdysi se tahle země jmenovala Siam, což v překladu znamená „svoboda“. A svobodně se tu budete cítit i dnes. Své si tu najde milovník pulsujících velkoměst, který zaplesá nad svítícím a rušným    Bangkokem, ale i obdivovatelé panenské    přírody, národních parků s pralesy a vodopády nebo sněhobílých pláží. A až se unavíte sledováním okolních krás, pohodlně se usaďte a nechte si naservírovat cokoliv ze zdejší kuchyně. Vyhlášená je    po celém světě, ale můžeme vám    zaručit, že takové dobroty jako tady mimo území Thajska neochutnáte.

Kde složit hlavu

Zvlášť v hlavní sezóně, která trvá od listopadu do března, je radno domluvit si ubytování předem. Jestli toužíte po komfortu a hýčkání, zaměřte se na čtyřhvězdičkové rezorty. Za noc v nich    zaplatíte řádově méně než u nás a můžete se    spolehnout, že servis bude perfektní. Ubytování dokážete najít i na místě, ale obrňte se trpělivostí.

                Noční ulice

Vzpomínky na celý život

Ať zvolíte jakýkoliv typ svého pobytu v Thajsku, můžete se spolehnout, že vás ve všech ohledech nadchne. Výstražný prst bychom zvedli jen v jednom případě, a to jsou drogy. Jejich držení a    užívání je trestné a cizinci bývají snadným    terčem jak drogové mafie, tak policie.

Does anyone happen to know how can I achieve this? Any documentation that explains this issue in depth? Thanks for any suggestions.

Body:
You could add text-align: justify to make the text break at the place

.article {
  display: block;
  width: 40%;
  height: auto;
  padding: 10px;
  background-color: lightgray;
  color: black;
  text-align: justify;
}

<div class="article">
  <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Nihil molestiae voluptatum sunt nostrum eos maxime in temporibus accusamus, a vero laudantium sapiente? Officiis minima animi magnam sequi recusandae reiciendis libero!</p>
</div>


来源: stackexchange

问:
Django Templating: how to access properties of the first item in a list
Pretty simple. I have a Python list that I am passing to a Django template.

I can specifically access the first item in this list using

```<code>{{ thelist|first }}
</code>```

However, I also want to access a property of that item... ideally you'd think it would look like this:

```<code>{{ thelist|first.propertyName }}
</code>```

But alas, it does not.

Is there any template solution to this, or am I just going to find myself passing an extra template variable...

答:
a potentially clearer answer/syntax for accessing a ManyToManyField property in an object list provided to the django template would look like this:</p>

```<code>{{ object_list.0.m2m_fieldname.all.0.item_property }}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Pretty simple. I have a Python list that I am passing to a Django template.

I can specifically access the first item in this list using

{{ thelist|first }}

However, I also want to access a property of that item... ideally you'd think it would look like this:

{{ thelist|first.propertyName }}

But alas, it does not.

Is there any template solution to this, or am I just going to find myself passing an extra template variable...

Body:
a potentially clearer answer/syntax for accessing a ManyToManyField property in an object list provided to the django template would look like this:

{{ object_list.0.m2m_fieldname.all.0.item_property }}

ContentLicense: CC BY-SA 4.0


问:
Embed editable Google Docs spreadsheet without footer sheet toolbar
I am sharing an editable Google sheet on my website (shared with any user on Google sheet side), using https://docs.google.com/spreadsheets/d/[hash]/edit?rm=minimal
Adding the rm=minimal allows to remove the Google navigation and toolbar at the top.

Is there a way to remove the bottom bar allowing to add new sheets?

答:
No.

A document may be shared as editable, or shared as not editable, or not shared at all.

There is not fine grained control over prohibiting the addition/deletion of individual sheets in the document.

That's why there's no URI argument to hide the UI elements relating to this feature — the feature is one of the things you're explicitly granting access to, by making the share editable.


问:
How to determine and show the expiry time of a specific session
I am using spring-session and wondering how to know a specific session expired.

Querying Redis persistence, I find a couple of the following lines

```<code>[ root@redis-master-6fbbc44567-cc28m:/data ]$ redis-cli
127.0.0.1:6379> keys *
1) "spring:session:expirations:1581796140000"
2) "spring:session:sessions:23d6aff1-cb43-44f6-920d-cc3536ab6d46"
127.0.0.1:6379>
</code>```

Converting the expirations to date, they are equavalent to Mon 14 Feb 52095 16:40:00 GMT which looks weird at the year.
We might extract the expired time from HttpSession:

```<code>HttpSession httpSession = request.getSession()
long currTime = System.currentTimeMillis()
long expiryTime = currTime + httpSession.getMaxInactiveInterval()
</code>```

But the snippet doesn't show exactly what weed anticipate.

I reckon we need to retrieve expirations from Redis server instead.

What am I doing wrong here?

Any of you know how to retrieve sessions and expirations from Redis?

答: The expiration timestamp 1581796140000 is a Unix epoch in milliseconds and translates to GMT: Saturday, February 15, 2020 7:49:00 PM.

Body:
I am using spring-session and wondering how to know a specific session expired.

Querying Redis persistence, I find a couple of the following lines

[ root@redis-master-6fbbc44567-cc28m:/data ]$ redis-cli
127.0.0.1:6379> keys *
1) "spring:session:expirations:1581796140000"
2) "spring:session:sessions:23d6aff1-cb43-44f6-920d-cc3536ab6d46"
127.0.0.1:6379>

Converting the expirations to date, they are equavalent to Mon 14 Feb 52095 16:40:00 GMT which looks weird at the year.
We might extract the expired time from HttpSession:

HttpSession httpSession = request.getSession()
long currTime = System.currentTimeMillis()
long expiryTime = currTime + httpSession.getMaxInactiveInterval()

But the snippet doesn't show exactly what weed anticipate.

I reckon we need to retrieve expirations from Redis server instead.

What am I doing wrong here?

Any of you know how to retrieve sessions and expirations from Redis?


问:
Javascript : How can I put this data in better way ? (string to array/object)
I have a string that could look like this :

```<code>str = "4bobsCat3carsOfThisGarage10this1that0whatever";
</code>```

My string always starts with a number from 0 to 99, I have multiple character chains made up of lower and upper case letters separated by numbers from 0 to 99. This string is basically :

number from 0 to 99

characters a to z or A to Z

This pattern repeats itself a couple times.
I want to create an object/array to class this weird kind of data in a better way ...
It would be great if I could get something like :

```<code>array = [4, "bobsCat", 3, "carsOfThisGarage", 10, "this", 1, "that", 0, "whatever"]
</code>```

Or like this :

```<code>object["bobsCat"] = {number : 4};
object["carsOfThisGarage"] = {number : 3};
object["this"] = {number : 10};
object["that"] = {number : 1};
object["whatever"] = {number : 0}
</code>```

Thanks !

答:
To get the second object structure, you could use the new method matchAll, and unary plus operator to convert the digits to number type:

let str = "4bobsCat3carsOfThisGarage10this1that0whatever";

let obj = {};
for (let [, dig, key] of str.matchAll(/(\d+)(\D+)/g)) {
    obj[key] = { number: +dig };
}

console.log(obj);```

Body:
I have a string that could look like this :

str = "4bobsCat3carsOfThisGarage10this1that0whatever";

My string always starts with a number from 0 to 99, I have multiple character chains made up of lower and upper case letters separated by numbers from 0 to 99. This string is basically :

number from 0 to 99

characters a to z or A to Z

This pattern repeats itself a couple times.
I want to create an object/array to class this weird kind of data in a better way ...
It would be great if I could get something like :

array = [4, "bobsCat", 3, "carsOfThisGarage", 10, "this", 1, "that", 0, "whatever"]

Or like this :

object["bobsCat"] = {number : 4};
object["carsOfThisGarage"] = {number : 3};
object["this"] = {number : 10};
object["that"] = {number : 1};
object["whatever"] = {number : 0}

Thanks !


问:
jQuery selector chaining
We're having an issue trying to chain selectors together. We are trying to get all checkboxes that are checked and have the data-action attribute with hideplan as the value. I've got a page that has two checkboxes, one button and this javascript on it:

```<code><script type="text/javascript">
    var hiddenplans = $('input:checkbox[data-action="hideplan":checked');
    $("#hide_btn").click(function() {
        hiddenplans.each(

        function(index) {
            alert('checked' + index);
        });
    });
</script>
</code>```

This doesn't display any alerts when one or more checkboxes are selected - hiddenplans is empty. However, if we copy $('input:checkbox[data-action="hideplan":checked'); and put it into the firebug console and run it we will get results if one or more checkboxes are selected. If I remove :checked it will alert for checkboxes with data-action=hideplan.

We've tried several different ways of writing the selector (i.e. $("input[type=checkbox][data-action=hideplan]:checked") and $("input[type=checkbox][data-action=hideplan]").filter(":checked"); and more) and they work in the console but will not return alerts.

I've created a Fiddle with the full code in case we missed something obvious http://jsfiddle.net/xCnSs/5/

答:
You're caching the selected set in a variable so it will only return which items are checked on page load.  Move this selector into your click function and it will work:

```<code>$("#hide_btn").click(function () {
    var hiddenplans = $("input[type=checkbox][data-action=hideplan]:checked");
    hiddenplans.each(function (index) {
        alert('checked' + index);
    });
});
</code>```

http://jsfiddle.net/xCnSs/6/

Title: jQuery selector chaining

Body:
We're having an issue trying to chain selectors together. We are trying to get all checkboxes that are checked and have the data-action attribute with hideplan as the value. I've got a page that has two checkboxes, one button and this javascript on it:

This doesn't display any alerts when one or more checkboxes are selected - hiddenplans is empty. However, if we copy $('input:checkbox[data-action="hideplan":checked'); and put it into the firebug console and run it we will get results if one or more checkboxes are selected. If I remove :checked it will alert for checkboxes with data-action=hideplan.

We've tried several different ways of writing the selector (i.e. $("input[type=checkbox][data-action=hideplan]:checked") and $("input[type=checkbox][data-action=hideplan]").filter(":checked"); and more) and they work in the console but will not return alerts.

I've created a Fiddle with the full code in case we missed something obvious http://jsfiddle.net/xCnSs/5/

Body:
You're caching the selected set in a variable so it will only return which items are checked on page load.  Move this selector into your click function and it will work:

$("#hide_btn").click(function () {
    var hiddenplans = $("input[type=checkbox][data-action=hideplan]:checked");
    hiddenplans.each(function (index) {
        alert('checked' + index);
    });
});

http://jsfiddle.net/xCnSs/6/


问:
How to Check If a Value Already Exists in a Text Field in Javascript
I have a set of users. Each time the delete button is click it is added up to the input text field which I already implemented. If the users is already on the deleted_user field, how can I display the remaining unselected users.

Ex. If Jan and Mike are already on deleted_user field. Next is clicking the submit users button, only Sam will appear

```<code>        <td><button onclick="deleteVal('Jan');" > Delete </button></td>
        <td><input type="text" name="users[]" value="Jan"> </td>

        <td><button onclick="deleteVal('Mike');"> Delete </button></td>
        <td> <input type="text" name="users[]" value="Mike"> </td>

        <td><button onclick="deleteVal('Sam');"> Delete </button></td>
        <td> <input type="text" name="users[]" value="Sam"> </td>

Deleted Users: <input type="text" id="deleted_user">

<button type="button" id="submit_users"> Submit Users </button>
Final Users:<input type="text" id="final_users">
</code>```

This is my code.

```<code> function deleteVal(val) {
    var delete_id = val;
    var deleted_user = document.getElementById('deleted_user').value

    if(!deleted_user.includes(delete_id)) {
       var tempVal = document.getElementById('deleted_user').value += val + ',';
    }
  }
</code>```

答:
Hope this help you.

var array_user = $("input[name='users[]']")
  .map(function() {
    return $(this).val();
  }).get();

function deleteVal(val) {

  array_user = jQuery.grep(array_user, function(value) {
    return value != val;
  });

  var delete_id = val;
  var deleted_user = document.getElementById('deleted_user').value

  if (!deleted_user.includes(delete_id)) {
    var tempVal = document.getElementById('deleted_user').value += val + ',';
  }
  jQuery('#final_users').val(array_user.toString());
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<td><button onclick="deleteVal('Jan');"> Delete </button></td>
<td><input type="text" name="users[]" value="Jan"> </td>

<td><button onclick="deleteVal('Mike');"> Delete </button></td>
<td> <input type="text" name="users[]" value="Mike"> </td>

<td><button onclick="deleteVal('Sam');"> Delete </button></td>
<td> <input type="text" name="users[]" value="Sam"> </td>

Deleted Users: <input type="text" id="deleted_user">

<button type="button" id="submit_users"> Submit Users </button> Final Users:<input type="text" id="final_users"></code>```

Body:
I have a set of users. Each time the delete button is click it is added up to the input text field which I already implemented. If the users is already on the deleted_user field, how can I display the remaining unselected users.

Ex. If Jan and Mike are already on deleted_user field. Next is clicking the submit users button, only Sam will appear

        <button onclick="deleteVal('Jan');" > Delete </button>
        <input type="text" name="users[]" value="Jan">

        <button onclick="deleteVal('Mike');"> Delete </button>
         <input type="text" name="users[]" value="Mike">

        <button onclick="deleteVal('Sam');"> Delete </button>
         <input type="text" name="users[]" value="Sam">

Deleted Users: <input type="text" id="deleted_user">

<button type="button" id="submit_users"> Submit Users </button>
Final Users:<input type="text" id="final_users">

This is my code.

 function deleteVal(val) {
    var delete_id = val;
    var deleted_user = document.getElementById('deleted_user').value

    if(!deleted_user.includes(delete_id)) {
       var tempVal = document.getElementById('deleted_user').value += val + ',';
    }
  }

Body:
Hope this help you.

var array_user = $("input[name='users[]']")
  .map(function() {
    return $(this).val();
  }).get();

function deleteVal(val) {

  array_user = jQuery.grep(array_user, function(value) {
    return value != val;
  });

  var delete_id = val;
  var deleted_user = document.getElementById('deleted_user').value

  if (!deleted_user.includes(delete_id)) {
    var tempVal = document.getElementById('deleted_user').value += val + ',';
  }
  jQuery('#final_users').val(array_user.toString());
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<td><button onclick="deleteVal('Jan');"> Delete </button></td>
<td><input type="text" name="users[]" value="Jan"> </td>

<td><button onclick="deleteVal('Mike');"> Delete </button></td>
<td> <input type="text" name="users[]" value="Mike"> </td>

<td><button onclick="deleteVal('Sam');"> Delete </button></td>
<td> <input type="text" name="users[]" value="Sam"> </td>

Deleted Users: <input type="text" id="deleted_user">

<button type="button" id="submit_users"> Submit Users </button> Final Users:<input type="text" id="final_users">


问:
Hugo .Data.Pages in partial only works on root (index.html) but not on other pages
I have a nav.html partial with this in it:

```<code>            <div class="dropdown-menu dropdown-primary" aria-labelledby="navbarDropdownMenuLink">
                {{ range $.Data.Pages }}
                {{ if ( not ( .IsPage) )}}
                <a class="dropdown-item" href={{ .Permalink }}>{{ .Name }}</a>
                {{ end }}
                {{ end }}
            </div>
</code>```

It works on the root of my site, but does not work when rendering a page or list "inside" the site.

How do I access the "root" context .Data.Pages no matter where I am in the site so my nav partial works all the time?

答:
I found it, .Data.Pages is for the current node, I wanted this:

```<code>              {{ range $.Site.Pages }}
               {{ if ( eq .Kind "section" )}}
                <a class="dropdown-item" href={{ .Permalink }}>{{ .Name }}</a>
               {{ end }}
              {{ end }}
</code>```

https://gohugo.io/variables/page/

Body:
I have a nav.html partial with this in it:

                {{ range $.Data.Pages }}
                {{ if ( not ( .IsPage) )}}
                {{ .Name }}
                {{ end }}
                {{ end }}

It works on the root of my site, but does not work when rendering a page or list "inside" the site.

How do I access the "root" context .Data.Pages no matter where I am in the site so my nav partial works all the time?

Body:
I found it, .Data.Pages is for the current node, I wanted this:

              {{ range $.Site.Pages }}
               {{ if ( eq .Kind "section" )}}
                <a class="dropdown-item" href={{ .Permalink }}>{{ .Name }}</a>
               {{ end }}
              {{ end }}

https://gohugo.io/variables/page/


问:
What does it mean to pre-increment $#array?
I've come across the following line of code.  It has issues:

it is intended to do the same as push

it ought to have used push

it's hard to read, understand

I've since changed it to use push

it does something I thought was illegal, but clearly isn't

here it is:

```<code>$array [++$#array] = 'data';
</code>```

My question is: what does it mean to pre-increment $#array?  I always considered $#array to be an attribute of an array, and not writable.

答: Assigning a value larger than the current array length to $#array extends the array.

OwnerDisplayName: Paul Beckingham

ContentLicense: CC BY-SA 2.5

Body:
I've come across the following line of code.  It has issues:

it is intended to do the same as push

it ought to have used push

it's hard to read, understand

I've since changed it to use push

it does something I thought was illegal, but clearly isn't

here it is:

$array [++$#array] = 'data';

My question is: what does it mean to pre-increment $#array?  I always considered $#array to be an attribute of an array, and not writable.

LastEditorDisplayName: brian d foy

OwnerDisplayName: Manu


问:
Error: Could not find or load main class files\kafka_2.12-2.4.0\libs\activation-1.1.1.jar;

Error: Could not find or load main class
  files\kafka_2.12-2.4.0\libs\activation-1.1.1.jar;

答:
It would appear you may have put Kafka in "Program files" directory.

On windows, the kafka path cannot contain spaces. Try c:\kafka


问:
Scale iFrame css width 100% like an image
I want to scale an iFrame through CSS to width: 100%, and the height should scale proportionally to the width.

With an  tag this works fine.

Both the image and the iFrame have defined width and height in the html.

Here some examples:

```

<p>This works great on images, but I would like the same behaviour for iFrames:</p>

<pre class="lang-html prettyprint-override"><code><html>
    <style>
        #a{ width: 900px; background: grey;}
        iframe{ width: 100%; height: auto }
    </style>
    <body>
        <div id="a">
            <iframe width="560" height="315" src="http://www.youtube.com/embed/RksyMaJiD8Y" frameborder="0" allowfullscreen></iframe>
        </div>
    </body>
</code>```

The iFrame renders 100% wide but does not scale it's height proportional like the image does.

答:
None of these solutions worked for me inside a Weebly "add your own html" box.  Not sure what they are doing with their code.  But I found this solution at https://benmarshall.me/responsive-iframes/   and it works perfectly.

CSS

```<code>.iframe-container {
  overflow: hidden;
  padding-top: 56.25%;
  position: relative;
}

.iframe-container iframe {
   border: 0;
   height: 100%;
   left: 0;
   position: absolute;
   top: 0;
   width: 100%;
}

/* 4x3 Aspect Ratio */
.iframe-container-4x3 {
  padding-top: 75%;
}
</code>```

HTML

```<code><div class="iframe-container">
  <iframe src="https://player.vimeo.com/video/106466360" allowfullscreen></iframe>
</div>
</code>```

Body:
I want to scale an iFrame through CSS to width: 100%, and the height should scale proportionally to the width.

With an  tag this works fine.

Both the image and the iFrame have defined width and height in the html.

Here some examples:

This works great on images, but I would like the same behaviour for iFrames:

The iFrame renders 100% wide but does not scale it's height proportional like the image does.

Body:
None of these solutions worked for me inside a Weebly "add your own html" box.  Not sure what they are doing with their code.  But I found this solution at https://benmarshall.me/responsive-iframes/   and it works perfectly.

CSS

.iframe-container {
  overflow: hidden;
  padding-top: 56.25%;
  position: relative;
}

.iframe-container iframe {
   border: 0;
   height: 100%;
   left: 0;
   position: absolute;
   top: 0;
   width: 100%;
}

/* 4x3 Aspect Ratio */
.iframe-container-4x3 {
  padding-top: 75%;
}

HTML

<div class="iframe-container">
  <iframe src="https://player.vimeo.com/video/106466360" allowfullscreen></iframe>
</div>


问:
Add List box to List<ListBox> to pass to foreach loop ASP.NET
Hi I'm trying to create a list of ListBox's in ASP.NET so that I can then iterate it to test if it has been selected.

```<code>    List<string> con = new List<string>();
    List<ListBox> lb = new List<ListBox>();
    foreach (Control c in _pH_Outer_MainCri.Controls)
    {
        if (c is ListBox)
        {
            con.Add(c.ID.ToString());
            lb.Add(c.??);
        }
    }
</code>```

I'm getting caught up on that last part.  Basically then I can

```<code>foreach(ListBox a in lb)
    {
        if(a.TestSelection() == true )
        {
            BuildQuery(a);
        }
    }
</code>```

Thanks in advance for the help ...

答:
You can avoid placing the controls in a list by using LINQ, like this:

```<code>var listboxen =
    from control in _pH_Outer_MainCri.Controls
    where control is ListBox
    select control as ListBox;
</code>```

You can then foreach through the list boxes without having to build an intermediate collection.

Body:
Hi I'm trying to create a list of ListBox's in ASP.NET so that I can then iterate it to test if it has been selected.

    List<string> con = new List<string>();
    List<ListBox> lb = new List<ListBox>();
    foreach (Control c in _pH_Outer_MainCri.Controls)
    {
        if (c is ListBox)
        {
            con.Add(c.ID.ToString());
            lb.Add(c.??);
        }
    }

I'm getting caught up on that last part.  Basically then I can

foreach(ListBox a in lb)
    {
        if(a.TestSelection() == true )
        {
            BuildQuery(a);
        }
    }

Thanks in advance for the help ...

Body:
You can avoid placing the controls in a list by using LINQ, like this:

var listboxen =
    from control in _pH_Outer_MainCri.Controls
    where control is ListBox
    select control as ListBox;

You can then foreach through the list boxes without having to build an intermediate collection.


Title: How can I turn list of proxies into json of proxies

Body:
I have a list of proxies:

proxies = [
  "188.166.78.120:8080",
  "18.210.69.172:3128",
  "178.128.166.50:8118"
]

But for a library I need JSON like this:

proxies = {
  "http":  "http://188.166.78.120:8080",
  "https": "http://188.166.78.120:8080",
  "http":  "http://18.210.69.172:3128",
  "https": "http://18.210.69.172:3128",
  "http":  "http://178.128.166.50:8118",
  "https": "http://178.128.166.50:8118"
}

How can I make that?
I have tried this but I only get last one

new = {}

    for i in proxies:
        proxy = {
                "http":"http/"+i,
                "https":"http/"+i
        }
        new.update(proxy)

Body:
As you have to use unique key for python dictionary. You need to use list in dict for multiple value.

Below is solution of your problem

import json

proxies = [
  "188.166.78.120:8080",
  "18.210.69.172:3128",
  "178.128.166.50:8118"
]
js = dict()

for i in proxies:
    js.setdefault('http',[])
    js.setdefault('https',[])
    js['http'].append('http://'+i)
    js['https'].append('http://'+i)

x = json.dumps(js)
y = json.loads(x)
print(js)
print(x)
print(y["http"])

python dictionary:

{'http': ['http://188.166.78.120:8080',
  'http://18.210.69.172:3128',
  'http://178.128.166.50:8118'],
 'https': ['http://188.166.78.120:8080',
  'http://18.210.69.172:3128',
  'http://178.128.166.50:8118']}

json:

{"http": ["http://188.166.78.120:8080", "http://18.210.69.172:3128", "http://178.128.166.50:8118"], "https": ["http://188.166.78.120:8080", "http://18.210.69.172:3128", "http://178.128.166.50:8118"]}

http list:

['http://188.166.78.120:8080', 'http://18.210.69.172:3128', 'http://178.128.166.50:8118']


问:
What is this problem "dereferencing pointer to incomplete type 'struct cashier' "?
I am learning data structure of queue, and making a cashier structure like this:1 There are 2 integers,1 float and 1 queue data type in it.2 So I wanted to make a cashier pointer to point to the cashier structure.`

```<code>struct cashier {
    int numberOfCustomersServed; /* This should be initialized to 0 */
    int totalCustomerWaitingTime; /* This should be initialized to 0 */
    float totalAmountReceived; /* This should be initialized to 0 */
    queueADT customerQ; /* This should be initialized to an empty queue */
}cashier;

struct cashier* initCashier(void){
    struct cashier *y;
    y->numberOfCusCustomersServed=0;
    y->totalCustomerWaitingTime=0;
    y->totalAmountReceived=0.0;
    y->customerQ=getEmptyQueue();

    return y;
};
</code>```

But then I get the error:

```<code>/cygdrive/c/Users/Heta/Desktop/CLionHWQ2/supermarket.c:8:6: error: dereferencing pointer to incomplete type 'struct cashier'
     y->numberOfCusCustomersServed=0;
</code>```

And below is basically the queue function.3
The main() is not yet finished, mostly just empty.4
Any help from this will be appreciated. :)

答:
1.

```<code>struct cashier *y;
</code>```

y is a pointer to struct cashier, but it was not set to point to a variable of type struct cashier.

Thus,

```<code>    y->numberOfCusCustomersServed=0;
    y->totalCustomerWaitingTime=0;
    y->totalAmountReceived=0.0;
    y->customerQ=getEmptyQueue();

    return y;      // discussed further at point 2.
</code>```

doesn´t work, since y has not been initialized to point to a valid variable of type struct cashier.

Rather use:

```<code>    struct cashier x;                  // x is a variable of type `struct cashier`.
    struct cashier *y = &x;            // y is a pointer to x.

    y->numberOfCusCustomersServed = 0;
    y->totalCustomerWaitingTime = 0;
    y->totalAmountReceived = 0.0;
    y->customerQ = getEmptyQueue();
</code>```

with x as a variable of type struct cashier and y as pointer to it, or alternatively:

```<code>    struct cashier x;

    x.numberOfCusCustomersServed = 0;
    x.totalCustomerWaitingTime = 0;
    x.totalAmountReceived = 0.0;
    x.customerQ = getEmptyQueue();
</code>```

since the pointer of y is redundant.

2.

```<code>return y;
</code>```

You cannot return a pointer to an inner-scope variable from a function, because the variable the pointer points to does no longer exist when the function is finished.

If you really want to return a structure, you should do it like that:

```<code>struct cashier initCashier(void){

    struct cashier x;                  // x is a variable of type `struct cashier`.
    struct cashier *y = &x;            // y is a pointer to x.

    y->numberOfCusCustomersServed = 0;
    y->totalCustomerWaitingTime = 0;
    y->totalAmountReceived = 0.0;
    y->customerQ = getEmptyQueue();

    return x;                           // returning the complete structure.
};
</code>```

or alternatively, since you do not need to use y, a pointer to the structure, otherwise:

```<code>struct cashier initCashier(void){

    struct cashier x;                  // only the structure variable x.

    x.numberOfCusCustomersServed = 0;
    x.totalCustomerWaitingTime = 0;
    x.totalAmountReceived = 0.0;
    x.customerQ = getEmptyQueue();

    return x;                           // returning the complete structure.
};
</code>```

Be sure to also change the respective type of the return value of the function initCashier() from struct cashier* to struct cashier.

3.

```<code>struct cashier {
    int numberOfCustomersServed; /* This should be initialized to 0 */
    int totalCustomerWaitingTime; /* This should be initialized to 0 */
    float totalAmountReceived; /* This should be initialized to 0 */
    queueADT customerQ; /* This should be initialized to an empty queue */
}cashier;
 _______
</code>```

The second cashier defines a global variable of type struct cashier with the identifier of cashier, which is permissible because structure tag and global variables are in different name spaces, but you do not use this variable in the provided code, so either you can omit it (if you do not need it):

```<code>struct cashier {
    int numberOfCustomersServed; /* This should be initialized to 0 */
    int totalCustomerWaitingTime; /* This should be initialized to 0 */
    float totalAmountReceived; /* This should be initialized to 0 */
    queueADT customerQ; /* This should be initialized to an empty queue */
};
</code>```

or you can use this one, which would solve half of the problems mentioned above, if you only want to use the global variable cashier of type struct cashier for the function initCashier():

```<code>struct cashier {
    int numberOfCustomersServed;   /* This should be initialized to 0 */
    int totalCustomerWaitingTime;  /* This should be initialized to 0 */
    float totalAmountReceived;     /* This should be initialized to 0 */
    queueADT customerQ;       /* This should be initialized to an empty queue */
}cashier;                     // global variable `cashier` of type `struct cashier`.

void initCashier(void){                        // return type of `void`.
    cashier.numberOfCusCustomersServed = 0;    // the variable `cashier` is used directly.
    cashier.totalCustomerWaitingTime = 0;
    cashier.totalAmountReceived = 0.0;
    cashier.customerQ = getEmptyQueue();
};
</code>```

Body:
I am learning data structure of queue, and making a cashier structure like this:1 There are 2 integers,1 float and 1 queue data type in it.2 So I wanted to make a cashier pointer to point to the cashier structure.`

struct cashier {
    int numberOfCustomersServed; /* This should be initialized to 0 */
    int totalCustomerWaitingTime; /* This should be initialized to 0 */
    float totalAmountReceived; /* This should be initialized to 0 */
    queueADT customerQ; /* This should be initialized to an empty queue */
}cashier;

struct cashier* initCashier(void){
    struct cashier *y;
    y->numberOfCusCustomersServed=0;
    y->totalCustomerWaitingTime=0;
    y->totalAmountReceived=0.0;
    y->customerQ=getEmptyQueue();

    return y;
};

But then I get the error:

/cygdrive/c/Users/Heta/Desktop/CLionHWQ2/supermarket.c:8:6: error: dereferencing pointer to incomplete type 'struct cashier'
     y->numberOfCusCustomersServed=0;

And below is basically the queue function.3
The main() is not yet finished, mostly just empty.4
Any help from this will be appreciated. :)

Body:
1.

struct cashier *y;

y is a pointer to struct cashier, but it was not set to point to a variable of type struct cashier.

Thus,

    y->numberOfCusCustomersServed=0;
    y->totalCustomerWaitingTime=0;
    y->totalAmountReceived=0.0;
    y->customerQ=getEmptyQueue();

    return y;      // discussed further at point 2.

doesn´t work, since y has not been initialized to point to a valid variable of type struct cashier.

Rather use:

    struct cashier x;                  // x is a variable of type `struct cashier`.
    struct cashier *y = &x;            // y is a pointer to x.

    y->numberOfCusCustomersServed = 0;
    y->totalCustomerWaitingTime = 0;
    y->totalAmountReceived = 0.0;
    y->customerQ = getEmptyQueue();

with x as a variable of type struct cashier and y as pointer to it, or alternatively:

    struct cashier x;

    x.numberOfCusCustomersServed = 0;
    x.totalCustomerWaitingTime = 0;
    x.totalAmountReceived = 0.0;
    x.customerQ = getEmptyQueue();

since the pointer of y is redundant.

2.

return y;

You cannot return a pointer to an inner-scope variable from a function, because the variable the pointer points to does no longer exist when the function is finished.

If you really want to return a structure, you should do it like that:

struct cashier initCashier(void){

    struct cashier x;                  // x is a variable of type `struct cashier`.
    struct cashier *y = &x;            // y is a pointer to x.

    y->numberOfCusCustomersServed = 0;
    y->totalCustomerWaitingTime = 0;
    y->totalAmountReceived = 0.0;
    y->customerQ = getEmptyQueue();

    return x;                           // returning the complete structure.
};

or alternatively, since you do not need to use y, a pointer to the structure, otherwise:

struct cashier initCashier(void){

    struct cashier x;                  // only the structure variable x.

    x.numberOfCusCustomersServed = 0;
    x.totalCustomerWaitingTime = 0;
    x.totalAmountReceived = 0.0;
    x.customerQ = getEmptyQueue();

    return x;                           // returning the complete structure.
};

Be sure to also change the respective type of the return value of the function initCashier() from struct cashier* to struct cashier.

3.

struct cashier {
    int numberOfCustomersServed; /* This should be initialized to 0 */
    int totalCustomerWaitingTime; /* This should be initialized to 0 */
    float totalAmountReceived; /* This should be initialized to 0 */
    queueADT customerQ; /* This should be initialized to an empty queue */
}cashier;
 _______

The second cashier defines a global variable of type struct cashier with the identifier of cashier, which is permissible because structure tag and global variables are in different name spaces, but you do not use this variable in the provided code, so either you can omit it (if you do not need it):

struct cashier {
    int numberOfCustomersServed; /* This should be initialized to 0 */
    int totalCustomerWaitingTime; /* This should be initialized to 0 */
    float totalAmountReceived; /* This should be initialized to 0 */
    queueADT customerQ; /* This should be initialized to an empty queue */
};

or you can use this one, which would solve half of the problems mentioned above, if you only want to use the global variable cashier of type struct cashier for the function initCashier():

struct cashier {
    int numberOfCustomersServed;   /* This should be initialized to 0 */
    int totalCustomerWaitingTime;  /* This should be initialized to 0 */
    float totalAmountReceived;     /* This should be initialized to 0 */
    queueADT customerQ;       /* This should be initialized to an empty queue */
}cashier;                     // global variable `cashier` of type `struct cashier`.

void initCashier(void){                        // return type of `void`.
    cashier.numberOfCusCustomersServed = 0;    // the variable `cashier` is used directly.
    cashier.totalCustomerWaitingTime = 0;
    cashier.totalAmountReceived = 0.0;
    cashier.customerQ = getEmptyQueue();
};


问:
Using a SP to retrieve information or generate it if data exists in table
I have a requirement in which I need to run a select statement for data in a table if that data exists I need to return the values in a few of the columns. If the data doesn't exist, I need to insert a new row and return the inserted data.

I'll be using an API to execute the stored procedure and return the data, and then write that to a machine via OPC.

What I'm struggling with currently, is that a new entry is created, but does not increment the two columns I need to increment by a digit. In the code below, a new entry will create, but still returns and inputs the same value as the previous lot number. Is there a better way to achieve what I'm wanting to do?

```<code>CREATE PROCEDURE [dbo].[Lotconfirmation]
    @plcid nvarchar(6) OUTPUT,
    @supplierlot nvarchar(25),
    @internallotnum nvarchar(25)OUTPUT,
    @plclotnum nvarchar(25) OUTPUT,
    @suppliercode nvarchar(1),
    @supplierpartnum nvarchar(25),
    @suppliermodel nvarchar(25),
    @qtyconsumed int,
    @id int OUTPUT,
    @errormsg nvarchar(max) OUTPUT,
    @errornum int OUTPUT,
    @errorproc nvarchar(max) OUTPUT,
    @errorstate int OUTPUT,
    @errorline int OUTPUT
AS
BEGIN
    BEGIN TRY
        /* Check if lot already exists */
        SELECT
            @internallotnum = InternalLotNum, @plcid = PLCID,
            @plclotnum = plclotnum, @id = id
        FROM
            dbo.ShrinkLotData
        WHERE
            SupplierMfgLot = @supplierlot

        IF @internallotnum IS NULL
        BEGIN
            DECLARE @table TABLE
                           (
                                plcid nvarchar(6),
                                internallotnum nvarchar(25),
                                plclotnum nvarchar(25),
                                id int
                           )

            INSERT INTO dbo.ShrinkLotData(PLCID, SupplierMfgLot, InternalLotNum, PLCLotNum, SupplierCode, SupplierPartNum, SupplierModel, QtyConsumed, Month, Day, Year, TimeStamp)
            OUTPUT inserted.plcid, inserted.InternalLotNum, inserted.PLCLotNum, inserted.ID
            VALUES (@plcid, @supplierlot,
                    (SELECT (MAX(InternalLotNum) + 1) FROM dbo.ShrinkLotData),
                    (SELECT MAX(RIGHT(InternalLotNum, 2) + 1) FROM dbo.ShrinkLotData),
                    @suppliercode, @supplierpartnum, @suppliermodel,
                    @qtyconsumed,
                    MONTH(GETDATE()), DAY(GETDATE()), YEAR(GETDATE()),
                    CURRENT_TIMESTAMP)

            SELECT @plcid = plcid, @internallotnum = internallotnum, @plclotnum = plclotnum, @id = id
            FROM @table
        END
    END TRY
    /*   E-mail if errors occurs   */
    BEGIN CATCH
        SET @errormsg = 'SP Failed with msg:' + ERROR_MESSAGE()
        SET @errornum = ERROR_NUMBER()
        SET @errorproc = ERROR_PROCEDURE()
        SET @errorstate = ERROR_STATE()
        SET @errorline = ERROR_LINE()

        /* Place holder to insert fail data into a table
        INSERT INTO KSError (datestamp, errormsg, errorproc, errorstate, errorline)
        VALUES (@datestamp, @errormsg, @errornum, @errorproc, @errorstate, @errorline)
        */

        EXECUTE msdb.dbo.sp_send_dbmail
                     @recipients = 'email@domain.com',
                     @profile_name = 'Profile Alert',
                     @subject = 'KepServer Stored Procedure:',
                     @body = @errormsg

    END CATCH
END
GO
</code>```

EDIT:

It seems to be working when I cast values as an integer, so I'll need to review those data types and probably just set them up as integers.

```<code>(SELECT MAX(CAST(InternalLotNum AS INT)) + 1 FROM dbo.ShrinkLotData),
(SELECT MAX(RIGHT(CAST(InternalLotNum AS Int), 2) + 1) FROM dbo.ShrinkLotData),
</code>```

While the question is still up, do you guys see a better / more efficient way to do what I'm hoping?

Thanks!

答:
Your OUTPUT clause is returning the values directly to the client, instead of inserting them into your table variable.  Should be something like:</p>

```<code>    INSERT INTO dbo.ShrinkLotData(PLCID, SupplierMfgLot, InternalLotNum, PLCLotNum, SupplierCode, SupplierPartNum, SupplierModel, QtyConsumed, Month, Day, Year, TimeStamp)
    OUTPUT inserted.plcid, inserted.InternalLotNum, inserted.PLCLotNum, inserted.ID
    INTO @table(plcid,InternalLotNum,PLCLotNum,ID)
    VALUES (@plcid, @supplierlot,
            (SELECT (MAX(InternalLotNum) + 1) FROM dbo.ShrinkLotData),
            (SELECT MAX(RIGHT(InternalLotNum, 2) + 1) FROM dbo.ShrinkLotData),
            @suppliercode, @supplierpartnum, @suppliermodel,
            @qtyconsumed,
            MONTH(GETDATE()), DAY(GETDATE()), YEAR(GETDATE()),
            CURRENT_TIMESTAMP)

    SELECT @plcid = plcid, @internallotnum = internallotnum, @plclotnum = plclotnum, @id = id
    FROM @table
</code>```

Body:
I have a requirement in which I need to run a select statement for data in a table if that data exists I need to return the values in a few of the columns. If the data doesn't exist, I need to insert a new row and return the inserted data.

I'll be using an API to execute the stored procedure and return the data, and then write that to a machine via OPC.

What I'm struggling with currently, is that a new entry is created, but does not increment the two columns I need to increment by a digit. In the code below, a new entry will create, but still returns and inputs the same value as the previous lot number. Is there a better way to achieve what I'm wanting to do?

CREATE PROCEDURE [dbo].[Lotconfirmation]
    @plcid nvarchar(6) OUTPUT,
    @supplierlot nvarchar(25),
    @internallotnum nvarchar(25)OUTPUT,
    @plclotnum nvarchar(25) OUTPUT,
    @suppliercode nvarchar(1),
    @supplierpartnum nvarchar(25),
    @suppliermodel nvarchar(25),
    @qtyconsumed int,
    @id int OUTPUT,
    @errormsg nvarchar(max) OUTPUT,
    @errornum int OUTPUT,
    @errorproc nvarchar(max) OUTPUT,
    @errorstate int OUTPUT,
    @errorline int OUTPUT
AS
BEGIN
    BEGIN TRY
        /* Check if lot already exists */
        SELECT
            @internallotnum = InternalLotNum, @plcid = PLCID,
            @plclotnum = plclotnum, @id = id
        FROM
            dbo.ShrinkLotData
        WHERE
            SupplierMfgLot = @supplierlot

        IF @internallotnum IS NULL
        BEGIN
            DECLARE @table TABLE
                           (
                                plcid nvarchar(6),
                                internallotnum nvarchar(25),
                                plclotnum nvarchar(25),
                                id int
                           )

            INSERT INTO dbo.ShrinkLotData(PLCID, SupplierMfgLot, InternalLotNum, PLCLotNum, SupplierCode, SupplierPartNum, SupplierModel, QtyConsumed, Month, Day, Year, TimeStamp)
            OUTPUT inserted.plcid, inserted.InternalLotNum, inserted.PLCLotNum, inserted.ID
            VALUES (@plcid, @supplierlot,
                    (SELECT (MAX(InternalLotNum) + 1) FROM dbo.ShrinkLotData),
                    (SELECT MAX(RIGHT(InternalLotNum, 2) + 1) FROM dbo.ShrinkLotData),
                    @suppliercode, @supplierpartnum, @suppliermodel,
                    @qtyconsumed,
                    MONTH(GETDATE()), DAY(GETDATE()), YEAR(GETDATE()),
                    CURRENT_TIMESTAMP)

            SELECT @plcid = plcid, @internallotnum = internallotnum, @plclotnum = plclotnum, @id = id
            FROM @table
        END
    END TRY
    /*   E-mail if errors occurs   */
    BEGIN CATCH
        SET @errormsg = 'SP Failed with msg:' + ERROR_MESSAGE()
        SET @errornum = ERROR_NUMBER()
        SET @errorproc = ERROR_PROCEDURE()
        SET @errorstate = ERROR_STATE()
        SET @errorline = ERROR_LINE()

        /* Place holder to insert fail data into a table
        INSERT INTO KSError (datestamp, errormsg, errorproc, errorstate, errorline)
        VALUES (@datestamp, @errormsg, @errornum, @errorproc, @errorstate, @errorline)
        */

        EXECUTE msdb.dbo.sp_send_dbmail
                     @recipients = 'email@domain.com',
                     @profile_name = 'Profile Alert',
                     @subject = 'KepServer Stored Procedure:',
                     @body = @errormsg

    END CATCH
END
GO

EDIT:

It seems to be working when I cast values as an integer, so I'll need to review those data types and probably just set them up as integers.

(SELECT MAX(CAST(InternalLotNum AS INT)) + 1 FROM dbo.ShrinkLotData),
(SELECT MAX(RIGHT(CAST(InternalLotNum AS Int), 2) + 1) FROM dbo.ShrinkLotData),

While the question is still up, do you guys see a better / more efficient way to do what I'm hoping?

Thanks!

Body:
Your OUTPUT clause is returning the values directly to the client, instead of inserting them into your table variable.  Should be something like:

    INSERT INTO dbo.ShrinkLotData(PLCID, SupplierMfgLot, InternalLotNum, PLCLotNum, SupplierCode, SupplierPartNum, SupplierModel, QtyConsumed, Month, Day, Year, TimeStamp)
    OUTPUT inserted.plcid, inserted.InternalLotNum, inserted.PLCLotNum, inserted.ID
    INTO @table(plcid,InternalLotNum,PLCLotNum,ID)
    VALUES (@plcid, @supplierlot,
            (SELECT (MAX(InternalLotNum) + 1) FROM dbo.ShrinkLotData),
            (SELECT MAX(RIGHT(InternalLotNum, 2) + 1) FROM dbo.ShrinkLotData),
            @suppliercode, @supplierpartnum, @suppliermodel,
            @qtyconsumed,
            MONTH(GETDATE()), DAY(GETDATE()), YEAR(GETDATE()),
            CURRENT_TIMESTAMP)

    SELECT @plcid = plcid, @internallotnum = internallotnum, @plclotnum = plclotnum, @id = id
    FROM @table


问:
How to write SQL query to find the total bonus amount they should receive given that the bonus gets calculated only for referrals_valid=1
```<code>SELECT P.profile_id
       , (P.first_name+' '+P.last_name) AS [Full Name]
       , P.email
       , P.phone
       , P.referral_code
       , R.[Total referrals]
       , R.[Total Bonus Amount]
FROM Profiles P
JOIN (SELECT referrer_id
             , SUM(referrer_bonus_amount) AS [Total Bonus Amount]
             , COUNT(referrer_id) AS [Total referrals]
      FROM Referrals
      GROUP BY referrer_id) R
ON P.profile_id=R.referrer_id
WHERE R.[Total referrals] > 1
</code>```

Above is the code for which I am getting the results as below
Query results image but now I need to calculate the Total Bonus Amount only for valid_referrals column equal to 1
(Note: valid_referrals column comes from Referrals table.)

Can someone help me out with the code....??

答:
With case when :

```<code>SELECT P.profile_id
       , (P.first_name+' '+P.last_name) AS [Full Name]
       , P.email
       , P.phone
       , P.referral_code
       , R.[Total referrals]
       , R.[Total Bonus Amount]
       , R.[Total Valid Bonus Amount]
FROM Profiles P
JOIN (SELECT R1.referrer_id
             , SUM(R1.referrer_bonus_amount) AS [Total Bonus Amount]
             , SUM(case when valid_referrals = 1 then R1.referrer_bonus_amount
                    else 0
               end) AS [Total Valid Bonus Amount]
             , COUNT(referrer_id) AS [Total referrals]
      FROM Referrals R1
      GROUP BY referrer_id) R
ON P.profile_id=R.referrer_id
WHERE R.[Total referrals] > 1
</code>```

With subquery:

```<code>SELECT P.profile_id
       , (P.first_name+' '+P.last_name) AS [Full Name]
       , P.email
       , P.phone
       , P.referral_code
       , R.[Total referrals]
       , R.[Total Bonus Amount]
       , R.[Total Valid Bonus Amount]
FROM Profiles P
JOIN (SELECT R1.referrer_id
             , SUM(R1.referrer_bonus_amount) AS [Total Bonus Amount]
             , (select sum(R2.referrer_bonus_amount)
                from Referrals R2
                where R1.referrer_id = R2.referrer_id
                and valid_referrals = 1) AS [Total Valid Bonus Amount]
             , COUNT(referrer_id) AS [Total referrals]
      FROM Referrals R1
      GROUP BY referrer_id) R
ON P.profile_id=R.referrer_id
WHERE R.[Total referrals] > 1
</code>```

Body:
SELECT P.profile_id
       , (P.first_name+' '+P.last_name) AS [Full Name]
       , P.email
       , P.phone
       , P.referral_code
       , R.[Total referrals]
       , R.[Total Bonus Amount]
FROM Profiles P
JOIN (SELECT referrer_id
             , SUM(referrer_bonus_amount) AS [Total Bonus Amount]
             , COUNT(referrer_id) AS [Total referrals]
      FROM Referrals
      GROUP BY referrer_id) R
ON P.profile_id=R.referrer_id
WHERE R.[Total referrals] > 1

Above is the code for which I am getting the results as below
Query results image but now I need to calculate the Total Bonus Amount only for valid_referrals column equal to 1
(Note: valid_referrals column comes from Referrals table.)

Can someone help me out with the code....??

Body:
With case when :

SELECT P.profile_id
       , (P.first_name+' '+P.last_name) AS [Full Name]
       , P.email
       , P.phone
       , P.referral_code
       , R.[Total referrals]
       , R.[Total Bonus Amount]
       , R.[Total Valid Bonus Amount]
FROM Profiles P
JOIN (SELECT R1.referrer_id
             , SUM(R1.referrer_bonus_amount) AS [Total Bonus Amount]
             , SUM(case when valid_referrals = 1 then R1.referrer_bonus_amount
                    else 0
               end) AS [Total Valid Bonus Amount]
             , COUNT(referrer_id) AS [Total referrals]
      FROM Referrals R1
      GROUP BY referrer_id) R
ON P.profile_id=R.referrer_id
WHERE R.[Total referrals] > 1

With subquery:

SELECT P.profile_id
       , (P.first_name+' '+P.last_name) AS [Full Name]
       , P.email
       , P.phone
       , P.referral_code
       , R.[Total referrals]
       , R.[Total Bonus Amount]
       , R.[Total Valid Bonus Amount]
FROM Profiles P
JOIN (SELECT R1.referrer_id
             , SUM(R1.referrer_bonus_amount) AS [Total Bonus Amount]
             , (select sum(R2.referrer_bonus_amount)
                from Referrals R2
                where R1.referrer_id = R2.referrer_id
                and valid_referrals = 1) AS [Total Valid Bonus Amount]
             , COUNT(referrer_id) AS [Total referrals]
      FROM Referrals R1
      GROUP BY referrer_id) R
ON P.profile_id=R.referrer_id
WHERE R.[Total referrals] > 1


问:
Finding the different elements between two ArrayLists in Java
How can I know the different element between 2 array list in java? I need the exact element not a Boolean value which can be retrieved using removeAll().

答:
```<code>LinkedHashMap table;
for each element e of array A
    if table.get(e) != null
        table.put( e, table.get(e) + 1 )
    else
       table.put( e, 0 )

//Do the same for array B
for each element e of array B
    if table.get(e) != null
        table.put( e, table.get(e) + 1 )
    else
       table.put( e, 0 )
</code>```

At the end of the for loops elements in table with value=0 are the different ones.

Body:
LinkedHashMap table;
for each element e of array A
    if table.get(e) != null
        table.put( e, table.get(e) + 1 )
    else
       table.put( e, 0 )

//Do the same for array B
for each element e of array B
    if table.get(e) != null
        table.put( e, table.get(e) + 1 )
    else
       table.put( e, 0 )

At the end of the for loops elements in table with value=0 are the different ones.


问:
Bigquery: Extract data from an array of json
(This is an extension to this question, but my reputation is too low to comment or ask more questions on that topic...)

We work on bigquery, hence limited in importing packages or using other languages. And, as per the link above, js is a solution, but not what I'm looking for here. I implemented it in js, and it was too slow for our needs.

Suppose one of our columns is a string that look like this (array of json):

[{"location":[22.99902,66.000],"t":1},{"location":[55.32168,140.556],"t":2},{"location":[85.0002,20.0055],"t":3}]

I want to extract from the column the json for which "t":2

Where:

some columns don't have elements "t":2

Some columns have several elements "t":2

The number of json elements in each string can change

element "t":2 is not always in second position.

I don't know regexp well enough for this. We tried regexp_extract with  this pattern: r'(\{.*?\"t\":2.*?\})')), but that doesn't work. It extracts everything that precedes "t":2, including the json for "t":2. We only want the json of element "t":2.

Could you advise a regexp pattern that would work?

EDIT:

I have a preference for a solution that gives me 1 match. Suppose I have this string:
[{"location":[22.99902,66.000],"t":1},{"location":[55.32168,140.556],"t":2},{"location":[55.33,141.785],"t":2}],

I would prefer receiving only 1 answer, the first one.

In that case perhaps regexp is less appropriate, but I'm really not sure?

答:
May 1st, 2020 Update

A new function, JSON_EXTRACT_ARRAY, has been just added to the list of JSON
    functions. This function allows you to extract the contents of a JSON document as
    a string array.

so in below you can replace use of json2array UDF with just in-built function JSON_EXTRACT_ARRAY as in below example

```<code>#standardSQL
SELECT id,
  (
    SELECT x
    FROM UNNEST(JSON_EXTRACT_ARRAY(json, '$')) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`
</code>```

==============

Below is for BigQuery Standard SQL

```<code>#standardSQL
CREATE TEMP FUNCTION json2array(json STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS """
  return JSON.parse(json).map(x=>JSON.stringify(x));
""";
SELECT id,
  (
    SELECT x
    FROM UNNEST(json2array(JSON_EXTRACT(json, '$'))) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`
</code>```

You can test, play with above using dummy data as in below example

```<code>#standardSQL
CREATE TEMP FUNCTION json2array(json STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS """
  return JSON.parse(json).map(x=>JSON.stringify(x));
""";
WITH `project.dataset.table` AS (
  SELECT 1 id, '[{"location":[22.99902,66.000],"t":1},{"location":[55.32168,140.556],"t":2},{"location":[85.0002,20.0055],"t":3}]' json UNION ALL
  SELECT 2, '[{"location":[22.99902,66.000],"t":11},{"location":[85.0002,20.0055],"t":13}]'
)
SELECT id,
  (
    SELECT x
    FROM UNNEST(json2array(JSON_EXTRACT(json, '$'))) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`
</code>```

with output

```<code>Row id  extracted
1   1   {"location":[55.32168,140.556],"t":2}
2   2   null
</code>```

Above assumes that there is no more than one element with "t":2 in json column. In case if there can be more than one - you should add ARRAY as below

```<code>SELECT id,
  ARRAY(
    SELECT x
    FROM UNNEST(json2array(JSON_EXTRACT(json, '$'))) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`
</code>```

Body:
May 1st, 2020 Update

A new function, JSON_EXTRACT_ARRAY, has been just added to the list of JSON
    functions. This function allows you to extract the contents of a JSON document as
    a string array.

so in below you can replace use of json2array UDF with just in-built function JSON_EXTRACT_ARRAY as in below example

#standardSQL
SELECT id,
  (
    SELECT x
    FROM UNNEST(JSON_EXTRACT_ARRAY(json, '$')) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`

==============

Below is for BigQuery Standard SQL

#standardSQL
CREATE TEMP FUNCTION json2array(json STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS """
  return JSON.parse(json).map(x=>JSON.stringify(x));
""";
SELECT id,
  (
    SELECT x
    FROM UNNEST(json2array(JSON_EXTRACT(json, '$'))) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`

You can test, play with above using dummy data as in below example

#standardSQL
CREATE TEMP FUNCTION json2array(json STRING)
RETURNS ARRAY<STRING>
LANGUAGE js AS """
  return JSON.parse(json).map(x=>JSON.stringify(x));
""";
WITH `project.dataset.table` AS (
  SELECT 1 id, '[{"location":[22.99902,66.000],"t":1},{"location":[55.32168,140.556],"t":2},{"location":[85.0002,20.0055],"t":3}]' json UNION ALL
  SELECT 2, '[{"location":[22.99902,66.000],"t":11},{"location":[85.0002,20.0055],"t":13}]'
)
SELECT id,
  (
    SELECT x
    FROM UNNEST(json2array(JSON_EXTRACT(json, '$'))) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`

with output

Row id  extracted
1   1   {"location":[55.32168,140.556],"t":2}
2   2   null

Above assumes that there is no more than one element with "t":2 in json column. In case if there can be more than one - you should add ARRAY as below

SELECT id,
  ARRAY(
    SELECT x
    FROM UNNEST(json2array(JSON_EXTRACT(json, '$'))) x
    WHERE JSON_EXTRACT_SCALAR(x, '$.t') = '2'
  ) extracted
FROM `project.dataset.table`


问:
Any imaginary parameter in the laravel command
Is it possible tu pass any imaginary parameter with laravel command? This parameter shouldn't be defined in command implementation.
For example here is command signature:

```<code>protected $signature = 'generateInvoices {--filter=*}';
</code>```

Then I can use this command by:

```<code>php artisan generateInvoices --filter=filter1 --filter=filter2
</code>```

but I want to use other params:

```<code>php artisan generateInvoices --filter=filter1 --filter=filter2 --somethingelse=23 --thisIsNextParam=4 myImaginaryparam=54
</code>```

答:
You can not do dynamic option "parameters" (marked with --), but you can do an array of optional arguments.

```<code>protected $signature = 'generateInvoices {--filter=*} {extraArgs?*}';
</code>```

Then running the extra parts without the --, you can get an array of extra arguments that you need to parse separately.

```<code>php artisan generateInvoices --filter=filter1 --filter=filter2 somethingelse=23 thisIsNextParam=4 myImaginaryparam=54
</code>```

Using $this->argument('extraArgs)` will give you an array of parsable values.

Results of all data being available to your command:

```<code>"Options: "
array:9 [
  "filter" => array:2 [
    0 => "filter1"
    1 => "filter2"
  ]
  "help" => false
  "quiet" => false
  "verbose" => false
  "version" => false
  "ansi" => false
  "no-ansi" => false
  "no-interaction" => false
  "env" => null
]
"Arguments: "
array:2 [
  "command" => "generateInvoices"
  "extraArgs" => array:3 [
    0 => "somethingelse=23"
    1 => "thisIsNextParam=4"
    2 => "myImaginaryparam=54"
  ]
]
</code>```

Body:
Is it possible tu pass any imaginary parameter with laravel command? This parameter shouldn't be defined in command implementation.
For example here is command signature:

protected $signature = 'generateInvoices {--filter=*}';

Then I can use this command by:

php artisan generateInvoices --filter=filter1 --filter=filter2

but I want to use other params:

php artisan generateInvoices --filter=filter1 --filter=filter2 --somethingelse=23 --thisIsNextParam=4 myImaginaryparam=54

Body:
You can not do dynamic option "parameters" (marked with --), but you can do an array of optional arguments.

protected $signature = 'generateInvoices {--filter=*} {extraArgs?*}';

Then running the extra parts without the --, you can get an array of extra arguments that you need to parse separately.

php artisan generateInvoices --filter=filter1 --filter=filter2 somethingelse=23 thisIsNextParam=4 myImaginaryparam=54

Using $this->argument('extraArgs)` will give you an array of parsable values.

Results of all data being available to your command:

"Options: "
array:9 [
  "filter" => array:2 [
    0 => "filter1"
    1 => "filter2"
  ]
  "help" => false
  "quiet" => false
  "verbose" => false
  "version" => false
  "ansi" => false
  "no-ansi" => false
  "no-interaction" => false
  "env" => null
]
"Arguments: "
array:2 [
  "command" => "generateInvoices"
  "extraArgs" => array:3 [
    0 => "somethingelse=23"
    1 => "thisIsNextParam=4"
    2 => "myImaginaryparam=54"
  ]
]


问:
How to generate test report using pytest?
How can I generate test report using pytest? I searched for it but whatever i got was about coverage report.
I tried with this command:

```<code>py.test sanity_tests.py --cov=C:\Test\pytest --cov-report=xml
</code>```

But as parameters represents it generates coverage report not test report.

答: I haven't tried it yet but you can try referring to https://github.com/pytest-dev/pytest-html. A python library that can generate HTML output.</p>

Body:
How can I generate test report using pytest? I searched for it but whatever i got was about coverage report.
I tried with this command:

py.test sanity_tests.py --cov=C:\Test\pytest --cov-report=xml

But as parameters represents it generates coverage report not test report.


问:
How to edit filters and fields in Odoo 11 that appear in add custom filter option
I need to change some of the fields in Odoo 11which appear when clicking on Filters/Add Custom Filter. Does anybody have a clue?

Thanks for the help.
enter image description here

答:
You can Add/Updated/Delete here  Settings / Technical / User-defined Filters

Thanks


问:
Renaming Sub Column names and then creating a data frame using renamed column in R
I am having a tricky dataset3922327258060dat.txt for which I have to create a function to read three columns. This dataset is having multiple columns, out of those columns I need to change name of 3 columns (Date, HrMn, Slp) to (Date, Time, AtmosPressure) and then make a data frame of these 3 columns. BUT the tricky thing is the columns has sub heading as those names(Date, HrMn, Slp) as when I am trying to write
colnames(noaaFilename)
 it is giving me this result
"Identification" "SLP"            "X3"
I am trying to do this, but unable to get result with sub column names and values.

Please help me to create a data frame with three main columns with name "Date", "Time", "AtmosPressure"

```<code>noaaFilename <- read_table2("3922327258060dat.txt")

readNOAAData <- function(filename=noaaFilename) {

  colnames(noaaFilename)
  noaaFilename <- read_table2("3922327258060dat.txt")

  names(noaaFilename)[names(noaaFilename) == "Date"] <- "Date"
  names(noaaFilename)[names(noaaFilename) == "HrMn"] <- "Time"
  names(noaaFilename)[names(noaaFilename) == "Slp"] <- "AtmosPressure"

  noaaFiledf <- data.frame(Date, Time, AtmosPressure)

  noaaData <- subset(noaaFilename, Name == "ATLANTIC CITY", select = c("Date", "Time", "AtmosPressure"))

  ## Stop editing here
  return(noaaData)
}
</code>```

Sorry as this comes too long

```<code>dput(head(noaaFilename, 20))
</code>```

```<code>structure(list(Identification = c("Name", "ATLANTIC", "ATLANTIC",
"ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC",
"ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC",
"ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC"),
    SLP = c("USAF", "CITY", "CITY", "CITY", "CITY", "CITY", "CITY",
    "CITY", "CITY", "CITY", "CITY", "CITY", "CITY", "CITY", "CITY",
    "CITY", "CITY", "CITY", "CITY", "CITY"), X3 = c("NCDC", ",997270,99999,20121029,0000,4,FM-18,",
    ",997270,99999,20121029,0100,4,FM-18,", ",997270,99999,20121029,0200,4,FM-18,",
    ",997270,99999,20121029,0300,4,FM-18,", ",997270,99999,20121029,0400,4,FM-18,",
    ",997270,99999,20121029,0500,4,FM-18,", ",997270,99999,20121029,0600,4,FM-18,",
    ",997270,99999,20121029,0700,4,FM-18,", ",997270,99999,20121029,0800,4,FM-18,",
    ",997270,99999,20121029,0900,4,FM-18,", ",997270,99999,20121029,1000,4,FM-18,",
    ",997270,99999,20121029,1100,4,FM-18,", ",997270,99999,20121029,1200,4,FM-18,",
    ",997270,99999,20121029,1300,4,FM-18,", ",997270,99999,20121029,1400,4,FM-18,",
    ",997270,99999,20121029,1500,4,FM-18,", ",997270,99999,20121029,1600,4,FM-18,",
    ",997270,99999,20121029,1700,4,FM-18,", ",997270,99999,20121029,1800,4,FM-18,"
    )), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-20L), problems = structure(list(row = 1:94, col = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_), expected = c("3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns"), actual = c("11 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "4 columns",
"4 columns", "4 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns"), file = c("'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'"
)), row.names = c(NA, -94L), class = c("tbl_df", "tbl", "data.frame"
)))
</code>```

答:
Consider read.csv (wrapper to read.table) with skip (to avoid problematic, non-combat delimiter lines) and col.names  (for all columns) arguments:

```<code>noaaRaw <- read.csv('3922327258060dat.txt',
                    skip = 2,
                    header = FALSE,
                    col.names = c("Name", "USAF", "NCDC",
                                  "Date", "Time", "I",
                                  "Type", "QCP", "AtmosPressure", "Q")
           )

noaaData <- subset(noaaRaw, Name == "ATLANTIC CITY",
                   select = c(Date, Time, AtmosPressure)
</code>```

Body:
I am having a tricky dataset3922327258060dat.txt for which I have to create a function to read three columns. This dataset is having multiple columns, out of those columns I need to change name of 3 columns (Date, HrMn, Slp) to (Date, Time, AtmosPressure) and then make a data frame of these 3 columns. BUT the tricky thing is the columns has sub heading as those names(Date, HrMn, Slp) as when I am trying to write
colnames(noaaFilename)
 it is giving me this result
"Identification" "SLP"            "X3"
I am trying to do this, but unable to get result with sub column names and values.

Please help me to create a data frame with three main columns with name "Date", "Time", "AtmosPressure"

noaaFilename <- read_table2("3922327258060dat.txt")

readNOAAData <- function(filename=noaaFilename) {

  colnames(noaaFilename)
  noaaFilename <- read_table2("3922327258060dat.txt")

  names(noaaFilename)[names(noaaFilename) == "Date"] <- "Date"
  names(noaaFilename)[names(noaaFilename) == "HrMn"] <- "Time"
  names(noaaFilename)[names(noaaFilename) == "Slp"] <- "AtmosPressure"

  noaaFiledf <- data.frame(Date, Time, AtmosPressure)

  noaaData <- subset(noaaFilename, Name == "ATLANTIC CITY", select = c("Date", "Time", "AtmosPressure"))

  ## Stop editing here
  return(noaaData)
}

Sorry as this comes too long

dput(head(noaaFilename, 20))

structure(list(Identification = c("Name", "ATLANTIC", "ATLANTIC",
"ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC",
"ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC",
"ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC", "ATLANTIC"),
    SLP = c("USAF", "CITY", "CITY", "CITY", "CITY", "CITY", "CITY",
    "CITY", "CITY", "CITY", "CITY", "CITY", "CITY", "CITY", "CITY",
    "CITY", "CITY", "CITY", "CITY", "CITY"), X3 = c("NCDC", ",997270,99999,20121029,0000,4,FM-18,",
    ",997270,99999,20121029,0100,4,FM-18,", ",997270,99999,20121029,0200,4,FM-18,",
    ",997270,99999,20121029,0300,4,FM-18,", ",997270,99999,20121029,0400,4,FM-18,",
    ",997270,99999,20121029,0500,4,FM-18,", ",997270,99999,20121029,0600,4,FM-18,",
    ",997270,99999,20121029,0700,4,FM-18,", ",997270,99999,20121029,0800,4,FM-18,",
    ",997270,99999,20121029,0900,4,FM-18,", ",997270,99999,20121029,1000,4,FM-18,",
    ",997270,99999,20121029,1100,4,FM-18,", ",997270,99999,20121029,1200,4,FM-18,",
    ",997270,99999,20121029,1300,4,FM-18,", ",997270,99999,20121029,1400,4,FM-18,",
    ",997270,99999,20121029,1500,4,FM-18,", ",997270,99999,20121029,1600,4,FM-18,",
    ",997270,99999,20121029,1700,4,FM-18,", ",997270,99999,20121029,1800,4,FM-18,"
    )), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-20L), problems = structure(list(row = 1:94, col = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_), expected = c("3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns", "3 columns", "3 columns",
"3 columns", "3 columns", "3 columns"), actual = c("11 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "5 columns", "5 columns", "5 columns", "4 columns",
"4 columns", "4 columns", "5 columns", "5 columns", "5 columns",
"5 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns", "4 columns", "4 columns",
"4 columns", "4 columns", "4 columns"), file = c("'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'",
"'3922327258060dat.txt'", "'3922327258060dat.txt'", "'3922327258060dat.txt'"
)), row.names = c(NA, -94L), class = c("tbl_df", "tbl", "data.frame"
)))

Body:
Consider read.csv (wrapper to read.table) with skip (to avoid problematic, non-combat delimiter lines) and col.names  (for all columns) arguments:

noaaRaw <- read.csv('3922327258060dat.txt',
                    skip = 2,
                    header = FALSE,
                    col.names = c("Name", "USAF", "NCDC",
                                  "Date", "Time", "I",
                                  "Type", "QCP", "AtmosPressure", "Q")
           )

noaaData <- subset(noaaRaw, Name == "ATLANTIC CITY",
                   select = c(Date, Time, AtmosPressure)


问:
commit changes in the submodules with the only command
I am trying to commit changes made in a few submodules:

```<code>$ git submodule foreach git commit -m 'fixed header guards'
Entering 'libs/BaseDisplay'
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
fatal: run_command returned non-zero status for libs/BaseDisplay
.
</code>```

I see process stops on the first submodule which is up to date...
However, there are many other submodules which have staged files.
How to commit changes made in such submodule with the only command?

答:
Short version, change your command to:

```<code>git submodule foreach "git commit -m 'fixed header guards' || :"
</code>```

Longer version: As man page states:

A non-zero return from the command in any submodule causes the processing to terminate.

And recommends:

This can be overridden by adding || : to the end of the command.

What this does is:

An OR list has the form

```<code>command1 || command2
</code>```

command2 is executed if, and only if, command1 returns a non-zero exit status.  The return status of AND and OR lists is the exit status of the last command executed in the list.

And : is bash's nop: do nothing, (and always) return success.

Double quotes around the command part of submodule foreach ensure it all gets passed to git as a single argument and the shell you're calling it from does not parse the || : bit itself.

Body:
I am trying to commit changes made in a few submodules:

$ git submodule foreach git commit -m 'fixed header guards'
Entering 'libs/BaseDisplay'
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
fatal: run_command returned non-zero status for libs/BaseDisplay
.

I see process stops on the first submodule which is up to date...
However, there are many other submodules which have staged files.
How to commit changes made in such submodule with the only command?

Body:
Short version, change your command to:

git submodule foreach "git commit -m 'fixed header guards' || :"

Longer version: As man page states:

A non-zero return from the command in any submodule causes the processing to terminate.

And recommends:

This can be overridden by adding || : to the end of the command.

What this does is:

An OR list has the form

command1 || command2

command2 is executed if, and only if, command1 returns a non-zero exit status.  The return status of AND and OR lists is the exit status of the last command executed in the list.

And : is bash's nop: do nothing, (and always) return success.

Double quotes around the command part of submodule foreach ensure it all gets passed to git as a single argument and the shell you're calling it from does not parse the || : bit itself.


问:
Akka Typed Actors and AKka Http - cannot find ActorRefFactory
I am trying to work with typed actors version 2.6.3 and akka http version 10.1.11
while all worked fine in non typed actors , now I am getting compilation error

```<code>object Main extends App {

   def createServer(implicit system: ActorSystem[IdentityCalculated]) = {

implicit val materializer = ActorMaterializer()

 }
 def apply(): Behavior[IdentityCalculated] = {
Behaviors.setup { context =>

  val identityManager = context.spawn(IdentityManager(), "identity-manager")

  implicit val timeout = Timeout(10, TimeUnit.SECONDS)
  implicit val scheduler = context.system.scheduler

  identityManager.tell(CalculateIdentity(context.self))

  Behaviors.receiveMessage{
    case IdentityCalculated(_,_,_) =>
      println("got response")
      Behaviors.same
  }
}

}
ActorSystem(Main(), "credentials-manager")

}
</code>```

what am I missing?
I want to create http server when I get the message that the identity was calculated how ever i am getting compilation error in the materializer
creation

Main.scala:19:50: implicit ActorRefFactory required: if outside of an Actor you need an implicit ActorSystem, inside of an actor this should be the implicit ActorContext
  [error]     implicit val materializer = ActorMaterializer()
  [error]                                                  ^
  [error] one error found

thanks

答: I had to use akka-stream-typed and not akka-stream</p>

Body:
I am trying to work with typed actors version 2.6.3 and akka http version 10.1.11
while all worked fine in non typed actors , now I am getting compilation error

object Main extends App {

   def createServer(implicit system: ActorSystem[IdentityCalculated]) = {

implicit val materializer = ActorMaterializer()

 }
 def apply(): Behavior[IdentityCalculated] = {
Behaviors.setup { context =>

  val identityManager = context.spawn(IdentityManager(), "identity-manager")

  implicit val timeout = Timeout(10, TimeUnit.SECONDS)
  implicit val scheduler = context.system.scheduler

  identityManager.tell(CalculateIdentity(context.self))

  Behaviors.receiveMessage{
    case IdentityCalculated(_,_,_) =>
      println("got response")
      Behaviors.same
  }
}

}
ActorSystem(Main(), "credentials-manager")

}

what am I missing?
I want to create http server when I get the message that the identity was calculated how ever i am getting compilation error in the materializer
creation

Main.scala:19:50: implicit ActorRefFactory required: if outside of an Actor you need an implicit ActorSystem, inside of an actor this should be the implicit ActorContext
  [error]     implicit val materializer = ActorMaterializer()
  [error]                                                  ^
  [error] one error found

thanks