问:
Removing supplementary characters from a Java string
I have a Java string that contains supplementary characters (characters in the Unicode standard whose code points are above U+FFFF). These characters could for example be emojis. I want to remove those characters from the string, i.e. replace them with the empty string "".

How do I remove supplementary characters from a string?

How do I remove characters from an arbitrary code point range? (For example all characters in the range 1F000–1FFFF)?

答:
You can get a character's unicode value by simply converting it to an int.

Therefore, you'll want to do the following:

Convert your String to a char[], or do something like have the loop condition iterate through each character in the String using String.charAt()

Check if the unicode value is one you want to remove.

If so, replace the character with "".

This is just to start you off, however if you're still struggling I can try type out a whole example.

Good luck!


来源: stackexchange

问:
How to find the bin number of the frequency of interest from an fft signal in python?
I am doing a task which involves taking two signals from a phase doppler anemometry system and calculating the phase shift and the frequency which will further help in finding the velocity and diameter of the droplet. Before getting into the actual task, I am now taking two sine signals from a function generator and producing a phase shift and then calculating the phase and frequency via a program in python with FFT to verify if both are the same. In that process, I am now getting the frequency value same as what I have set in the function generator. So frequency problem is solved. I am currently stuck up in a state where I need to find the bin number where my frequency belongs and using that I can calculate the exact phase shift.
Also, I would like to know how to find the number of bins used in the FFT.
My signal is 40MHz, my sampling frequency is 125MHz.

Thank you!

答:
It might be slightly overkilling but you can use numpy.where to find the index of a specific value in an array</p>

```<code>>>> import numpy as np
>>> np.where(np.linspace(1,10,10)==4)
(array([3]),)
</code>```

ContentLicense: CC BY-SA 3.0

Body:
It might be slightly overkilling but you can use numpy.where to find the index of a specific value in an array

>>> import numpy as np
>>> np.where(np.linspace(1,10,10)==4)
(array([3]),)


问:
How to get current zoom in React-Mapbox-GL?
How can i get current zoom of map in react mapbox gl?

Package: https://github.com/alex3165/react-mapbox-gl/tree/0df46b1dcf194cdf140638f653221d8a82f0b195

I have tried on example from "How to start" to use getZoom method on Mapbut it's not working. I have error that Map.getZoom is not a function.

EDIT ================

When i try to access it by refs then i have problem like on screenshot. How to get this .state.map.e which have my getZoom function?

答:
The Map you are using is a ReactMapboxGl object which is a wrapper of mapbox-gl-js. You want to call getZoom() on the mapboxgl.Map object.

To use the original Mapbox API use onStyleLoad property, the callback function will receive the map object as a first arguments, then you can add your own logic alongside react-mapbox-gl. [source]

So you can get it from:

```<code><ReactMapboxGl onStyleLoad={ el => this.map = el } />
</code>```

Then you could use it here:

```<code>componentDidMount() {
    const currentZoom = this.map.getZoom();
}
</code>```

Body:
The Map you are using is a ReactMapboxGl object which is a wrapper of mapbox-gl-js. You want to call getZoom() on the mapboxgl.Map object.

To use the original Mapbox API use onStyleLoad property, the callback function will receive the map object as a first arguments, then you can add your own logic alongside react-mapbox-gl. [source]

So you can get it from:

<ReactMapboxGl onStyleLoad={ el => this.map = el } />

Then you could use it here:

componentDidMount() {
    const currentZoom = this.map.getZoom();
}


问:
Show message or run script on first login after reboot of ubuntu server
essentially I would like to make sure I mount an encrypted drive after each reboot of my ubuntu server. Since this obviously requires me to type in my password, there are two ways I can imagine this to work:

either show a message on each first log in of my user following a reboot (basically a reminder), or

automatically running a script on each first log in of my user following a reboot.

Is either of the two possible at all and/or is there another (possibly more elegant) way to achieve this?

Thanks a ton for your advice!

Best,

J

See suggestion below for the first step toward a working solution. Basically, here's what I ended up doing:

write script, which checks if device is mounted and execute mounting command if not:

```mount | grep -c mapper/[device mapper] # this returns 1 if mounted, 0 if not```

Run this as cronjob

答:
You could run a script on startup via cron.
Simply run crontab -e to create a cron-table. (It will create an empty one if you don't already have one.)

To run your script on startup, use

@reboot     /home/user/script_at_reboot.sh.

Further documentation in the ubuntu wiki.

Body:
essentially I would like to make sure I mount an encrypted drive after each reboot of my ubuntu server. Since this obviously requires me to type in my password, there are two ways I can imagine this to work:

either show a message on each first log in of my user following a reboot (basically a reminder), or

automatically running a script on each first log in of my user following a reboot.

Is either of the two possible at all and/or is there another (possibly more elegant) way to achieve this?

Thanks a ton for your advice!

Best,

J

See suggestion below for the first step toward a working solution. Basically, here's what I ended up doing:

write script, which checks if device is mounted and execute mounting command if not:

mount | grep -c mapper/[device mapper] # this returns 1 if mounted, 0 if not

Run this as cronjob


问:
How do set environment variable in gradle via task?
I have gradle application. And my main gradle-file include some tasks (groovy).
I need when start a my task - environment variable "LANG" set encoding = ru_RU.koi8-r (for windows, linux), and after the completion of the my task - environment variable contains the initial value (en_US.UTF-8).
How do it? Help me, please.</p>

答:
I had to do some research in this topic and will try to clarify some open issues. I would do that in two comments instead, but I do not have enough reputation yet. Since I found Igor Ganapolsky's comment also on other Websites but without an answer everytime I feel the need to write another answer here even if the question actually is already answered.

As Martin Rajniak stated you can set an environment variable like he showed. But that variable is only valid for the task it is defined in or the corresponding process respectively. That means you cannot use it in another following task. I verified that by defining two depending tasks like so:

```<code>task('firstTask', type:Exec) {
    environment "FOO", "bar"

    workingDir '.'
    commandLine 'cmd', '/c', 'print.bat'
}

task ('secondTask', type:Exec) {
    dependsOn firstTask

    workingDir '.'
    commandLine 'cmd', '/c', 'print.bat'
}
</code>```

The command print.bat does only echo the environment variable:

```<code>@echo off
echo %FOO%
</code>```

Running the build using the command gradle secondTask will yield:

```<code>> Task :firstTask
bar

> Task :secondTask
ECHO ist ausgeschaltet (OFF).
</code>```

So the environment variable is not there anymore for secondTask.

So much for the actual topic, but there is another important thing, which may be the cause for Igor's problem:
The method environment is not available for every Gradle task. As you can see in the documentation of the Exec-task-type the method environment is explicitly defined for the Exec-task-type.

To be complete I want to mention that you can pass variables to a java process by using the JavaExec-task-type and its method systemProperty. But you can not use environment here, because that method is not defined for the JavaExec-task-type.

However, I myself am still looking for a way to define an environment variable that is valid for the whole build without defining it directly via the operating system.

Body:
I had to do some research in this topic and will try to clarify some open issues. I would do that in two comments instead, but I do not have enough reputation yet. Since I found Igor Ganapolsky's comment also on other Websites but without an answer everytime I feel the need to write another answer here even if the question actually is already answered.

As Martin Rajniak stated you can set an environment variable like he showed. But that variable is only valid for the task it is defined in or the corresponding process respectively. That means you cannot use it in another following task. I verified that by defining two depending tasks like so:

task('firstTask', type:Exec) {
    environment "FOO", "bar"

    workingDir '.'
    commandLine 'cmd', '/c', 'print.bat'
}

task ('secondTask', type:Exec) {
    dependsOn firstTask

    workingDir '.'
    commandLine 'cmd', '/c', 'print.bat'
}

The command print.bat does only echo the environment variable:

@echo off
echo %FOO%

Running the build using the command gradle secondTask will yield:

> Task :firstTask
bar

> Task :secondTask
ECHO ist ausgeschaltet (OFF).

So the environment variable is not there anymore for secondTask.

So much for the actual topic, but there is another important thing, which may be the cause for Igor's problem:
The method environment is not available for every Gradle task. As you can see in the documentation of the Exec-task-type the method environment is explicitly defined for the Exec-task-type.

To be complete I want to mention that you can pass variables to a java process by using the JavaExec-task-type and its method systemProperty. But you can not use environment here, because that method is not defined for the JavaExec-task-type.

However, I myself am still looking for a way to define an environment variable that is valid for the whole build without defining it directly via the operating system.


问:
Unable to uncheck input type checkbox in mobile view
I'm trying to create a responsive table, I have the most part of this down, I am trying to make it accordion like when viewed on smaller resolutions, unfortunately when the checkbox is clicked, it will not uncheck (retract). I'm probably missing something very obvious or doing something completely wrong. I've tried using JS to create the function. Could someone please point me in the right direction with this?

$(function() {

  $(".close").on('change', function(e) {
    var el = $(this); {
      $(".close").not(el).prop('checked', false);
    }

  });

});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  background: #cacaca;
  margin: 0;
  padding: 20px;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
}

#table {
  display: table;
  width: 100%;
  background: #fff;
  margin: 0;
  box-sizing: border-box;
}

.caption {
  display: block;
  width: 100%;
  background: #64e0ef;
  height: 55px;
  padding-left: 10px;
  color: #fff;
  font-size: 20px;
  line-height: 55px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
  box-sizing: border-box;
}

.header-row {
  background: #8b8b8b;
  color: #fff;
}

.row {
  display: table-row;
}

.cell {
  display: table-cell;
  padding: 6px;
  border-bottom: 1px solid #e5e5e5;
  text-align: center;
}

.primary {
  text-align: left;
}

input[type="radio"],
input[type="checkbox"] {
  display: none;
}

