问:
launching wireguard with a keybining in I3
i'm trying to use some keybinding to start my wireguard vpn, so I've used the following:

```<code>bindsym Ctrl+$alt+o exec --no-startup-id wg-quick down wg0 || wg-quick up wg0
</code>```

but nothing seems to happen, I've also tried to set the suid bit to wg-quick, but still no luck.
after reading that ||might cause some issue, i've also tried only the first part

```<code>bindsym Ctrl+$alt+o exec --no-startup-id wg-quick down wg0
</code>```

with and without --no-startup-id but with no luck.
Any ideas?

答:
This should be a solution:

Create and add the line to the file: /etc/sudoers.d/wg-quick

yourusername yourhostname = (root) NOPASSWD: /usr/bin/wg-quick

(https://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-password)

And then use the full path to wg0.conf in i3/config:

```<code>bindsym $mod+o exec "sudo wg-quick up /etc/wireguard/wg0.conf"
</code>```

Body:
i'm trying to use some keybinding to start my wireguard vpn, so I've used the following:

bindsym Ctrl+$alt+o exec --no-startup-id wg-quick down wg0 || wg-quick up wg0

but nothing seems to happen, I've also tried to set the suid bit to wg-quick, but still no luck.
after reading that ||might cause some issue, i've also tried only the first part

bindsym Ctrl+$alt+o exec --no-startup-id wg-quick down wg0

with and without --no-startup-id but with no luck.
Any ideas?

Body:
This should be a solution:

Create and add the line to the file: /etc/sudoers.d/wg-quick

yourusername yourhostname = (root) NOPASSWD: /usr/bin/wg-quick

(https://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-password)

And then use the full path to wg0.conf in i3/config:

bindsym $mod+o exec "sudo wg-quick up /etc/wireguard/wg0.conf"


来源: stackexchange

问:
RecyclerView data not showing
My ReycyclerView is not showing data, but once i removed .setHasFixedSize(true), then only it will display. However, this causes another problem. On the first time entering the fragment, it works fine, my actionBar is displaying, but on the second time, it somehow overlaps or pushes away my ActionBar.

I guess .sethasFixedSize is necessary but if i keep it, it will not display data. What causes this?

First time entering:

Second time entering (before notifyItemInserted()):

After notifyItemInserted():

fragment.xml:

```<code><RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/cartItemRv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>
</code>```

fragment.kt:

```<code>onCreateView() {
    binding.cartItemRv.layoutManager = LinearLayoutManager(context)
    binding.cartItemRv.setHasFixedSize(true)
    cartAdapter = CartAdapter(productNameList, productVariationList, cartItemList)
    binding.cartItemRv.adapter = cartAdapter

    //code for retrieving data from Firebase
    cartAdapter.notifyItemInserted(productNameList.size-1)
}
</code>```

Adapter:

```<code>class CartAdapter(...: RecyclerView.Adapter<CartAdapter.CartViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartViewHolder {
        val itemView = LayoutInflater.from(parent.context).inflate(R.layout.cart_item, parent, false)
        return CartViewHolder(itemView, mListener)
    }

    override fun onBindViewHolder(holder: CartViewHolder, position: Int) {
        ...
    }

    override fun getItemCount(): Int {
        return productNameList.size
    }

    inner class CartViewHolder(itemView: View, listener: onItemClickListener) : RecyclerView.ViewHolder(itemView){
        ...
    }
}
</code>```

答:
about sethasFixedSize , if the size of  your the RecyclerView depends on the adapter's content you have to set the sethasFixedSize vlaue :  false
otherwise set it true .

// for depending on adapter
mRecyclerView.setHasFixedSize(false);

// for doesn't  depend on adapter
mRecyclerView.setHasFixedSize(true);

ContentLicense: CC BY-SA 4.0

Title: RecyclerView data not showing

Body:
My ReycyclerView is not showing data, but once i removed .setHasFixedSize(true), then only it will display. However, this causes another problem. On the first time entering the fragment, it works fine, my actionBar is displaying, but on the second time, it somehow overlaps or pushes away my ActionBar.

I guess .sethasFixedSize is necessary but if i keep it, it will not display data. What causes this?

First time entering:

Second time entering (before notifyItemInserted()):

After notifyItemInserted():

fragment.xml:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/cartItemRv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

fragment.kt:

onCreateView() {
    binding.cartItemRv.layoutManager = LinearLayoutManager(context)
    binding.cartItemRv.setHasFixedSize(true)
    cartAdapter = CartAdapter(productNameList, productVariationList, cartItemList)
    binding.cartItemRv.adapter = cartAdapter

    //code for retrieving data from Firebase
    cartAdapter.notifyItemInserted(productNameList.size-1)
}

Adapter:

class CartAdapter(...: RecyclerView.Adapter<CartAdapter.CartViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartViewHolder {
        val itemView = LayoutInflater.from(parent.context).inflate(R.layout.cart_item, parent, false)
        return CartViewHolder(itemView, mListener)
    }

    override fun onBindViewHolder(holder: CartViewHolder, position: Int) {
        ...
    }

    override fun getItemCount(): Int {
        return productNameList.size
    }

    inner class CartViewHolder(itemView: View, listener: onItemClickListener) : RecyclerView.ViewHolder(itemView){
        ...
    }
}


问:
Why is it wrong to replace curly brackets of block with "do..end" in Ruby?
I am trying to use "reduce" to select the largest number in an array, and the specific logical judgment is written in a block. If I wrap the block in curly brackets, I get the expected result. If I wrap the block with "do..end", I get a TypeError (0 is not a symbol nor a string).

Here is the code:

```<code>p [5, 2, 9, 10, 7, 89, 70].reduce(0) { |acc, cv|
  if cv > acc
    acc = cv
  else
    acc
  end
}
</code>```

答:
The Ruby parser does not understand your code if you don't supply
the parenthesis for the p method.

This version works:

```<code>p([5, 2, 9, 10, 7, 89, 70].reduce(0) do |acc, cv|
  if cv > acc
    acc = cv
  else
    acc
  end
end)
</code>```

Body:
I am trying to use "reduce" to select the largest number in an array, and the specific logical judgment is written in a block. If I wrap the block in curly brackets, I get the expected result. If I wrap the block with "do..end", I get a TypeError (0 is not a symbol nor a string).

Here is the code:

p [5, 2, 9, 10, 7, 89, 70].reduce(0) { |acc, cv|
  if cv > acc
    acc = cv
  else
    acc
  end
}

Body:
The Ruby parser does not understand your code if you don't supply
the parenthesis for the p method.

This version works:

p([5, 2, 9, 10, 7, 89, 70].reduce(0) do |acc, cv|
  if cv > acc
    acc = cv
  else
    acc
  end
end)


问:
Logging exception without catching it
I want to log an unhandled exception in my domain layer without catching it.

I mean that the exception should be thrown after logging to be caught again in upper levels. As you know, throwing has an overhead that I want to avoid.

Any idea in Dotnet platform (C#) ?

答:
```<code>public static void Main(string[] args)
{
    try
    {
        throw new System.Exception("some exception");
    }
    catch (System.Exception ex) when (LogUsingSerilogOrNLogOrBla(ex)) { }
    finally
    {
        Console.WriteLine("exception logged, but not handled :), there is no need to throw");
    }
}

public static bool LogUsingSerilogOrNLogOrBla(System.Exception ex)
{
    Console.WriteLine(ex);
    return false;
}
</code>```

Title: Logging exception without catching it


问:
How to make segmentation mask using given coordinates in xml file in python?
I have xml files that contain coordinates for creating masks. I am using this code to pass the coordinates and to extract the mask from it:

```<code>def extract_masks(self, filename):
   # load and parse the file
    tree = ET.parse(filename)
    # get the root of the document
    root = tree.getroot()
    # extract each bounding box
    # get details of image
    info = self.image_info[image_id]
    # define box file location
    path = info['annotation']
    masks = np.zeros((224, 224), dtype=np.uint8)
    classes = []
    points = []
    for member in root.findall('object'):
      points = member[4].text
      print(points)
      point = np.array(points)
      cv2.fillPoly(masks, point, 255)
      #cv2.drawContours(masks, [pts],-1, (0,255,0), -1)
      classes.append(self.class_names.index(member[0].text))
    return masks, classes
</code>```

But I didn't get the required output instead I got the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-9-2d5205c6367c> in <module>()
      3 for image_id in image_ids:
      4     image = dataset_train.load_image(image_id)
----> 5     mask, class_ids = dataset_train.load_mask(image_id)
      6     visualize.display_top_masks(image, mask, class_ids, dataset_train.class_names)

1 frames
<ipython-input-7-110d0d3d701f> in extract_masks(self, filename)
     51           print(points)
     52           point = np.array(points)
---> 53           cv2.fillPoly(masks, [point], 255)
     54           #cv2.drawContours(masks, [pts],-1, (0,255,0), -1)
     55           classes.append(self.class_names.index(member[0].text))

TypeError: pts data type = 19 is not supported```
</div>
</div>
</p>
<p>Here is my XML file:</p>
```<annotation>
<folder>G:\Mask RCNN\train_xml</folder>
<filename>R_Image [1].jpeg</filename>
<path>G:\YOLO\Train\imagesR_Image [1].jpeg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>224</width>
<height>224</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>Meningioma</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<points>[[97,41], [96,42], [92,42], [91,43], [89,43], [88,44], [87,44], [86,45], [85,45], [81,49], [80,49], [74,55], [74,57], [73,58], [73,66], [74,67], [74,69], [75,70], [75,71], [76,72], [76,73], [81,78], [82,78], [86,82], [87,82], [91,86], [92,86], [96,90], [97,90], [99,92], [100,92], [101,93], [102,93], [103,94], [104,93], [105,94], [107,94], [108,93], [111,93], [112,92], [113,92], [114,91], [115,91], [119,87], [120,87], [120,86], [121,85], [121,84], [122,83], [122,82], [123,81], [123,80], [122,79], [122,72], [121,71], [121,70], [120,69], [120,68], [119,67], [119,66], [118,65], [118,64], [116,62], [116,61], [115,60], [115,58], [113,56], [113,55], [112,54], [112,45], [109,42], [107,42], [106,41]]</points>
<bndbox>
<xmin>117</xmin>
<ymin>77</ymin>
<xmax>166</xmax>
<ymax>111</ymax>
</bndbox>
</object>
</annotation>
```

Any assistance on this matter will be greatly appreciated, Thanks.

答:
As stated in my comment, I think you can parse the points coming from the xml file in a string form with the below function. The below should be more permissive to having spaces or brackets in a slighlty different arrangement.

polygon = "[[3603,100], [3676,110], [3676,137], [3603,147]  ]"
def points_string_to_array(points_string):
    # remove space and square brackets
    points_string = points_string.replace('[', '').replace(']', '').replace(' ', '')
    # create a 1D array with only floats
    polygon_array = np.array([float(x) for x in points_string.split(",")])
    # reshape the array to have a 2D array
    polygon_array = polygon_array.reshape((len(polygon_array)//2, 2))
    return polygon_array

points_string_to_array(polygon)
```
<p>For the below result:</p>
<pre class="lang-sh prettyprint-override"><code>array([[3603.,  100.],
       [3676.,  110.],
       [3676.,  137.],
       [3603.,  147.]])
</code>```

Body:
I have xml files that contain coordinates for creating masks. I am using this code to pass the coordinates and to extract the mask from it:

def extract_masks(self, filename):
   # load and parse the file
    tree = ET.parse(filename)
    # get the root of the document
    root = tree.getroot()
    # extract each bounding box
    # get details of image
    info = self.image_info[image_id]
    # define box file location
    path = info['annotation']
    masks = np.zeros((224, 224), dtype=np.uint8)
    classes = []
    points = []
    for member in root.findall('object'):
      points = member[4].text
      print(points)
      point = np.array(points)
      cv2.fillPoly(masks, point, 255)
      #cv2.drawContours(masks, [pts],-1, (0,255,0), -1)
      classes.append(self.class_names.index(member[0].text))
    return masks, classes

But I didn't get the required output instead I got the following error:

TypeError                                 Traceback (most recent call last)
<ipython-input-9-2d5205c6367c> in <module>()
      3 for image_id in image_ids:
      4     image = dataset_train.load_image(image_id)
----> 5     mask, class_ids = dataset_train.load_mask(image_id)
      6     visualize.display_top_masks(image, mask, class_ids, dataset_train.class_names)

1 frames
<ipython-input-7-110d0d3d701f> in extract_masks(self, filename)
     51           print(points)
     52           point = np.array(points)
---> 53           cv2.fillPoly(masks, [point], 255)
     54           #cv2.drawContours(masks, [pts],-1, (0,255,0), -1)
     55           classes.append(self.class_names.index(member[0].text))

TypeError: pts data type = 19 is not supported

Here is my XML file:

<annotation>
<folder>G:\Mask RCNN\train_xml</folder>
<filename>R_Image [1].jpeg</filename>
<path>G:\YOLO\Train\imagesR_Image [1].jpeg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>224</width>
<height>224</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>Meningioma</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<points>[[97,41], [96,42], [92,42], [91,43], [89,43], [88,44], [87,44], [86,45], [85,45], [81,49], [80,49], [74,55], [74,57], [73,58], [73,66], [74,67], [74,69], [75,70], [75,71], [76,72], [76,73], [81,78], [82,78], [86,82], [87,82], [91,86], [92,86], [96,90], [97,90], [99,92], [100,92], [101,93], [102,93], [103,94], [104,93], [105,94], [107,94], [108,93], [111,93], [112,92], [113,92], [114,91], [115,91], [119,87], [120,87], [120,86], [121,85], [121,84], [122,83], [122,82], [123,81], [123,80], [122,79], [122,72], [121,71], [121,70], [120,69], [120,68], [119,67], [119,66], [118,65], [118,64], [116,62], [116,61], [115,60], [115,58], [113,56], [113,55], [112,54], [112,45], [109,42], [107,42], [106,41]]</points>
<bndbox>
<xmin>117</xmin>
<ymin>77</ymin>
<xmax>166</xmax>
<ymax>111</ymax>
</bndbox>
</object>
</annotation>

Any assistance on this matter will be greatly appreciated, Thanks.

Body:
As stated in my comment, I think you can parse the points coming from the xml file in a string form with the below function. The below should be more permissive to having spaces or brackets in a slighlty different arrangement.

polygon = "[[3603,100], [3676,110], [3676,137], [3603,147]  ]"
def points_string_to_array(points_string):
    # remove space and square brackets
    points_string = points_string.replace('[', '').replace(']', '').replace(' ', '')
    # create a 1D array with only floats
    polygon_array = np.array([float(x) for x in points_string.split(",")])
    # reshape the array to have a 2D array
    polygon_array = polygon_array.reshape((len(polygon_array)//2, 2))
    return polygon_array

points_string_to_array(polygon)

For the below result:

array([[3603.,  100.],
       [3676.,  110.],
       [3676.,  137.],
       [3603.,  147.]])


问:
regular expression to match start character of string + space then digits like currency
How do I test a string that contains a character at the start then a space and whatever comes after that which could be an integer or float?

Example:

'$ 15'

'$ 15.95'

答:
You can use below regular expression :

. \d+(?:.\d+)?

Test it here : https://regex101.com/r/1oqIO8/1


问:
How to install rvlib?
I'm trying to install the rvlib on windows, but im finding some issues, this occur when python is building wheel for rvlib
Why im getting this error? Im already installed VS 14.0
How can i fix this "pragma warning" error?

:

```<code>```ERROR: Command errored out with exit status 1:
ERROR: Failed building wheel for rvlib
Running setup.py clean for rvlib
Failed to build rvlib
 running install
 c:\users\user\appdata\local\programs\python\python38\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.

 cl : Command line warning D9002 : ignoring unknown option '-std=c99'
 rvlib._rmath_ffi.c
 include\Rconfig.h(16): warning C4005: 'HAVE_HYPOT': macro redefinition
 c:\users\user\appdata\local\programs\python\python38\include\pyconfig.h(61): note: see previous definition of 'HAVE_HYPOT'
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc -Iinclude -Ic:\users\user\appdata\local\programs\python\python38\include -Ic:\users\user\appdata\local\programs\python\python38\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt" /Tcsrc\bd0.c /Fobuild\temp.win-amd64-3.8\Release\src\bd0.obj -DMATHLIB_STANDALONE -std=c99
 cl : Command line warning D9002 : ignoring unknown option '-std=c99'
 bd0.c
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\stdarg.h(13): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\stdarg.h(14): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\stdarg.h(29): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_stdio_config.h(12): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_stdio_config.h(13): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_stdio_config.h(131): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(15): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(16): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1130): warning C4996: '_vsnwprintf_l': This function or variable may be unsafe. Consider using _vsnwprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1640): warning C4996: '_vsnwprintf_l': This function or variable may be unsafe. Consider using _vsnwprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1662): warning C4996: '_vsnwprintf_l': This function or variable may be unsafe. Consider using _vsnwprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1797): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1798): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1854): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(2094): warning C4996: '_vsnwscanf_l': This function or variable may be unsafe. Consider using _vsnwscanf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(2116): warning C4996: '_vsnwscanf_l': This function or variable may be unsafe. Consider using _vsnwscanf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(2171): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(15): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(16): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1412): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1459): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1474): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1755): warning C4996: '_vsprintf_l': This function or variable may be unsafe. Consider using _vsprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1776): warning C4996: '_vsprintf_l': This function or variable may be unsafe. Consider using _vsprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1899): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2192): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2193): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2216): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2300): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2301): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2398): warning C4068: unknown pragma 'Rf_warning'
 src\bd0.c(42): warning C4068: unknown pragma 'Rf_warning'
 src\bd0.c(42): warning C4068: unknown pragma 'Rf_warning'
 src\bd0.c(42): error C2124: divide or mod by zero
 error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
 ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\user\appdata\local\programs\python\python38\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-d3kgh8kz\\rvlib_6ae0b3c702e9456c94dc497fe29412da\\setup.py'"'"'; __file__='"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-d3kgh8kz\\rvlib_6ae0b3c702e9456c94dc497fe29412da\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-62kmmddr\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\user\appdata\local\programs\python\python38\Include\rvlib' Check the logs for full command output.```
</code>```

答:
Got the exact same error. I could solve it by installing rvlib using conda.

```<code>conda install -c conda-forge rvlib
</code>```

Title: How to install rvlib?

Body:
I'm trying to install the rvlib on windows, but im finding some issues, this occur when python is building wheel for rvlib
Why im getting this error? Im already installed VS 14.0
How can i fix this "pragma warning" error?

:

```ERROR: Command errored out with exit status 1:
ERROR: Failed building wheel for rvlib
Running setup.py clean for rvlib
Failed to build rvlib
 running install
 c:\users\user\appdata\local\programs\python\python38\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.

 cl : Command line warning D9002 : ignoring unknown option '-std=c99'
 rvlib._rmath_ffi.c
 include\Rconfig.h(16): warning C4005: 'HAVE_HYPOT': macro redefinition
 c:\users\user\appdata\local\programs\python\python38\include\pyconfig.h(61): note: see previous definition of 'HAVE_HYPOT'
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc -Iinclude -Ic:\users\user\appdata\local\programs\python\python38\include -Ic:\users\user\appdata\local\programs\python\python38\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt" /Tcsrc\bd0.c /Fobuild\temp.win-amd64-3.8\Release\src\bd0.obj -DMATHLIB_STANDALONE -std=c99
 cl : Command line warning D9002 : ignoring unknown option '-std=c99'
 bd0.c
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\stdarg.h(13): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\stdarg.h(14): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\stdarg.h(29): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_stdio_config.h(12): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_stdio_config.h(13): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_stdio_config.h(131): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(15): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(16): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1130): warning C4996: '_vsnwprintf_l': This function or variable may be unsafe. Consider using _vsnwprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1640): warning C4996: '_vsnwprintf_l': This function or variable may be unsafe. Consider using _vsnwprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1662): warning C4996: '_vsnwprintf_l': This function or variable may be unsafe. Consider using _vsnwprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1797): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1798): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(1854): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(2094): warning C4996: '_vsnwscanf_l': This function or variable may be unsafe. Consider using _vsnwscanf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(2116): warning C4996: '_vsnwscanf_l': This function or variable may be unsafe. Consider using _vsnwscanf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_wstdio.h(2171): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(15): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(16): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1412): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1459): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1474): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1755): warning C4996: '_vsprintf_l': This function or variable may be unsafe. Consider using _vsprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1776): warning C4996: '_vsprintf_l': This function or variable may be unsafe. Consider using _vsprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(1899): warning C4996: '_vsnprintf_l': This function or variable may be unsafe. Consider using _vsnprintf_s_l instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2192): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2193): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2216): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2300): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2301): warning C4068: unknown pragma 'Rf_warning'
 C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\stdio.h(2398): warning C4068: unknown pragma 'Rf_warning'
 src\bd0.c(42): warning C4068: unknown pragma 'Rf_warning'
 src\bd0.c(42): warning C4068: unknown pragma 'Rf_warning'
 src\bd0.c(42): error C2124: divide or mod by zero
 error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
 ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\user\appdata\local\programs\python\python38\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-d3kgh8kz\\rvlib_6ae0b3c702e9456c94dc497fe29412da\\setup.py'"'"'; __file__='"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-d3kgh8kz\\rvlib_6ae0b3c702e9456c94dc497fe29412da\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-62kmmddr\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\user\appdata\local\programs\python\python38\Include\rvlib' Check the logs for full command output.```

