问:
Installation of ProductivityPowerTools 2017 corrupts privateregistry.user.bin of VisualStudio 2017
After installing ProductivityPowerTools 2017 in Visual Studio Professional 15.4.5 without admin rights on Windows7 I am not able to restart VisualStudio.

I get an access denied error for the package manager, pointing to ActivityLog.xml (see below).

Also see

Package management initialization failed: Access Denied Error when opening Visual Studio 2017

https://developercommunity.visualstudio.com/content/problem/79829/access-denied-when-trying-to-enableinstall-an-exte.html

https://developercommunity.visualstudio.com/content/problem/79829/access-denied-when-trying-to-enableinstall-an-exte.html

and ActivityLog.xml below.

If I delete

C:\Users\eis\AppData\Local\Microsoft\VisualStudio\15.0_551ecb7a\privateregistry.user.bin

I am able to restart VisualStudio. However, my settings are lost, which is very annoying.

=>Is there a way to repair privateregistry.user.bin?

(This is not addresse by the first referenced question.)

ActivityLog.xml:

```<code><?xml version="1.0" encoding="utf-16"?>
<?xml-stylesheet type="text/xsl" href="ActivityLog.xsl"?>
<activity>
  <entry>
    <record>1</record>
    <time>2017/11/30 16:07:29.758</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Microsoft Visual Studio 2017 version: 15.0.27004.2010</description>
  </entry>
  <entry>
    <record>2</record>
    <time>2017/11/30 16:07:29.758</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Log ID</description>
    <guid>{3BFB2164-4995-477D-9B0A-FF7A61B74431}</guid>
  </entry>
  <entry>
    <record>3</record>
    <time>2017/11/30 16:07:29.761</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Running in isolation mode.</description>
  </entry>
  <entry>
    <record>4</record>
    <time>2017/11/30 16:07:29.762</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Looking for master PkgDef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\master.pkgdef</path>
  </entry>
  <entry>
    <record>5</record>
    <time>2017/11/30 16:07:29.765</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Creating PkgDefCacheNonVolatile</description>
  </entry>
  <entry>
    <record>6</record>
    <time>2017/11/30 16:07:29.786</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Double-checking master pkgdef file</description>
  </entry>
  <entry>
    <record>7</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefManagement initialized</description>
  </entry>
  <entry>
    <record>8</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>RootFolder</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\</path>
  </entry>
  <entry>
    <record>9</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>ShellFolder</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\</path>
  </entry>
  <entry>
    <record>10</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefSearchPath</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.admin.pkgdef</path>
  </entry>
  <entry>
    <record>11</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>ImageManifestSearchPath</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions;C:\Users\eis\AppData\Local\Microsoft\VisualStudio\15.0_551ecb7a\Extensions</path>
  </entry>
  <entry>
    <record>12</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>ApplicationExtensionsFolder</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions</path>
  </entry>
  <entry>
    <record>13</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>"ZeroImpact" = dword:0, "MergeRegistry" = dword:3</description>
  </entry>
  <entry>
    <record>14</record>
    <time>2017/11/30 16:07:29.790</time>
    <type>Information</type>
    <source>Microsoft Visual Studio Appid Stub</source>
    <description>Application launch on system with DPI X/Y: 96/96</description>
  </entry>
  <entry>
    <record>15</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>No previous pkgdef cache data</description>
    <hr>80070002</hr>
    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>16</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefCache fast check: the timestamps are not current because the cache is either missing or corrupt.</description>
  </entry>
  <entry>
    <record>17</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefManagement: PkgDef cache fast check returned false; cache will be regenerated.</description>
  </entry>
  <entry>
    <record>18</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Searching for PkgDefs from search path</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.admin.pkgdef</path>
  </entry>
  <entry>
    <record>19</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Missing folder or file during PkgDef scan</description>
    <hr>80030002</hr>
    <errorinfo></errorinfo>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.admin.pkgdef</path>
  </entry>
  <entry>
    <record>20</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Discovered 265 PkgDef files</description>
  </entry>
  <entry>
    <record>21</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefCache flags</description>
    <hr>00013801</hr>
    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>22</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>No previous pkgdef cache data</description>
    <hr>80070002</hr>
    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>23</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefCache fast check: the timestamps are not current because the cache is either missing or corrupt.</description>
  </entry>
  <entry>
    <record>24</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>CPkgDefCacheNonVolatileBase: PkgDef cache is out of date.</description>
  </entry>
  <entry>
    <record>25</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Initializing non-volatile pkgdef cache</description>
  </entry>
  <entry>
    <record>26</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting configuration if it exists</description>
  </entry>
  <entry>
    <record>27</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting abandoned volatile cache</description>
  </entry>
  <entry>
    <record>28</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Pre initializing cache</description>
  </entry>
  <entry>
    <record>29</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Importing config package defs</description>
  </entry>
  <entry>
    <record>30</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Loading discovered pkgdef files</description>
  </entry>
  <entry>
    <record>31</record>
    <time>2017/11/30 16:07:29.906</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\master.pkgdef</path>
  </entry>
  <entry>
    <record>32</record>
    <time>2017/11/30 16:07:29.908</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>33</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Failed to process PkgDef file</description>
    <hr>80070005 - E_ACCESSDENIED</hr>
    <errorinfo></errorinfo>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>34</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>PkgDef loading aborted</description>
    <hr>80070005 - E_ACCESSDENIED</hr>
    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>35</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>CPkgDefCacheNonVolatileBase: PkgDef cache creation failed. Going volatile and trying again.</description>
    <hr>80070005 - E_ACCESSDENIED</hr>
    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>36</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Going volatile: Recalculated pkgdef configuration root</description>
    <path>Software\Microsoft\VisualStudio\15.0_551ecb7a_Config_2072</path>
  </entry>
  <entry>
    <record>37</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>On Windows 7 - keep REG_OPTION_NON_VOLATILE</description>
  </entry>
  <entry>
    <record>38</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Initializing non-volatile pkgdef cache</description>
  </entry>
  <entry>
    <record>39</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting configuration if it exists</description>
  </entry>
  <entry>
    <record>40</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting abandoned volatile cache</description>
  </entry>
  <entry>
    <record>41</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Pre initializing cache</description>
  </entry>
  <entry>
    <record>42</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Importing config package defs</description>
  </entry>
  <entry>
    <record>43</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Loading discovered pkgdef files</description>
  </entry>
  <entry>
    <record>44</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\master.pkgdef</path>
  </entry>
  <entry>
    <record>45</record>
    <time>2017/11/30 16:07:29.912</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>46</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Failed to process PkgDef file</description>
    <hr>80070005 - E_ACCESSDENIED</hr>
    <errorinfo></errorinfo>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>47</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>PkgDef loading aborted</description>
    <hr>80070005 - E_ACCESSDENIED</hr>
    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>48</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Error or timeout while initializing non-volatile pkgdef cache</description>
    <hr>80070005 - E_ACCESSDENIED</hr>
    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>49</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefManagement startup complete</description>
  </entry>
  <entry>
    <record>50</record>
    <time>2017/11/30 16:07:29.914</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Configuration is Volatile.</description>
  </entry>
  <entry>
    <record>51</record>
    <time>2017/11/30 16:07:29.914</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Configuration file to be used for CLR initialization</description>
    <path>C:\Users\eis\AppData\Local\Temp\devEB50.tmp</path>
  </entry>
  <entry>
    <record>52</record>
    <time>2017/11/30 16:07:29.914</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Failure calling FinishInitialize.</description>
    <hr>80070005 - E_ACCESSDENIED</hr>
    <errorinfo></errorinfo>
  </entry>
</activity>
</code>```

答:
It is a VisualStudio bug, that has been resolved with version 15.5 (released yesterday)

I was not able to repair the settings file privateregistry.user.bin.

Body:
After installing ProductivityPowerTools 2017 in Visual Studio Professional 15.4.5 without admin rights on Windows7 I am not able to restart VisualStudio.

I get an access denied error for the package manager, pointing to ActivityLog.xml (see below).

Also see

Package management initialization failed: Access Denied Error when opening Visual Studio 2017

https://developercommunity.visualstudio.com/content/problem/79829/access-denied-when-trying-to-enableinstall-an-exte.html

https://developercommunity.visualstudio.com/content/problem/79829/access-denied-when-trying-to-enableinstall-an-exte.html

and ActivityLog.xml below.

If I delete

C:\Users\eis\AppData\Local\Microsoft\VisualStudio\15.0_551ecb7a\privateregistry.user.bin

I am able to restart VisualStudio. However, my settings are lost, which is very annoying.

=>Is there a way to repair privateregistry.user.bin?

(This is not addresse by the first referenced question.)

ActivityLog.xml:

