问:
Containers and divs in CSS
Good day,
I'm not new to CSS or DIVs but have been out of touch for long enough. Trying to work out with Containers and nested DIVs but not getting much success in doing what I'm trying to do. Have already searched enough on SO and Goog but, hopefully you can help me.

Here's the representation of what I wish to achieve.

Screenshot of the layout

And here is what I have done so far ..

.dealsglobal {
    width: 45%;
    display: inline-block;
    float: left;
    margin-right:20px;
    height: auto;
    overflow: auto;
}

.dealsglobal h2 {
    margin-left: 10px;
}

.dealsindia {
    width: 45%;
    height: auto;
    overflow: auto;
}

.dealsindia h2 {
    margin-left: 10px;
}

.dealsleft {
    margin: 0px 25px 10px 0px;
    padding: 5px;
    border: 1px solid #ccc;
    height: auto;
    position: relative;
    width: 40%;
    float: left;
    display: inline-block;
    overflow: auto;
}

.dealsleft img {
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 4px;
    margin-left: auto;
    margin-right: auto;
    width: 100px;
}

.dealsright {
    margin-bottom: 10px;
    padding: 5px;
    border: 1px solid #ccc;
    height: auto;
    position: relative;
    width: 40%;
    display: inline-block;
    overflow: auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="dealsglobal">
<h2>Global Coupons</h2>
    <div class="dealsleft">
 <img src="thumb-heavengifts.jpg" alt="HeavenGifts.com Web Store" align="middle" />
    </div>
    <div class="dealsright">
    Test
    </div>
</div>

<div class="dealsindia">
<h2>Indian Coupons</h2>
    <div class="dealsleft">
    Test
    </div>
    <div class="dealsright">
 Test
    </div>
</div></code>```

The image just wont center, no matter what I do. I believe, somewhere I have set the property to align left or something. Can anyone please point me to the correct direction? Thanks for your help!

答:
I have added background colors for visualization purposes.

* {
  box-sizing: border-box;
}

#container {
  width: 100%;
  padding: 10px;
  background-color: red;
  display: flex;
  justify-content: space-between;
}

.subcontainer-outer {
  width: 49%;
  background-color: green;
}

.subcontainer {
  width: 100%;
  background-color: blue;
  display: flex;
  justify-content: space-between;
}

.content {
  width: 45%;
  text-align: center;
  background-color: yellow;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><h3>Container</h3>
<div id="container">
  <div class="subcontainer-outer">
    <h4>Sub container 1</h4>
    <div class="subcontainer">
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
    </div>
  </div>
  <div class="subcontainer-outer">
    <h4>Sub container 2</h4>
    <div class="subcontainer">
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
    </div>
  </div>
</div></code>```

Title: Containers and divs in CSS

Body:
Good day,
I'm not new to CSS or DIVs but have been out of touch for long enough. Trying to work out with Containers and nested DIVs but not getting much success in doing what I'm trying to do. Have already searched enough on SO and Goog but, hopefully you can help me.

Here's the representation of what I wish to achieve.

Screenshot of the layout

And here is what I have done so far ..

.dealsglobal {
    width: 45%;
    display: inline-block;
    float: left;
    margin-right:20px;
    height: auto;
    overflow: auto;
}

.dealsglobal h2 {
    margin-left: 10px;
}

.dealsindia {
    width: 45%;
    height: auto;
    overflow: auto;
}

.dealsindia h2 {
    margin-left: 10px;
}

.dealsleft {
    margin: 0px 25px 10px 0px;
    padding: 5px;
    border: 1px solid #ccc;
    height: auto;
    position: relative;
    width: 40%;
    float: left;
    display: inline-block;
    overflow: auto;
}

.dealsleft img {
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 4px;
    margin-left: auto;
    margin-right: auto;
    width: 100px;
}

.dealsright {
    margin-bottom: 10px;
    padding: 5px;
    border: 1px solid #ccc;
    height: auto;
    position: relative;
    width: 40%;
    display: inline-block;
    overflow: auto;
}

Global Coupons

    Test

Indian Coupons

    Test

 Test

The image just wont center, no matter what I do. I believe, somewhere I have set the property to align left or something. Can anyone please point me to the correct direction? Thanks for your help!

Body:
I have added background colors for visualization purposes.

* {
  box-sizing: border-box;
}

#container {
  width: 100%;
  padding: 10px;
  background-color: red;
  display: flex;
  justify-content: space-between;
}

.subcontainer-outer {
  width: 49%;
  background-color: green;
}

.subcontainer {
  width: 100%;
  background-color: blue;
  display: flex;
  justify-content: space-between;
}

.content {
  width: 45%;
  text-align: center;
  background-color: yellow;
}

<h3>Container</h3>
<div id="container">
  <div class="subcontainer-outer">
    <h4>Sub container 1</h4>
    <div class="subcontainer">
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
    </div>
  </div>
  <div class="subcontainer-outer">
    <h4>Sub container 2</h4>
    <div class="subcontainer">
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
      <div class="content">
        <img src="http://placehold.it/100" />
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
      </div>
    </div>
  </div>
</div>


来源: stackexchange

问:
MVC Razor view Intellisense broken in VS 2013/2015/2017
I have an existing project written in VS2010 which when loaded in VS2010 works perfectly.

When I load this same project in VS2013 the MVC Razor views contain lots of errors as if the config file is missing from the views folder.

It appears to have not loaded the Razor editor correctly using the config files from both the root and the views folder and instead gives me errors like ...

```<code>The name 'model' does not exist in the current context
</code>```

and ...

```<code>'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor'
and no extension method 'LabelFor' accepting a first argument of type
'System.Web.WebPages.Html.HtmlHelper' could be found
(are you missing a using directive or an assembly reference?)
</code>```

...

Any idea what would cause this?

Edit:
Config files as requested ....