Body:
Got the exact same error. I could solve it by installing rvlib using conda.

conda install -c conda-forge rvlib


问:
Can I force my old versions of my app users in iOS to update?
My app's old versions interfere with my firebase in a way that crashes the app for my newest version
How do I force old versions to stop working?</p>

答:
You can't do anything about versions out there in the wild, but moving forward, you can add version checking to your system (e.g., I generally have a “minimum required” and “latest” version number stored in some configuration resource in my web service) and I have the app check those when it launches. But obviously, this version checking logic is not in the versions already distributed. Just on a “go forward” basis.

An even easier solution is something like Siren. But, again, this will not help you with versions already out there.

If you really have old app that is corrupting database for new releases, you can either

Make the new release more tolerant of this old, invalid data; or

Make a change in the database that isolates the old app from the new one or simply breaks the old app (e.g. rename some key table that it needs)

I would really advise against the second solution, but sometimes you gotta do what you gotta do.


问:
ffmpeg Error: Too many packets buffered for output stream
I am working on an electron app that uses ffmpeg, I am developing on a win10 machine so I am using command prompt and I have installed the npm package 'ffmpeg-ffprobe-static'. I can run ffmpeg commands in the terminal by calling the package like so:

```<code>C:\Users\martin\myproject\node_modules\ffmpeg-ffprobe-static>ffmpeg.exe -h
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200621
....
</code>```