<?xml version="1.0" encoding="utf-16"?>
<?xml-stylesheet type="text/xsl" href="ActivityLog.xsl"?>
<activity>
  <entry>
    <record>1</record>
    <time>2017/11/30 16:07:29.758</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Microsoft Visual Studio 2017 version: 15.0.27004.2010</description>
  </entry>
  <entry>
    <record>2</record>
    <time>2017/11/30 16:07:29.758</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Log ID</description>
    <guid>{3BFB2164-4995-477D-9B0A-FF7A61B74431}</guid>
  </entry>
  <entry>
    <record>3</record>
    <time>2017/11/30 16:07:29.761</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Running in isolation mode.</description>
  </entry>
  <entry>
    <record>4</record>
    <time>2017/11/30 16:07:29.762</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Looking for master PkgDef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\master.pkgdef</path>
  </entry>
  <entry>
    <record>5</record>
    <time>2017/11/30 16:07:29.765</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Creating PkgDefCacheNonVolatile</description>
  </entry>
  <entry>
    <record>6</record>
    <time>2017/11/30 16:07:29.786</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Double-checking master pkgdef file</description>
  </entry>
  <entry>
    <record>7</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefManagement initialized</description>
  </entry>
  <entry>
    <record>8</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>RootFolder</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\</path>
  </entry>
  <entry>
    <record>9</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>ShellFolder</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\</path>
  </entry>
  <entry>
    <record>10</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefSearchPath</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.admin.pkgdef</path>
  </entry>
  <entry>
    <record>11</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>ImageManifestSearchPath</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions;C:\Users\eis\AppData\Local\Microsoft\VisualStudio\15.0_551ecb7a\Extensions</path>
  </entry>
  <entry>
    <record>12</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>ApplicationExtensionsFolder</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions</path>
  </entry>
  <entry>
    <record>13</record>
    <time>2017/11/30 16:07:29.787</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>"ZeroImpact" = dword:0, "MergeRegistry" = dword:3</description>
  </entry>
  <entry>
    <record>14</record>
    <time>2017/11/30 16:07:29.790</time>
    <type>Information</type>
    <source>Microsoft Visual Studio Appid Stub</source>
    <description>Application launch on system with DPI X/Y: 96/96</description>
  </entry>
  <entry>
    <record>15</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>No previous pkgdef cache data</description>

80070002

    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>16</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefCache fast check: the timestamps are not current because the cache is either missing or corrupt.</description>
  </entry>
  <entry>
    <record>17</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefManagement: PkgDef cache fast check returned false; cache will be regenerated.</description>
  </entry>
  <entry>
    <record>18</record>
    <time>2017/11/30 16:07:29.791</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Searching for PkgDefs from search path</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.admin.pkgdef</path>
  </entry>
  <entry>
    <record>19</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Missing folder or file during PkgDef scan</description>

80030002

    <errorinfo></errorinfo>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv.admin.pkgdef</path>
  </entry>
  <entry>
    <record>20</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Discovered 265 PkgDef files</description>
  </entry>
  <entry>
    <record>21</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefCache flags</description>

00013801

    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>22</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Warning</type>
    <source>VisualStudio</source>
    <description>No previous pkgdef cache data</description>

80070002

    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>23</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefCache fast check: the timestamps are not current because the cache is either missing or corrupt.</description>
  </entry>
  <entry>
    <record>24</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>CPkgDefCacheNonVolatileBase: PkgDef cache is out of date.</description>
  </entry>
  <entry>
    <record>25</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Initializing non-volatile pkgdef cache</description>
  </entry>
  <entry>
    <record>26</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting configuration if it exists</description>
  </entry>
  <entry>
    <record>27</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting abandoned volatile cache</description>
  </entry>
  <entry>
    <record>28</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Pre initializing cache</description>
  </entry>
  <entry>
    <record>29</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Importing config package defs</description>
  </entry>
  <entry>
    <record>30</record>
    <time>2017/11/30 16:07:29.905</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Loading discovered pkgdef files</description>
  </entry>
  <entry>
    <record>31</record>
    <time>2017/11/30 16:07:29.906</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\master.pkgdef</path>
  </entry>
  <entry>
    <record>32</record>
    <time>2017/11/30 16:07:29.908</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>33</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Failed to process PkgDef file</description>

80070005 - E_ACCESSDENIED

    <errorinfo></errorinfo>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>34</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>PkgDef loading aborted</description>

80070005 - E_ACCESSDENIED

    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>35</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>CPkgDefCacheNonVolatileBase: PkgDef cache creation failed. Going volatile and trying again.</description>

80070005 - E_ACCESSDENIED

    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>36</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Going volatile: Recalculated pkgdef configuration root</description>
    <path>Software\Microsoft\VisualStudio\15.0_551ecb7a_Config_2072</path>
  </entry>
  <entry>
    <record>37</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>On Windows 7 - keep REG_OPTION_NON_VOLATILE</description>
  </entry>
  <entry>
    <record>38</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Initializing non-volatile pkgdef cache</description>
  </entry>
  <entry>
    <record>39</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting configuration if it exists</description>
  </entry>
  <entry>
    <record>40</record>
    <time>2017/11/30 16:07:29.909</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Deleting abandoned volatile cache</description>
  </entry>
  <entry>
    <record>41</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Pre initializing cache</description>
  </entry>
  <entry>
    <record>42</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>InitializeCache: Importing config package defs</description>
  </entry>
  <entry>
    <record>43</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Loading discovered pkgdef files</description>
  </entry>
  <entry>
    <record>44</record>
    <time>2017/11/30 16:07:29.910</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\master.pkgdef</path>
  </entry>
  <entry>
    <record>45</record>
    <time>2017/11/30 16:07:29.912</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Importing pkgdef file</description>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>46</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Failed to process PkgDef file</description>

80070005 - E_ACCESSDENIED

    <errorinfo></errorinfo>
    <path>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\DSLTextTemplatingRegistry_x86.pkgdef</path>
  </entry>
  <entry>
    <record>47</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>PkgDef loading aborted</description>

80070005 - E_ACCESSDENIED

    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>48</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Error or timeout while initializing non-volatile pkgdef cache</description>

80070005 - E_ACCESSDENIED

    <errorinfo></errorinfo>
  </entry>
  <entry>
    <record>49</record>
    <time>2017/11/30 16:07:29.913</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>PkgDefManagement startup complete</description>
  </entry>
  <entry>
    <record>50</record>
    <time>2017/11/30 16:07:29.914</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Configuration is Volatile.</description>
  </entry>
  <entry>
    <record>51</record>
    <time>2017/11/30 16:07:29.914</time>
    <type>Information</type>
    <source>VisualStudio</source>
    <description>Configuration file to be used for CLR initialization</description>
    <path>C:\Users\eis\AppData\Local\Temp\devEB50.tmp</path>
  </entry>
  <entry>
    <record>52</record>
    <time>2017/11/30 16:07:29.914</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>Failure calling FinishInitialize.</description>

80070005 - E_ACCESSDENIED

    <errorinfo></errorinfo>
  </entry>
</activity>


来源: stackexchange

问:
Visual Studio Code, how to switch from powershell.exe to cmd.exe
I would like to switch from powershell.exe to cmd.exe in the terminal but i'm not sure how to do so. Provided screenshot for clarification.

答:
open settings (ctrl+comma)

find terminal.integrated.shell.windows

replace its value with C:\\Windows\\System32\\cmd.exe

ContentLicense: CC BY-SA 3.0


问:
Regular Expression to match a list of strings and ignore a list of strings
I am looking for a regular expression that meets the below requirement

Ignore all the strings that starts with zzTest

Match all the strings that contains the word rest and not started with zzTest

Input Strings:

```<code>zzTest.docs:service1
zzTest.rest:service2
Regression.rest:service1
Regression.docs.service2
</code>```

Expected output:

```<code>Regression.rest:service1
</code>```

Tried with the regular expression \s*(?!\w*(zzTest)\w*)\w*(rest)\w*\s*
Its works when there is no dot(.) in the input String

Any help appreciated

答:
Try this:

```<code>stringList.stream().filter(s -> !s.startsWith("zzTest")).filter(s -> s.contains("rest"));
</code>```

Although this is not a regular expression solution.

Body:
I am looking for a regular expression that meets the below requirement

Ignore all the strings that starts with zzTest

Match all the strings that contains the word rest and not started with zzTest

Input Strings:

zzTest.docs:service1
zzTest.rest:service2
Regression.rest:service1
Regression.docs.service2

Expected output:

Regression.rest:service1

Tried with the regular expression \s*(?!\w*(zzTest)\w*)\w*(rest)\w*\s*
Its works when there is no dot(.) in the input String

Any help appreciated

Body:
Try this:

stringList.stream().filter(s -> !s.startsWith("zzTest")).filter(s -> s.contains("rest"));

Although this is not a regular expression solution.


问:
Woocommerce, get products by category with wp query
I tried many methods, but I can't show products with category name or id</p>

```<code>                  $args = array(
                       'post_type'             => 'product',
                       'post_status'           => 'publish',
                       'ignore_sticky_posts'   => 1,
                       'cat'                   => 40,
                       'posts_per_page'        => '12',
                   );

                  $loop = new WP_Query( $args );
</code>```

答:
Try tax_query

```<code>$args = array(
   'post_type'             => 'product',
   'post_status'           => 'publish',
   'ignore_sticky_posts'   => 1,
   'posts_per_page'        => '12',
   'tax_query'             => array(
        array(
            'taxonomy'  => 'product_cat',
            'field'     => 'term_id',
            'terms'     => array('40'),
            'operator'  => 'IN',
        )
   )
);

$loop = new WP_Query( $args );
</code>```

https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

Body:
I tried many methods, but I can't show products with category name or id

                  $args = array(
                       'post_type'             => 'product',
                       'post_status'           => 'publish',
                       'ignore_sticky_posts'   => 1,
                       'cat'                   => 40,
                       'posts_per_page'        => '12',
                   );

                  $loop = new WP_Query( $args );

Body:
Try tax_query