From main web.config file (not all of it as it's way too big to post)

```<code><runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Ninject" culture="neutral" publicKeyToken="c7192dc5380945e7" />
            <bindingRedirect newVersion="3.0.0.0" oldVersion="0.0.0.0-3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Validation" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect newVersion="5.0.505.0" oldVersion="0.0.0.0-5.0.505.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>
</code>```

Config file in "~/Views/" ...

```<code><?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />
                <add namespace="Emedia.Common.Mvc.Views.Helpers"/>
                <add namespace="Emedia.Common.Mvc.Views.Extensions"/>
        <add namespace="Emedia.Common.Utilities"/>
        <add namespace="Emedia.Common.Utilities.Extensions"/>
        <add namespace="Emedia.Common.Mvc.Controllers.Helpers"/>
                <add namespace="Emedia.Resources.Service"/>
        <add namespace="Emedia.Subscriber.Controllers"/>
        <add namespace="Emedia.Subscriber.Controllers.ViewModels"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>

    <appSettings>
        <add key="webpages:Enabled" value="false" />
    </appSettings>

    <system.web>
        <httpHandlers>
            <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <controls>
                <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
    </pages>
</system.web>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
        <remove name="BlockViewHandler"/>
        <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
</system.webServer>
</code>```

答:
I have tried almost every solutions but did not get intellisense and at the end I found a solution:

Go to Solution Explorer

Right click on .cshtml file or any view file

Select "Open With" option and make HTML Editor(Default) set as default

ContentLicense: CC BY-SA 3.0

Body:
I have an existing project written in VS2010 which when loaded in VS2010 works perfectly.

When I load this same project in VS2013 the MVC Razor views contain lots of errors as if the config file is missing from the views folder.

It appears to have not loaded the Razor editor correctly using the config files from both the root and the views folder and instead gives me errors like ...

The name 'model' does not exist in the current context

and ...

'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor'
and no extension method 'LabelFor' accepting a first argument of type
'System.Web.WebPages.Html.HtmlHelper' could be found
(are you missing a using directive or an assembly reference?)

...

Any idea what would cause this?

Edit:
Config files as requested ....

From main web.config file (not all of it as it's way too big to post)

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Ninject" culture="neutral" publicKeyToken="c7192dc5380945e7" />
            <bindingRedirect newVersion="3.0.0.0" oldVersion="0.0.0.0-3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Validation" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect newVersion="5.0.505.0" oldVersion="0.0.0.0-5.0.505.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Config file in "~/Views/" ...

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

        </sectionGroup>
    </configSections>

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />
                <add namespace="Emedia.Common.Mvc.Views.Helpers"/>
                <add namespace="Emedia.Common.Mvc.Views.Extensions"/>
        <add namespace="Emedia.Common.Utilities"/>
        <add namespace="Emedia.Common.Utilities.Extensions"/>
        <add namespace="Emedia.Common.Mvc.Controllers.Helpers"/>
                <add namespace="Emedia.Resources.Service"/>
        <add namespace="Emedia.Subscriber.Controllers"/>
        <add namespace="Emedia.Subscriber.Controllers.ViewModels"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>

    <appSettings>
        <add key="webpages:Enabled" value="false" />
    </appSettings>

    <system.web>
        <httpHandlers>
            <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <controls>
                <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
    </pages>
</system.web>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
        <remove name="BlockViewHandler"/>
        <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
</system.webServer>


问:
Is mouse over Form?
This code is not working for me on Delphi XE:

http://delphi.about.com/cs/adptips2000/a/bltip0800_5.htm

```<code>procedure TForm1.FormDeactivate(Sender: TObject) ;
begin
   ReleaseCapture;
end;

procedure TForm1.FormMouseMove
(Sender: TObject; Shift: TShiftState; X,Y: Integer) ;
begin
  If GetCapture = 0 then
    SetCapture(Form1.Handle) ;
    if PtInRect(Rect(Form1.Left,
                    Form1.Top,
                    Form1.Left + Form1.Width,
                    Form1.Top + Form1.Height),
                    ClientToScreen(Point(x, y))) then
     Form1.Caption := 'Mouse is over form' else
     Form1.Caption := 'Mouse is outside of form';
end;
</code>```

No errors - it just has no effect.

Please help.

EDIT 1

It turned out the problem is not with the code, even mouse FormMouseEnter and FormMouseLeave are not working because I'm passing the form to a Unit I created with a function like this:

procedure Slide(Form: TForm; Show: Boolean);

I'm calling the Show method from inside this procedure. How can I overcome this problem?

Thanks.

EDIT 2

I don't want to use the function I posted now. I want to use what the people suggested below (FormMouseEnter and FormMouseLeave) but it's not working in my case as well.

答:
As far as I understand, using SetCapture for this is a bad idea. If it functioned like you wish, you would be robbing everyone else of the mouse messages just because you don't know a better way to track mouse.

But MSDN says (http://msdn.microsoft.com/en-us/library/ms646262(VS.85).aspx) that even with SetCapture, mouse messages from outside would not be redirected to your window unless mouse button is down (probably a measure to prevent exactly what are you trying to achieve: stealing mouse without a valid reason).

It doesn't matter where are you calling Show() from, so your problem is not in that.

ContentLicense: CC BY-SA 2.5

Title: Is mouse over Form?

Body:
This code is not working for me on Delphi XE:

http://delphi.about.com/cs/adptips2000/a/bltip0800_5.htm

procedure TForm1.FormDeactivate(Sender: TObject) ;
begin
   ReleaseCapture;
end;

procedure TForm1.FormMouseMove
(Sender: TObject; Shift: TShiftState; X,Y: Integer) ;
begin
  If GetCapture = 0 then
    SetCapture(Form1.Handle) ;
    if PtInRect(Rect(Form1.Left,
                    Form1.Top,
                    Form1.Left + Form1.Width,
                    Form1.Top + Form1.Height),
                    ClientToScreen(Point(x, y))) then
     Form1.Caption := 'Mouse is over form' else
     Form1.Caption := 'Mouse is outside of form';
end;

No errors - it just has no effect.

Please help.

EDIT 1

It turned out the problem is not with the code, even mouse FormMouseEnter and FormMouseLeave are not working because I'm passing the form to a Unit I created with a function like this:

procedure Slide(Form: TForm; Show: Boolean);

I'm calling the Show method from inside this procedure. How can I overcome this problem?

Thanks.

EDIT 2

I don't want to use the function I posted now. I want to use what the people suggested below (FormMouseEnter and FormMouseLeave) but it's not working in my case as well.


问:
rgdal installation difficulty on ubuntu 16.04 LTS
I searched for an answer helping my situation to avoid duplicate, but to no avail.

I want to install 'rgdal' package to R on ubuntu 16.04 LTS. If I code in R-studio as follows

```<code>install.packages("rgdal", type = "source")
</code>```

it gives the following error;

```<code>Installing package into ‘/home/kocesat/R/x86_64-pc-linux-gnu-library/3.2’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘rgdal’ is not available (for R version 3.2.3)
</code>```

Then I try to install libgdal1-dev , libproj-dev  as the following

```<code>$ sudo apt-get install libgdal1-dev libproj-dev
</code>```

It succesfully installed the dev files.Then I tried to install again "rgdal" in R-studio with the same command. It did not work again.

Then I  installed homebrew and try to get gdal with

```<code>~$ brew install gdal
</code>```

it returned

```<code>Error: undefined method `rebuild' for
#<BottleSpecification:0x000000015ddc60>
Please report this bug:
https://github.com/Linuxbrew/linuxbrew/blob/master/share/doc/homebrew
/Troubleshooting.md#troubleshooting
/home/kocesat/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula
/jpeg.rb:9:in `block in <class:Jpeg>'
/home/kocesat/.linuxbrew/Library/Homebrew/software_spec.rb:91:in
`instance_eval'
/home/kocesat/.linuxbrew/Library/Homebrew/software_spec.rb:91:in `bottle'
/home/kocesat/.linuxbrew/Library/Homebrew/formula.rb:1729:in `bottle'
/home/kocesat/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula
/jpeg.rb:7:in `<class:Jpeg>'
/home/kocesat/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula
/jpeg.rb:1:in `load_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:21:in `module_eval'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:21:in
`load_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:34:in
`load_formula_from_path'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:83:in `load_file'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:74:in `klass'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:70:in `get_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:207:in `factory'
/home/kocesat/.linuxbrew/Library/Homebrew/dependency.rb:32:in `to_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/dependency.rb:93:in `block in
expand'
/home/kocesat/.linuxbrew/Library/Homebrew/dependencies.rb:9:in `each'
/home/kocesat/.linuxbrew/Library/Homebrew/dependencies.rb:9:in `each'
/home/kocesat/.linuxbrew/Library/Homebrew/dependency.rb:80:in `expand'
/home/kocesat/.linuxbrew/Library/Homebrew/formula.rb:1223:in
`recursive_dependencies'
/home/kocesat/.linuxbrew/Library/Homebrew/requirement.rb:196:in `expand'
/home/kocesat/.linuxbrew/Library/Homebrew/formula.rb:1229:in `recursive_requirements'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:313:in `expand_requirements'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:263:in `compute_dependencies'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:130:in `verify_deps_exist'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:123:in `prelude'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:231:in `install_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:93:in `block in install'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:93:in `each'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:93:in `install'
/home/kocesat/.linuxbrew/Library/brew.rb:84:in `<main>'
</code>```

Now, what I should I do? Any input will be appreciated.

答:
Here is what I use to install on Ubuntu 16.04 with the latest R-cran PPA repositories:

```<code>sudo add-apt-repository 'deb https://mirror.ibcp.fr/pub/CRAN/bin/linux/ubuntu xenial/'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt-get update
sudo apt-get install libgdal1-dev libproj-dev libgeos-dev
sudo apt-get install r-base-core
</code>```

You can use another CRAN mirror depending on your location:
https://cran.r-project.org/mirrors.html

Then, install.packages("rgdal") should work.

If you want the latest spatial libraries on Ubuntu LTS versions, you can also use ubuntugis PPA: https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa

```<code>sudo add-apt-repository 'deb http://ppa.launchpad.net/ubuntugis/ppa/ubuntu xenial main'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 314DF160
sudo apt update
sudo apt upgrade
</code>```

Body:
I searched for an answer helping my situation to avoid duplicate, but to no avail.

I want to install 'rgdal' package to R on ubuntu 16.04 LTS. If I code in R-studio as follows

install.packages("rgdal", type = "source")

it gives the following error;

Installing package into ‘/home/kocesat/R/x86_64-pc-linux-gnu-library/3.2’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘rgdal’ is not available (for R version 3.2.3)

Then I try to install libgdal1-dev , libproj-dev  as the following

$ sudo apt-get install libgdal1-dev libproj-dev

It succesfully installed the dev files.Then I tried to install again "rgdal" in R-studio with the same command. It did not work again.

Then I  installed homebrew and try to get gdal with

~$ brew install gdal

it returned

Error: undefined method `rebuild' for
#<BottleSpecification:0x000000015ddc60>
Please report this bug:
https://github.com/Linuxbrew/linuxbrew/blob/master/share/doc/homebrew
/Troubleshooting.md#troubleshooting
/home/kocesat/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula
/jpeg.rb:9:in `block in <class:Jpeg>'
/home/kocesat/.linuxbrew/Library/Homebrew/software_spec.rb:91:in
`instance_eval'
/home/kocesat/.linuxbrew/Library/Homebrew/software_spec.rb:91:in `bottle'
/home/kocesat/.linuxbrew/Library/Homebrew/formula.rb:1729:in `bottle'
/home/kocesat/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula
/jpeg.rb:7:in `<class:Jpeg>'
/home/kocesat/.linuxbrew/Library/Taps/homebrew/homebrew-core/Formula
/jpeg.rb:1:in `load_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:21:in `module_eval'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:21:in
`load_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:34:in
`load_formula_from_path'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:83:in `load_file'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:74:in `klass'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:70:in `get_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/formulary.rb:207:in `factory'
/home/kocesat/.linuxbrew/Library/Homebrew/dependency.rb:32:in `to_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/dependency.rb:93:in `block in
expand'
/home/kocesat/.linuxbrew/Library/Homebrew/dependencies.rb:9:in `each'
/home/kocesat/.linuxbrew/Library/Homebrew/dependencies.rb:9:in `each'
/home/kocesat/.linuxbrew/Library/Homebrew/dependency.rb:80:in `expand'
/home/kocesat/.linuxbrew/Library/Homebrew/formula.rb:1223:in
`recursive_dependencies'
/home/kocesat/.linuxbrew/Library/Homebrew/requirement.rb:196:in `expand'
/home/kocesat/.linuxbrew/Library/Homebrew/formula.rb:1229:in `recursive_requirements'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:313:in `expand_requirements'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:263:in `compute_dependencies'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:130:in `verify_deps_exist'
/home/kocesat/.linuxbrew/Library/Homebrew/formula_installer.rb:123:in `prelude'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:231:in `install_formula'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:93:in `block in install'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:93:in `each'
/home/kocesat/.linuxbrew/Library/Homebrew/cmd/install.rb:93:in `install'
/home/kocesat/.linuxbrew/Library/brew.rb:84:in `'

Now, what I should I do? Any input will be appreciated.

Body:
Here is what I use to install on Ubuntu 16.04 with the latest R-cran PPA repositories:

sudo add-apt-repository 'deb https://mirror.ibcp.fr/pub/CRAN/bin/linux/ubuntu xenial/'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
sudo apt-get update
sudo apt-get install libgdal1-dev libproj-dev libgeos-dev
sudo apt-get install r-base-core

You can use another CRAN mirror depending on your location:
https://cran.r-project.org/mirrors.html

Then, install.packages("rgdal") should work.

If you want the latest spatial libraries on Ubuntu LTS versions, you can also use ubuntugis PPA: https://launchpad.net/~ubuntugis/+archive/ubuntu/ppa

sudo add-apt-repository 'deb http://ppa.launchpad.net/ubuntugis/ppa/ubuntu xenial main'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 314DF160
sudo apt update
sudo apt upgrade


问:
Set text in the centre of AppBar
I this is my xml:

```<code><RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="57dp"
        android:layout_width="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Ranger"
            android:id="@+id/logoSign"/>
    </android.support.design.widget.AppBarLayout>
</RelativeLayout>
</code>```

I want to do the TextView in the centre of the AppBar. But I get this:

Thanks for your help. :)

答:
What you can do is Take a RelativeLayout inside the AppBar with height and width as "match_parent" and put the TextView inside the RelativeLayout and make it as

```<code>android:layout_centerInParent="true"
</code>```

Hope this helps.

Title: Set text in the centre of AppBar

Body:
I this is my xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="57dp"
        android:layout_width="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Ranger"
            android:id="@+id/logoSign"/>
    </android.support.design.widget.AppBarLayout>
</RelativeLayout>

I want to do the TextView in the centre of the AppBar. But I get this:

Thanks for your help. :)

Body:
What you can do is Take a RelativeLayout inside the AppBar with height and width as "match_parent" and put the TextView inside the RelativeLayout and make it as

android:layout_centerInParent="true"

Hope this helps.


问:
Inversify : contextual injection with class name
I am trying to inject loggers into different classes using inversify. I want to pass the target class name to the logger to categorize it.

The problem is I can't access the target name from where i'm creating the binding:

```<code>container.bind<log4js.Logger>(Types.Logger).toDynamicValue(context => {
    let className = context....?; // Finds class name
    return log4js.getLogger(className);
});
</code>```

Is there any way of doing this other than setting it once the logger is created in the object receiving the logger?

Thank you!

Antoine

答:
Update:

This new feature makes it possible to access the class name from the context. The name will be minified though. This can be solved by comparing against the class.

```<code>container.bind<Warrior>(TYPE.Warrior)to(Ninja).inActivation((context) => {
    const currentClass = context.currentRequest.bindings[0].implementationType;
    if (currentClass) {
        if (currentClass === Ninja) {
            // ...
        }
    }
</code>```

Original post:

Thanks for asking this question. What you are looking for it is not possible at the moment but I have created an issue in GitHub to ensure that we do something about it. You can learn more about it at https://github.com/inversify/InversifyJS/issues/576

Body:
I am trying to inject loggers into different classes using inversify. I want to pass the target class name to the logger to categorize it.

The problem is I can't access the target name from where i'm creating the binding:

container.bind<log4js.Logger>(Types.Logger).toDynamicValue(context => {
    let className = context....?; // Finds class name
    return log4js.getLogger(className);
});

Is there any way of doing this other than setting it once the logger is created in the object receiving the logger?

Thank you!

Antoine

Body:
Update:

This new feature makes it possible to access the class name from the context. The name will be minified though. This can be solved by comparing against the class.

container.bind<Warrior>(TYPE.Warrior)to(Ninja).inActivation((context) => {
    const currentClass = context.currentRequest.bindings[0].implementationType;
    if (currentClass) {
        if (currentClass === Ninja) {
            // ...
        }
    }

Original post:

Thanks for asking this question. What you are looking for it is not possible at the moment but I have created an issue in GitHub to ensure that we do something about it. You can learn more about it at https://github.com/inversify/InversifyJS/issues/576


问:
File path not getting set using 'save_screenshot' for python selenium in ubuntu
I am using python selenium to get a screenshot of test, but in ubuntu the saved screenshot is taking the path name as file name and getting saved on the desktop. I have used the same code on windows and the file was being saved in the correct destination:

```<code>def shot():
    ts = time.time()
    path = "\home\sudhanshu\Desktop\shots\sb"
    extension = ".png"
    screensave = datetime.datetime.fromtimestamp(ts).strftime('%d%m%Y%H%M%S')
    print (path+screensave+extension)
    wd.save_screenshot(path+screensave+extension)
</code>```

Here, if you see the path, I want to save the file with timestamp as file name in a folder named shots present on desktop, but it takes the complete path as file name and gets saved on the desktop. The same thing worked perfectly on windows. I have tried adding the path differently like setting ~\sudhanshu\Desktop\shots06062017170730.png as path but nothing works. Can anyone please suggest something.

答:
You should use os.path.join and os.filesep to manipulate filepaths.

```<code>import os
import time
def shot():
    ts = time.time()
    path = os.path.join("home","sudhanshu","Desktop","shots","sb")
    extention = ".png"
    screensave = datetime.datetime.fromtimestamp(ts).strftime('%d%m%Y%H%M%S')
    print(os.path.join(path, screensave+extention))
    wd.save_screenshot(os.path.join(path, screensave+extention))
</code>```

Body:
I am using python selenium to get a screenshot of test, but in ubuntu the saved screenshot is taking the path name as file name and getting saved on the desktop. I have used the same code on windows and the file was being saved in the correct destination:

def shot():
    ts = time.time()
    path = "\home\sudhanshu\Desktop\shots\sb"
    extension = ".png"
    screensave = datetime.datetime.fromtimestamp(ts).strftime('%d%m%Y%H%M%S')
    print (path+screensave+extension)
    wd.save_screenshot(path+screensave+extension)

Here, if you see the path, I want to save the file with timestamp as file name in a folder named shots present on desktop, but it takes the complete path as file name and gets saved on the desktop. The same thing worked perfectly on windows. I have tried adding the path differently like setting ~\sudhanshu\Desktop\shots06062017170730.png as path but nothing works. Can anyone please suggest something.

Body:
You should use os.path.join and os.filesep to manipulate filepaths.

import os
import time
def shot():
    ts = time.time()
    path = os.path.join("home","sudhanshu","Desktop","shots","sb")
    extention = ".png"
    screensave = datetime.datetime.fromtimestamp(ts).strftime('%d%m%Y%H%M%S')
    print(os.path.join(path, screensave+extention))
    wd.save_screenshot(os.path.join(path, screensave+extention))


问:
Zero initialising class member which is a struct in C++11
I've tried reading the C++ docs, but I find it so hard to follow. I like to zero initialise my structs like this:

```<code>MyStruct myStruct = {};
</code>```

But if I have this struct as a class member, how do I zero initialise in the constructor?

```<code>struct MyStruct
{
 int x;
 int y;
}

class MyClass
{
 MyStruct mMyStruct;
public:
 MyClass();
}

// is this fine?
MyClass::MyClass()
 : mMyStruct()
{}

// or this?
MyClass::MyClass()
 : mMyStruct({})
{}

// or do I need this?
MyClass::MyClass()
 : mMyStruct()
{
 mMyStruct = {};
}
</code>```

答:
One way is:</p>

```<code>class MyClass
{
    MyStruct mMyStruct = {};
public:
    MyClass();   // actually unnecessary
};
</code>```

Body:
I've tried reading the C++ docs, but I find it so hard to follow. I like to zero initialise my structs like this:

MyStruct myStruct = {};

But if I have this struct as a class member, how do I zero initialise in the constructor?

struct MyStruct
{
 int x;
 int y;
}

class MyClass
{
 MyStruct mMyStruct;
public:
 MyClass();
}

// is this fine?
MyClass::MyClass()
 : mMyStruct()
{}

// or this?
MyClass::MyClass()
 : mMyStruct({})
{}

// or do I need this?
MyClass::MyClass()
 : mMyStruct()
{
 mMyStruct = {};
}

Body:
One way is:

class MyClass
{
    MyStruct mMyStruct = {};
public:
    MyClass();   // actually unnecessary
};


问:
How do I use vector values as variables in R
I have a dataframe called repay and I have created a vector for the variables names of the variables I am interested in called variables.

```<code>variables<-names(repay)[22:36]
</code>```

I want to write a for loop that does some univariate analysis on each of the variables in variables. For example:

```<code>for (i in 1:length(variables))
{
model<-glm(Successful~ variables[i]
,data=repay
,family=binomial(link='logit'))
}
</code>```

However it doesn't recognize variables[i] as a variable, giving the following error message:

Error in model.frame.default(formula = Successful ~ variables[i], data
  = repay,  : variable lengths differ (found for 'variables[i]')

答:
You could create a language object from a string,</p>

```<code>var = "cyl"
lm(as.formula(sprintf("mpg ~ %s", var)), data=mtcars)
# alternative (see also substitute)
lm(bquote(mpg~.(as.name(var))), data=mtcars)
</code>```

Body:
I have a dataframe called repay and I have created a vector for the variables names of the variables I am interested in called variables.

variables<-names(repay)[22:36]

I want to write a for loop that does some univariate analysis on each of the variables in variables. For example:

for (i in 1:length(variables))
{
model<-glm(Successful~ variables[i]
,data=repay
,family=binomial(link='logit'))
}

However it doesn't recognize variables[i] as a variable, giving the following error message:

Error in model.frame.default(formula = Successful ~ variables[i], data
  = repay,  : variable lengths differ (found for 'variables[i]')

Body:
You could create a language object from a string,

var = "cyl"
lm(as.formula(sprintf("mpg ~ %s", var)), data=mtcars)
# alternative (see also substitute)
lm(bquote(mpg~.(as.name(var))), data=mtcars)


问:
connect Oracle developer with Access or Microsoft SQL database
I was wondering if it's possible to connect Oracle Developer to Microsoft SQL database or Microsoft Access Database. I believe there is a way to do that. If there is, I would rather to know how.</p>

答:
Oracle SQL Developer can connect to MSFT SQL Server. You just need to get the jTDS jdbc driver and add it to SQLDev via the preferences.

For Access, you'll need an older version of SQL Developer - I recommend version 3.1. We removed support for Access because newer versions of Java don't support an ODBC bridge that we were using.

I talk about how to add the JDBC drivers here.


问:
How to view DLL functions?
I have a DLL file. How can I view the functions in that DLL?</p>

答: For native code it's probably best to use Dependency Walker.  It also possible to use dumpbin command line utility that comes with Visual Studio.</p>

Title: How to view DLL functions?


问:
Cannot find the data record in database table qtype_multichoice_options - Moodle
When accessing a question of a quiz, I receive the following message:

"Cannot find the data record in database table qtype_multichoice_options qtype_multichoice_options"

But I checked at database all the related data, and everything seems to be there. Any ideas?

答:
Ok guys, these are the steps that can be done to solve the problem:
Edit the quiz. Open question by question until you find the one that has some kind of issue.
Delete that question and open the quiz again, probably everything gonna works fine, otherwise, look for more questions with the same issue and delete them.
Maybe a question is messed up because some strange characters were included during importation or creation process.

Check for more detailed info: http://www.moodlenews.com/2014/how-to-fix-cannot-find-the-data-record-in-database-table-question_multichoice/


问:
Jbase query to select last 14 days data
I am new to jbase and stuck in one query.
I want to extract last 14 days data using jbase.
I have written the following query :

```<code>Select filename WITH DATE > '14-MAY-2013'
</code>```

I hardcoded '14-MAY-2013', becouse I dont know how to get currentdate i used CURRENTDATE also but hard luck .

答:
You can use EVAL to write a program inside your SELECT or LIST statement. In your case it depends on what format the DATE field is stored in the jBase.

For example you could write something like this:

SELECT filename WITH DATE GE EVAL "OCONV(DATE()-14, 'D-YMD')"

The "DATE()-14" will return current date as number of days since December 31, 1967 minus 14 days, OCONV(x, 'D-YMD') will format the x to a date separated by '-' dashes.

Title: Jbase query to select last 14 days data

Body:
I am new to jbase and stuck in one query.
I want to extract last 14 days data using jbase.
I have written the following query :

Select filename WITH DATE > '14-MAY-2013'

I hardcoded '14-MAY-2013', becouse I dont know how to get currentdate i used CURRENTDATE also but hard luck .


问:
How show only links to modules that I can active in Angular?
I use router and guards with CanActivate. It works fine, but I need show only in my menu the "activable" links.

Has router any option as "isActivable"?

Example:

```<code><ul>
 <li routerLink="home" routerLinkActive="active" *ngIf="isActivable">Home</li>
<ul>
</code>```

答:
You can just inject your Guard in the constructor of your Component.
Like this:

```<code>constructor(private yourGuard: YourGuard){}
</code>```

And int the Template:

```<code><ul>
 <li routerLink="home" routerLinkActive="active" *ngIf="yourGuard.canActivate()">Home</li>
<ul>
</code>```

Of course you have to specify your guard in the Router...

Body:
I use router and guards with CanActivate. It works fine, but I need show only in my menu the "activable" links.

Has router any option as "isActivable"?

Example:

Home

Body:
You can just inject your Guard in the constructor of your Component.
Like this:

constructor(private yourGuard: YourGuard){}

And int the Template:

<ul>
 <li routerLink="home" routerLinkActive="active" *ngIf="yourGuard.canActivate()">Home</li>
<ul>

Of course you have to specify your guard in the Router...


问:
Hibernate mapping missing column error
I am using hibernate mapping in a project in Java and I have an error that I cannot figured out. I have several tables that includes column names all in lower case (e.g. db_id). To use them in Java, in my .hbm.xml file I am mapping them with the following line:

```<code><id name="dbId" type="long" column="DB_ID">
</code>```

I haven't got any error until now. Even if I use upper case above (column="DB_ID"), mapping was successfull. However, I now get a missing column error when I try running the project. The error line is like:

```<code>org.hibernate.HibernateException: Missing column: DB_ID in public.x.account
        at org.hibernate.mapping.Table.validateColumns(Table.java:277)
</code>```

When I change the column name from db_id to DB_ID manually in pgAdmin or Navicat(I am using PostgreSQL), this error disappears and the next column name gives error. I have tens of tables and hundreds of column names. I have also many .hbm.xml files for mapping. (This is a part of a big project.) So I do not want to change all column names manually or change the all column attributes in .hbm.xml files.

How can I make hibernate mapping case insensitive? Even if I use column="DB_ID" in my .hbm.xml file, I want my db_id column to be recognized in mapping.

答:
The problem is solved.

I guess the issue stems from the fact that the language of the operating system or java is not set in English. So I created a setenv.bat file in the apache-tomcat/bin directory and fill it with the following statement

```<code>set JAVA_OPTS=%JAVA_OPTS% -Duser.language=en -Duser.region=US
</code>```

It is solved with this way. I hope this will be helpful for the people who are experiencing the same issue.

Title: Hibernate mapping missing column error

Body:
I am using hibernate mapping in a project in Java and I have an error that I cannot figured out. I have several tables that includes column names all in lower case (e.g. db_id). To use them in Java, in my .hbm.xml file I am mapping them with the following line:

<id name="dbId" type="long" column="DB_ID">

I haven't got any error until now. Even if I use upper case above (column="DB_ID"), mapping was successfull. However, I now get a missing column error when I try running the project. The error line is like:

org.hibernate.HibernateException: Missing column: DB_ID in public.x.account
        at org.hibernate.mapping.Table.validateColumns(Table.java:277)

When I change the column name from db_id to DB_ID manually in pgAdmin or Navicat(I am using PostgreSQL), this error disappears and the next column name gives error. I have tens of tables and hundreds of column names. I have also many .hbm.xml files for mapping. (This is a part of a big project.) So I do not want to change all column names manually or change the all column attributes in .hbm.xml files.

How can I make hibernate mapping case insensitive? Even if I use column="DB_ID" in my .hbm.xml file, I want my db_id column to be recognized in mapping.

Body:
The problem is solved.

I guess the issue stems from the fact that the language of the operating system or java is not set in English. So I created a setenv.bat file in the apache-tomcat/bin directory and fill it with the following statement

set JAVA_OPTS=%JAVA_OPTS% -Duser.language=en -Duser.region=US

It is solved with this way. I hope this will be helpful for the people who are experiencing the same issue.


问:
Handling Local vs Remote Database TimeZone Differences in Tests
I have unit test in Java that writes a constant Timestamp to a row in my local test database, reads it back and compares it to what I expected. This works fine on my local laptop which is under the GMT timezone.

When I commit the code to our continuous integration server, the test fails with the different in time being -5 hours. This is no surprise since our integration server is hosted on AWS on the East Coast of US. However, it is causing a problem...

Short of changing my local MySQL server to have the same timezone as the remote server (and having all the developers in my team do so also), can anyone show me how to fix this issue in code without getting too hacky?

```<code>//Fetch actual table contents
IDataSet databaseDataSet = databaseTester.getConnection().createDataSet();
ITable actualTable = databaseDataSet.getTable("batch");

// Load expected data from an XML dataset
IDataSet expectedDataSet = new XmlDataSet(getClass().getResourceAsStream("/dbunit/expected_insert_batch.xml"));
ITable expectedTable = expectedDataSet.getTable("batch");

// Assert actual database table match expected table
Assertion.assertEquals(expectedTable, actualTable);
</code>```

Thanks,

答:
If you're creating the timestamp in Java, I recommend using a mock so that it isn't system-dependent at all.

See the answers to this question for ideas.

Body:
I have unit test in Java that writes a constant Timestamp to a row in my local test database, reads it back and compares it to what I expected. This works fine on my local laptop which is under the GMT timezone.

When I commit the code to our continuous integration server, the test fails with the different in time being -5 hours. This is no surprise since our integration server is hosted on AWS on the East Coast of US. However, it is causing a problem...

Short of changing my local MySQL server to have the same timezone as the remote server (and having all the developers in my team do so also), can anyone show me how to fix this issue in code without getting too hacky?

//Fetch actual table contents
IDataSet databaseDataSet = databaseTester.getConnection().createDataSet();
ITable actualTable = databaseDataSet.getTable("batch");

// Load expected data from an XML dataset
IDataSet expectedDataSet = new XmlDataSet(getClass().getResourceAsStream("/dbunit/expected_insert_batch.xml"));
ITable expectedTable = expectedDataSet.getTable("batch");

// Assert actual database table match expected table
Assertion.assertEquals(expectedTable, actualTable);

Thanks,


问:
Mongodb does not fetch the embedded document with php
Here is the code it does not featch the embedded documents.

```<code><?php
   include 'vendor/dbcon.php';
       $documentlist = $state -> find(['s_name' => 'West Bengal'],
            ['projection' =>  ['_id' => 0, 'places._id' => 1]] );

    foreach ($documentlist as $doc) {
     echo $doc["places._id"] . "\n";
   }
 ?>
</code>```

ERROR shows:   Notice: Undefined index: places._id in C:\xampp\htdocs\Education\Home.php on line 130

if the code is like:

```<code>foreach ($documentlist as $doc) {
         echo $doc["_id"] . "\n";
       }
</code>```

then ERROR::   Notice: Undefined index: _id in C:\xampp\htdocs\Education\Home.php on line 130

database structure: Mongodb

```<code> db.state.find().pretty()

{
        "_id" : "state1",
        "s_name" : "West Bengal",
        "places" : [
                {
                        "_id" : "Bardhaman",
                        "pin" : "754216"
                },
                {
                        "_id" : "Jalpaiguri",
                        "pin" : "754217"
                }
        ]
}
</code>```

please help me how can i print all places._id list(ex. Bardhaman, Jalpaiguri )

答:
Nothing wrong with the projection, it's just the notation to access is PHP notation and not "Dot notation" when in PHP. And of course "places" is an array, so you need to iterate:

```<code>  $documentlist = $state->find([],[ '_id' => 0, 'places._id' => 1 ]);

  foreach ($documentlist as $doc) {
    foreach($doc['places'] as $place) {
      echo $place['_id'] . "\n";
    }
  }
</code>```

Produces:

```<code>Bardhaman
Jalpaiguri
</code>```

Body:
Here is the code it does not featch the embedded documents.

<?php
   include 'vendor/dbcon.php';
       $documentlist = $state -> find(['s_name' => 'West Bengal'],
            ['projection' =>  ['_id' => 0, 'places._id' => 1]] );

    foreach ($documentlist as $doc) {
     echo $doc["places._id"] . "\n";
   }
 ?>

ERROR shows:   Notice: Undefined index: places._id in C:\xampp\htdocs\Education\Home.php on line 130

if the code is like:

foreach ($documentlist as $doc) {
         echo $doc["_id"] . "\n";
       }

then ERROR::   Notice: Undefined index: _id in C:\xampp\htdocs\Education\Home.php on line 130

database structure: Mongodb

 db.state.find().pretty()

{
        "_id" : "state1",
        "s_name" : "West Bengal",
        "places" : [
                {
                        "_id" : "Bardhaman",
                        "pin" : "754216"
                },
                {
                        "_id" : "Jalpaiguri",
                        "pin" : "754217"
                }
        ]
}

please help me how can i print all places._id list(ex. Bardhaman, Jalpaiguri )

Body:
Nothing wrong with the projection, it's just the notation to access is PHP notation and not "Dot notation" when in PHP. And of course "places" is an array, so you need to iterate:

  $documentlist = $state->find([],[ '_id' => 0, 'places._id' => 1 ]);

  foreach ($documentlist as $doc) {
    foreach($doc['places'] as $place) {
      echo $place['_id'] . "\n";
    }
  }

Produces:

Bardhaman
Jalpaiguri


问:
Deployment Assembly: The currently displayed page contains invalid values
I imported a Java Web application from Sourceforge, and I did three working weeks efforts to get rid off all red crosses attached to the project name and packages, but now I couldn't make the application run on my Eclipse & tomcat6 developing environment. In project properties when I tried to set the Deployment Assembly, the dialog box showed: the currently displayed page contains invalid values. And in the error log, I found when I click the Deployment Assembly, The following error message was showed:

Error

```<code>
Wed Jan 09 10:25:16 CST 2013
Problems occurred when invoking code from plug-in: "org.eclipse.jface".

java.lang.NullPointerException
    at org.eclipse.wst.common.componentcore.internal.resources.VirtualFolder.getFirstTaggedResource(VirtualFolder.java:185)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getDefaultDeploymentDescriptorFolder(J2EEModuleVirtualComponent.java:542)
    at org.eclipse.jst.j2ee.internal.ui.JavaEEDeploymentAssemblyAdvancedSectionBuilder.(JavaEEDeploymentAssemblyAdvancedSectionBuilder.java:86)
    at org.eclipse.jst.j2ee.internal.ui.J2EEModuleDependenciesPropertyPage.getAdvancedSectionBuilder(J2EEModuleDependenciesPropertyPage.java:381)
    at org.eclipse.jst.j2ee.internal.ui.J2EEModuleDependenciesPropertyPage.(J2EEModuleDependenciesPropertyPage.java:65)
    at org.eclipse.jst.servlet.ui.internal.WebDependencyPropertyPage.(WebDependencyPropertyPage.java:34)
    at org.eclipse.jst.servlet.ui.internal.WebModuleDependencyPageProvider.createPages(WebModuleDependencyPageProvider.java:54)
    at org.eclipse.wst.common.componentcore.ui.propertypage.ModuleAssemblyRootPage.createContents(ModuleAssemblyRootPage.java:195)
    at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:232)
    at org.eclipse.wst.common.componentcore.ui.propertypage.ModuleAssemblyRootPage.createControl(ModuleAssemblyRootPage.java:346)
    at org.eclipse.jface.preference.PreferenceDialog.createPageControl(PreferenceDialog.java:1502)
    at org.eclipse.jface.preference.PreferenceDialog$14.run(PreferenceDialog.java:1259)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.preference.PreferenceDialog.showPage(PreferenceDialog.java:1253)
    at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.showPage(FilteredPreferenceDialog.java:675)
    at org.eclipse.jface.preference.PreferenceDialog$10.run(PreferenceDialog.java:709)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.jface.preference.PreferenceDialog$9.selectionChanged(PreferenceDialog.java:705)
    at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.java:888)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(StructuredViewer.java:886)
    at org.eclipse.jface.viewers.StructuredViewer.handlePostSelect(StructuredViewer.java:1226)
    at org.eclipse.jface.viewers.StructuredViewer$5.widgetSelected(StructuredViewer.java:1251)
    at org.eclipse.jface.util.OpenStrategy.firePostSelectionEvent(OpenStrategy.java:262)
    at org.eclipse.jface.util.OpenStrategy.access$5(OpenStrategy.java:256)
    at org.eclipse.jface.util.OpenStrategy$3.run(OpenStrategy.java:433)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4144)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at org.eclipse.ui.dialogs.PropertyDialogAction.run(PropertyDialogAction.java:158)
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:585)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
</code>```

I googled many times , but I cannot find the solutions. Can anyone give a favor to let the Deployment Assembly work? I think this is the key why my app cannot run. Thanks in advance.

答:
I experienced this issue as well. It was caused by me deleting another project on which my current project was dependent. I fixed the issue by opening the file org.eclipse.wst.common.component in the .settings folder and deleting the dependency. This fixed the issues and I was able to edit the deployment assembly.

Section I removed: (utility.jar is the name of my offending jar)

```<code>   <dependent-module archiveName="utility.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/utility/utility">
        <dependency-type>uses</dependency-type>
    </dependent-module>
</code>```

Someone else I work with was able to fix it by deleting the jar from their build path.

Hope this helps anyone that hits this issue.

Body:
I imported a Java Web application from Sourceforge, and I did three working weeks efforts to get rid off all red crosses attached to the project name and packages, but now I couldn't make the application run on my Eclipse & tomcat6 developing environment. In project properties when I tried to set the Deployment Assembly, the dialog box showed: the currently displayed page contains invalid values. And in the error log, I found when I click the Deployment Assembly, The following error message was showed:

Error

Wed Jan 09 10:25:16 CST 2013
Problems occurred when invoking code from plug-in: "org.eclipse.jface".

java.lang.NullPointerException
    at org.eclipse.wst.common.componentcore.internal.resources.VirtualFolder.getFirstTaggedResource(VirtualFolder.java:185)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getDefaultDeploymentDescriptorFolder(J2EEModuleVirtualComponent.java:542)
    at org.eclipse.jst.j2ee.internal.ui.JavaEEDeploymentAssemblyAdvancedSectionBuilder.(JavaEEDeploymentAssemblyAdvancedSectionBuilder.java:86)
    at org.eclipse.jst.j2ee.internal.ui.J2EEModuleDependenciesPropertyPage.getAdvancedSectionBuilder(J2EEModuleDependenciesPropertyPage.java:381)
    at org.eclipse.jst.j2ee.internal.ui.J2EEModuleDependenciesPropertyPage.(J2EEModuleDependenciesPropertyPage.java:65)
    at org.eclipse.jst.servlet.ui.internal.WebDependencyPropertyPage.(WebDependencyPropertyPage.java:34)
    at org.eclipse.jst.servlet.ui.internal.WebModuleDependencyPageProvider.createPages(WebModuleDependencyPageProvider.java:54)
    at org.eclipse.wst.common.componentcore.ui.propertypage.ModuleAssemblyRootPage.createContents(ModuleAssemblyRootPage.java:195)
    at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:232)
    at org.eclipse.wst.common.componentcore.ui.propertypage.ModuleAssemblyRootPage.createControl(ModuleAssemblyRootPage.java:346)
    at org.eclipse.jface.preference.PreferenceDialog.createPageControl(PreferenceDialog.java:1502)
    at org.eclipse.jface.preference.PreferenceDialog$14.run(PreferenceDialog.java:1259)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.preference.PreferenceDialog.showPage(PreferenceDialog.java:1253)
    at org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.showPage(FilteredPreferenceDialog.java:675)
    at org.eclipse.jface.preference.PreferenceDialog$10.run(PreferenceDialog.java:709)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.jface.preference.PreferenceDialog$9.selectionChanged(PreferenceDialog.java:705)
    at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredViewer.java:888)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.StructuredViewer.firePostSelectionChanged(StructuredViewer.java:886)
    at org.eclipse.jface.viewers.StructuredViewer.handlePostSelect(StructuredViewer.java:1226)
    at org.eclipse.jface.viewers.StructuredViewer$5.widgetSelected(StructuredViewer.java:1251)
    at org.eclipse.jface.util.OpenStrategy.firePostSelectionEvent(OpenStrategy.java:262)
    at org.eclipse.jface.util.OpenStrategy.access$5(OpenStrategy.java:256)
    at org.eclipse.jface.util.OpenStrategy$3.run(OpenStrategy.java:433)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4144)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
    at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
    at org.eclipse.jface.window.Window.open(Window.java:801)
    at org.eclipse.ui.dialogs.PropertyDialogAction.run(PropertyDialogAction.java:158)
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:585)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

I googled many times , but I cannot find the solutions. Can anyone give a favor to let the Deployment Assembly work? I think this is the key why my app cannot run. Thanks in advance.

Body:
I experienced this issue as well. It was caused by me deleting another project on which my current project was dependent. I fixed the issue by opening the file org.eclipse.wst.common.component in the .settings folder and deleting the dependency. This fixed the issues and I was able to edit the deployment assembly.

Section I removed: (utility.jar is the name of my offending jar)

   <dependent-module archiveName="utility.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/utility/utility">
        <dependency-type>uses</dependency-type>
    </dependent-module>

Someone else I work with was able to fix it by deleting the jar from their build path.

Hope this helps anyone that hits this issue.


问:
How to match multiple element tags with single XPath
```<code><a data-ft="{"tn":"T"}" data-hovercard="/ajax/hovercard/hovercard.php?id=1063783263698960&extragetparams=%7B%22on_public_ufi%22%3Atrue%2C%22hc_location%22%3A%22ufi%22%7D" href="https://www.facebook.com/aslanneferler.org/?rc=p" class="img _8o _8s UFIImageBlockImage" tabindex="-1" aria-hidden="true" aria-controls="js_23b" aria-haspopup="true" aria-describedby="js_23c" id="js_23d"><img alt="Aslan Neferler Tim" class="img UFIActorImage _54ru img" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-1/p32x32/16649279_1243625492381402_3963550962824882029_n.jpg?oh=7b12626e660bc99add267af31ed0c47e&oe=59E2A54C"></a>

<img alt="Abdurrezzak Taşkın" class="img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-1/p32x32/18838939_1832790993710312_8699687160338170698_n.jpg?oh=0f627688abff94244dce906bd99dc56b&oe=59A4A24B">
</code>```

How can I select two of the tags you have seen above? I want to select 10 elements in total in one "a tagged", nine "img tagged" in total.

I wrote the following lines of code. But I did not get the result I wanted. What do you recommend. I want to do this using Selenium in Python.

```<code>driver.find_elements_by_xpath(
                    '//img[@class="img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img"]') or driver.find_elements_by_xpath('//*[@id="js_kq"]')
</code>```

答:
Use below xpath for the same and let me know if any issue</p>

```<code>//a[@id='js_23d'] | //img[@class='img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img']
</code>```

Body:
How can I select two of the tags you have seen above? I want to select 10 elements in total in one "a tagged", nine "img tagged" in total.

I wrote the following lines of code. But I did not get the result I wanted. What do you recommend. I want to do this using Selenium in Python.

driver.find_elements_by_xpath(
                    '//img[@class="img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img"]') or driver.find_elements_by_xpath('//*[@id="js_kq"]')

Body:
Use below xpath for the same and let me know if any issue

//a[@id='js_23d'] | //img[@class='img UFIActorImage _54ru img _8o _8s UFIImageBlockImage img']


问:
Is it possible to get what package.json script has been called in NodeJS code?
Is it possible to get what package.json script has been called in NodeJS code?

My package.json file contains a script that builds the application:

```<code>{
    "name": "notes-app",
    "version": "0.0.1",
    "license": "MIT",
    "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build && node server.js"
    },
    etc, etc...
</code>```

Can I then write in my server.js file an if statement like:

```<code>if (script === 'build') {
  // Do something
}
</code>```

Is there a way of knowing what script was called when starting the app. I would start this using the command npm run build. Also I'm using windows if that would make any difference.

答:
I agree with yury, you must be detecting this for a reason, and maybe a more fit solution lies in that context. </p>

<p>However, when this is important (like for system administration) it is usually done by setting an environment variable in the scripts section and then testing process.env in the node js. </p>

Body:
Is it possible to get what package.json script has been called in NodeJS code?

My package.json file contains a script that builds the application:

{
    "name": "notes-app",
    "version": "0.0.1",
    "license": "MIT",
    "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build && node server.js"
    },
    etc, etc...

Can I then write in my server.js file an if statement like:

if (script === 'build') {
  // Do something
}

Is there a way of knowing what script was called when starting the app. I would start this using the command npm run build. Also I'm using windows if that would make any difference.

Body:
I agree with yury, you must be detecting this for a reason, and maybe a more fit solution lies in that context.

However, when this is important (like for system administration) it is usually done by setting an environment variable in the scripts section and then testing process.env in the node js.


问:
Passe data in bundle to the activity of the gallery
I had this code, without the bundle it works very well, but when I add the bundle in the intent, in my onActivityResult I don't found this id_q in data, I found just the path of the chosen picture.

```<code>Intent intent = new Intent();
        Bundle b = new Bundle();
        b.putInt("id_q", q.getId());
        intent.putExtras(b);
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_IMAGE);
</code>```

this is onActivityResult :

```<code>public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == SELECT_IMAGE)
                onSelectFromGalleryResult(data);