I have an ffmpeg command to combine two flac files into a single mp3 file that has been working fine until I encountered this error:

```<code>[mjpeg @ 0000022537ace640] bits 85 is invalid
Error while decoding stream #0:1: Invalid data found when processing input
Too many packets buffered for output stream 0:0.
[libmp3lame @ 0000022537ac3480] 3 frames left in the queue on closing
Conversion failed!
</code>```

The same command works for other flac files, so there's something about these Billy Martin songs that can be played perfectly fine in vlc but cause ffmpeg to crash:

```<code>//running this command:

ffmpeg.exe -i "G:\RenderTune broken files\broken flac example\05 - Billy Martin - Phillie Dog.flac" -i "G:\RenderTune broken files\broken flac example\08 - Billy Martin - Stax.flac" -y -filter_complex concat=n=2:v=0:a=1 -c:a libmp3lame -b:a 320k "G:\RenderTune broken files\broken flac example\COMBINED_FILES.mp3"

//results in this output:
[mjpeg @ 0000022537ace640] bits 85 is invalid
Error while decoding stream #0:1: Invalid data found when processing input
Too many packets buffered for output stream 0:0.
[libmp3lame @ 0000022537ac3480] 3 frames left in the queue on closing
Conversion failed!
</code>```

I uploaded the broken flac files here: https://www.mediafire.com/folder/0v9hbfrap727y/broken+flac