@media only screen and (max-width: 760px) {
  body {
    padding: 0;
  }
  #table {
    display: block;
    margin: 44px 0 0 0;
  }
  .caption {
    position: fixed;
    top: 0;
    text-align: center;
    height: 44px;
    line-height: 44px;
    z-index: 5;
    border-bottom: 2px solid #999;
  }
  .row {
    position: relative;
    display: block;
    border-bottom: 1px solid #ccc;
  }
  .header-row {
    display: none;
  }
  .cell {
    display: block;
    border: none;
    position: relative;
    height: 45px;
    line-height: 45px;
    text-align: left;
  }
  .primary:after {
    content: "";
    display: block;
    position: absolute;
    right: 20px;
    top: 18px;
    z-index: 2;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #ccc;
  }
  .cell:nth-of-type(n+2) {
    display: none;
  }
  input[type="radio"],
  input[type="checkbox"] {
    display: block;
    position: absolute;
    z-index: 1;
    width: 99%;
    height: 100%;
    opacity: 0;
  }
  input[type="radio"]:checked,
  input[type="checkbox"]:checked {
    z-index: -1;
  }
  input[type="radio"]:checked~.cell,
  input[type="checkbox"]:checked~.cell {
    display: block;
    border-bottom: 1px solid #eee;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2),
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2) {
    background: #e0e0e0;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2):before,
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2):before {
    content: attr(data-label);
    display: inline-block;
    width: 60px;
    background: #999;
    border-radius: 10px;
    height: 20px;
    margin-right: 10px;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    color: white;
  }
  input[type="radio"]:checked~.primary,
  input[type="checkbox"]:checked~.primary {
    border-bottom: 2px solid #999;
  }
  input[type="radio"]:checked~.primary:after,
  input[type="checkbox"]:checked~.primary:after {
    position: absolute;
    right: 18px;
    top: 22px;
    border-right: 10px solid transparent;
    border-left: 10px solid transparent;
    border-top: 10px solid #ccc;
    z-index: 2;
  }
}</code>```

Main Title

    Developer
    Foundation
    Accelerator
    Enterprise

    <input type="checkbox" name="expand" class="close">
    Item 1
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 2
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 3
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 4
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 5
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 6
    Sub Item
    Sub Item
    Sub Item
    Sub Item

```

答:
You can fix it adding a new input checkbox before first div row. Check this:

$(function() {
    $(".close").on('click', function(e) {
        $(".close").not(this).prop('checked', false);
    });
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  background: #cacaca;
  margin: 0;
  padding: 20px;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
}

#table {
  display: table;
  width: 100%;
  background: #fff;
  margin: 0;
  box-sizing: border-box;
}

.caption {
  display: block;
  width: 100%;
  background: #64e0ef;
  height: 55px;
  padding-left: 10px;
  color: #fff;
  font-size: 20px;
  line-height: 55px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
  box-sizing: border-box;
}

.header-row {
  background: #8b8b8b;
  color: #fff;
}

.row {
  display: table-row;
}

.cell {
  display: table-cell;
  padding: 6px;
  border-bottom: 1px solid #e5e5e5;
  text-align: center;
}

.primary {
  text-align: left;
}

input[type="radio"],
input[type="checkbox"] {
  display: none;
}

@media only screen and (max-width: 760px) {
  body {
    padding: 0;
  }
  #table {
    display: block;
    margin: 44px 0 0 0;
  }
  .caption {
    position: fixed;
    top: 0;
    text-align: center;
    height: 44px;
    line-height: 44px;
    z-index: 5;
    border-bottom: 2px solid #999;
  }
  .row {
    position: relative;
    display: block;
    border-bottom: 1px solid #ccc;
  }
  .header-row {
    display: none;
  }
  .cell {
    display: block;
    border: none;
    position: relative;
    height: 45px;
    line-height: 45px;
    text-align: left;
  }
  .primary:after {
    content: "";
    display: block;
    position: absolute;
    right: 20px;
    top: 18px;
    z-index: 2;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #ccc;
  }
  .cell:nth-of-type(n+2) {
    display: none;
  }
  input[type="radio"],
  input[type="checkbox"] {
    display: block;
    position: absolute;
    z-index: 1;
    width: 99%;
    height: 100%;
    opacity: 0;
  }
  input[type="radio"]:checked,
  input[type="checkbox"]:checked {
    z-index: -1;
  }
  input[type="radio"]:checked~.cell,
  input[type="checkbox"]:checked~.cell {
    display: block;
    border-bottom: 1px solid #eee;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2),
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2) {
    background: #e0e0e0;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2):before,
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2):before {
    content: attr(data-label);
    display: inline-block;
    width: 60px;
    background: #999;
    border-radius: 10px;
    height: 20px;
    margin-right: 10px;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    color: white;
  }
  input[type="radio"]:checked~.primary,
  input[type="checkbox"]:checked~.primary {
    border-bottom: 2px solid #999;
  }
  input[type="radio"]:checked~.primary:after,
  input[type="checkbox"]:checked~.primary:after {
    position: absolute;
    right: 18px;
    top: 22px;
    border-right: 10px solid transparent;
    border-left: 10px solid transparent;
    border-top: 10px solid #ccc;
    z-index: 2;
  }
}</code>```

Main Title

    Developer
    Foundation
    Accelerator
    Enterprise

  <input type="checkbox" name="expand" class="close">

    <input type="checkbox" name="expand" class="close">
    Item 1
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 2
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 3
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 4
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 5
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 6
    Sub Item
    Sub Item
    Sub Item
    Sub Item

```

Body:
I'm trying to create a responsive table, I have the most part of this down, I am trying to make it accordion like when viewed on smaller resolutions, unfortunately when the checkbox is clicked, it will not uncheck (retract). I'm probably missing something very obvious or doing something completely wrong. I've tried using JS to create the function. Could someone please point me in the right direction with this?

$(function() {

  $(".close").on('change', function(e) {
    var el = $(this); {
      $(".close").not(el).prop('checked', false);
    }

  });

});

body {
  background: #cacaca;
  margin: 0;
  padding: 20px;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
}

#table {
  display: table;
  width: 100%;
  background: #fff;
  margin: 0;
  box-sizing: border-box;
}

.caption {
  display: block;
  width: 100%;
  background: #64e0ef;
  height: 55px;
  padding-left: 10px;
  color: #fff;
  font-size: 20px;
  line-height: 55px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
  box-sizing: border-box;
}

.header-row {
  background: #8b8b8b;
  color: #fff;
}

.row {
  display: table-row;
}

.cell {
  display: table-cell;
  padding: 6px;
  border-bottom: 1px solid #e5e5e5;
  text-align: center;
}

.primary {
  text-align: left;
}

input[type="radio"],
input[type="checkbox"] {
  display: none;
}

@media only screen and (max-width: 760px) {
  body {
    padding: 0;
  }
  #table {
    display: block;
    margin: 44px 0 0 0;
  }
  .caption {
    position: fixed;
    top: 0;
    text-align: center;
    height: 44px;
    line-height: 44px;
    z-index: 5;
    border-bottom: 2px solid #999;
  }
  .row {
    position: relative;
    display: block;
    border-bottom: 1px solid #ccc;
  }
  .header-row {
    display: none;
  }
  .cell {
    display: block;
    border: none;
    position: relative;
    height: 45px;
    line-height: 45px;
    text-align: left;
  }
  .primary:after {
    content: "";
    display: block;
    position: absolute;
    right: 20px;
    top: 18px;
    z-index: 2;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #ccc;
  }
  .cell:nth-of-type(n+2) {
    display: none;
  }
  input[type="radio"],
  input[type="checkbox"] {
    display: block;
    position: absolute;
    z-index: 1;
    width: 99%;
    height: 100%;
    opacity: 0;
  }
  input[type="radio"]:checked,
  input[type="checkbox"]:checked {
    z-index: -1;
  }
  input[type="radio"]:checked~.cell,
  input[type="checkbox"]:checked~.cell {
    display: block;
    border-bottom: 1px solid #eee;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2),
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2) {
    background: #e0e0e0;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2):before,
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2):before {
    content: attr(data-label);
    display: inline-block;
    width: 60px;
    background: #999;
    border-radius: 10px;
    height: 20px;
    margin-right: 10px;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    color: white;
  }
  input[type="radio"]:checked~.primary,
  input[type="checkbox"]:checked~.primary {
    border-bottom: 2px solid #999;
  }
  input[type="radio"]:checked~.primary:after,
  input[type="checkbox"]:checked~.primary:after {
    position: absolute;
    right: 18px;
    top: 22px;
    border-right: 10px solid transparent;
    border-left: 10px solid transparent;
    border-top: 10px solid #ccc;
    z-index: 2;
  }
}

Main Title

    Developer
    Foundation
    Accelerator
    Enterprise

    <input type="checkbox" name="expand" class="close">
    Item 1
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 2
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 3
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 4
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 5
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 6
    Sub Item
    Sub Item
    Sub Item
    Sub Item

Body:
You can fix it adding a new input checkbox before first div row. Check this:

$(function() {
    $(".close").on('click', function(e) {
        $(".close").not(this).prop('checked', false);
    });
});

body {
  background: #cacaca;
  margin: 0;
  padding: 20px;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
}

#table {
  display: table;
  width: 100%;
  background: #fff;
  margin: 0;
  box-sizing: border-box;
}

.caption {
  display: block;
  width: 100%;
  background: #64e0ef;
  height: 55px;
  padding-left: 10px;
  color: #fff;
  font-size: 20px;
  line-height: 55px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
  box-sizing: border-box;
}

.header-row {
  background: #8b8b8b;
  color: #fff;
}

.row {
  display: table-row;
}

.cell {
  display: table-cell;
  padding: 6px;
  border-bottom: 1px solid #e5e5e5;
  text-align: center;
}