$args = array(
   'post_type'             => 'product',
   'post_status'           => 'publish',
   'ignore_sticky_posts'   => 1,
   'posts_per_page'        => '12',
   'tax_query'             => array(
        array(
            'taxonomy'  => 'product_cat',
            'field'     => 'term_id',
            'terms'     => array('40'),
            'operator'  => 'IN',
        )
   )
);

$loop = new WP_Query( $args );

https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

ContentLicense: CC BY-SA 4.0


问:
UPDATE record if present; else INSERT in Oracle
Is there any Oracle function that indicate the existence of a record, or any other useful technique to achieve this?

EDIT: using the MERGE statement I did:

```<code>MERGE
 INTO  lims_min.mytab src
 USING lims_min.mytab tgt
    ON (    src.col1 = tgt.col1
        AND tgt.col1 = p_val1
        AND src.col2 = tgt.col2
        AND tgt.col2 = p_val2
       )

 WHEN MATCHED
 THEN
 UPDATE
  SET tgt.col3=p_val3,
      tgt.col4=p_val4

 WHEN NOT MATCHED
 THEN
 INSERT  (col1, col2, col3, col4)
 VALUES  (val1, val2, val2, val4);
</code>```

I get the error saying that col3 is invalid identifier. No typos, and it is existing column.p_val1, p_val2, p_val3 and p_val4 are string parameters that are passed to the stored procedure. i am thinking that the issue may lie in these params, perhaps they should be placed inside a WHERE statement?
Any ideas?

答:
Look into the MERGE statement

http://psoug.org/reference/merge.html

ContentLicense: CC BY-SA 2.5

Body:
Is there any Oracle function that indicate the existence of a record, or any other useful technique to achieve this?

EDIT: using the MERGE statement I did:

MERGE
 INTO  lims_min.mytab src
 USING lims_min.mytab tgt
    ON (    src.col1 = tgt.col1
        AND tgt.col1 = p_val1
        AND src.col2 = tgt.col2
        AND tgt.col2 = p_val2
       )

 WHEN MATCHED
 THEN
 UPDATE
  SET tgt.col3=p_val3,
      tgt.col4=p_val4

 WHEN NOT MATCHED
 THEN
 INSERT  (col1, col2, col3, col4)
 VALUES  (val1, val2, val2, val4);

I get the error saying that col3 is invalid identifier. No typos, and it is existing column.p_val1, p_val2, p_val3 and p_val4 are string parameters that are passed to the stored procedure. i am thinking that the issue may lie in these params, perhaps they should be placed inside a WHERE statement?
Any ideas?


问:
LLBL GEN PRO 3.1 Select distinct two fields
Is it posible to use DefineField and AggregateFunction.SumDistinct with two fields in LLBL GenPro 3.1?
For example I have this:

```<code>ResultsetFields myFields = new ResultsetFields(2);

//I want this amount to be distinct but with specific userId
myFields.DefineField(UserFields.Amount, 0, AggregateFunction.SumDistinct);
myFields.DefineField(UserFields.Id, 1, "ResultCount", AggregateFunction.CountDistinct);
</code>```

In SQL, I want it end up with something like:

```<code>SELECT DISTINCT SUM(u.Amount), u.Id
FROM Users u
  INNER JOIN someOtherTablesat ON sot.UserId = u.Id
GROUP BY
  u.Id
</code>```

This join I have in LLBL and it duplicates amount, because someOtherTable has few data for same user. I need that join for some another reason.
So, is it possible to do that with LLBL and how?

答:
Finally I found solution:

```<code>var fields = new ResultsetFields(1);
fields.DefineField(OrderFields.Freight, 0, AggregateFunction.Sum);

var bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(new FieldCompareSetPredicate(
    OrderFields.OrderId, null, OrderDetailFields.OrderId, null,
    SetOperator.In, (OrderDetailFields.ProductId ==1)));

DataTable dynamicList = new DataTable();

using (var adapter = new DataAccessAdapter())
{
    adapter.FetchTypedList(fields, dynamicList, bucket);
}
</code>```

In SQL that is more like

```<code>Select SUM(Freight) from Orders
Where OrderID IN
(
    Select OrderID from [Order Details] where ProductID = 1
)
</code>```

Body:
Is it posible to use DefineField and AggregateFunction.SumDistinct with two fields in LLBL GenPro 3.1?
For example I have this:

ResultsetFields myFields = new ResultsetFields(2);

//I want this amount to be distinct but with specific userId
myFields.DefineField(UserFields.Amount, 0, AggregateFunction.SumDistinct);
myFields.DefineField(UserFields.Id, 1, "ResultCount", AggregateFunction.CountDistinct);

In SQL, I want it end up with something like:

SELECT DISTINCT SUM(u.Amount), u.Id
FROM Users u
  INNER JOIN someOtherTablesat ON sot.UserId = u.Id
GROUP BY
  u.Id

This join I have in LLBL and it duplicates amount, because someOtherTable has few data for same user. I need that join for some another reason.
So, is it possible to do that with LLBL and how?

Body:
Finally I found solution:

var fields = new ResultsetFields(1);
fields.DefineField(OrderFields.Freight, 0, AggregateFunction.Sum);

var bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(new FieldCompareSetPredicate(
    OrderFields.OrderId, null, OrderDetailFields.OrderId, null,
    SetOperator.In, (OrderDetailFields.ProductId ==1)));

DataTable dynamicList = new DataTable();

using (var adapter = new DataAccessAdapter())
{
    adapter.FetchTypedList(fields, dynamicList, bucket);
}

In SQL that is more like

Select SUM(Freight) from Orders
Where OrderID IN
(
    Select OrderID from [Order Details] where ProductID = 1
)


问:
Convert bit type to Yes or No by query Sql Server 2005
I Want convert bit type to Yes or No

For Example:

```<code>SELECT FirstName, LastName, IsMale from members
</code>```

Results:

```<code>Ramy    Said    1
</code>```

Expected Result:

```<code>Ramy    Said    Yes
</code>```

答:
SQL Server 2012 introduces two new keywords FORMAT and IIF that can provide a more compact means of converting an integer or bit to string:

```<code>DECLARE @MyInt int = 123
PRINT 'Hello '+FORMAT(@MyInt,'')

-- (note: the "+0" converts a bit type to int then outputs '0' or '1')
DECLARE @MyBit bit = 0
PRINT 'Hello '+FORMAT(@MyBit+0,'')
</code>```

But to convert a bit type to Yes or No I would now use:

```<code>PRINT 'Hello '+IIF(@MyBit=1,'Yes','No')
</code>```

Body:
I Want convert bit type to Yes or No

For Example:

SELECT FirstName, LastName, IsMale from members

Results:

Ramy    Said    1

Expected Result:

Ramy    Said    Yes

Body:
SQL Server 2012 introduces two new keywords FORMAT and IIF that can provide a more compact means of converting an integer or bit to string:

DECLARE @MyInt int = 123
PRINT 'Hello '+FORMAT(@MyInt,'')

-- (note: the "+0" converts a bit type to int then outputs '0' or '1')
DECLARE @MyBit bit = 0
PRINT 'Hello '+FORMAT(@MyBit+0,'')

But to convert a bit type to Yes or No I would now use:

PRINT 'Hello '+IIF(@MyBit=1,'Yes','No')


问:
Sorting POST data to update MySQL table rows via id in the POST name
I have made a form application in PHP and now I'm trying to implement updating the fields. I have made it so the POST contains data like this:

```<code>Array (
    '17-label' => "select label 0 ",
    '17-placeholder' => "select placeholder 0 ",
    '17-answer' => Array (
        "Answer 1",
        "Answer 2",
        "Answer 3"
    ),
    '18-label' => "textfield label 1",
    '18-placeholder' => "textfield placeholder 1",
    '19-label' => "textfield label 2",
    '19-placeholder' => "textfield placeholder 2"
)
</code>```

Now as you can see I use the id of the row I want to update as the start, and then a - to identify the break and the actual column name I want to update in the column.

But how do I do this?

I know how to update, it is just, how to make sure everything goes to the right column. The first number is the id, and after the - sign it is the actual column name. But how do I do this?

答: While writing the sql, put NULL for the column 'id'. It will automatically generate 'id', assuming it is auto-incremented.</p>

Body:
I have made a form application in PHP and now I'm trying to implement updating the fields. I have made it so the POST contains data like this:

Array (
    '17-label' => "select label 0 ",
    '17-placeholder' => "select placeholder 0 ",
    '17-answer' => Array (
        "Answer 1",
        "Answer 2",
        "Answer 3"
    ),
    '18-label' => "textfield label 1",
    '18-placeholder' => "textfield placeholder 1",
    '19-label' => "textfield label 2",
    '19-placeholder' => "textfield placeholder 2"
)

Now as you can see I use the id of the row I want to update as the start, and then a - to identify the break and the actual column name I want to update in the column.

But how do I do this?

I know how to update, it is just, how to make sure everything goes to the right column. The first number is the id, and after the - sign it is the actual column name. But how do I do this?


问:
Fill GridLayout in Python's Kivy with an image
I have a kivy GridLayout of 3 rows, and nested BoxLayout in each row. I need to fill a box within a row entirely with an image. It maintains the image's original size regardless of adjustments I make within the kv file (e.g. size: self.size, size_hint_x: 1, and the steps outlined in this stack overflow Resizing an image to variable/fixed dimensions?).

Example screenshot for what I have - I'd like to enlarge the purple foo image to fill the entire red rectangle (aspect ratio isn't important to me):

Some sample code:

```<code><MyGridLayout>:

      rows: 3
      padding: 0
      spacing: 0

      BoxLayout:
          orientation: "horizontal"
          size_hint: 0.15, 0.2

          Button:
              text: 'FOO_BUTTON'
              size_hint_x: 0.25

          Label:
              text: ''

      BoxLayout:
          orientation: "horizontal"

          Image :
              source: 'C:/my/path.png'

          Label :
              size_hint_x: 0.3
              text: "foo"

      BoxLayout:
          orientation: "horizontal"
          Label :
              size_hint_x: 0.7
              text: "foo"

          Label :
              size_hint_x: 0.3
              text: "foo"
</code>```

答:
To make the image size maximized to fit in the image box you can use allow_stretch and keep_ratio properties:

```<code>from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder

Builder.load_string("""
<MyGridLayout>:
    rows: 3
    padding: 0
    spacing: 0

    BoxLayout:
        orientation: "horizontal"
        size_hint: 0.15, 0.2

        Button:
            text: 'FOO_BUTTON'
            size_hint_x: 0.25

        Label:
            text: ''

    BoxLayout:
        orientation: "horizontal"

        Image :
            source: 'C:/my/path.png'
            allow_stretch: True
            keep_ratio: False

        Label :
            size_hint_x: 0.3
            text: "foo5"

    BoxLayout:
        orientation: "horizontal"
        Label :
            size_hint_x: 0.7
            text: "foo"

        Label :
            size_hint_x: 0.3
            text: "foo"
""")

class MyGridLayout(GridLayout):
    pass

class Test(App):
    def build(self):
        return MyGridLayout()

if __name__ == '__main__':
    Test().run()
</code>```

Result:

Body:
I have a kivy GridLayout of 3 rows, and nested BoxLayout in each row. I need to fill a box within a row entirely with an image. It maintains the image's original size regardless of adjustments I make within the kv file (e.g. size: self.size, size_hint_x: 1, and the steps outlined in this stack overflow Resizing an image to variable/fixed dimensions?).

Example screenshot for what I have - I'd like to enlarge the purple foo image to fill the entire red rectangle (aspect ratio isn't important to me):

Some sample code:

<MyGridLayout>:

      rows: 3
      padding: 0
      spacing: 0

      BoxLayout:
          orientation: "horizontal"
          size_hint: 0.15, 0.2

          Button:
              text: 'FOO_BUTTON'
              size_hint_x: 0.25

          Label:
              text: ''

      BoxLayout:
          orientation: "horizontal"

          Image :
              source: 'C:/my/path.png'

          Label :
              size_hint_x: 0.3
              text: "foo"

      BoxLayout:
          orientation: "horizontal"
          Label :
              size_hint_x: 0.7
              text: "foo"

          Label :
              size_hint_x: 0.3
              text: "foo"

Body:
To make the image size maximized to fit in the image box you can use allow_stretch and keep_ratio properties:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder

Builder.load_string("""
<MyGridLayout>:
    rows: 3
    padding: 0
    spacing: 0

    BoxLayout:
        orientation: "horizontal"
        size_hint: 0.15, 0.2

        Button:
            text: 'FOO_BUTTON'
            size_hint_x: 0.25

        Label:
            text: ''

    BoxLayout:
        orientation: "horizontal"

        Image :
            source: 'C:/my/path.png'
            allow_stretch: True
            keep_ratio: False

        Label :
            size_hint_x: 0.3
            text: "foo5"

    BoxLayout:
        orientation: "horizontal"
        Label :
            size_hint_x: 0.7
            text: "foo"

        Label :
            size_hint_x: 0.3
            text: "foo"
""")

class MyGridLayout(GridLayout):
    pass

class Test(App):
    def build(self):
        return MyGridLayout()

if __name__ == '__main__':
    Test().run()

Result:


问:
Hyperlink to ID - HTML
I have a contact div in my home page.

```<code><div id="contact">....</div>
</code>```

In my Menu, I have link to #contact that scrolls down smoothly to contact div.

```<code><a href="#contact">Contact Us</a>
</code>```

While on another page, I have to use

```<code><a href="www.mywebsite.com/#contact">
</code>```

While working with wordpress where I have single menu for all pages, can I have both functionalities simultaneously or I have to create 2 different menus, one for home, one for the rest of the pages?

答:
Add custom link as,href="www.mywebsite.com#contact">

in your custom jquery add

```<code>//jQuery for Page Scroll - Single page
$('a[href*="#"]:not([href="#"])').click(function() {
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
            if (target.length) {
                $('html, body').animate({
                    scrollTop: target.offset().top
                }, 500);
                return false;
            }
    }
});

// jQuery for Page Navigation
$( window ).load(function() {

            if(window.location.hash) {
                var url=window.location.href;
                var hash = url.substring(url.indexOf('#')+1);
                $('html, body').stop().animate({
                    scrollTop: $("#"+hash).offset().top
                }, 1000);
            }
});
</code>```

Title: Hyperlink to ID - HTML

Body:
I have a contact div in my home page.

....

In my Menu, I have link to #contact that scrolls down smoothly to contact div.

Contact Us

While on another page, I have to use

While working with wordpress where I have single menu for all pages, can I have both functionalities simultaneously or I have to create 2 different menus, one for home, one for the rest of the pages?

Body:
Add custom link as,<a href="www.mywebsite.com#contact">

in your custom jquery add

//jQuery for Page Scroll - Single page
$('a[href*="#"]:not([href="#"])').click(function() {
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
            if (target.length) {
                $('html, body').animate({
                    scrollTop: target.offset().top
                }, 500);
                return false;
            }
    }
});

// jQuery for Page Navigation
$( window ).load(function() {

            if(window.location.hash) {
                var url=window.location.href;
                var hash = url.substring(url.indexOf('#')+1);
                $('html, body').stop().animate({
                    scrollTop: $("#"+hash).offset().top
                }, 1000);
            }
});


问:
Docker Network Nginx Resolver
I am trying to get rid of deprecated Docker links in my configuration. What's left is getting rid of those Bad Gateway nginx reverse proxy errors when I recreated a container.

Note: I am using Docker networks in bridge mode. (docker network create nettest)

I am using the following configuration snippet inside nginx:

```<code>location / {
      resolver 127.0.0.1 valid=30s;
      set $backend "http://confluence:8090";
      proxy_pass $backend;
</code>```

I started a container with hostname confluence on my Docker network with name nettest.

Then I started the nginx container on network nettest.

I can ping confluence from inside the nginx container

confluence is listed inside the nginx container's /etc/hosts file

nginx log says send() failed (111: Connection refused) while resolving, resolver: 127.0.0.1:53

I tried the docker network default dns resolver 127.0.0.11 from /etc/resol.conf

nginx log says confluence could not be resolved (3: Host not found)

Anybody knows how to configure nginx resolver with Docker Networks or an alternative on how to force Nginx to correctly resolve the Docker network hostname?

答:
Maybe you should check your container's /etc/resolv.conf

It shows your container's correct DNS config and then use that DNS server IP for resolver.

127.0.0.11 does not works in Rancher

Title: Docker Network Nginx Resolver

Body:
I am trying to get rid of deprecated Docker links in my configuration. What's left is getting rid of those Bad Gateway nginx reverse proxy errors when I recreated a container.

Note: I am using Docker networks in bridge mode. (docker network create nettest)

I am using the following configuration snippet inside nginx:

location / {
      resolver 127.0.0.1 valid=30s;
      set $backend "http://confluence:8090";
      proxy_pass $backend;

I started a container with hostname confluence on my Docker network with name nettest.

Then I started the nginx container on network nettest.

I can ping confluence from inside the nginx container

confluence is listed inside the nginx container's /etc/hosts file

nginx log says send() failed (111: Connection refused) while resolving, resolver: 127.0.0.1:53

I tried the docker network default dns resolver 127.0.0.11 from /etc/resol.conf

nginx log says confluence could not be resolved (3: Host not found)

Anybody knows how to configure nginx resolver with Docker Networks or an alternative on how to force Nginx to correctly resolve the Docker network hostname?


问:
How to check the checksum through commandline?
I want to do something like this on commandline on my UNIX variant

```<code>if (shasum httpd-2.4.7.tar.bz2 == 19asdasdasd56462e44d61a093ea57e964cf0af05c0e) echo 'good to go'
</code>```

I dont want to write a separate script text page just to check this.

 This above thing is showing syntax error.
 But there must be a slick way to get around this?

How to do this?

答:
I use the exit code of the previous/last command:

If the checksum is valid the exit code of the last executed command is 0:

```<code>> echo "${PROMETHEUS_CHECKSUM} prometheus-${PROMETHEUS_VERSION}.linux-arm64.tar.gz" | sha256sum -c
> echo $?
0
</code>```

If the checksum is not correct, then the exit code is different than 0:

```<code>> export PROMETHEUS_CHECKSUM='some garbage'
> echo "${PROMETHEUS_CHECKSUM} prometheus-${PROMETHEUS_VERSION}.linux-arm64.tar.gz" | sha256sum -c
prometheus-2.0.0.linux-arm64.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
> echo $?
1
</code>```

And here is the whole example with an if statement:

```<code>#!/bin/bash

...

echo "${PROMETHEUS_CHECKSUM} prometheus-${PROMETHEUS_VERSION}.linux-arm64.tar.gz" | sha256sum -c

if [ $? != 0 ]; then
  echo 'Prometheus checksum is not valid'
  exit 1
fi
</code>```

Body:
I want to do something like this on commandline on my UNIX variant

if (shasum httpd-2.4.7.tar.bz2 == 19asdasdasd56462e44d61a093ea57e964cf0af05c0e) echo 'good to go'

I dont want to write a separate script text page just to check this.

 This above thing is showing syntax error.
 But there must be a slick way to get around this?

How to do this?

Body:
I use the exit code of the previous/last command:

If the checksum is valid the exit code of the last executed command is 0:

> echo "${PROMETHEUS_CHECKSUM} prometheus-${PROMETHEUS_VERSION}.linux-arm64.tar.gz" | sha256sum -c
> echo $?
0

If the checksum is not correct, then the exit code is different than 0:

> export PROMETHEUS_CHECKSUM='some garbage'
> echo "${PROMETHEUS_CHECKSUM} prometheus-${PROMETHEUS_VERSION}.linux-arm64.tar.gz" | sha256sum -c
prometheus-2.0.0.linux-arm64.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
> echo $?
1

And here is the whole example with an if statement:

#!/bin/bash

...

echo "${PROMETHEUS_CHECKSUM} prometheus-${PROMETHEUS_VERSION}.linux-arm64.tar.gz" | sha256sum -c

if [ $? != 0 ]; then
  echo 'Prometheus checksum is not valid'
  exit 1
fi


问:
Packaging Angular 5 UI-Components - Module not found
I'm developing UI Components for usage in different Web-Projects across the company. We want to publish the components as npm package on our local Repository, ideally with sources included (for debugging). I found this article about exporting Angular Components and stick to it widely.

Unfortunately, when I npm install and import the package in another project, the module is not found:

```<code>import { TidUIComponentsModule } from '@tid/ui-components';
</code>```

ERROR in src/app/app.module.ts(4,40): error TS2307: Cannot find module '@tid/ui-components'.

Where should the (ES5/ES6/TS?) module be located in the npm package? And which configuration is required for this?

My directory structure before packaging looks like this:

With package.json:

```<code>{
   "name": "@tid/ui-components",
   "version": "0.0.1",
   "main": "./bundles/tidcomponents.umd.js",
   "module": "./index.js",
   "typings": "./index.d.ts",
   "peerDependencies": {
      "@angular/core": "5.0.3",
      "@angular/common": "5.0.3",
      "@angular/forms": "5.0.3",
      "@ng-bootstrap/ng-bootstrap": "1.0.0-beta.6"
   },
   "license": "proprietary",
   "publishConfig": {
      "registry": "http://maven/repository/npm-internal/"
   },
   "files": [
      "dist"
   ]
}
</code>```

index.ts:

```<code>export { TidUIComponentsModule } from './src/tid-ui-components.module';
export { ButtonComponent } from './src/components/button/button.component';
export { FormComponent } from './src/components/form/form.component';
export { FormRowComponent } from './src/components/form-row/form-row.component';
</code>```

rollup.config.js

```<code>export default {
   input: 'dist/index.js',
   output: {
      format: 'umd',
      file: 'dist/bundles/tidcomponents.umd.js'
   },
   exports: 'named',
   sourceMap: false,
   name: 'tid.components',
   globals: {
      '@angular/core': 'ng.core',
      '@angular/common': 'ng.common',
      '@angular/forms': 'ng.forms',
      '@ng-bootstrap/ng-bootstrap': 'ngb.ng-bootstrap',
   },
   external: [
      '@angular/core',
      '@angular/common',
      '@angular/forms',
      '@ng-bootstrap/ng-bootstrap'
   ]
}
</code>```

tsconfig.json

```<code>{
  "compilerOptions": {
    "baseUrl": ".",
    "declaration": true,
    "stripInternal": true,
    "experimentalDecorators": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "module": "es2015",
    "moduleResolution": "node",
    "paths": {
      "@angular/core": ["node_modules/@angular/core"],
      "@angular/common": ["node_modules/@angular/common"],
      "@angular/forms": ["node_modules/@angular/forms"],
      "@ng-bootstrap/ng-bootstrap": ["node_modules/@ng-bootstrap/ng-bootstrap"]
    },
    "rootDir": ".",
    "outDir": "dist",
    "sourceMap": true,
    "inlineSources": true,
    "target": "es5",
    "skipLibCheck": true,
    "lib": [
      "es2015",
      "dom"
    ]
  },
  "files": [
    "index.ts"
  ],
  "angularCompilerOptions": {
    "strictMetadataEmit": true
  }
}
</code>```

After packaging it with ngc && rollup -c && uglifyjs dist/bundles/tidcomponents.umd.js --screw-ie8 --compress --mangle --comments all --output dist/bundles/tidcomponents.umd.min.js, this structure is created:

After npm install, the folder in node_modules looks like this:

答:
Probably this import works:

```<code>import { TidUIComponentsModule } from '@tid/ui-components/dist';
</code>```

Because that's where your index is located and your bundles folder. I believe changing your package.json would be enough:

Change your main, module and typings entries to:

```<code>"main": "./dist/bundles/tidcomponents.umd.js",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts",
</code>```

You should also add some extra angularCompilerOptions to your tsconfig.json, and perhaps guide ngc to this config:

```<code>"angularCompilerOptions": {
    "skipTemplateCodegen": true,
    "annotateForClosureCompiler": true,
    "strictMetadataEmit": true,
    "flatModuleOutFile": "index",
    "flatModuleId": "tid-components"
}
</code>```

and package it using:

```<code>ngc -p ./tsconfig.json && rollup ... etc
</code>```

Body:
I'm developing UI Components for usage in different Web-Projects across the company. We want to publish the components as npm package on our local Repository, ideally with sources included (for debugging). I found this article about exporting Angular Components and stick to it widely.

Unfortunately, when I npm install and import the package in another project, the module is not found:

import { TidUIComponentsModule } from '@tid/ui-components';

ERROR in src/app/app.module.ts(4,40): error TS2307: Cannot find module '@tid/ui-components'.

Where should the (ES5/ES6/TS?) module be located in the npm package? And which configuration is required for this?

My directory structure before packaging looks like this:

With package.json:

{
   "name": "@tid/ui-components",
   "version": "0.0.1",
   "main": "./bundles/tidcomponents.umd.js",
   "module": "./index.js",
   "typings": "./index.d.ts",
   "peerDependencies": {
      "@angular/core": "5.0.3",
      "@angular/common": "5.0.3",
      "@angular/forms": "5.0.3",
      "@ng-bootstrap/ng-bootstrap": "1.0.0-beta.6"
   },
   "license": "proprietary",
   "publishConfig": {
      "registry": "http://maven/repository/npm-internal/"
   },
   "files": [
      "dist"
   ]
}

index.ts:

export { TidUIComponentsModule } from './src/tid-ui-components.module';
export { ButtonComponent } from './src/components/button/button.component';
export { FormComponent } from './src/components/form/form.component';
export { FormRowComponent } from './src/components/form-row/form-row.component';

rollup.config.js

export default {
   input: 'dist/index.js',
   output: {
      format: 'umd',
      file: 'dist/bundles/tidcomponents.umd.js'
   },
   exports: 'named',
   sourceMap: false,
   name: 'tid.components',
   globals: {
      '@angular/core': 'ng.core',
      '@angular/common': 'ng.common',
      '@angular/forms': 'ng.forms',
      '@ng-bootstrap/ng-bootstrap': 'ngb.ng-bootstrap',
   },
   external: [
      '@angular/core',
      '@angular/common',
      '@angular/forms',
      '@ng-bootstrap/ng-bootstrap'
   ]
}

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "declaration": true,
    "stripInternal": true,
    "experimentalDecorators": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "module": "es2015",
    "moduleResolution": "node",
    "paths": {
      "@angular/core": ["node_modules/@angular/core"],
      "@angular/common": ["node_modules/@angular/common"],
      "@angular/forms": ["node_modules/@angular/forms"],
      "@ng-bootstrap/ng-bootstrap": ["node_modules/@ng-bootstrap/ng-bootstrap"]
    },
    "rootDir": ".",
    "outDir": "dist",
    "sourceMap": true,
    "inlineSources": true,
    "target": "es5",
    "skipLibCheck": true,
    "lib": [
      "es2015",
      "dom"
    ]
  },
  "files": [
    "index.ts"
  ],
  "angularCompilerOptions": {
    "strictMetadataEmit": true
  }
}

After packaging it with ngc && rollup -c && uglifyjs dist/bundles/tidcomponents.umd.js --screw-ie8 --compress --mangle --comments all --output dist/bundles/tidcomponents.umd.min.js, this structure is created:

After npm install, the folder in node_modules looks like this:

Body:
Probably this import works:

import { TidUIComponentsModule } from '@tid/ui-components/dist';

Because that's where your index is located and your bundles folder. I believe changing your package.json would be enough:

Change your main, module and typings entries to:

"main": "./dist/bundles/tidcomponents.umd.js",
"module": "./dist/index.js",
"typings": "./dist/index.d.ts",

You should also add some extra angularCompilerOptions to your tsconfig.json, and perhaps guide ngc to this config:

"angularCompilerOptions": {
    "skipTemplateCodegen": true,
    "annotateForClosureCompiler": true,
    "strictMetadataEmit": true,
    "flatModuleOutFile": "index",
    "flatModuleId": "tid-components"
}

and package it using:

ngc -p ./tsconfig.json && rollup ... etc


问:
App not opened programmatically?
I installed Meeseva app on my device. When I try to open it programmatically it's not opening.