If I run this same command with other flac files it works fine:

```<code>ffmpeg.exe -i "G:\RenderTune broken files\working flac example\5. Gossip.flac" -i "G:\RenderTune broken files\working flac example\6. Let The Children Play.flac" -y -filter_complex concat=n=2:v=0:a=1 -c:a libmp3lame -b:a 320k "G:\RenderTune broken files\working flac example\COMBINED_FILES.mp3"
</code>```

I have tried adding -max_muxing_queue_size 9999 to my ffmpeg command like many posts suggest but that does not fix it, does anybody know how to prevent this error?

[edit]
I tried one of the posted solutions:

```<code>ffmpeg.exe -y -i "G:\RenderTune broken files\working flac example\5. Gossip.flac" -i "G:\RenderTune broken files\working flac example\6. Let The Children Play.flac" -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1[a]" -map "[a]" -c:a libmp3lame -b:a 320k "G:\RenderTune broken files\working flac example\COMBINED_FILES.mp3"
</code>```

which crashed with a different error:

```<code>[libmp3lame @ 000002453725f3c0] Queue input is backward in time.9x
... lots of these [mp3 @ ..] messages
[mp3 @ 0000024537344400] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2449071 >= 2445999
[mp3 @ 0000024537344400] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2449071 >= 2447151
[mp3 @ 0000024537344400] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2449071 >= 2448303
[flac @ 00000245372d4140] invalid residual315.7kbits/s speed=59.7x
[flac @ 00000245372d4140] decode_frame() failed
Error while decoding stream #1:0: Invalid data found when processing input
size=   24871kB time=00:10:37.09 bitrate= 319.8kbits/s speed=60.5x
video:0kB audio:24869kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.004673%
</code>```