.primary {
  text-align: left;
}

input[type="radio"],
input[type="checkbox"] {
  display: none;
}

@media only screen and (max-width: 760px) {
  body {
    padding: 0;
  }
  #table {
    display: block;
    margin: 44px 0 0 0;
  }
  .caption {
    position: fixed;
    top: 0;
    text-align: center;
    height: 44px;
    line-height: 44px;
    z-index: 5;
    border-bottom: 2px solid #999;
  }
  .row {
    position: relative;
    display: block;
    border-bottom: 1px solid #ccc;
  }
  .header-row {
    display: none;
  }
  .cell {
    display: block;
    border: none;
    position: relative;
    height: 45px;
    line-height: 45px;
    text-align: left;
  }
  .primary:after {
    content: "";
    display: block;
    position: absolute;
    right: 20px;
    top: 18px;
    z-index: 2;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #ccc;
  }
  .cell:nth-of-type(n+2) {
    display: none;
  }
  input[type="radio"],
  input[type="checkbox"] {
    display: block;
    position: absolute;
    z-index: 1;
    width: 99%;
    height: 100%;
    opacity: 0;
  }
  input[type="radio"]:checked,
  input[type="checkbox"]:checked {
    z-index: -1;
  }
  input[type="radio"]:checked~.cell,
  input[type="checkbox"]:checked~.cell {
    display: block;
    border-bottom: 1px solid #eee;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2),
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2) {
    background: #e0e0e0;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2):before,
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2):before {
    content: attr(data-label);
    display: inline-block;
    width: 60px;
    background: #999;
    border-radius: 10px;
    height: 20px;
    margin-right: 10px;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    color: white;
  }
  input[type="radio"]:checked~.primary,
  input[type="checkbox"]:checked~.primary {
    border-bottom: 2px solid #999;
  }
  input[type="radio"]:checked~.primary:after,
  input[type="checkbox"]:checked~.primary:after {
    position: absolute;
    right: 18px;
    top: 22px;
    border-right: 10px solid transparent;
    border-left: 10px solid transparent;
    border-top: 10px solid #ccc;
    z-index: 2;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="caption">Main Title</div>
<div id="table">
  <div class="header-row row">
    <span class="cell primary">
      <!--stuff here to add text in first prim cell --></span>
    <span class="cell">Developer</span>
    <span class="cell">Foundation</span>
    <span class="cell">Accelerator</span>
    <span class="cell">Enterprise</span>
  </div>
  <input type="checkbox" name="expand" class="close">
  <div class="row">
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 1</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
  </div>
  <div class="row">
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 2</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
  </div>
  <div class="row">
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 3</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
  </div>
  <div class="row">
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 4</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
  </div>
  <div class="row">
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 5</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
  </div>
  <div class="row">
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 6</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
  </div>
</div>


问:
ASP.NET MVC Global Variables
How do you declare global variables in ASP.NET MVC?</p>

答:
The steel is far from hot, but I combined @abatishchev's solution with the answer from this post and got to this result. Hope it's useful:</p>

```<code>public static class GlobalVars
{
    private const string GlobalKey = "AllMyVars";

    static GlobalVars()
    {
        Hashtable table = HttpContext.Current.Application[GlobalKey] as Hashtable;

        if (table == null)
        {
            table = new Hashtable();
            HttpContext.Current.Application[GlobalKey] = table;
        }
    }

    public static Hashtable Vars
    {
        get { return HttpContext.Current.Application[GlobalKey] as Hashtable; }
    }

    public static IEnumerable<SomeClass> SomeCollection
    {
        get { return GetVar("SomeCollection") as IEnumerable<SomeClass>; }
        set { WriteVar("SomeCollection", value); }
    }

    internal static DateTime SomeDate
    {
        get { return (DateTime)GetVar("SomeDate"); }
        set { WriteVar("SomeDate", value); }
    }

    private static object GetVar(string varName)
    {
        if (Vars.ContainsKey(varName))
        {
            return Vars[varName];
        }

        return null;
    }

    private static void WriteVar(string varName, object value)
    {
        if (value == null)
        {
            if (Vars.ContainsKey(varName))
            {
                Vars.Remove(varName);
            }
            return;
        }

        if (Vars[varName] == null)
        {
            Vars.Add(varName, value);
        }
        else
        {
            Vars[varName] = value;
        }
    }
}
</code>```

ContentLicense: CC BY-SA 2.5

Title: ASP.NET MVC Global Variables

Body:
The steel is far from hot, but I combined @abatishchev's solution with the answer from this post and got to this result. Hope it's useful:

public static class GlobalVars
{
    private const string GlobalKey = "AllMyVars";

    static GlobalVars()
    {
        Hashtable table = HttpContext.Current.Application[GlobalKey] as Hashtable;

        if (table == null)
        {
            table = new Hashtable();
            HttpContext.Current.Application[GlobalKey] = table;
        }
    }

    public static Hashtable Vars
    {
        get { return HttpContext.Current.Application[GlobalKey] as Hashtable; }
    }

    public static IEnumerable<SomeClass> SomeCollection
    {
        get { return GetVar("SomeCollection") as IEnumerable<SomeClass>; }
        set { WriteVar("SomeCollection", value); }
    }

    internal static DateTime SomeDate
    {
        get { return (DateTime)GetVar("SomeDate"); }
        set { WriteVar("SomeDate", value); }
    }

    private static object GetVar(string varName)
    {
        if (Vars.ContainsKey(varName))
        {
            return Vars[varName];
        }

        return null;
    }

    private static void WriteVar(string varName, object value)
    {
        if (value == null)
        {
            if (Vars.ContainsKey(varName))
            {
                Vars.Remove(varName);
            }
            return;
        }

        if (Vars[varName] == null)
        {
            Vars.Add(varName, value);
        }
        else
        {
            Vars[varName] = value;
        }
    }
}


问:
Triple DES Java not working
I'm using this programs code Programs code full and i can't figure it out why wouldn't my Triple DES work. How and what did i try?

I added 3key inputs (as well arrays for keybits) that i would use to encrypt the hex and converted them:

```<code>    String keyy1 = new Scanner(System.in).nextLine();
    int keyBitstriple1[] = new int[64];
        for(int i=0 ; i < 14 ; i++) {
        String s = Integer.toBinaryString(Integer.parseInt(keyy1.charAt(i) + "", 16));
                while(s.length() < 4) {
                    s = "0" + s;
                }
                for(int j=0 ; j < 4 ; j++) {
                    keyBitstriple1[(4*i)+j] = Integer.parseInt(s.charAt(j) + "");
                }
            }
</code>```

Then i encrypted the hexa:

```<code>    System.out.println("1st encrypt");
    int outputBits[] = permute(inputBits, keyBitstriple1, false);
    int outputBits2[] = Arrays.copyOf(outputBits, outputBits.length);
    System.out.println("-----------------------------------------------------------");
    System.out.println("2nd enrypt");
    int outputBits3[] = permute(outputBits2, keyBitstriple2, false);
    int outputBits4[] = Arrays.copyOf(outputBits3, outputBits3.length);
    System.out.println("-----------------------------------------------------------");
    System.out.println("3rd enrypt");
    int outputBits5[] = permute(outputBits4, keyBitstriple3, false);
 );
 int outputBits6[] = Arrays.copyOf(outputBits5, outputBits5.length);
//a copy of end encrypt
</code>```

Encryption is completely correct, even when i check with online DES encryption software results was the same.

Then i saved the end encryption in outputBits6 and made a user enter 3 more keys to what decrypt that encrypted text. The same as first step.

```<code> String keyy4 = new Scanner(System.in).nextLine();
 String keyy5 = new Scanner(System.in).nextLine();
 String keyy6 = new Scanner(System.in).nextLine();
</code>```

Then i took first user entered key to decrypt the hexa text. (outputbits6)

```<code>    System.out.println("-----------------------------------------------------------");
    System.out.println("First decrypt");
    int outputBits7[] =  permute(outputBits6, keyBitstriple4, true);
    System.out.println("-----------------------------------------------------------");
    System.out.println("2nd decrypt");
    int outputBits8[] = permute(outputBits7, keyBitstriple5, true);
    System.out.println("-----------------------------------------------------------");
    System.out.println("3rd decrypt");
    int outputBits9[] = permute(outputBits8, keyBitstriple6, true);
</code>```

Every time decryption is wrong and i can't figure it out why but encryption is correct. MY FULL CODE

Thanks in advance.

答: One thing that is missing is that generally 3DES encryption is ede: encrypt with the 1st key, decrypt with the 2nd key and encrypt with the 3rd key. The reverse ded for decryption.

Title: Triple DES Java not working

Body:
I'm using this programs code Programs code full and i can't figure it out why wouldn't my Triple DES work. How and what did i try?

I added 3key inputs (as well arrays for keybits) that i would use to encrypt the hex and converted them:

    String keyy1 = new Scanner(System.in).nextLine();
    int keyBitstriple1[] = new int[64];
        for(int i=0 ; i < 14 ; i++) {
        String s = Integer.toBinaryString(Integer.parseInt(keyy1.charAt(i) + "", 16));
                while(s.length() < 4) {
                    s = "0" + s;
                }
                for(int j=0 ; j < 4 ; j++) {
                    keyBitstriple1[(4*i)+j] = Integer.parseInt(s.charAt(j) + "");
                }
            }

Then i encrypted the hexa:

    System.out.println("1st encrypt");
    int outputBits[] = permute(inputBits, keyBitstriple1, false);
    int outputBits2[] = Arrays.copyOf(outputBits, outputBits.length);
    System.out.println("-----------------------------------------------------------");
    System.out.println("2nd enrypt");
    int outputBits3[] = permute(outputBits2, keyBitstriple2, false);
    int outputBits4[] = Arrays.copyOf(outputBits3, outputBits3.length);
    System.out.println("-----------------------------------------------------------");
    System.out.println("3rd enrypt");
    int outputBits5[] = permute(outputBits4, keyBitstriple3, false);
 );
 int outputBits6[] = Arrays.copyOf(outputBits5, outputBits5.length);