</code>```

and in onSelectFromGalleryResult(data) I had this :

```<code>       if (data != null && data.getExtras() != null) {
            Bundle b = data.getExtras();
            int id_q = b.getInt("id_q");}
</code>```

答:
If you really want to assign the id_q you can achieve it like this way.

Step 1: Create a global variable lets say int counter = 0; and
  also the arraylist or list whatever you taken for your ids. lets say for e.g.

```<code>ArrayList<Integer> myList;
</code>```

Step 2: Now, Call your Intent to choose image inside for loop

For E.g

```<code>For loop (up to your n number of size)
{
  // Now Call your intent here.
}
</code>```

Step 3: Inside your OnActivityResult in your
  onSelectFromGalleryResult(data);

int id_q = yourArrayList.get(counter);

increase the size of Counter.

counter++;

Now, you don't need to do anything further once you pick one by one image from Gallery it comes to startActivityResult and you will get all the ids and your counter increases too so you got all the new values from arrayList from particular position.

I hope this will help you out.

Body:
I had this code, without the bundle it works very well, but when I add the bundle in the intent, in my onActivityResult I don't found this id_q in data, I found just the path of the chosen picture.

Intent intent = new Intent();
        Bundle b = new Bundle();
        b.putInt("id_q", q.getId());
        intent.putExtras(b);
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_IMAGE);

this is onActivityResult :

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == SELECT_IMAGE)
                onSelectFromGalleryResult(data);

and in onSelectFromGalleryResult(data) I had this :

       if (data != null && data.getExtras() != null) {
            Bundle b = data.getExtras();
            int id_q = b.getInt("id_q");}

Body:
If you really want to assign the id_q you can achieve it like this way.

Step 1: Create a global variable lets say int counter = 0; and
  also the arraylist or list whatever you taken for your ids. lets say for e.g.

ArrayList<Integer> myList;

Step 2: Now, Call your Intent to choose image inside for loop

For E.g

For loop (up to your n number of size)
{
  // Now Call your intent here.
}

Step 3: Inside your OnActivityResult in your
  onSelectFromGalleryResult(data);

int id_q = yourArrayList.get(counter);

increase the size of Counter.

counter++;

Now, you don't need to do anything further once you pick one by one image from Gallery it comes to startActivityResult and you will get all the ids and your counter increases too so you got all the new values from arrayList from particular position.

I hope this will help you out.


问:
codeignite file_get_contens not working when angularjs variable through file path is send
$scope.formatfilename = response.filename[0].filepath;//Itcontains my filepath e.g. http://localhost:8080/abc/myfloder/ab.html

$filename1 ='{{formatfilename}}'; // I accessing above path in codeIgniter view. When I echo this variable it has the file path also

```<code>echo file_get_contents($filename1);
</code>```

It gives me file not found error. but If, I pass static url to file_get_contents() method that time it gives the result.
any solution ??

答:
maybe typo error. should be <code>$filename1</code> </p>

```<code>echo file_get_contents($filename1);
</code>```

Body:
$scope.formatfilename = response.filename[0].filepath;//Itcontains my filepath e.g. http://localhost:8080/abc/myfloder/ab.html

$filename1 ='{{formatfilename}}'; // I accessing above path in codeIgniter view. When I echo this variable it has the file path also

echo file_get_contents($filename1);

It gives me file not found error. but If, I pass static url to file_get_contents() method that time it gives the result.
any solution ??

Body:
maybe typo error. should be $filename1

echo file_get_contents($filename1);


问:
Set Variable Varchar2 to date fields
I have a Script that I update a Date field

this is a part of my script

```<code>    var VARCHAR2(8 char);