答:
This solved the problem to me (afterwards says about broken flags but this is easily fixed by recodening again or by playing with settings).

Linux 21.04, ffmpeg
ffmpeg version 4.2.3

File example: here (for few days)

```<code> ffmpeg -fflags +genpts -i peta_alien.ogv  -map 0 -c:v copy -c:a aac -max_muxing_queue_size 4000 peta_alien.avi
</code>```

Body:
I am working on an electron app that uses ffmpeg, I am developing on a win10 machine so I am using command prompt and I have installed the npm package 'ffmpeg-ffprobe-static'. I can run ffmpeg commands in the terminal by calling the package like so:

C:\Users\martin\myproject\node_modules\ffmpeg-ffprobe-static>ffmpeg.exe -h
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200621
....

I have an ffmpeg command to combine two flac files into a single mp3 file that has been working fine until I encountered this error:

[mjpeg @ 0000022537ace640] bits 85 is invalid
Error while decoding stream #0:1: Invalid data found when processing input
Too many packets buffered for output stream 0:0.
[libmp3lame @ 0000022537ac3480] 3 frames left in the queue on closing
Conversion failed!

The same command works for other flac files, so there's something about these Billy Martin songs that can be played perfectly fine in vlc but cause ffmpeg to crash:

//running this command:

ffmpeg.exe -i "G:\RenderTune broken files\broken flac example\05 - Billy Martin - Phillie Dog.flac" -i "G:\RenderTune broken files\broken flac example\08 - Billy Martin - Stax.flac" -y -filter_complex concat=n=2:v=0:a=1 -c:a libmp3lame -b:a 320k "G:\RenderTune broken files\broken flac example\COMBINED_FILES.mp3"

//results in this output:
[mjpeg @ 0000022537ace640] bits 85 is invalid
Error while decoding stream #0:1: Invalid data found when processing input
Too many packets buffered for output stream 0:0.
[libmp3lame @ 0000022537ac3480] 3 frames left in the queue on closing
Conversion failed!