//a copy of end encrypt

Encryption is completely correct, even when i check with online DES encryption software results was the same.

Then i saved the end encryption in outputBits6 and made a user enter 3 more keys to what decrypt that encrypted text. The same as first step.

 String keyy4 = new Scanner(System.in).nextLine();
 String keyy5 = new Scanner(System.in).nextLine();
 String keyy6 = new Scanner(System.in).nextLine();

Then i took first user entered key to decrypt the hexa text. (outputbits6)

    System.out.println("-----------------------------------------------------------");
    System.out.println("First decrypt");
    int outputBits7[] =  permute(outputBits6, keyBitstriple4, true);
    System.out.println("-----------------------------------------------------------");
    System.out.println("2nd decrypt");
    int outputBits8[] = permute(outputBits7, keyBitstriple5, true);
    System.out.println("-----------------------------------------------------------");
    System.out.println("3rd decrypt");
    int outputBits9[] = permute(outputBits8, keyBitstriple6, true);

Every time decryption is wrong and i can't figure it out why but encryption is correct. MY FULL CODE

Thanks in advance.


问:
Publish DACPAC to SQL Server 2014 using SqlPackage.exe?
I've been successfully publishing DACPACs to SQL Server 2008-2012 instances using SqlPackage.exe, as installed by SQL Server Data Tools (and typically found in C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin). However, in attempting to publish a 2014-targeted DACPAC to a SQL Server 2014 instance using this same SqlPackage.exe, I get the following:

```<code>*** Could not deploy package.
Internal Error. The database platform service with type Microsoft.Data.Tools.
Schema.Sql.Sql120DatabaseSchemaProvider is not valid. You must make sure the
service is loaded, or you must provide the full type name of a valid database
platform service.
</code>```

I've found minimal info regarding this; the closest I have found is was a problem publishing to Azure.

I've kept up to date with SSDT patches but would guess that the SqlPackage.exe I have (which shows an 11.0.2902.0 version) is simply incompatible. I am able to publish to this same instance using Visual Studio 2012's Publish command so the instance itself does not seem to be the issue.

Is there a newer version of SqlPackage available that would support publishing a 2014 DACPAC to a 2014 server? Or another scriptable way to do this?

答:
SSDT installs the Dac DLLs inside Visual Studio in the latest releases. This is to avoid side by side issues (Visual Studio 2012 vs 2013 vs SSMS) that required all to be updated to use the latest code.
If you have updated to the latest SSDT, you'll find SqlPackage.exe and the related DLLs in the VS Install Directory\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130. For VS2013 the VS install directory is C:\Program Files (x86)\Microsoft Visual Studio 12.0, and it's 14.0 for VS2015.
SQL Server Management Studio (SSMS) and the standalone Dac Framework MSI both install to the system-wide location. This is C:\Program Files (x86)\Microsoft SQL Server\130\Dac\bin.

**Ans of Mr. Kevin Cunnane. is a right process but if the database in sql2016 use 140\dac  **

Body:
I've been successfully publishing DACPACs to SQL Server 2008-2012 instances using SqlPackage.exe, as installed by SQL Server Data Tools (and typically found in C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin). However, in attempting to publish a 2014-targeted DACPAC to a SQL Server 2014 instance using this same SqlPackage.exe, I get the following:

*** Could not deploy package.
Internal Error. The database platform service with type Microsoft.Data.Tools.
Schema.Sql.Sql120DatabaseSchemaProvider is not valid. You must make sure the
service is loaded, or you must provide the full type name of a valid database
platform service.

I've found minimal info regarding this; the closest I have found is was a problem publishing to Azure.

I've kept up to date with SSDT patches but would guess that the SqlPackage.exe I have (which shows an 11.0.2902.0 version) is simply incompatible. I am able to publish to this same instance using Visual Studio 2012's Publish command so the instance itself does not seem to be the issue.

Is there a newer version of SqlPackage available that would support publishing a 2014 DACPAC to a 2014 server? Or another scriptable way to do this?


问:
Play 2.6 using Logging Markers to carry request uuid similar to Java MDC
I'm trying to use Logging Markers to carry contextual information during the whole cycle of a request. Basically, I want to assign a uuid to a request and after that, all logging related to that HTTP request, should print that request uuid.

https://www.playframework.com/documentation/2.6.x/ScalaLogging#using-markers-and-marker-contexts

I see the example with logstash, but I don't use logstash.

I know it can be done with the MDC. Can/How can it be done with Logging Markers ?

答:
You don't say what your logging configuration looks like. The examples from your link use the marker to annotate each log entry. If you go to the next link, SettingsLogger, you will see how to configure logback to print out your logs to a file. You will need to modify the layout encoder to add "%marker" to the pattern layout. For instance,

```<code> "%-5level (%marker)[%thread]: %message%n"
</code>```

will print out your log item with the UUID just before the thread name.

Body:
You don't say what your logging configuration looks like. The examples from your link use the marker to annotate each log entry. If you go to the next link, SettingsLogger, you will see how to configure logback to print out your logs to a file. You will need to modify the layout encoder to add "%marker" to the pattern layout. For instance,

 "%-5level (%marker)[%thread]: %message%n"

will print out your log item with the UUID just before the thread name.


答:
Use a label around the content.

$(function() {

  $(".close").on('change', function(e) {
    var el = $(this); {
      $(".close").not(el).prop('checked', false);
    }

  });

});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  background: #cacaca;
  margin: 0;
  padding: 20px;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
}

#table {
  display: table;
  width: 100%;
  background: #fff;
  margin: 0;
  box-sizing: border-box;
}

.caption {
  display: block;
  width: 100%;
  background: #64e0ef;
  height: 55px;
  padding-left: 10px;
  color: #fff;
  font-size: 20px;
  line-height: 55px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
  box-sizing: border-box;
}

.header-row {
  background: #8b8b8b;
  color: #fff;
}

.row {
  display: table-row;
}

.cell {
  display: table-cell;
  padding: 6px;
  border-bottom: 1px solid #e5e5e5;
  text-align: center;
}

.primary {
  text-align: left;
}

input[type="radio"],
input[type="checkbox"] {
  display: none;
}

@media only screen and (max-width: 760px) {
  body {
    padding: 0;
  }
  #table {
    display: block;
    margin: 44px 0 0 0;
  }
  .caption {
    position: fixed;
    top: 0;
    text-align: center;
    height: 44px;
    line-height: 44px;
    z-index: 5;
    border-bottom: 2px solid #999;
  }
  .row {
    position: relative;
    display: block;
    border-bottom: 1px solid #ccc;
  }
  .header-row {
    display: none;
  }
  .cell {
    display: block;
    border: none;
    position: relative;
    height: 45px;
    line-height: 45px;
    text-align: left;
  }
  .primary:after {
    content: "";
    display: block;
    position: absolute;
    right: 20px;
    top: 18px;
    z-index: 2;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #ccc;
  }
  .cell:nth-of-type(n+2) {
    display: none;
  }
  input[type="radio"],
  input[type="checkbox"] {
    display: block;
    position: absolute;
    z-index: 1;
    width: 99%;
    height: 100%;
    opacity: 0;
  }
  input[type="radio"]:checked,
  input[type="checkbox"]:checked {
    z-index: -1;
  }
  input[type="radio"]:checked~.cell,
  input[type="checkbox"]:checked~.cell {
    display: block;
    border-bottom: 1px solid #eee;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2),
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2) {
    background: #e0e0e0;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2):before,
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2):before {
    content: attr(data-label);
    display: inline-block;
    width: 60px;
    background: #999;
    border-radius: 10px;
    height: 20px;
    margin-right: 10px;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    color: white;
  }
  input[type="radio"]:checked~.primary,
  input[type="checkbox"]:checked~.primary {
    border-bottom: 2px solid #999;
  }
  input[type="radio"]:checked~.primary:after,
  input[type="checkbox"]:checked~.primary:after {
    position: absolute;
    right: 18px;
    top: 22px;
    border-right: 10px solid transparent;
    border-left: 10px solid transparent;
    border-top: 10px solid #ccc;
    z-index: 2;
  }
}</code>```

Main Title

    Developer
    Foundation
    Accelerator
    Enterprise

    <input type="checkbox" name="expand" class="close">
    Item 1
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 2
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 3
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 4
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 5
    Sub Item
    Sub Item
    Sub Item
    Sub Item

    <input type="checkbox" name="expand" class="close">
    Item 6
    Sub Item
    Sub Item
    Sub Item
    Sub Item

```

Title: Unable to uncheck input type checkbox in mobile view

Body:
Use a label around the content.

$(function() {

  $(".close").on('change', function(e) {
    var el = $(this); {
      $(".close").not(el).prop('checked', false);
    }

  });

});

body {
  background: #cacaca;
  margin: 0;
  padding: 20px;
  font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  font-weight: 300;
}

#table {
  display: table;
  width: 100%;
  background: #fff;
  margin: 0;
  box-sizing: border-box;
}

.caption {
  display: block;
  width: 100%;
  background: #64e0ef;
  height: 55px;
  padding-left: 10px;
  color: #fff;
  font-size: 20px;
  line-height: 55px;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .3);
  box-sizing: border-box;
}

.header-row {
  background: #8b8b8b;
  color: #fff;
}

.row {
  display: table-row;
}

.cell {
  display: table-cell;
  padding: 6px;
  border-bottom: 1px solid #e5e5e5;
  text-align: center;
}