```<code>if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"Meeseva App://location?id=1"]]) {
    NSString *mystr=[[NSString alloc] initWithFormat:@"Meeseva App://location?id=1"];
    NSURL *myurl=[[NSURL alloc] initWithString:mystr];
    [[UIApplication sharedApplication] openURL:myurl];
}
</code>```

When I opened fb, twitter, google+ and etc... all are opening successfully.
Can any solve this this issue?

App link is
https://itunes.apple.com/in/app/meeseva-app/id1121539928?mt=8

Is there any another way to open installed app programatically?

答:
If your app can receive specially formatted URLs, you should register the corresponding URL schemes with the system. Apps often use custom URL schemes to vend services to other apps.

Hence "Meeseva" app might not have created a custom url for their app. So you can't do anything for it.

As mentioned above the apps which want to provide support for url schema then they have to create a custom URL schemes.

Title: App not opened programmatically?

Body:
I installed Meeseva app on my device. When I try to open it programmatically it's not opening.

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"Meeseva App://location?id=1"]]) {
    NSString *mystr=[[NSString alloc] initWithFormat:@"Meeseva App://location?id=1"];
    NSURL *myurl=[[NSURL alloc] initWithString:mystr];
    [[UIApplication sharedApplication] openURL:myurl];
}

When I opened fb, twitter, google+ and etc... all are opening successfully.
Can any solve this this issue?

App link is
https://itunes.apple.com/in/app/meeseva-app/id1121539928?mt=8

Is there any another way to open installed app programatically?


问:
Get first element from a Set, if it exists, in Haskell
I'm using the containers library and I'm trying to extract the first element out of a set using this approach in the REPL:

```<code>let initialSet = insert "x" empty
let setWithTwoElems = insert "y" initialSet
elemAt 0 (filter (\v -> v == "x") setWithTwoElems)
</code>```

While this works it's not safe if the predicate passed to filter doesn't match any of the elements in the Set. If I do for example:

```<code>elemAt 0 (filter (\v -> v == "z") setWithTwoElems)
</code>```

it'll blow up saying:

```<code>"*** Exception: Set.elemAt: index out of range
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Set/Base.hs:1186:16 in containers-0.5.7.1:Data.Set.Base
</code>```

which kind of defies the purpose of using Haskell? I'd like something similar to elemAt (or just first) that returns a Maybe result instead.

How can I do this?

答:
The function you are looking for is called find and comes from Data.Foldable.

From the documentation:

The find function takes a predicate and a structure and returns the leftmost element of the structure matching the predicate, or Nothing if there is no such element.

Therefore, you can use find (\v -> v == "x") setWithTwoElems

Body:
I'm using the containers library and I'm trying to extract the first element out of a set using this approach in the REPL:

let initialSet = insert "x" empty
let setWithTwoElems = insert "y" initialSet
elemAt 0 (filter (\v -> v == "x") setWithTwoElems)

While this works it's not safe if the predicate passed to filter doesn't match any of the elements in the Set. If I do for example:

elemAt 0 (filter (\v -> v == "z") setWithTwoElems)

it'll blow up saying:

"*** Exception: Set.elemAt: index out of range
CallStack (from HasCallStack):
  error, called at libraries/containers/Data/Set/Base.hs:1186:16 in containers-0.5.7.1:Data.Set.Base

which kind of defies the purpose of using Haskell? I'd like something similar to elemAt (or just first) that returns a Maybe result instead.

How can I do this?


问:
Convert Object To Byte Array without Serialization nor Padding
It seems easy but I can't see it easy at all. My question is I have a struct and I need to convert it to byte stream without any additional bytes for types nor padding nor metadata. Assume I have a struct

```<code>[StructLayout(LayoutKind.Sequential)]
public struct MyStruct
{
    public ushort a;
    public uint b;
    public uint c;
    public ushort d;
}
</code>```

Remark: I can't change the pack here to 1(Project constrains), so using the following solution won't work as there's a padding added

```<code>int size = Marshal.SizeOf(typeof(T));
byte[] arr = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(str, ptr, true);
Marshal.Copy(ptr, arr, 0, size);
Marshal.FreeHGlobal(ptr);
</code>```

Also Remark: I can't use Binary format serialization as there's a metadata added.  All what I want simply if a=1 b=2 c=3 d=4 to get binary format in a GENERIC WAY as

```<code>    arr {byte[12]}  byte[]
    [0]  1  byte
    [1]  0  byte
    [2]  2  byte
    [3]  0  byte
    [4]  0  byte
    [5]  0  byte
    [6]  3  byte
    [7]  0  byte
    [8]  0  byte
    [9]  0  byte
    [10] 4  byte
    [11] 0  byte
</code>```

Any help?

答:
If you don't mind a bit of manual work, you can write your own converter and handle each datatype differently, for example:

```<code>public static class StructSerializer
{
    public static byte[] Serialize<T>(T data) where T : struct
    {
        List<byte> result = new List<byte>();
        Type type = data.GetType();
        IEnumerable<FieldInfo> orderedFields = type.GetFields().OrderBy(f => Marshal.OffsetOf(type, f.Name).ToInt32());

        foreach (FieldInfo fieldInfo in orderedFields)
        {
            object value = fieldInfo.GetValue(data);
            MethodInfo conversion = typeof(BitConverter).GetMethod(nameof(BitConverter.GetBytes), new[]{fieldInfo.FieldType});
            if (conversion == null) continue;
            byte[] converted = (byte[])conversion.Invoke(null, new []{value});
            result.AddRange(converted);
        }

        return result.ToArray();
    }
}
</code>```

You didn't specifically mention it, but keep the ByteOrder in mind. You can check the byte order with BitConverter.IsLittleEndian.

Body:
It seems easy but I can't see it easy at all. My question is I have a struct and I need to convert it to byte stream without any additional bytes for types nor padding nor metadata. Assume I have a struct

[StructLayout(LayoutKind.Sequential)]
public struct MyStruct
{
    public ushort a;
    public uint b;
    public uint c;
    public ushort d;
}

Remark: I can't change the pack here to 1(Project constrains), so using the following solution won't work as there's a padding added

int size = Marshal.SizeOf(typeof(T));
byte[] arr = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(str, ptr, true);
Marshal.Copy(ptr, arr, 0, size);
Marshal.FreeHGlobal(ptr);

Also Remark: I can't use Binary format serialization as there's a metadata added.  All what I want simply if a=1 b=2 c=3 d=4 to get binary format in a GENERIC WAY as

    arr {byte[12]}  byte[]
    [0]  1  byte
    [1]  0  byte
    [2]  2  byte
    [3]  0  byte
    [4]  0  byte
    [5]  0  byte
    [6]  3  byte
    [7]  0  byte
    [8]  0  byte
    [9]  0  byte
    [10] 4  byte
    [11] 0  byte

Any help?

Body:
If you don't mind a bit of manual work, you can write your own converter and handle each datatype differently, for example:

public static class StructSerializer
{
    public static byte[] Serialize<T>(T data) where T : struct
    {
        List<byte> result = new List<byte>();
        Type type = data.GetType();
        IEnumerable<FieldInfo> orderedFields = type.GetFields().OrderBy(f => Marshal.OffsetOf(type, f.Name).ToInt32());

        foreach (FieldInfo fieldInfo in orderedFields)
        {
            object value = fieldInfo.GetValue(data);
            MethodInfo conversion = typeof(BitConverter).GetMethod(nameof(BitConverter.GetBytes), new[]{fieldInfo.FieldType});
            if (conversion == null) continue;
            byte[] converted = (byte[])conversion.Invoke(null, new []{value});
            result.AddRange(converted);
        }

        return result.ToArray();
    }
}

You didn't specifically mention it, but keep the ByteOrder in mind. You can check the byte order with BitConverter.IsLittleEndian.


问:
Why are these semicolumns in this for loop?
I was just looking at W3schools, and was looking at the "for loops". I saw this code example:

```<code>var cars = ["BMW", "Volvo", "Saab", "Ford"];
var i = 0;
var text = "";
for (;cars[i];) {
    text += cars[i] + "<br>";
    i++;
}
document.getElementById("demo").innerHTML = text;
</code>```

I saw these semicolumns in the "for loop", I removed them and tried running it again. And as you expect, I got an error. Why are these semicolumns there? This is the first time I saw this and I'm really curious why these need to be there.

Thanks if you can give me some information about this because I couldn't find anything about it...

答:
for loop is composed by 3 parts as follows:

The first part initializes the loop; the second decides whether or not to continue the loop, and the third does something at the end of each iteration.

But, each of them is optional.

for (;cars[i];) statement is same as

```<code>while(cars[i]){
    //code
}
</code>```

Note: it also exists for(;;) which is equivalent to :

```<code>while(true){ }
</code>```

Body:
I was just looking at W3schools, and was looking at the "for loops". I saw this code example:

var cars = ["BMW", "Volvo", "Saab", "Ford"];
var i = 0;
var text = "";
for (;cars[i];) {
    text += cars[i] + "
";
    i++;
}
document.getElementById("demo").innerHTML = text;

I saw these semicolumns in the "for loop", I removed them and tried running it again. And as you expect, I got an error. Why are these semicolumns there? This is the first time I saw this and I'm really curious why these need to be there.

Thanks if you can give me some information about this because I couldn't find anything about it...

Body:
for loop is composed by 3 parts as follows:

The first part initializes the loop; the second decides whether or not to continue the loop, and the third does something at the end of each iteration.

But, each of them is optional.

for (;cars[i];) statement is same as