I uploaded the broken flac files here: https://www.mediafire.com/folder/0v9hbfrap727y/broken+flac

If I run this same command with other flac files it works fine:

ffmpeg.exe -i "G:\RenderTune broken files\working flac example\5. Gossip.flac" -i "G:\RenderTune broken files\working flac example\6. Let The Children Play.flac" -y -filter_complex concat=n=2:v=0:a=1 -c:a libmp3lame -b:a 320k "G:\RenderTune broken files\working flac example\COMBINED_FILES.mp3"

I have tried adding -max_muxing_queue_size 9999 to my ffmpeg command like many posts suggest but that does not fix it, does anybody know how to prevent this error?

[edit]
I tried one of the posted solutions:

ffmpeg.exe -y -i "G:\RenderTune broken files\working flac example\5. Gossip.flac" -i "G:\RenderTune broken files\working flac example\6. Let The Children Play.flac" -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1[a]" -map "[a]" -c:a libmp3lame -b:a 320k "G:\RenderTune broken files\working flac example\COMBINED_FILES.mp3"

which crashed with a different error:

[libmp3lame @ 000002453725f3c0] Queue input is backward in time.9x
... lots of these [mp3 @ ..] messages
[mp3 @ 0000024537344400] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2449071 >= 2445999
[mp3 @ 0000024537344400] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2449071 >= 2447151
[mp3 @ 0000024537344400] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 2449071 >= 2448303
[flac @ 00000245372d4140] invalid residual315.7kbits/s speed=59.7x
[flac @ 00000245372d4140] decode_frame() failed
Error while decoding stream #1:0: Invalid data found when processing input
size=   24871kB time=00:10:37.09 bitrate= 319.8kbits/s speed=60.5x
video:0kB audio:24869kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.004673%

Body:
This solved the problem to me (afterwards says about broken flags but this is easily fixed by recodening again or by playing with settings).

Linux 21.04, ffmpeg
ffmpeg version 4.2.3

File example: here (for few days)

 ffmpeg -fflags +genpts -i peta_alien.ogv  -map 0 -c:v copy -c:a aac -max_muxing_queue_size 4000 peta_alien.avi


问:
Simulating a probability problem: 3 independent dice
I decided to simulate a probability question from a textbook:

Three fair dice are rolled independently, what is the probability that one dice shows 6 and the other two show two non-equal numbers (and neither is equal 6)

The dice is assumed fair, so "theoretical" answer will be $\frac{\binom{5}{2}}{\binom{6}{3}}=0.5$; I decided to simulate this in Julia, here is the function I wrote for this:

```<code>function simulation(n_experiments::Int = 100)
    dice = [DiscreteUniform(1, 6) for i in 1:3] # 3 independent fair dice
    successes = 0
    for trial in 1:n_experiments
        experiment = rand.(dice) # roll
        one_six = sum(r == 6 for r in experiment) == 1 # check if there is only one "6"
        others = filter(num -> num != 6, experiment)
        no_duplicates = length(Set(others)) == 2 # check if other two are distinct
        if no_duplicates
            if one_six
                successes += 1 # count "success"
            end
        end
    end
    return successes / n_experiments
end
</code>```

I expected this to return something around 0.5, but in fact it returns ~0.27 after about 10^5 iterations (n_experiments). Can anyone please help me find the flaw in the code?

答:
I think your code is right, but your math wrong:

```<code>julia> function simulation(n_experiments=100)
           chains = rand.(fill(DiscreteUniform(1, 6), 3), n_experiments)
           return (1/n_experiments) * mapreduce(+, chains...) do d1, d2, d3
               (d1 == 6 && d2 != 6 && d3 != 6 && d2 != d3) || (d1 != 6 && d2 == 6 && d3 != 6 && d1 != d3) || (d1 != 6 && d2 != 6 && d3 == 6 && d1 != d2)
           end
       end
simulation (generic function with 1 method)

julia> simulation(10_000)
0.279

julia> count(Iterators.product(1:6, 1:6, 1:6)) do (d1, d2, d3)
           (d1 == 6 && d2 != 6 && d3 != 6 && d2 != d3) || (d1 != 6 && d2 == 6 && d3 != 6 && d1 != d3) || (d1 != 6 && d2 != 6 && d3 == 6 && d1 != d2)
       end
60

julia> 60 / 6^3
0.2777777777777778
</code>```

I'd love to see a concise way to encode the condition.  I avoided your variant due to allocations, and mine is only verbose make sure it's correct -- but way too long...

Addendum

Here's the optimized variant with a generated condition.  Not relevant for the question, but because I find it cool.  Credit for the condition formula goes to Bogumił.

```<code>julia> @generated function condition(xs::NTuple{N,<:Any}) where {N}
           offdiagonals = ((i, j) for i = 1:N for j = (i+1):N)
           names = Symbol.(:xs, 1:N)
           assignments = [:($(names[i]) = xs[$i]) for i = 1:N]
           comparisons = [:($(names[i]) != $(names[j])) for (i, j) in offdiagonals]
           condition = Expr(:&&, :(maximum(xs) == 6), comparisons...)
           return quote
               $(assignments...)
               $condition
           end
       end
condition (generic function with 1 method)

julia> @code_warntype condition((1,2,3))
MethodInstance for condition(::Tuple{Int64, Int64, Int64})
  from condition(xs::Tuple{Vararg{var"#s17", N}} where var"#s17") where N in Main at REPL[71]:1
Static Parameters
  N = 3
Arguments
  #self#::Core.Const(condition)
  xs::Tuple{Int64, Int64, Int64}
Locals
  xs3::Int64
  xs2::Int64
  xs1::Int64
Body::Bool
1 ─       (xs1 = Base.getindex(xs, 1))
│         (xs2 = Base.getindex(xs, 2))
│         (xs3 = Base.getindex(xs, 3))
│   %4  = Main.maximum(xs)::Int64
│   %5  = (%4 == 6)::Bool
└──       goto #7 if not %5
2 ─ %7  = (xs1 != xs2)::Bool
└──       goto #6 if not %7
3 ─ %9  = (xs1 != xs3)::Bool
└──       goto #5 if not %9
4 ─ %11 = (xs2 != xs3)::Bool
└──       return %11
5 ─       return false
6 ─       return false
7 ─       return false

julia> function simulation(n_experiments=100)
           (1/n_experiments) * sum(1:n_experiments) do _
               dice = (rand(1:6), rand(1:6), rand(1:6))
               condition(dice)
           end
       end
simulation (generic function with 2 methods)

julia> @time simulation(10_000_000)
  0.157303 seconds
0.2777498
</code>```