var = '01/01/22';
    update table1 t set t.date = to_date(var,'dd/mm/yy');
</code>```

and then I got a null value in field date

why I dont have a 01/01/22 value ??

could you help me please !!

ANSWER       :::::::::::     PETIT PAPA merci :D

I created I new Varible with Date type

and I affecte the to_date to this variable

```<code>date_var Date;

date_var :=to_date(var,'dd/mm/yy');

update table1 t set t.date = date_var where ...;
</code>```

and it work THANK YOU everyONE

答:
I try this code to me, and work fine:

```<code>create table t( data date);
</code>```

Then

```<code>insert into t (data)
values (to_date('01/01/22','dd/mm/yy'));
</code>```

Now we check data in table

```<code>select * from t;
</code>```

We got expected result. That's for inserting.
For updating

```<code>update t set data = to_date('01/02/22','dd/mm/yy');
</code>```

Now check

```<code>select * from t;
</code>```

We got 01-FEB-22

But beware when updating without where clause it will update all records

Title: Set Variable Varchar2 to date fields

Body:
I have a Script that I update a Date field

this is a part of my script

    var VARCHAR2(8 char);

var = '01/01/22';
    update table1 t set t.date = to_date(var,'dd/mm/yy');

and then I got a null value in field date

why I dont have a 01/01/22 value ??

could you help me please !!

ANSWER       :::::::::::     PETIT PAPA merci :D

I created I new Varible with Date type

and I affecte the to_date to this variable

date_var Date;

date_var :=to_date(var,'dd/mm/yy');

update table1 t set t.date = date_var where ...;

and it work THANK YOU everyONE

Body:
I try this code to me, and work fine:

create table t( data date);

Then

insert into t (data)
values (to_date('01/01/22','dd/mm/yy'));

Now we check data in table

select * from t;

We got expected result. That's for inserting.
For updating

update t set data = to_date('01/02/22','dd/mm/yy');

Now check

select * from t;

We got 01-FEB-22

But beware when updating without where clause it will update all records


问:
I am getting an error in node.js service: the string "date" is not a valid AllXsd value
I need help. While passing a datetime parameter to a web service,  i am getting an error: Input XML was not in a correct format.  The value "date" is not a valid AllXsd value.
I have installed npm date-time and npm dateformat.

Code snippet:

```<code>Var datetime=require("date-time");
Var dateformat = require("dateformat");