while(cars[i]){
    //code
}

Note: it also exists for(;;) which is equivalent to :

while(true){ }


问:
Switching classes onClick toggle
I am learning by doing and have hit a road block while developing a website. I have a menu with 4 options, there is an active state and off state in css as well as the first option is active by default. When clicking any option it toggles it to the active state but does not change the previous one to the off state.

Code:

function myFunc(e) {
  if (e.className == 'channel') {
    e.className = 'channel active';
  } else {
    e.className = 'channel';
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><li id="test" class="channel active" data-v-a3c933a2="" onclick="openPlayer('option1'); myFunc(this)">
  <div class="status offline" data-v-a3c933a2="">Offline <span class="viewers" data-v-a3c933a2="">0</span>
  </div>Option1
</li>
<li id="test" class="channel" data-v-a3c933a2="" onclick="openPlayer('option2'); myFunc(this)">
  <div class="status offline" data-v-a3c933a2="">Offline <span class="viewers" data-v-a3c933a2="">0</span>
  </div>Option2
</li>
<li id="test" class="channel" data-v-a3c933a2="" onclick="openPlayer('option3'); myFunc(this)">
  <div class="status offline" data-v-a3c933a2="">Offline <span class="viewers" data-v-a3c933a2="">0</span>
  </div>Option3
</li>
<li id="test" class="channel" data-v-a3c933a2="" onclick="openPlayer('option4'); myFunc(this)">
  <div class="status offline" data-v-a3c933a2="">Offline <span class="viewers" data-v-a3c933a2="">0</span>
  </div>Option4
</li></code>```

How do I go about having all nonactive options actually display in the off state instead of just toggling per-click?

Thank you for your time!

答:
Check this is simple example as per your requirement.</p>

```<code>    <ul id="navlist">
    <li id="home"><a class="nav" href="home">Home</a></li>
    <li id="about"><a class="nav" href="about-us">About Us</a></li>
</ul>
<script>
$('#navlist a').click(function(e) {
    e.preventDefault(); //prevent the link from being followed
    $('#navlist a').removeClass('selected');
    $(this).addClass('selected');
});
<script>
</code>```

Title: Switching classes onClick toggle

Body:
I am learning by doing and have hit a road block while developing a website. I have a menu with 4 options, there is an active state and off state in css as well as the first option is active by default. When clicking any option it toggles it to the active state but does not change the previous one to the off state.

Code:

function myFunc(e) {
  if (e.className == 'channel') {
    e.className = 'channel active';
  } else {
    e.className = 'channel';
  }
}

Offline 0

Option1

Offline 0

Option2

Offline 0

Option3

Offline 0

Option4

How do I go about having all nonactive options actually display in the off state instead of just toggling per-click?

Thank you for your time!

Body:
Check this is simple example as per your requirement.

    <ul id="navlist">
    <li id="home"><a class="nav" href="home">Home</a></li>
    <li id="about"><a class="nav" href="about-us">About Us</a></li>
</ul>
<script>
$('#navlist a').click(function(e) {
    e.preventDefault(); //prevent the link from being followed
    $('#navlist a').removeClass('selected');
    $(this).addClass('selected');
});
<script>


问:
Cannot modify managed objects outside of a write transaction - React Native, Realm
```<code>onPressFavourites(item) {
    let realm = Realm.open({
    path: RNFS.DocumentDirectoryPath +'/trees.realm',
    schema: [sightingSchema, treeSchema],
    schemaVersion: 7,
   }).then(realm => {
    if(item.favourites === 0) {
     realm.write(() => {
        item.favourites = 1;
        item.favouritesColour = '#91b54d';
    });

    } else {
        realm.write(() => {
      item.favourites = 0;
        item.favouritesColour = 'transparent';
          });
    }
        });
    alert(item.favourites)// Update a property value
    }
</code>```

I am trying to update an object in the Realm when a button is clicked however I get the error

"Possible Unhandled Promise Rejection (id: 0):
Error: Cannot modify managed objects outside of a write transaction."

This code was working a couple days ago but is now throwing the above error.

I am still learning React Native and Realm but from my understanding and following examples and the Realm docs, I am using the correct code so it should work.

EDIT

Seems the realm and write transactions were fine.
We were able to find a roundabout way to fix it however now the updates don't display until the app is refreshed.

It seems the error Possible Unhandled Promise Rejection (id: 0):
Error: Cannot modify managed objects outside of a write transaction. was produced when using the argument item to define the chosen Realm Object. However, if we create a variable related to the item, it doesn't produce that error. Any ideas why this would happen?

```<code>onPressFavourites(item) {
    //console.log(realm);
    let realm = Realm.open({
        path: RNFS.DocumentDirectoryPath +'/trees.realm',
        schema: [sightingSchema, treeSchema],
        schemaVersion: 7,
    }).then(realm => {
        let trees = realm.objects('TreeInfo');
        for(var i=0; i<trees.length;i++){
            if(trees[i].commonName == item.commonName){
                var chosen = trees[i];
                break;
            }
        }
        console.log(chosen);
        if(item.favourites === 0) {
                realm.write(() => {
                    //item.favourites = 1;
                    //item.favouritesColour = '#91b54d';
                    chosen.favourites = 1;
                    chosen.favouritesColour = '#91b54d';
                });
        }
        else {
            realm.write(() => {
                chosen.favourites = 0;
                chosen.favouritesColour = 'transparent';
            });
        }
    });
    alert(item.favourites)// Update a property value
}
</code>```

EDIT

```<code>render() {
    var treeList = this.state.trees;
    console.log(treeList);
    const {navigate} = this.props.navigation;
     //var  tree = treeList[0];
    return(
        <Container>
            <Header searchBar style={styles.searchBar}>
              <Item style={styles.searchBarInner}>
                <Icon name="ios-search" />
                <Input placeholder="Search" />
              </Item>
            </Header>
            <List dataArray={treeList}
                renderRow={(item) =>
                    <ListItem style={styles.ListItem} button={true}>
                        <ListButton item={item}
                            onSelect={(item) => this.saveTreeInfo(item)}
                            onSelectFavourites={(item) =>                               this.onPressFavourites(item)
                            }
                        />
                    </ListItem>
                }
            >
            </List>
        </Container>
    );
}
</code>```

Above is where item is being passed to the onPressFavourites function. item is being generated from an array of Realm Objects treelist and displayed in a list.

The treelist array comes from the variable this.state.trees which is displayed below.

```<code>filterContent(){
        Realm.open({
            path: RNFS.DocumentDirectoryPath +'/trees.realm',
            schema: [sightingSchema, treeSchema],
            schemaVersion: 7,
            }).then(realm => {
                let trees = realm.objects('TreeInfo');
                let length = trees.length;
                let treeRealm = trees.sorted('commonName');

                console.log(this.state.leafEdges);
                if (this.state.leafEdges === 'smooth') {
                    var smoothLeaf = treeRealm.filtered('leafEdges CONTAINS "Smooth"');
                    this.setState({trees:smoothLeaf});
                }
                if (this.state.leafEdges === 'toothed') {
                    var toothedLeaf = treeRealm.filtered('leafEdges CONTAINS "Toothed"');
                    this.setState({trees:toothedLeaf});
                }
                if (this.state.leafEdges === 'notsure') {
                    this.setState({trees:treeRealm});
                }
                else if (this.state.leafEdges === 'null') {
                    this.setState({trees:treeRealm});
                }
            });
    }
</code>```

答:
这个trees 里面关联了realm里的一些东西，所以不能改变，要重新复制一个数组，像这样

let trees = realm.objects('TreeInfo');

```<code>var arr=[];
for (let i = 0;trees && i < trees .length; i++) {
  var item=trees[i];
  var item2={
    id: item.id,
     ....
  }
arr.push(item2);
}
</code>```

Body:
onPressFavourites(item) {
    let realm = Realm.open({
    path: RNFS.DocumentDirectoryPath +'/trees.realm',
    schema: [sightingSchema, treeSchema],
    schemaVersion: 7,
   }).then(realm => {
    if(item.favourites === 0) {
     realm.write(() => {
        item.favourites = 1;
        item.favouritesColour = '#91b54d';
    });

    } else {
        realm.write(() => {
      item.favourites = 0;
        item.favouritesColour = 'transparent';
          });
    }
        });
    alert(item.favourites)// Update a property value
    }

I am trying to update an object in the Realm when a button is clicked however I get the error

"Possible Unhandled Promise Rejection (id: 0):
Error: Cannot modify managed objects outside of a write transaction."

This code was working a couple days ago but is now throwing the above error.

I am still learning React Native and Realm but from my understanding and following examples and the Realm docs, I am using the correct code so it should work.

EDIT

Seems the realm and write transactions were fine.
We were able to find a roundabout way to fix it however now the updates don't display until the app is refreshed.

It seems the error Possible Unhandled Promise Rejection (id: 0):
Error: Cannot modify managed objects outside of a write transaction. was produced when using the argument item to define the chosen Realm Object. However, if we create a variable related to the item, it doesn't produce that error. Any ideas why this would happen?

onPressFavourites(item) {
    //console.log(realm);
    let realm = Realm.open({
        path: RNFS.DocumentDirectoryPath +'/trees.realm',
        schema: [sightingSchema, treeSchema],
        schemaVersion: 7,
    }).then(realm => {
        let trees = realm.objects('TreeInfo');
        for(var i=0; i<trees.length;i++){
            if(trees[i].commonName == item.commonName){
                var chosen = trees[i];
                break;
            }
        }
        console.log(chosen);
        if(item.favourites === 0) {
                realm.write(() => {
                    //item.favourites = 1;
                    //item.favouritesColour = '#91b54d';
                    chosen.favourites = 1;
                    chosen.favouritesColour = '#91b54d';
                });
        }
        else {
            realm.write(() => {
                chosen.favourites = 0;
                chosen.favouritesColour = 'transparent';
            });
        }
    });
    alert(item.favourites)// Update a property value
}

EDIT

render() {
    var treeList = this.state.trees;
    console.log(treeList);
    const {navigate} = this.props.navigation;
     //var  tree = treeList[0];
    return(
        <Container>

              <Item style={styles.searchBarInner}>
                <Icon name="ios-search" />
                <Input placeholder="Search" />
              </Item>

            <List dataArray={treeList}
                renderRow={(item) =>
                    <ListItem style={styles.ListItem} button={true}>
                        <ListButton item={item}
                            onSelect={(item) => this.saveTreeInfo(item)}
                            onSelectFavourites={(item) =>                               this.onPressFavourites(item)
                            }
                        />
                    </ListItem>
                }
            >
            </List>
        </Container>
    );
}

Above is where item is being passed to the onPressFavourites function. item is being generated from an array of Realm Objects treelist and displayed in a list.

The treelist array comes from the variable this.state.trees which is displayed below.

filterContent(){
        Realm.open({
            path: RNFS.DocumentDirectoryPath +'/trees.realm',
            schema: [sightingSchema, treeSchema],
            schemaVersion: 7,
            }).then(realm => {
                let trees = realm.objects('TreeInfo');
                let length = trees.length;
                let treeRealm = trees.sorted('commonName');

                console.log(this.state.leafEdges);
                if (this.state.leafEdges === 'smooth') {
                    var smoothLeaf = treeRealm.filtered('leafEdges CONTAINS "Smooth"');
                    this.setState({trees:smoothLeaf});
                }
                if (this.state.leafEdges === 'toothed') {
                    var toothedLeaf = treeRealm.filtered('leafEdges CONTAINS "Toothed"');
                    this.setState({trees:toothedLeaf});
                }
                if (this.state.leafEdges === 'notsure') {
                    this.setState({trees:treeRealm});
                }
                else if (this.state.leafEdges === 'null') {
                    this.setState({trees:treeRealm});
                }
            });
    }

Body:
这个trees 里面关联了realm里的一些东西，所以不能改变，要重新复制一个数组，像这样

let trees = realm.objects('TreeInfo');

var arr=[];
for (let i = 0;trees && i < trees .length; i++) {
  var item=trees[i];
  var item2={
    id: item.id,
     ....
  }
arr.push(item2);
}


问:
Python if loop time.sleep only execute once
Below code is for a PIR sensor written in Python.

What it should do

When the sensor was activate the first time, it should wait for 10 second once and then keep printing  "Intruder detected" until the sensor was = 0.

what is actually do

Rather than waiting 10s once, the code below wait ever 10s when the pir sensor was tigger.

Why is that?

```<code>import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)         #Read output from PIR motion sensor
GPIO.setup(3, GPIO.OUT)         #LED output pin
while True:
       i=GPIO.input(11)
       if i==0:                 #When output from motion sensor is LOW
             print "No intruders",i
             GPIO.output(3, 0)  #Turn OFF LED
             time.sleep(0.1)
       elif i==1:               #When output from motion sensor is HIGH
             time.sleep(10)     #This should be only run once when the pir sensor is trigger
             print "Intruder detected",i
             GPIO.output(3, 1)  #Turn ON LED
             time.sleep(0.1)
</code>```

答:
Simply remember if it was triggererd:

```<code>import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)         # Read output from PIR motion sensor
GPIO.setup(3, GPIO.OUT)         # LED output pin
wasTriggered = False            # not yet triggered
while True:
       i=GPIO.input(11)
       if i == 0:                          # When output from motion sensor is LOW
             print "No intruders",i
             wasTriggered = False          # reset trigger if True else does nothing
             GPIO.output(3, 0)             # Turn OFF LED
             time.sleep(0.1)
       elif i == 1:                        # When output from motion sensor is HIGH
             if wasTriggered == False:     # already triggered ?
                 time.sleep(10)            # only run once when the pir sensor is trigger
                 print "Intruder detected",i
                 GPIO.output(3, 1)         # Turn ON LED
                 wasTriggered = True       # set was triggered
             time.sleep(0.1)