This has no allocations at all.  sum is exactly as fast as a manual loop!

Body:
I decided to simulate a probability question from a textbook:

Three fair dice are rolled independently, what is the probability that one dice shows 6 and the other two show two non-equal numbers (and neither is equal 6)

The dice is assumed fair, so "theoretical" answer will be $\frac{\binom{5}{2}}{\binom{6}{3}}=0.5$; I decided to simulate this in Julia, here is the function I wrote for this:

function simulation(n_experiments::Int = 100)
    dice = [DiscreteUniform(1, 6) for i in 1:3] # 3 independent fair dice
    successes = 0
    for trial in 1:n_experiments
        experiment = rand.(dice) # roll
        one_six = sum(r == 6 for r in experiment) == 1 # check if there is only one "6"
        others = filter(num -> num != 6, experiment)
        no_duplicates = length(Set(others)) == 2 # check if other two are distinct
        if no_duplicates
            if one_six
                successes += 1 # count "success"
            end
        end
    end
    return successes / n_experiments
end

I expected this to return something around 0.5, but in fact it returns ~0.27 after about 10^5 iterations (n_experiments). Can anyone please help me find the flaw in the code?

Body:
I think your code is right, but your math wrong:

julia> function simulation(n_experiments=100)
           chains = rand.(fill(DiscreteUniform(1, 6), 3), n_experiments)
           return (1/n_experiments) * mapreduce(+, chains...) do d1, d2, d3
               (d1 == 6 && d2 != 6 && d3 != 6 && d2 != d3) || (d1 != 6 && d2 == 6 && d3 != 6 && d1 != d3) || (d1 != 6 && d2 != 6 && d3 == 6 && d1 != d2)
           end
       end
simulation (generic function with 1 method)

julia> simulation(10_000)
0.279

julia> count(Iterators.product(1:6, 1:6, 1:6)) do (d1, d2, d3)
           (d1 == 6 && d2 != 6 && d3 != 6 && d2 != d3) || (d1 != 6 && d2 == 6 && d3 != 6 && d1 != d3) || (d1 != 6 && d2 != 6 && d3 == 6 && d1 != d2)
       end
60

julia> 60 / 6^3
0.2777777777777778

I'd love to see a concise way to encode the condition.  I avoided your variant due to allocations, and mine is only verbose make sure it's correct -- but way too long...

Addendum

Here's the optimized variant with a generated condition.  Not relevant for the question, but because I find it cool.  Credit for the condition formula goes to Bogumił.

julia> @generated function condition(xs::NTuple{N,<:Any}) where {N}
           offdiagonals = ((i, j) for i = 1:N for j = (i+1):N)
           names = Symbol.(:xs, 1:N)
           assignments = [:($(names[i]) = xs[$i]) for i = 1:N]
           comparisons = [:($(names[i]) != $(names[j])) for (i, j) in offdiagonals]
           condition = Expr(:&&, :(maximum(xs) == 6), comparisons...)
           return quote
               $(assignments...)
               $condition
           end
       end
condition (generic function with 1 method)

julia> @code_warntype condition((1,2,3))
MethodInstance for condition(::Tuple{Int64, Int64, Int64})
  from condition(xs::Tuple{Vararg{var"#s17", N}} where var"#s17") where N in Main at REPL[71]:1
Static Parameters
  N = 3
Arguments
  #self#::Core.Const(condition)
  xs::Tuple{Int64, Int64, Int64}
Locals
  xs3::Int64
  xs2::Int64
  xs1::Int64
Body::Bool
1 ─       (xs1 = Base.getindex(xs, 1))
│         (xs2 = Base.getindex(xs, 2))
│         (xs3 = Base.getindex(xs, 3))
│   %4  = Main.maximum(xs)::Int64
│   %5  = (%4 == 6)::Bool
└──       goto #7 if not %5
2 ─ %7  = (xs1 != xs2)::Bool
└──       goto #6 if not %7
3 ─ %9  = (xs1 != xs3)::Bool
└──       goto #5 if not %9
4 ─ %11 = (xs2 != xs3)::Bool
└──       return %11
5 ─       return false
6 ─       return false
7 ─       return false

julia> function simulation(n_experiments=100)
           (1/n_experiments) * sum(1:n_experiments) do _
               dice = (rand(1:6), rand(1:6), rand(1:6))
               condition(dice)
           end
       end
simulation (generic function with 2 methods)

julia> @time simulation(10_000_000)
  0.157303 seconds
0.2777498

This has no allocations at all.  sum is exactly as fast as a manual loop!


问:
Change php variable based on javascript value
how can i change/assign a value to php variable depending on a javascript variable?
here is my code.