Var dt="#6/2/2017 5:02:03 PM#";
Var d=new date(dt);  //tried with this but getting error
Var d=new date(dt).toISOString();   //this throws error too but a diff one..input string was not in a correct format
Var d=datetime({local:false}); //also not working
Var d=dateformat(dt, "m/d/yyyy hh:mm:ss TT");  // throws error
Var dtime = [d.getMonth() + 1,
                  d.getDate(),
                  d.getYear()].join('/')];  //this also throws error

//Service call
service.method(<d>/<dt>, (result) => {
res(result);
</code>```

});

答:
Use var d = new Date(dt);

Notice the 'D' in Date(dt). You used date(dt).

Body:
I need help. While passing a datetime parameter to a web service,  i am getting an error: Input XML was not in a correct format.  The value "date" is not a valid AllXsd value.
I have installed npm date-time and npm dateformat.

Code snippet:

Var datetime=require("date-time");
Var dateformat = require("dateformat");

Var dt="#6/2/2017 5:02:03 PM#";
Var d=new date(dt);  //tried with this but getting error
Var d=new date(dt).toISOString();   //this throws error too but a diff one..input string was not in a correct format
Var d=datetime({local:false}); //also not working
Var d=dateformat(dt, "m/d/yyyy hh:mm:ss TT");  // throws error
Var dtime = [d.getMonth() + 1,
                  d.getDate(),
                  d.getYear()].join('/')];  //this also throws error

//Service call
service.method(<d>/
, (result) => {
res(result);

});


问:
How to remove components created with Angular-CLI
I am working on angular2 for my new project, newly with this technology. I have set-up my project with angular CLI (Reference site https://github.com/angular/angular-cli).
I have created 4 components using command ng generate component my-new-component
For testing purpose, created one component app-testing, need to remove that component from my project. Else need to rename for that component. I have tried several like. ng destroy component app-testing but showing error The destroy command is not supported by Angular-CLI., Please help me with solution.
Thanks in advance.

答:
version control is your friend here, do a diff or equivalent and you should see what's been added/modified.

In fact, removing the component folder might not be enough; with Angular-CLI v1.0, the command ng generate component my-new-component also edits your app.module.ts file by adding the respective import line and the component to the providers array.