</code>```

This is creating a "memory" - it will only reset once the Sensor reports one 0 on pin 11. You might want to switch the "Led goes red + Output text" and the sleep around to make it more "snappy" - meaning it will react immediately to the sensor change and then pause for 10s instead of pausing for 10s and then switch the light & print text which would disconnect the "Act"->"React" sequence.

Body:
Below code is for a PIR sensor written in Python.

What it should do

When the sensor was activate the first time, it should wait for 10 second once and then keep printing  "Intruder detected" until the sensor was = 0.

what is actually do

Rather than waiting 10s once, the code below wait ever 10s when the pir sensor was tigger.

Why is that?

import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)         #Read output from PIR motion sensor
GPIO.setup(3, GPIO.OUT)         #LED output pin
while True:
       i=GPIO.input(11)
       if i==0:                 #When output from motion sensor is LOW
             print "No intruders",i
             GPIO.output(3, 0)  #Turn OFF LED
             time.sleep(0.1)
       elif i==1:               #When output from motion sensor is HIGH
             time.sleep(10)     #This should be only run once when the pir sensor is trigger
             print "Intruder detected",i
             GPIO.output(3, 1)  #Turn ON LED
             time.sleep(0.1)

Body:
Simply remember if it was triggererd:

import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)         # Read output from PIR motion sensor
GPIO.setup(3, GPIO.OUT)         # LED output pin
wasTriggered = False            # not yet triggered
while True:
       i=GPIO.input(11)
       if i == 0:                          # When output from motion sensor is LOW
             print "No intruders",i
             wasTriggered = False          # reset trigger if True else does nothing
             GPIO.output(3, 0)             # Turn OFF LED
             time.sleep(0.1)
       elif i == 1:                        # When output from motion sensor is HIGH
             if wasTriggered == False:     # already triggered ?
                 time.sleep(10)            # only run once when the pir sensor is trigger
                 print "Intruder detected",i
                 GPIO.output(3, 1)         # Turn ON LED
                 wasTriggered = True       # set was triggered
             time.sleep(0.1)

This is creating a "memory" - it will only reset once the Sensor reports one 0 on pin 11. You might want to switch the "Led goes red + Output text" and the sleep around to make it more "snappy" - meaning it will react immediately to the sensor change and then pause for 10s instead of pausing for 10s and then switch the light & print text which would disconnect the "Act"->"React" sequence.


问:
Find XPath attribute name contains specific string
I have <form data-v-4db188a6=""> tag.
I need find only form tag contains 'data' in the attribute name not attribute value!
.//form[contains(@prop, 'data')] not work.
Is it even possible?

答:
Yes, this is possible:</p>

```<code>//form[attribute::*[contains(local-name(), 'data')]]
</code>```

Body:
Yes, this is possible:

//form[attribute::*[contains(local-name(), 'data')]]


问:
'More than one file was found with OS independent path project.properties' Error in android
I'm getting this error after I added google translate api on my project. I am using Android Studio 3.0, Gradle 3.0.0.

```<code> Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
 More than one file was found with OS independent path 'project.properties'
</code>```

I have tried the solution presented here and here, but with no success.
Also I tried downgrading gradle to version 2.3 but that didn't solve the problem either.

My build.gradle file :

```<code>android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.aim.fjalortest"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/project.properties'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'

    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    compile 'com.android.support:recyclerview-v7:25.4.0'
    compile 'com.google.android.gms:play-services-vision:9.0.0+'
    compile 'com.android.support:design:25.4.0'
    compile 'com.google.cloud:google-cloud-translate:1.12.0'
    //annotationProcessor 'com.google.cloud:google-cloud-translate:1.12.0'

    //jackson
    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
    compile 'com.fasterxml.jackson.core:jackson-core:2.8.5'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.5'

}
</code>```

Can anyone help me figuring out what's causing this error?

答:
Adding the following lines solved my problem: </p>

```<code>packagingOptions {

        exclude 'project.properties'
        exclude 'META-INF/INDEX.LIST'
    }
</code>```

Body:
I'm getting this error after I added google translate api on my project. I am using Android Studio 3.0, Gradle 3.0.0.

 Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
 More than one file was found with OS independent path 'project.properties'

I have tried the solution presented here and here, but with no success.
Also I tried downgrading gradle to version 2.3 but that didn't solve the problem either.

My build.gradle file :

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.aim.fjalortest"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/project.properties'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'

    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    compile 'com.android.support:recyclerview-v7:25.4.0'
    compile 'com.google.android.gms:play-services-vision:9.0.0+'
    compile 'com.android.support:design:25.4.0'
    compile 'com.google.cloud:google-cloud-translate:1.12.0'
    //annotationProcessor 'com.google.cloud:google-cloud-translate:1.12.0'

    //jackson
    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
    compile 'com.fasterxml.jackson.core:jackson-core:2.8.5'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.5'

}

Can anyone help me figuring out what's causing this error?

Body:
Adding the following lines solved my problem:

packagingOptions {

        exclude 'project.properties'
        exclude 'META-INF/INDEX.LIST'
    }