.primary {
  text-align: left;
}

input[type="radio"],
input[type="checkbox"] {
  display: none;
}

@media only screen and (max-width: 760px) {
  body {
    padding: 0;
  }
  #table {
    display: block;
    margin: 44px 0 0 0;
  }
  .caption {
    position: fixed;
    top: 0;
    text-align: center;
    height: 44px;
    line-height: 44px;
    z-index: 5;
    border-bottom: 2px solid #999;
  }
  .row {
    position: relative;
    display: block;
    border-bottom: 1px solid #ccc;
  }
  .header-row {
    display: none;
  }
  .cell {
    display: block;
    border: none;
    position: relative;
    height: 45px;
    line-height: 45px;
    text-align: left;
  }
  .primary:after {
    content: "";
    display: block;
    position: absolute;
    right: 20px;
    top: 18px;
    z-index: 2;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 10px solid #ccc;
  }
  .cell:nth-of-type(n+2) {
    display: none;
  }
  input[type="radio"],
  input[type="checkbox"] {
    display: block;
    position: absolute;
    z-index: 1;
    width: 99%;
    height: 100%;
    opacity: 0;
  }
  input[type="radio"]:checked,
  input[type="checkbox"]:checked {
    z-index: -1;
  }
  input[type="radio"]:checked~.cell,
  input[type="checkbox"]:checked~.cell {
    display: block;
    border-bottom: 1px solid #eee;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2),
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2) {
    background: #e0e0e0;
  }
  input[type="radio"]:checked~.cell:nth-of-type(n+2):before,
  input[type="checkbox"]:checked~.cell:nth-of-type(n+2):before {
    content: attr(data-label);
    display: inline-block;
    width: 60px;
    background: #999;
    border-radius: 10px;
    height: 20px;
    margin-right: 10px;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    color: white;
  }
  input[type="radio"]:checked~.primary,
  input[type="checkbox"]:checked~.primary {
    border-bottom: 2px solid #999;
  }
  input[type="radio"]:checked~.primary:after,
  input[type="checkbox"]:checked~.primary:after {
    position: absolute;
    right: 18px;
    top: 22px;
    border-right: 10px solid transparent;
    border-left: 10px solid transparent;
    border-top: 10px solid #ccc;
    z-index: 2;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="caption">Main Title</div>
<div id="table">
  <div class="header-row row">
    <span class="cell primary">
      <!--stuff here to add text in first prim cell --></span>
    <span class="cell">Developer</span>
    <span class="cell">Foundation</span>
    <span class="cell">Accelerator</span>
    <span class="cell">Enterprise</span>
  </div>
  <div class="row"><label>
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 1</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
</label>
  </div>
  <div class="row"><label>
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 2</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
</label>
  </div>
  <div class="row"><label>
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 3</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span></label>
  </div>
  <div class="row"><label>
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 4</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span></label>
  </div>
  <div class="row"><label>
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 5</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span></label>
  </div>
  <div class="row"><label>
    <input type="checkbox" name="expand" class="close">
    <span class="cell primary" data-label="Category">Item 6</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span>
    <span class="cell" data-label="Category">Sub Item</span></label>
  </div>
</div>


问:
How do I set LoginBehaviour when using react-native-fbsdk LoginManager?
If I use the LoginButton from react-native-fbsdk the LoginBehaviour seems to be "native" in that the SDK communicates with the installed FB app, sees that I've already granted permissions and just logs me in without showing any dialogs, etc.

When I use the LoginManger.logInWithPublishPermissions() mechanism I'm always taken to the brower and a screen that says I've already given permission to my app. I assume I can change this by setting the login behaviour, but I can't figure out how to do that successfully. Here's what I've tried

```<code>import { GraphRequest, GraphRequestManager, LoginManager, LoginBehaviorIOS } from 'react-native-fbsdk';
LoginManager.setLoginBehavior(LoginBehaviorIOS);

//ERROR: Argument 0 (FBSDKLoginBehaviour) of FBLoginManager: must not be null
</code>```

Then I tried this:

```<code>LoginManager.setLoginBehavior('native');

// No error, but still gives me the same behaviour.
</code>```

When do LoginButton and LoginManager act differently? How do I set the login behaviour when using LoginManager so it works like the LoginButton?

I've added all of the code to the AppDelegate.m file and all other instructions included in the Getting Started Guide: https://developers.facebook.com/docs/ios/getting-started/

答:
I had a similar issue and managed to make it work by setting the login behavior as follows:

```<code>LoginManager.setLoginBehavior('NATIVE_ONLY');
</code>```

Facebook documentation is poor even in react-native-fbsdk GitHub repo about the subject :(

EDIT:
There is a catch by using natie_only behavior. User must have FB installed at this phone, otherwise the FB SDK fails silently. To address that I decided to launch the WEB_ONLY behavior in case the native_only fails. My example is tested for Android, not iOS yet.

```<code>let result;
try {
  LoginManager.setLoginBehavior('NATIVE_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
} catch (error) {
  LoginManager.setLoginBehavior('WEB_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
}
</code>```

EDIT EDIT:
I published an article on how to use Facebook SDK in React Native where I mention more stuff (i.e. how to perform graph requests). Check it out if you need more info on the subject.

Body:
If I use the LoginButton from react-native-fbsdk the LoginBehaviour seems to be "native" in that the SDK communicates with the installed FB app, sees that I've already granted permissions and just logs me in without showing any dialogs, etc.

When I use the LoginManger.logInWithPublishPermissions() mechanism I'm always taken to the brower and a screen that says I've already given permission to my app. I assume I can change this by setting the login behaviour, but I can't figure out how to do that successfully. Here's what I've tried

import { GraphRequest, GraphRequestManager, LoginManager, LoginBehaviorIOS } from 'react-native-fbsdk';
LoginManager.setLoginBehavior(LoginBehaviorIOS);

//ERROR: Argument 0 (FBSDKLoginBehaviour) of FBLoginManager: must not be null

Then I tried this:

LoginManager.setLoginBehavior('native');

// No error, but still gives me the same behaviour.

When do LoginButton and LoginManager act differently? How do I set the login behaviour when using LoginManager so it works like the LoginButton?

I've added all of the code to the AppDelegate.m file and all other instructions included in the Getting Started Guide: https://developers.facebook.com/docs/ios/getting-started/

Body:
I had a similar issue and managed to make it work by setting the login behavior as follows:

LoginManager.setLoginBehavior('NATIVE_ONLY');

Facebook documentation is poor even in react-native-fbsdk GitHub repo about the subject :(

EDIT:
There is a catch by using natie_only behavior. User must have FB installed at this phone, otherwise the FB SDK fails silently. To address that I decided to launch the WEB_ONLY behavior in case the native_only fails. My example is tested for Android, not iOS yet.

let result;
try {
  LoginManager.setLoginBehavior('NATIVE_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
} catch (error) {
  LoginManager.setLoginBehavior('WEB_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
}

EDIT EDIT:
I published an article on how to use Facebook SDK in React Native where I mention more stuff (i.e. how to perform graph requests). Check it out if you need more info on the subject.


问:
Complex object sent to web api angular 4
I'm trying to make a put request with the new HttpClient and HttpParams but it seems i can't send properly the updated object. I'm trying to put the object as a parameter like this :This is where i make my request and this is my class : myclass those are he request headers enter image description here and the params section :enter image description here the request response throws null reference exception because it can't map them i guess ?</p>

答:
HttpParams should be 3rd argument. So you should call put like this:</p>

```<code>this.http.put(this.url, myComplexObject, this.options);
</code>```

Body:
HttpParams should be 3rd argument. So you should call put like this:

this.http.put(this.url, myComplexObject, this.options);


问:
gulp-eslint: How to configure the "no-use-before-define" rule
I'm trying to turn off the "no-use-before-define" rule for functions, but leave it active for variables and classes.

In the documentation found here http://eslint.org/docs/rules/no-use-before-define it says that this is the correct configuration syntax:

```<code>"no-use-before-define": ["error", { "functions": false, "classes": true, "variables ": true }]
</code>```

When I run with that though I get this error:

```<code>[21:00:46] Error: CLI:
    Configuration for rule "no-use-before-define" is invalid:
    Severity should be one of the following: 0 = off, 1 = warning, 2 = error (you passed "error").
    Value "[object Object]" must be an enum value.

    at Object.validateRuleOptions (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\config\config-validator.js:102:15)
    at CLIEngine.<anonymous> (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine.js:421:19)
    at Array.forEach (native)
    at new CLIEngine (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine.js:420:43)
    at Object.gulpEslint (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\index.js:17:15)
    at E:/01-Dans stuff/Projects/00 - YeoSword/YeoSword-git/gulp/tasks/eslint.js:24:16
    at taskWrapper (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\undertaker\lib\set-task.js:13:15)
    at bound (domain.js:287:14)
    at runBound (domain.js:300:12)
    at asyncRunner (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\async-done\index.js:36:18)
</code>```

I know that the gulp-eslint syntax is a little bit different from the official eslint configuration syntax.

I can't figure out what the gulp-eslint syntax is for the { "functions": false, "classes": true, "variables ": true } bit though. There doesn't seem to be any documentation for it anywhere.

答:
You have an extra space in your rule, just after the word 'variables':

"no-use-before-define": ["error", { "functions": false, "classes": true, "variables ": true }]

This is illegal and would generate an error.

Body:
I'm trying to turn off the "no-use-before-define" rule for functions, but leave it active for variables and classes.

In the documentation found here http://eslint.org/docs/rules/no-use-before-define it says that this is the correct configuration syntax:

"no-use-before-define": ["error", { "functions": false, "classes": true, "variables ": true }]

When I run with that though I get this error:

[21:00:46] Error: CLI:
    Configuration for rule "no-use-before-define" is invalid:
    Severity should be one of the following: 0 = off, 1 = warning, 2 = error (you passed "error").
    Value "[object Object]" must be an enum value.

    at Object.validateRuleOptions (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\config\config-validator.js:102:15)
    at CLIEngine.<anonymous> (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine.js:421:19)
    at Array.forEach (native)
    at new CLIEngine (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\node_modules\eslint\lib\cli-engine.js:420:43)
    at Object.gulpEslint (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\gulp-eslint\index.js:17:15)
    at E:/01-Dans stuff/Projects/00 - YeoSword/YeoSword-git/gulp/tasks/eslint.js:24:16
    at taskWrapper (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\undertaker\lib\set-task.js:13:15)
    at bound (domain.js:287:14)
    at runBound (domain.js:300:12)
    at asyncRunner (E:\01-Dans stuff\Projects\00 - YeoSword\YeoSword-git\node_modules\async-done\index.js:36:18)

I know that the gulp-eslint syntax is a little bit different from the official eslint configuration syntax.

I can't figure out what the gulp-eslint syntax is for the { "functions": false, "classes": true, "variables ": true } bit though. There doesn't seem to be any documentation for it anywhere.


问:
How do I properly manage user permission on PHP?
I have read about ACL (Access Control Lists) but I don’t get what is the point of using it more than a pyramidal way of thinking. (Controller Admin extends Moderator which extends User).

What is the best way of doing it? Is it a bad practice to stack extends?

答:
Stacking extends is never really an issue if the objects belong to each other and have parental 'value'. So Admin -> Moderator -> User -> Anonymous -> UserBase is fine for authorization layering.

But as Giulio already mentioned, implementations of this are wide and broadly different across multiple projects, one can use packages or roll their own (if they know what they are doing, otherwise its a lot safer to go for preexisting packages like the ones mentioned above)


问:
ANTLR4 tells me: mismatched input 'little' expecting {'big', 'little'}
I have the following simple grammar:

```<code>grammar TestG;

p : pDecl+ ;

pDecl : endianDecl
    | dTDecl
    ;

endianType : E_BIG
    | E_LITTLE
    ;

endianDecl : 'endian' '=' endianType ';' ;

dTDecl : 'dT' '[' STRING ']' '=' ID ';' ;

STRING: '"'.*?'"' ;                //Embedded quotes?
COMMENT: '#' .*? [\n\r] -> skip ;  // Discard comments for now
ID :   [a-zA-Z][a-zA-Z0-9_]* ;
WS :   [ \t\n\r]+ -> skip ;
INT : ('0x')?[0-9]+ ;  // How to handle 0xDD and ensure non zero?
E_BIG : 'big' ;
E_LITTLE : 'little' ;
</code>```

When I run grun TestG p and input the following:

```<code>endian = little;
</code>```

I get the following:

```<code>line 1:9 mismatched input 'little' expecting {'big', 'little'}
</code>```

What have I done wrong?

答:
Because your lexer rule for ID precedes that for E_LITTLE, your 'little' input is being lexed as an ID.

```<code>[@0,0:5='endian',<'endian'>,1:0]
[@1,7:7='=',<'='>,1:7]
[@2,9:14='little',<ID>,1:9] <== see here it's being lexed as an ID
[@3,15:15=';',<';'>,1:15]
[@4,18:17='<EOF>',<EOF>,2:0]
line 1:9 mismatched input 'little' expecting {'big', 'little'}
</code>```

Moving the these lexer tokens above ID like so:

```<code>STRING: '"'.*?'"' ;                //Embedded quotes?
COMMENT: '#' .*? [\n\r] -> skip ;  // Discard comments for now
E_BIG : 'big' ;
E_LITTLE : 'little' ;
ID :   [a-zA-Z][a-zA-Z0-9_]* ;
WS :   [ \t\n\r]+ -> skip ;
INT : ('0x')?[0-9]+ ;  // How to handle 0xDD and ensure non zero?
</code>```

yields the correct output from your test input.

```<code>[@0,0:5='endian',<'endian'>,1:0]
[@1,7:7='=',<'='>,1:7]
[@2,9:14='little',<'little'>,1:9] <== see here being lexed correctly
[@3,15:15=';',<';'>,1:15]
[@4,18:17='<EOF>',<EOF>,2:0]
</code>```

Remember, for lexer tokens, the longest match wins, but in the case of a tie, the one that appears FIRST wins.  This is why you want your more specific lexer tokens at the top of the lexer token list, and the more general ones (like identifiers, strings, etc.) farther down.

Body:
I have the following simple grammar:

grammar TestG;

p : pDecl+ ;

pDecl : endianDecl
    | dTDecl
    ;

endianType : E_BIG
    | E_LITTLE
    ;

endianDecl : 'endian' '=' endianType ';' ;

dTDecl : 'dT' '[' STRING ']' '=' ID ';' ;

STRING: '"'.*?'"' ;                //Embedded quotes?
COMMENT: '#' .*? [\n\r] -> skip ;  // Discard comments for now
ID :   [a-zA-Z][a-zA-Z0-9_]* ;
WS :   [ \t\n\r]+ -> skip ;
INT : ('0x')?[0-9]+ ;  // How to handle 0xDD and ensure non zero?
E_BIG : 'big' ;
E_LITTLE : 'little' ;

When I run grun TestG p and input the following:

endian = little;

I get the following:

line 1:9 mismatched input 'little' expecting {'big', 'little'}

What have I done wrong?

Body:
Because your lexer rule for ID precedes that for E_LITTLE, your 'little' input is being lexed as an ID.

[@0,0:5='endian',<'endian'>,1:0]
[@1,7:7='=',<'='>,1:7]
[@2,9:14='little',<ID>,1:9] <== see here it's being lexed as an ID
[@3,15:15=';',<';'>,1:15]
[@4,18:17='<EOF>',<EOF>,2:0]
line 1:9 mismatched input 'little' expecting {'big', 'little'}

Moving the these lexer tokens above ID like so:

STRING: '"'.*?'"' ;                //Embedded quotes?
COMMENT: '#' .*? [\n\r] -> skip ;  // Discard comments for now
E_BIG : 'big' ;
E_LITTLE : 'little' ;
ID :   [a-zA-Z][a-zA-Z0-9_]* ;
WS :   [ \t\n\r]+ -> skip ;
INT : ('0x')?[0-9]+ ;  // How to handle 0xDD and ensure non zero?

yields the correct output from your test input.

[@0,0:5='endian',<'endian'>,1:0]
[@1,7:7='=',<'='>,1:7]
[@2,9:14='little',<'little'>,1:9] <== see here being lexed correctly
[@3,15:15=';',<';'>,1:15]
[@4,18:17='<EOF>',<EOF>,2:0]

Remember, for lexer tokens, the longest match wins, but in the case of a tie, the one that appears FIRST wins.  This is why you want your more specific lexer tokens at the top of the lexer token list, and the more general ones (like identifiers, strings, etc.) farther down.


问:
Retrieve Criteria1 values of filtered data based on Date
I have a worksheet filtered based on several criteria, one of which is based on date( I want the dates in 2018 for example)

I have found various routines such as the following:

http://www.vbaexpress.com/forum/archive/index.php/t-7564.html

However, whenever the loop goes to the column with the date criteria, the code crashes on the following line:

```<code>sMsg = sMsg & vbCrLf & sField & oFlt.Criteria1
</code>```

Do you have any idea how I can retrieve the criteria based on a date?

Regards

Thanasis

答:
Try to add this before the line with the error:

```<code>MsgBox CDate(oFlt.Criteria1)
sMsg = sMsg & vbCrLf & sField & oFlt.Criteria1
</code>```

Then try to work it out until you manage to get it through. Probably the Criteria1 cannot be converted as a date or similar.

Body:
I have a worksheet filtered based on several criteria, one of which is based on date( I want the dates in 2018 for example)

I have found various routines such as the following:

http://www.vbaexpress.com/forum/archive/index.php/t-7564.html

However, whenever the loop goes to the column with the date criteria, the code crashes on the following line:

sMsg = sMsg & vbCrLf & sField & oFlt.Criteria1

Do you have any idea how I can retrieve the criteria based on a date?

Regards

Thanasis

Body:
Try to add this before the line with the error:

MsgBox CDate(oFlt.Criteria1)
sMsg = sMsg & vbCrLf & sField & oFlt.Criteria1

Then try to work it out until you manage to get it through. Probably the Criteria1 cannot be converted as a date or similar.


问:
users?$expand=drive fails with InternalServerError
We want to be able to include the information about each individual user's personal site (OneDrive for Business) within a collection, to avoid inefficient subsequent requests to Microsoft Graph.

Microsoft Graph API doesn't allow to query for the mySite field when getting a user collection via /users?$select=id,mail,mySite. This fact is documented in the Graph API docs. Thus we were looking for an alternative, and came across:

```<code>GET /users?$expand=drive
</code>```

or

```<code>GET /users?$expand=drives
</code>```

because drive corresponds to the user's personal drive and has the field webUrl which is the same as mySite.

But the requests result in the following error:

{
    "error": {
        "code": "InternalServerError",
        "message": "Value cannot be null. Parameter name: source",
        "innerError": {
            "request-id": "15d69169-937a-4525-a904-e4107704d8f1",
            "date": "2017-11-08T02:11:17"
        }
    }
}
```

<p>This is a valid documented relationship. Also nowhere is it documented that this use of the <code>$expand</code> query parameter is not supported. Though there is a note here that says <code>$expand</code> is for now only supported by the <code>beta/users</code>, but this still fails with the same error.</p>

<p>A potential cause of the error could be that the user hasn't created a personal site yet, thus we tried <code>drives</code> (as stated above) assuming it might just return an empty list and also the following:</p>

```GET /users?$expand=drive&$filter=drive ne null
```

But this also returns an error, stating that Filter is not supported. Though that $filter can't be used like that is not documented. Only that $expand=drive($select=webUrl;$filter=webUrl ne null) is not supported as documented here (if we understand that correctly).

We searched the office feature suggestion platform, Stack Overflow, and the Microsoft's tech community developer group, without success.

There is still the discovery API but this is not really an option because we use an app-only token. Furthermore does it look like that Microsoft Graph is also supposed to replace it, as mentioned here.

答:
Expanding a drive from a user entity isn't supported by Microsoft Graph. As to why, I will attempt to explain.

To understand this behavior, it's imported to consider where a given entity is sourced from. In this case the user comes from Active Directory while the drive is sources from SharePoint.

As noted in the documentation:

Note: Not all relationships and resources support the $expand query parameter. For example, you can expand the directReports, manager, and memberOf relationships on a user, but you cannot expand its events, messages, or photo relationships.

Using just the example, notices that directReports, manager, and memberOf are all sourced from AD while events, messages, or photo are all source from Exchange.

What the documentation is attempting to explain (albeit in a rather confusing and round-about way) is that $expand can't cross service boundaries. If the relationship crosses from one service to another (i.e. Exchange and SharePoint), Microsoft Graph isn't able to navigate across that boundary in a single call.

Part of this stems from the various services surfaced through Microsoft Graph having different rules and constraints. For example, Exchange has different rules around throttling than OneNote. Crossing between services via $expand would present problems when it comes to resolving which rules to apply.

Hope this helps.

Body:
We want to be able to include the information about each individual user's personal site (OneDrive for Business) within a collection, to avoid inefficient subsequent requests to Microsoft Graph.

Microsoft Graph API doesn't allow to query for the mySite field when getting a user collection via /users?$select=id,mail,mySite. This fact is documented in the Graph API docs. Thus we were looking for an alternative, and came across:

GET /users?$expand=drive

or

GET /users?$expand=drives

because drive corresponds to the user's personal drive and has the field webUrl which is the same as mySite.

But the requests result in the following error:

{
    "error": {
        "code": "InternalServerError",
        "message": "Value cannot be null. Parameter name: source",
        "innerError": {
            "request-id": "15d69169-937a-4525-a904-e4107704d8f1",
            "date": "2017-11-08T02:11:17"
        }
    }
}

This is a valid documented relationship. Also nowhere is it documented that this use of the $expand query parameter is not supported. Though there is a note here that says $expand is for now only supported by the beta/users, but this still fails with the same error.

A potential cause of the error could be that the user hasn't created a personal site yet, thus we tried drives (as stated above) assuming it might just return an empty list and also the following:

GET /users?$expand=drive&$filter=drive ne null

But this also returns an error, stating that Filter is not supported. Though that $filter can't be used like that is not documented. Only that $expand=drive($select=webUrl;$filter=webUrl ne null) is not supported as documented here (if we understand that correctly).

We searched the office feature suggestion platform, Stack Overflow, and the Microsoft's tech community developer group, without success.

There is still the discovery API but this is not really an option because we use an app-only token. Furthermore does it look like that Microsoft Graph is also supposed to replace it, as mentioned here.


问:
How Do I collapse rows on null values in t-sql?
I'm in a weird situation with my query. My objective is to display the total deposits and withdrawals from multiple transactions for each person and display them. I am getting multiple rows that I need to collapse into one. This all needs to happen in one query

```<code>SELECT
       lastname,
       firsname,
       case when upper(category) = 'W' then sum(abs(principal)) end as Withdrawal,
       case when upper(category) = 'D' then sum(abs(principal)) end as Deposit,
       description
FROM
       table1
       JOIN table2 ON table1.id = table2.id
       JOIN table3 ON table2.c = table3.c
WHERE
       description = 'string'
GROUP BY
       lastname,
       firstname,
       description,
       category
</code>```

my result is

```<code> lastname    firstname    Withdrawal    Deposit    description
 john         smith       null           140.34    string
 john         smith       346.00          null     string
 jane         doe         null           68.03     string
 jane         doe         504.00          null     string
</code>```

and I am looking for

```<code> lastname    firstname    Withdrawal    Deposit    description
 john         smith       346.00        140.34     string
 jane         doe         504.00        68.03      string
</code>```

adding principal into the group does not work. any help on solving this will be greatly appreciated!

答:
Use conditional aggregation . . . the case is the argument to the sum():

```<code>select lastname, firsname,
       sum(case when upper(category) = 'W' then abs(principal) end) as Withdrawal,
       sum(case when upper(category) = 'D' then abs(principal) end) as Deposit,
       description
from table1 join
     table2
     on table2.id = table1.id join
     table3
     on table3.c = table2.c
where description = 'string'
group by lastname, firstname, description
</code>```

Body:
I'm in a weird situation with my query. My objective is to display the total deposits and withdrawals from multiple transactions for each person and display them. I am getting multiple rows that I need to collapse into one. This all needs to happen in one query

SELECT
       lastname,
       firsname,
       case when upper(category) = 'W' then sum(abs(principal)) end as Withdrawal,
       case when upper(category) = 'D' then sum(abs(principal)) end as Deposit,
       description
FROM
       table1
       JOIN table2 ON table1.id = table2.id
       JOIN table3 ON table2.c = table3.c
WHERE
       description = 'string'
GROUP BY
       lastname,
       firstname,
       description,
       category

my result is

 lastname    firstname    Withdrawal    Deposit    description
 john         smith       null           140.34    string
 john         smith       346.00          null     string
 jane         doe         null           68.03     string
 jane         doe         504.00          null     string

and I am looking for

 lastname    firstname    Withdrawal    Deposit    description
 john         smith       346.00        140.34     string
 jane         doe         504.00        68.03      string

adding principal into the group does not work. any help on solving this will be greatly appreciated!

Body:
Use conditional aggregation . . . the case is the argument to the sum():

select lastname, firsname,
       sum(case when upper(category) = 'W' then abs(principal) end) as Withdrawal,
       sum(case when upper(category) = 'D' then abs(principal) end) as Deposit,
       description
from table1 join
     table2
     on table2.id = table1.id join
     table3
     on table3.c = table2.c
where description = 'string'
group by lastname, firstname, description


问:
Restrict the value based on the value in other connected cell (both dependent on the same list)
```<code>    Sub Macro1()
'
' Macro1 Macro
'

'
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Sheet2!$A:$A"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    End Sub
</code>```

I have this VBA code which selects the dropdown values from list in sheet 2.
What I need is the following:
 Now the options shown in "A2" cell's dropdown should be all but A001 i.e. except the one that has been already selected above...And similarly with all the other dropdowns in the first column.

答:
I was rerouted here for my question being a "duplicate" but I'm not following the example above on how I would accomplish the following:

This question already has an answer here:
Restrict the value based on the value in other connected cell (both dependent on the same list)  1 answer

I have a drop down list of the following:

Max85k, Max110k, Max125k, Max150k, Max175k

These refer to the max amount that can fit into these buckets.

If the amount that is listed in another cell on my sheet is $105k for example, I don't want the Max85k selection to be allowed. If the value is 83K for example then all of the selections would be allowed b/c that amount could fit into any of the buckets. If the value was 135k then only the max150k and max175k selections would be allowed. Etc Etc.

Is there a way to do this?

Body:
    Sub Macro1()
'
' Macro1 Macro
'

'
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Sheet2!$A:$A"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    End Sub

I have this VBA code which selects the dropdown values from list in sheet 2.
What I need is the following:
 Now the options shown in "A2" cell's dropdown should be all but A001 i.e. except the one that has been already selected above...And similarly with all the other dropdowns in the first column.


问:
Design issue (how to avoid to break LSP)
I got the following two interfaces:

```<code>interface IModule
{
    IModuleResult Invoke(InstallerContext context, IModuleConfiguration config);
}

interface IModuleConfiguration
{

}
</code>```

The IModuleConfiguration is used to configure each module. It loads/stores config settings in XML files and are configured through a web app.

The flow is:

Runner -> Load configurations from a single XML file -> Load runner instructions from another XML file -> Invoke selected modules

The design works, but each module only works with it's own configuration. It breaks LSP and I'm wondering if there are any better way to design this.

Using a interface IModule<T> where T : IModuleConfiguration would not break LSP, but makes it hard to work with each module (as I need to store them as object in the List and use reflection to invoke them).

答:
I'm not quite clear how instances of these types come into being, and to what extent they're supposed to be interchangeable.  One approach which can be useful in some contexts is to use delegates.  For example, suppose some type of object is supposed to provide a method to save its state and later restore it.  If the state is supposed to be restored to the same object from which it was saved, the 'save context' routine could return a delegate which, when executed, will restore the object's state.  The delegate could contain any type of data whatsoever, but all the code would be type-safe.

Other options would be to make IModuleConfiguration generic with respect to the type of module it configures, and have IModuleConfiguration contain a ConfigureModule or InvokeModule method (which would in turn pass itself to the module's Configure or Invoke method), or have an IConfiguredModule interface, whose invocation method wouldn't say anything about the configuration (instances of the class would be expected to combine a module with an appropriate configuration).

Which approach would be most suitable would depend upon how the various instances are created and used.

Body:
I got the following two interfaces:

interface IModule
{
    IModuleResult Invoke(InstallerContext context, IModuleConfiguration config);
}

interface IModuleConfiguration
{

}

The IModuleConfiguration is used to configure each module. It loads/stores config settings in XML files and are configured through a web app.

The flow is:

Runner -> Load configurations from a single XML file -> Load runner instructions from another XML file -> Invoke selected modules

The design works, but each module only works with it's own configuration. It breaks LSP and I'm wondering if there are any better way to design this.

Using a interface IModule<T> where T : IModuleConfiguration would not break LSP, but makes it hard to work with each module (as I need to store them as object in the List and use reflection to invoke them).


问:
Remove duplicates by multiple conditions
I have data where an individual (Name) appears multiple times in a eggphase category. I would like for there only to be one sample per individual but I don't just want to keep the first one the R finds. I would like to keep the one where the group appears most in all other categories. Hopefully my example helps make this clear.

```<code>library(tidyverse)
myDF <- read.table(text="Tissue Food Eggphase Name Group
  wb fl after Kia a
  wb fl after Kia c
  wb wf before Kia b
  wb fl before Lucy c
  wb fl after Lucy b
  wb fl after Lucy c
  wb fl yolkdep Jess c
  wb fl yolkdep Betty a
  wb fl yolkdep Betty b", header = TRUE)
</code>```

I would like to just keep the rows where Name appears once grouped by Tissue, Food and Eggphase BUT I want to select the row where Group appears in most if not all different eggphases (with the same Tissue and Food combinations).

```<code>   #results I want
  Tissue Food Eggphase  Name Group
1     wb   fl    after   Kia     c
2     wb   wf   before   Kia     b
3     wb   fl   before  Lucy     c
4     wb   fl    after  Lucy     c
5     wb   fl  yolkdep  Jess     c
6     wb   fl  yolkdep Betty     b
</code>```

I tried

```<code>one_bird <- myDF %>%
  distinct(Tissue, Food, Eggphase, Name, .keep_all = TRUE)
</code>```

but it only keeps the first entry

```<code>  Tissue Food Eggphase  Name Group
1     wb   fl    after   Kia     a
2     wb   wf   before   Kia     b
3     wb   fl   before  Lucy     c
4     wb   fl    after  Lucy     b
5     wb   fl  yolkdep  Jess     c
6     wb   fl  yolkdep Betty     b
</code>```

Any ideas in how to tell it select the row where Groupappears in most (if not all) of the eggphases within a Tissue Food combination?
In my example the group that appears the most within the Tissue and Food combination of wb and fl is c and b but Kia doesn't appear in Group b and so c is a better option. Like this example, my data has duplicates which are from groups which are not the most common Group, how do I make it choose next most common just for that row?

I hope I have made enough sense.

答:
One option would be to create a frequency column grouped by 'Tissue', 'Food', 'Group', and then do a descending arrange on 'n' and use distinct

```<code>library(dplyr)
myDF %>%
     group_by(Tissue, Food, Group) %>%
     mutate(n = n()) %>% arrange(Tissue, Food, Eggphase, Name, desc(n)) %>%
     ungroup %>%
     distinct(Tissue, Food, Eggphase, Name, .keep_all = TRUE) %>%
     select(-n)
</code>```

Body:
I have data where an individual (Name) appears multiple times in a eggphase category. I would like for there only to be one sample per individual but I don't just want to keep the first one the R finds. I would like to keep the one where the group appears most in all other categories. Hopefully my example helps make this clear.

library(tidyverse)
myDF <- read.table(text="Tissue Food Eggphase Name Group
  wb fl after Kia a
  wb fl after Kia c
  wb wf before Kia b
  wb fl before Lucy c
  wb fl after Lucy b
  wb fl after Lucy c
  wb fl yolkdep Jess c
  wb fl yolkdep Betty a
  wb fl yolkdep Betty b", header = TRUE)

I would like to just keep the rows where Name appears once grouped by Tissue, Food and Eggphase BUT I want to select the row where Group appears in most if not all different eggphases (with the same Tissue and Food combinations).

   #results I want
  Tissue Food Eggphase  Name Group
1     wb   fl    after   Kia     c
2     wb   wf   before   Kia     b
3     wb   fl   before  Lucy     c
4     wb   fl    after  Lucy     c
5     wb   fl  yolkdep  Jess     c
6     wb   fl  yolkdep Betty     b

I tried

one_bird <- myDF %>%
  distinct(Tissue, Food, Eggphase, Name, .keep_all = TRUE)

but it only keeps the first entry

  Tissue Food Eggphase  Name Group
1     wb   fl    after   Kia     a
2     wb   wf   before   Kia     b
3     wb   fl   before  Lucy     c
4     wb   fl    after  Lucy     b
5     wb   fl  yolkdep  Jess     c
6     wb   fl  yolkdep Betty     b

Any ideas in how to tell it select the row where Groupappears in most (if not all) of the eggphases within a Tissue Food combination?
In my example the group that appears the most within the Tissue and Food combination of wb and fl is c and b but Kia doesn't appear in Group b and so c is a better option. Like this example, my data has duplicates which are from groups which are not the most common Group, how do I make it choose next most common just for that row?

I hope I have made enough sense.

Body:
One option would be to create a frequency column grouped by 'Tissue', 'Food', 'Group', and then do a descending arrange on 'n' and use distinct

library(dplyr)
myDF %>%
     group_by(Tissue, Food, Group) %>%
     mutate(n = n()) %>% arrange(Tissue, Food, Eggphase, Name, desc(n)) %>%
     ungroup %>%
     distinct(Tissue, Food, Eggphase, Name, .keep_all = TRUE) %>%
     select(-n)


问:
Slicing Pandas Dataframe based on a value present in a column which is a list of lists
I have a Pandas Dataframe with a million rows (ids) with one of the columns as a list of lists.
e.g.

df = pd.DataFrame({'id' : [1,2,3,4] ,'token_list' : [['a','b','c'],['c','d'],['a','e','f'],['c','f']]})

I want to create a dictionary of all the unique tokens - 'a', 'b', 'c', 'e', 'f' (which i already have as a separate list) as keys and all the ids that each key is associated with. For eg, {'a' : [1,3], 'b': [1], 'c': [1,  2,4]..} and so on.

My problem is there are 12000 such tokens, and I do not want to use loops to run through each row in the first frame. And is in does not seem to work.

Body:
df.set_index('id')['token_list'].\
    apply(pd.Series).stack().reset_index(name='V').\
       groupby('V')['id'].apply(list).to_dict()
Out[359]: {'a': [1, 3], 'b': [1], 'c': [1, 2, 4], 'd': [2], 'e': [3], 'f': [3, 4]}


问:
Is there no way to iterate over or copy all the values of a Java ThreadLocal?
Context: </p>

```<code>static ThreadLocal<MyType> threadLocalMyType = ...
</code>```

<p>What i'd like is to say something like: </p>

```<code>for (ThreadLocalEntry e: threadLocalMyType.getMapLikeThing() {
    // Thread t = e.getKey();
    // I don't need the thread value right now, but it might be useful for
    // something else.

    MyType theMyType = e.getValue();
    // [...do something with theMyType...]
}
</code>```

答:
I came acrosss the same problem and after seeing the answers here, I decided to use a hybrid approach:

```<code>public class PersistentThreadLocal<T> extends ThreadLocal<T> {

    final Map<Thread, T> allValues;
    final Supplier<? extends T> valueGetter;

    public PersistentThreadLocal(Supplier<? extends T> initialValue) {
        this(0, initialValue);
    }

    public PersistentThreadLocal(int numThreads, Supplier<? extends T> initialValue) {
        allValues = Collections.synchronizedMap(
            numThreads > 0 ? new WeakHashMap<>(numThreads) : new WeakHashMap<>()
        );
        valueGetter = initialValue;
    }

    @Override
    protected T initialValue() {
        T value = valueGetter != null ? valueGetter.get() : super.initialValue();
        allValues.put(Thread.currentThread(), value);
        return value;
    }

    @Override
    public void set(T value) {
        super.set(value);
        allValues.put(Thread.currentThread(), value);
    }

    @Override
    public void remove() {
        super.remove();
        allValues.remove(Thread.currentThread());
    }

    public Collection<T> getAll() {
        return allValues.values();
    }

    public void clear() {
        allValues.clear();
    }
}
</code>```

EDIT: if you plan to use this with a ThreadPoolExecutor, change the WeakHashMap to a regular HashMap, otherwise strange things will happen!

Body:
Context:

static ThreadLocal<MyType> threadLocalMyType = ...

What i'd like is to say something like:

for (ThreadLocalEntry e: threadLocalMyType.getMapLikeThing() {
    // Thread t = e.getKey();
    // I don't need the thread value right now, but it might be useful for
    // something else.

    MyType theMyType = e.getValue();
    // [...do something with theMyType...]
}

Body:
I came acrosss the same problem and after seeing the answers here, I decided to use a hybrid approach:

public class PersistentThreadLocal<T> extends ThreadLocal<T> {

    final Map<Thread, T> allValues;
    final Supplier<? extends T> valueGetter;

    public PersistentThreadLocal(Supplier<? extends T> initialValue) {
        this(0, initialValue);
    }

    public PersistentThreadLocal(int numThreads, Supplier<? extends T> initialValue) {
        allValues = Collections.synchronizedMap(
            numThreads > 0 ? new WeakHashMap<>(numThreads) : new WeakHashMap<>()
        );
        valueGetter = initialValue;
    }

    @Override
    protected T initialValue() {
        T value = valueGetter != null ? valueGetter.get() : super.initialValue();
        allValues.put(Thread.currentThread(), value);
        return value;
    }

    @Override
    public void set(T value) {
        super.set(value);
        allValues.put(Thread.currentThread(), value);
    }

    @Override
    public void remove() {
        super.remove();
        allValues.remove(Thread.currentThread());
    }

    public Collection<T> getAll() {
        return allValues.values();
    }

    public void clear() {
        allValues.clear();
    }
}

EDIT: if you plan to use this with a ThreadPoolExecutor, change the WeakHashMap to a regular HashMap, otherwise strange things will happen!