```<code><select id="reOutcome" name="reOutcome" onchange="OnChange(this.form.reOutcome);">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>

<script type="text/javascript">

function OnChange(dropdown)
{
    var myindex  = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value
    if(SelValue==2){
     <?php
    $sCOMPFields .= "|"."SreComments";
    $sCOMPFields .= "|"."rePrID";
     ?>
    }
    return true;
}
</script>
</code>```

The onchange function is working fine. I just don't know how to change the php variable. I searched online a lot. All im getting is how to assign php variable to javascript. That is not what im looking for.
Thanks for your help.

答:
The execution you want won`t occur, because the flow of the php scope and the javascript scope occurs on different moments. It is something like this:

So, you can`t execute php while the javascript is being executed on the computer of the user through the browser, but you can execute php on your server to generate the javascript you need to be executed on the user computer.

Actually, your question seems to be closer to a "what is the best way to do (something)"

ContentLicense: CC BY-SA 3.0

Body:
how can i change/assign a value to php variable depending on a javascript variable?
here is my code.

<select id="reOutcome" name="reOutcome" onchange="OnChange(this.form.reOutcome);">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
</select>

The onchange function is working fine. I just don't know how to change the php variable. I searched online a lot. All im getting is how to assign php variable to javascript. That is not what im looking for.
Thanks for your help.


问:
Within in a monorepo, is it possible to configure a package to 'use the uncompiled code if you can'?
I'm playing around with Yarn 2, and I want to do something like this.

I have a monorepo of the structure:

```<code>/
  packages/
    shared-ts/
       package.json
       src/
       lib*/
    app-ts/
       package.json
       src/
       lib*/
    app-js/
       package.json
       src/
       lib*/
</code>```

where lib* denotes that the folder is gitignored, but is where the compiled code will live.

In this example, I have a dependency library shared-ts that is used by two apps, app-ts and app-js.

The conventional approach

The conventional approach to configuring a monorepo like this, is that in shared-ts I would have a package.json like:

```<code>"main": "lib/index.js"
"scripts" : {
    "build": "tsc"
}

</code>```

Where the build script will build index.js and index.d.ts into the lib folder.

When both app-ts and app-js then resolve the package, they look in the lib folder and find the index.js and in app-ts's case - the index.d.ts.

This works fine, except that the developers need to remember to run the build script if they have made changes to shared-ts in order for the changes to propagate across.

Where this could potentially become problematic is where there are many layers of dependencies.

Attempted work around 1 - point main to src/index.ts.

I can change shared-ts package.json to

```<code>"main": "src/index.ts"
"scripts" : {
    "build": "tsc"
}
</code>```

This generally won't work, a plain node process won't be able to parse the syntax in the .ts file (eg. the import keyword).

Potential workaround - publishConfig

So something I'm considering, but haven't tried yet is, using the publishConfig
fields in the package.json

This field contains various settings that are only taken into consideration when a package is generated from your local sources (either through yarn pack or one of the publish commands like yarn npm publish).

```<code>"main": "src/index.ts",
"publishConfig": {
    "main": "lib/index.js"
}

</code>```

The idea being that:

When you publish a package to npm, lib/index.js will be used as main.  code is ready for consumption, no compilation required.

If being used directly in the monorepo src/index.ts will be used as main.  This kind of works as if you were running app-ts with ts-node for example.

However, where this starts breaking down is:

Running app-js in a development environment (where you don't have any additional syntax parsing set up).

Practical current best solution

My current best solution is to 'just give up on this 'no compile' aspiration' - if a developer makes changes to some code, they need to re-run build for the changes to propagate across.

答: I believe using nx will be good choice here. While it won't help you run the uncompiled code, it has pretty good features. In particular, you can automatically run the affected:apps on certain changes. For example, if you have a start command, it will run the start command for all the affected apps.

Body:
I'm playing around with Yarn 2, and I want to do something like this.

I have a monorepo of the structure:

/
  packages/
    shared-ts/
       package.json
       src/
       lib*/
    app-ts/
       package.json
       src/
       lib*/
    app-js/
       package.json
       src/
       lib*/

where lib* denotes that the folder is gitignored, but is where the compiled code will live.

In this example, I have a dependency library shared-ts that is used by two apps, app-ts and app-js.

The conventional approach

The conventional approach to configuring a monorepo like this, is that in shared-ts I would have a package.json like:

"main": "lib/index.js"
"scripts" : {
    "build": "tsc"
}

Where the build script will build index.js and index.d.ts into the lib folder.

When both app-ts and app-js then resolve the package, they look in the lib folder and find the index.js and in app-ts's case - the index.d.ts.

This works fine, except that the developers need to remember to run the build script if they have made changes to shared-ts in order for the changes to propagate across.

Where this could potentially become problematic is where there are many layers of dependencies.

Attempted work around 1 - point main to src/index.ts.

I can change shared-ts package.json to

"main": "src/index.ts"
"scripts" : {
    "build": "tsc"
}

This generally won't work, a plain node process won't be able to parse the syntax in the .ts file (eg. the import keyword).

Potential workaround - publishConfig

So something I'm considering, but haven't tried yet is, using the publishConfig
fields in the package.json

This field contains various settings that are only taken into consideration when a package is generated from your local sources (either through yarn pack or one of the publish commands like yarn npm publish).

"main": "src/index.ts",
"publishConfig": {
    "main": "lib/index.js"
}

The idea being that:

When you publish a package to npm, lib/index.js will be used as main.  code is ready for consumption, no compilation required.

If being used directly in the monorepo src/index.ts will be used as main.  This kind of works as if you were running app-ts with ts-node for example.

However, where this starts breaking down is:

Running app-js in a development environment (where you don't have any additional syntax parsing set up).

Practical current best solution

My current best solution is to 'just give up on this 'no compile' aspiration' - if a developer makes changes to some code, they need to re-run build for the changes to propagate across.