问:
Using Arrays to build a multiple choice quiz in Ruby
I want to create a Ruby program where users can take a multiple choice test.

I have a file for each test, where the questions and answers are stored like this:

```<code>Q;Who is the President of the USA?
A;Obama;0
A;Trump;1
A;Bush;0
Q;When did Iceland gain independence?
A;1944;1
A;1901;0
A;1974;0
</code>```

Q signifies a question and A signifies an answer option.
Value 1 is assigned to correct answers and 0 to incorrect answers.

I've converted the lines into arrays like so:

```<code>IO.foreach("#{test_name}.txt") do |line|
  line.chomp!
  exam = line.split(";")
end
</code>```

My issue is that I want to display a Question
and then the Answer options UNTIL I get to the next Question

I've been using puts inside the IO like so:

```<code>IO.foreach("#{test_name}.txt") do |line|
  line.chomp!
  exam = line.split(";")
puts exam[1] + "\n"
  end
end
</code>```

But of course that just returns the entire list from the file.

Essentially, I want the output to look like this:

```<code>    Who is the President of the USA?
    1. Obama
    2. Trump
    3. Bush
Please enter answer

    When did Iceland gain independence?
    1. 1944
    2. 1901
    3. 1974
Please enter answer
</code>```

Basically, I want to know if there is a method for reading a file like this, preferably numbering the answer options?

答:
There are many ways to do things in Ruby. This is one among many solutions, quickly made, just to put you on the right track. It lacks tests, for example to verify that the content of lines conforms to expectations.

```<code>class Question
    def initialize(p_text)
        @choices = []
        @text    = p_text
    end

    def add_answer(p_choice, p_validity)
        @choices << [p_choice, p_validity]
    end

    def ask
        valid_number = nil
        puts
        puts @text
        @choices.each_with_index do | choice_and_validity, i |
            choice, validity = choice_and_validity
            valid_number     = i if validity
            puts "#{i + 1}. #{choice}"
        end

        print 'Please enter answer', ' > '
        answer = gets.chomp.to_i - 1

        unless answer == valid_number
            puts 'Wrong answer.'
            ask
        end
    end
end

@questions = []

IO.foreach('input.txt') do | line |
    case line[0]
    when 'Q'
        code, text = line.chomp.split(';')
        @question  = Question.new(text)
        @questions << @question
    when 'A'
        code, choice, validity = line.chomp.split(';')
        @question.add_answer(choice, validity.strip == '1' ? true : false)
    else
        puts "Wrong code #{line[0]}"
    end
end

p @questions

@questions.each{ | question | question.ask }
</code>```

or

```<code>class Question
    attr_reader :choices, :text

    def initialize(p_text)
        @choices = []
        @text    = p_text
    end

    def add_answer(p_choice, p_validity)
        @choices << [p_choice, p_validity]
    end
end

@questions = []

IO.foreach('input.txt') do | line |
    code, text, validity = line.chomp.split(';')

    case code
    when 'Q'
        @question  = Question.new(text)
        @questions << @question
    when 'A'
        @question.add_answer(text, validity.strip == '1' ? true : false)
    else
        puts "Wrong code #{code}"
    end
end

p @questions

@questions.each do | question |
    answer       = nil
    valid_number = question.choices.index{ | item | item.last } # find the item [x, true]

    until answer == valid_number
        puts
        puts question.text
        question.choices.each_with_index do | choice, i |
            puts "#{i + 1}. #{choice.first}"
        end

        print 'Please enter answer > '
        answer = gets.chomp.to_i - 1

        puts 'Wrong answer.' unless answer == valid_number
    end
end
</code>```

Body:
I want to create a Ruby program where users can take a multiple choice test.

I have a file for each test, where the questions and answers are stored like this:

Q;Who is the President of the USA?
A;Obama;0
A;Trump;1
A;Bush;0
Q;When did Iceland gain independence?
A;1944;1
A;1901;0
A;1974;0

Q signifies a question and A signifies an answer option.
Value 1 is assigned to correct answers and 0 to incorrect answers.

I've converted the lines into arrays like so:

IO.foreach("#{test_name}.txt") do |line|
  line.chomp!
  exam = line.split(";")
end

My issue is that I want to display a Question
and then the Answer options UNTIL I get to the next Question

I've been using puts inside the IO like so:

IO.foreach("#{test_name}.txt") do |line|
  line.chomp!
  exam = line.split(";")
puts exam[1] + "\n"
  end
end

But of course that just returns the entire list from the file.

Essentially, I want the output to look like this:

    Who is the President of the USA?
    1. Obama
    2. Trump
    3. Bush
Please enter answer

    When did Iceland gain independence?
    1. 1944
    2. 1901
    3. 1974
Please enter answer

Basically, I want to know if there is a method for reading a file like this, preferably numbering the answer options?

Body:
There are many ways to do things in Ruby. This is one among many solutions, quickly made, just to put you on the right track. It lacks tests, for example to verify that the content of lines conforms to expectations.

class Question
    def initialize(p_text)
        @choices = []
        @text    = p_text
    end

    def add_answer(p_choice, p_validity)
        @choices << [p_choice, p_validity]
    end

    def ask
        valid_number = nil
        puts
        puts @text
        @choices.each_with_index do | choice_and_validity, i |
            choice, validity = choice_and_validity
            valid_number     = i if validity
            puts "#{i + 1}. #{choice}"
        end

        print 'Please enter answer', ' > '
        answer = gets.chomp.to_i - 1

        unless answer == valid_number
            puts 'Wrong answer.'
            ask
        end
    end
end

@questions = []

IO.foreach('input.txt') do | line |
    case line[0]
    when 'Q'
        code, text = line.chomp.split(';')
        @question  = Question.new(text)
        @questions << @question
    when 'A'
        code, choice, validity = line.chomp.split(';')
        @question.add_answer(choice, validity.strip == '1' ? true : false)
    else
        puts "Wrong code #{line[0]}"
    end
end

p @questions

@questions.each{ | question | question.ask }

or

class Question
    attr_reader :choices, :text

    def initialize(p_text)
        @choices = []
        @text    = p_text
    end

    def add_answer(p_choice, p_validity)
        @choices << [p_choice, p_validity]
    end
end

@questions = []

IO.foreach('input.txt') do | line |
    code, text, validity = line.chomp.split(';')

    case code
    when 'Q'
        @question  = Question.new(text)
        @questions << @question
    when 'A'
        @question.add_answer(text, validity.strip == '1' ? true : false)
    else
        puts "Wrong code #{code}"
    end
end

p @questions

@questions.each do | question |
    answer       = nil
    valid_number = question.choices.index{ | item | item.last } # find the item [x, true]

    until answer == valid_number
        puts
        puts question.text
        question.choices.each_with_index do | choice, i |
            puts "#{i + 1}. #{choice.first}"
        end

        print 'Please enter answer > '
        answer = gets.chomp.to_i - 1

        puts 'Wrong answer.' unless answer == valid_number
    end
end


来源: stackexchange

问:
How to select related in django model so it wont generate a lot of subqueries
I have lot of models that are referring to each other in some way, for example:

Port is referring to City, which in its turn refers to Country. Then in django admin I want to show in list_display Ports country:

```<code>class Country(models.Model):
    title = models.CharField()

class City(models.Model):
    title = models.CharField()

    country = models.ForeignKey(Country)

class Port(models.Model):
    city = models.ForeignKey(City)

    def __str__(self):
        return self.city.county.title
</code>```

So basically for each port django is generating more queries. I assume that select_related would help me somehow in this case, but how to use it properly within the model?

答:
Based on Ivan's answer, I came up with the following structure for multiple models related with "one to many" and "many to many" relations using select_related and prefetch_related accordingly.

In the provided example only select_related is required.

```<code>class Country(models.Model):
    title = models.CharField()

    def __str__(self):
        return '{0}'.format(self.title)

class CityManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().select_related('country')

class City(models.Model):
    title = models.CharField()
    country = models.ForeignKey(Country)
    objects = CityManager()

    def __str__(self):
        return '{0}-{1}'.format(
            self.title,
            self.country.__str__(),
        )

class PortManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().select_related('city')

class Port(models.Model):
    city = models.ForeignKey(City)
    objects = PortManager()

    def __str__(self):
        return self.city.__str__()
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have lot of models that are referring to each other in some way, for example:

Port is referring to City, which in its turn refers to Country. Then in django admin I want to show in list_display Ports country:

class Country(models.Model):
    title = models.CharField()

class City(models.Model):
    title = models.CharField()

    country = models.ForeignKey(Country)

class Port(models.Model):
    city = models.ForeignKey(City)

    def __str__(self):
        return self.city.county.title

So basically for each port django is generating more queries. I assume that select_related would help me somehow in this case, but how to use it properly within the model?

Body:
Based on Ivan's answer, I came up with the following structure for multiple models related with "one to many" and "many to many" relations using select_related and prefetch_related accordingly.

In the provided example only select_related is required.

class Country(models.Model):
    title = models.CharField()

    def __str__(self):
        return '{0}'.format(self.title)

class CityManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().select_related('country')

class City(models.Model):
    title = models.CharField()
    country = models.ForeignKey(Country)
    objects = CityManager()

    def __str__(self):
        return '{0}-{1}'.format(
            self.title,
            self.country.__str__(),
        )

class PortManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().select_related('city')

class Port(models.Model):
    city = models.ForeignKey(City)
    objects = PortManager()

    def __str__(self):
        return self.city.__str__()


问:
JQUERY $(function() { initialisation
I've been working with JQuery for some time now and I've always used the following to initalise my javascript:

```<code>$(document).ready( function() {
// Initalisation logic
});
</code>```

However, recently I've noticed a lot of examples using the following:

```<code>$(function() {

});
</code>```

Whats the difference?

Thanks

答:
The difference is that the first is more readable. So please just use this one.</p>

```<code>$(document).ready(function() {
// Initalisation logic
});
</code>```

ContentLicense: CC BY-SA 2.5

Title: JQUERY $(function() { initialisation

Body:
I've been working with JQuery for some time now and I've always used the following to initalise my javascript:

$(document).ready( function() {
// Initalisation logic
});

However, recently I've noticed a lot of examples using the following:

$(function() {

});

Whats the difference?

Thanks

Body:
The difference is that the first is more readable. So please just use this one.

$(document).ready(function() {
// Initalisation logic
});


问:
Azure B2C AD Redirect to Angular App
I am trying to run this Angular 4 example that uses Azure B2C Active Directory and adal-angular 4.

To run the app, in Azure I created a tenant, registered a the app in AD B2C and added a reply Url of https://localhost:4200.  I then added the app id and tenant to my Angular App.

When I run the app, it correctly redirects to https://login.microsoftonline.com... on load for login. Logging in correctly redirects to https://localhost:4200.

When I log out, there is a problem. The app is redirected to this static logout page which doesn't redirect back to my app.

I tried registering an app in Azure Active Directory (not B2C), moving its config data into my Angular App, and when I run it and a log out it redirects temporarily to this "logging you out" page which redirects back to the app.

The the redirect urls after logout are identical other than the tenant name, only the B2C just dies. This happens in both Chrome and Edge.

I expect that this is not just a difference in functionality between B2C and regular AD. I checked my configurations, but maybe this is something in the Azure portal I missed?

答:
You should use MSAL.js w/ Azure AD B2C.

ADAL ... is designed to only work against Azure AD "classic" (e.g. - NOT B2C)

Reference: MSAL or ADAL library for use with Azure AD B2C and Xamarin

See this Angular 4 example that uses MSAL.js.

ContentLicense: CC BY-SA 3.0

Title: Azure B2C AD Redirect to Angular App


问:
Can't build Ionic3 app since updating to ionic@3.19.0
I'm trying to build my ionic app with --prod flag but I'm getting issues doing it.

After upgrading to ionic 3.18, some time ago, there was some problems and I couldn't run my app anymore. I forgot what were the problems but I solved them somehow with some tweakings in my package.json, if I remember well, and I was able to run the app.

But since that, I can't get it to build with --prod flag (but it works fine without).

Today I was looking into this problem and tried deleting my node_modules and rebuilding it following this advice.
It solved the specific issue there was, but I still cannot build the app.

Here is the result of rebuilding node_modules folder running npm i: (I removed a few lines without any error in the middle, because it was too long to post otherwise.)

```<code>npm WARN deprecated cordova-plugin-console@1.1.0: This plugin has been deprecated since it is now included in the latest versions of cordova-ios
npm WARN prefer global node-gyp@3.6.2 should be installed with -g
npm WARN prefer global node-ninja@1.0.2 should be installed with -g

> leveldown@1.5.0 install /path/to/my/app/node_modules/leveldown
> prebuild --install

> node-sass@4.5.3 install /path/to/my/app/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.3/linux-x64-48_binding.node
Download complete .] - :
Binary saved to /path/to/my/app/node_modules/node-sass/vendor/linux-x64-48/binding.node
Caching binary to /home/userName/.npm/node-sass/4.5.3/linux-x64-48_binding.node

> uglifyjs-webpack-plugin@0.4.6 postinstall /path/to/my/app/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js

> node-sass@4.5.3 postinstall /path/to/my/app/node_modules/node-sass
> node scripts/build.js

Binary found at /path/to/my/app/node_modules/node-sass/vendor/linux-x64-48/binding.node
Testing binary
Binary is fine
userName@0.0.1 /path/to/my/app
├─┬ UNMET PEER DEPENDENCY @angular/common@5.0.5
│ └── tslib@1.8.0
├── @angular/compiler@5.0.1
├─┬ @angular/compiler-cli@5.0.1
│ ├─┬ chokidar@1.7.0
│ │ ├─┬ anymatch@1.3.2
│ │ │ ├─┬ micromatch@2.3.11
│ │ │ │ ├─┬ arr-diff@2.0.0
│ │ │ │ │ └── arr-flatten@1.1.0
│ │ │ │ ├── array-unique@0.2.1
│ │ │ │ ├─┬ braces@1.8.5
│ │ │ │ │ ├─┬ expand-range@1.8.2
│ │ │ │ │ │ └─┬ fill-range@2.2.3
│ │ │ │ │ │   ├── is-number@2.1.0
│ │ │ │ │ │   ├── isobject@2.1.0
│ │ │ │ │ │   ├─┬ randomatic@1.1.7
│ │ │ │ │ │   │ ├─┬ is-number@3.0.0
│ │ │ │ │ │   │ │ └── kind-of@3.2.2
│ │ │ │ │ │   │ └── kind-of@4.0.0
│ │ │ │ │ │   └── repeat-string@1.6.1
│ │ │ │ │ ├── preserve@0.2.0
│ │ │ │ │ └── repeat-element@1.1.2
│ │ │ │ ├─┬ expand-brackets@0.1.5
│ │ │ │ │ └── is-posix-bracket@0.1.1
│ │ │ │ ├── extglob@0.3.2
│ │ │ │ ├── filename-regex@2.0.1
│ │ │ │ ├─┬ kind-of@3.2.2
│ │ │ │ │ └── is-buffer@1.1.6
│ │ │ │ ├─┬ object.omit@2.0.1
│ │ │ │ │ ├─┬ for-own@0.1.5
│ │ │ │ │ │ └── for-in@1.0.2
│ │ │ │ │ └── is-extendable@0.1.1
│ │ │ │ ├─┬ parse-glob@3.0.4
│ │ │ │ │ ├── glob-base@0.3.0
│ │ │ │ │ └── is-dotfile@1.0.3
│ │ │ │ └─┬ regex-cache@0.4.4
│ │ │ │   └── is-equal-shallow@0.1.3
│ │ │ └─┬ normalize-path@2.1.1
│ │ │   └── remove-trailing-separator@1.1.0
│ │ ├── async-each@1.0.1
│ │ ├── glob-parent@2.0.0
│ │ ├─┬ is-binary-path@1.0.1
│ │ │ └── binary-extensions@1.11.0
│ │ ├─┬ is-glob@2.0.1
│ │ │ └── is-extglob@1.0.0
│ │ ├── path-is-absolute@1.0.1
│ │ └─┬ readdirp@2.1.0
│ │   ├─┬ readable-stream@2.3.3
│ │   │ └── isarray@1.0.0
│ │   └── set-immediate-shim@1.0.1
│ ├── minimist@1.2.0
│ ├── reflect-metadata@0.1.10
│ ├─┬ tsickle@0.24.1
│ │ ├─┬ mkdirp@0.5.1
│ │ │ └── minimist@0.0.8
│ │ ├── source-map@0.5.7
│ │ └── source-map-support@0.4.18
│ └── UNMET PEER DEPENDENCY typescript@2.4.2
├── UNMET PEER DEPENDENCY @angular/core@5.0.5
├── @angular/forms@5.0.1
├── @angular/http@5.0.1
├── @angular/platform-browser@5.0.1
├── @angular/platform-browser-dynamic@5.0.1
├── @ionic-native/app-availability@4.4.2
├── @ionic-native/brightness@4.4.2
├── @ionic-native/call-number@4.4.2
├── @ionic-native/clipboard@4.4.2
├── @ionic-native/contacts@4.4.2
├── @ionic-native/core@4.4.2
├── @ionic-native/file@4.4.2
├── @ionic-native/in-app-browser@4.4.2
├── @ionic-native/keyboard@4.4.2
├── @ionic-native/sms@4.4.2
├── @ionic-native/splash-screen@4.4.2
├── @ionic-native/status-bar@4.4.2
├─┬ @ionic/app-scripts@3.1.4
│ ├─┬ @angular-devkit/build-optimizer@0.0.33
│ │ ├─┬ loader-utils@1.1.0
│ │ │ ├── big.js@3.2.0
│ │ │ └── emojis-list@2.1.0
│ │ └─┬ webpack-sources@1.1.0
│ │   ├── source-list-map@2.0.0
│ │   └── source-map@0.6.1
│ ├─┬ autoprefixer@7.2.1
│ │ ├─┬ browserslist@2.10.0
│ │ │ └── electron-to-chromium@1.3.28
│ │ ├── caniuse-lite@1.0.30000780
│ │ ├── normalize-range@0.1.2
│ │ ├── num2fraction@1.2.2
│ │ └── postcss-value-parser@3.3.0
│ ├─┬ chalk@2.3.0
│ │ ├── ansi-styles@3.2.0
│ │ ├── escape-string-regexp@1.0.5
│ │ └─┬ supports-color@4.5.0
│ │   └── has-flag@2.0.0
│ ├── clean-css@4.1.9
│ ├─┬ cross-spawn@5.1.0
│ │ ├─┬ lru-cache@4.1.1
│ │ │ ├── pseudomap@1.0.2
│ │ │ └── yallist@2.1.2
│ │ ├─┬ shebang-command@1.2.0
│ │ │ └── shebang-regex@1.0.0
│ │ └─┬ which@1.3.0
│ │   └── isexe@2.0.0
│ ├─┬ express@4.16.2
│ │ ├─┬ accepts@1.3.4
│ │ │ └── negotiator@0.6.1
│ │ ├── array-flatten@1.1.1
│ │ ├─┬ body-parser@1.18.2
│ │ │ ├── bytes@3.0.0
│ │ │ ├── debug@2.6.9
│ │ │ ├─┬ http-errors@1.6.2
│ │ │ │ ├── setprototypeof@1.0.3
│ │ │ │ └── statuses@1.4.0
│ │ │ ├── iconv-lite@0.4.19
│ │ │ └── raw-body@2.3.2
│ │ ├── content-disposition@0.5.2
│ │ ├── content-type@1.0.4
│ │ ├── cookie@0.3.1
│ │ ├── cookie-signature@1.0.6
│ │ ├─┬ debug@2.6.9
│ │ │ └── ms@2.0.0
│ │ ├── depd@1.1.1
│ │ ├── encodeurl@1.0.1
│ │ ├── escape-html@1.0.3
│ │ ├── etag@1.8.1
│ │ ├─┬ finalhandler@1.1.0
│ │ │ ├── debug@2.6.9
│ │ │ ├── statuses@1.3.1
│ │ │ └── unpipe@1.0.0
│ │ ├── fresh@0.5.2
│ │ ├── merge-descriptors@1.0.1
│ │ ├── methods@1.1.2
│ │ ├─┬ on-finished@2.3.0
│ │ │ └── ee-first@1.1.1
│ │ ├── parseurl@1.3.2
│ │ ├── path-to-regexp@0.1.7
│ │ ├─┬ proxy-addr@2.0.2
│ │ │ ├── forwarded@0.1.2
│ │ │ └── ipaddr.js@1.5.2
│ │ ├── qs@6.5.1
│ │ ├── range-parser@1.2.0
│ │ ├── safe-buffer@5.1.1
│ │ ├─┬ send@0.16.1
│ │ │ ├── debug@2.6.9
│ │ │ ├── destroy@1.0.4
│ │ │ ├── mime@1.4.1
│ │ │ └── statuses@1.3.1
│ │ ├── serve-static@1.13.1
│ │ ├── setprototypeof@1.1.0
│ │ ├── statuses@1.3.1
│ │ ├─┬ type-is@1.6.15
│ │ │ └── media-typer@0.3.0
│ │ ├── utils-merge@1.0.1
│ │ └── vary@1.1.2
│ ├─┬ fs-extra@4.0.3
│ │ ├── graceful-fs@4.1.11
│ │ ├── jsonfile@4.0.0
│ │ └── universalify@0.1.1
│ ├─┬ glob@7.1.2
│ │ ├── fs.realpath@1.0.0
│ │ ├─┬ inflight@1.0.6
│ │ │ └── wrappy@1.0.2
│ │ ├─┬ minimatch@3.0.4
│ │ │ └─┬ brace-expansion@1.1.8
│ │ │   ├── balanced-match@1.0.0
│ │ │   └── concat-map@0.0.1
│ │ └── once@1.4.0
│ ├── json-loader@0.5.7
│ ├─┬ node-sass@4.5.3
│ │ ├── async-foreach@0.1.3
│ │ ├─┬ chalk@1.1.3
│ │ │ ├── ansi-styles@2.2.1
│ │ │ ├─┬ has-ansi@2.0.0
│ │ │ │ └── ansi-regex@2.1.1
│ │ │ ├─┬ strip-ansi@3.0.1
│ │ │ │ └── ansi-regex@2.1.1
│ │ │ └── supports-color@2.0.0
│ │ ├── cross-spawn@3.0.1
│ │ ├─┬ gaze@1.1.2
│ │ │ └── globule@1.2.0
│ │ ├── get-stdin@4.0.1
│ │ ├── in-publish@2.0.0
│ │ ├── lodash.assign@4.2.0
│ │ ├── lodash.clonedeep@4.5.0
│ │ ├── lodash.mergewith@4.6.0
│ │ ├─┬ meow@3.7.0
│ │ │ ├─┬ camelcase-keys@2.1.0
│ │ │ │ └── camelcase@2.1.1
│ │ │ ├── decamelize@1.2.0
│ │ │ ├─┬ loud-rejection@1.6.0
│ │ │ │ ├─┬ currently-unhandled@0.4.1
│ │ │ │ │ └── array-find-index@1.0.2
│ │ │ │ └── signal-exit@3.0.2
│ │ │ ├── map-obj@1.0.1
│ │ │ ├─┬ normalize-package-data@2.4.0
│ │ │ │ ├── hosted-git-info@2.5.0
│ │ │ │ ├── is-builtin-module@1.0.0
│ │ │ │ └─┬ validate-npm-package-license@3.0.1
│ │ │ │   ├─┬ spdx-correct@1.0.2
│ │ │ │   │ └── spdx-license-ids@1.2.2
│ │ │ │   └── spdx-expression-parse@1.0.4
│ │ │ ├─┬ read-pkg-up@1.0.1
│ │ │ │ ├─┬ find-up@1.1.2
│ │ │ │ │ ├── path-exists@2.1.0
│ │ │ │ │ └─┬ pinkie-promise@2.0.1
│ │ │ │ │   └── pinkie@2.0.4
│ │ │ │ └─┬ read-pkg@1.1.0
│ │ │ │   ├─┬ load-json-file@1.1.0
│ │ │ │   │ ├─┬ parse-json@2.2.0
│ │ │ │   │ │ └─┬ error-ex@1.3.1
│ │ │ │   │ │   └── is-arrayish@0.2.1
│ │ │ │   │ ├── pify@2.3.0
│ │ │ │   │ └─┬ strip-bom@2.0.0
│ │ │ │   │   └── is-utf8@0.2.1
│ │ │ │   └── path-type@1.1.0
│ │ │ ├─┬ redent@1.0.0
│ │ │ │ ├─┬ indent-string@2.1.0
│ │ │ │ │ └─┬ repeating@2.0.1
│ │ │ │ │   └── is-finite@1.0.2
│ │ │ │ └── strip-indent@1.0.1
│ │ │ └── trim-newlines@1.0.0
│ │ ├── nan@2.4.0
│ │ ├─┬ node-gyp@3.6.2
│ │ │ ├── fstream@1.0.11
│ │ │ ├─┬ nopt@3.0.6
│ │ │ │ └── abbrev@1.1.1
│ │ │ ├─┬ npmlog@2.0.4
│ │ │ │ ├── ansi@0.3.1
│ │ │ │ └─┬ gauge@1.2.7
│ │ │ │   ├── lodash.pad@4.5.1
│ │ │ │   ├── lodash.padend@4.6.1
│ │ │ │   └── lodash.padstart@4.6.1
│ │ │ ├─┬ osenv@0.1.4
│ │ │ │ └── os-tmpdir@1.0.2
│ │ │ ├── semver@5.3.0
│ │ │ └─┬ tar@2.2.1
│ │ │   └── block-stream@0.0.9
│ │ ├─┬ npmlog@4.1.2
│ │ │ ├─┬ are-we-there-yet@1.1.4
│ │ │ │ └── delegates@1.0.0
│ │ │ ├── console-control-strings@1.1.0
│ │ │ ├─┬ gauge@2.7.4
│ │ │ │ ├── aproba@1.2.0
│ │ │ │ ├── has-unicode@2.0.1
│ │ │ │ ├─┬ string-width@1.0.2
│ │ │ │ │ ├── code-point-at@1.1.0
│ │ │ │ │ └─┬ is-fullwidth-code-point@1.0.0
│ │ │ │ │   └── number-is-nan@1.0.1
│ │ │ │ └─┬ wide-align@1.1.2
│ │ │ │   └─┬ string-width@1.0.2
│ │ │ │     ├── is-fullwidth-code-point@1.0.0
│ │ │ │     └─┬ strip-ansi@3.0.1
│ │ │ │       └── ansi-regex@2.1.1
│ │ │ └── set-blocking@2.0.0
│ │ ├─┬ sass-graph@2.2.4
│ │ │ ├─┬ scss-tokenizer@0.2.3
│ │ │ │ ├── js-base64@2.4.0
│ │ │ │ └─┬ source-map@0.4.4
│ │ │ │   └── amdefine@1.0.1
│ │ │ └─┬ yargs@7.1.0
│ │ │   ├── camelcase@3.0.0
│ │ │   ├── os-locale@1.4.0
│ │ │   ├─┬ string-width@1.0.2
│ │ │   │ ├── is-fullwidth-code-point@1.0.0
│ │ │   │ └─┬ strip-ansi@3.0.1
│ │ │   │   └── ansi-regex@2.1.1
│ │ │   ├── which-module@1.0.0
│ │ │   └─┬ yargs-parser@5.0.0
│ │ │     └── camelcase@3.0.0
│ │ └── stdout-stream@1.4.0
│ ├─┬ os-name@2.0.1
│ │ ├── macos-release@1.1.0
│ │ └── win-release@1.1.1
│ ├─┬ postcss@6.0.14
│ │ └── source-map@0.6.1
│ ├── proxy-middleware@0.15.0
│ ├── rollup@0.50.0
│ ├─┬ rollup-plugin-commonjs@8.2.6
│ │ ├── acorn@5.2.1
│ │ ├── estree-walker@0.5.1
│ │ ├─┬ magic-string@0.22.4
│ │ │ └── vlq@0.2.3
│ │ ├─┬ resolve@1.5.0
│ │ │ └── path-parse@1.0.5
│ │ └─┬ rollup-pluginutils@2.0.1
│ │   └── estree-walker@0.3.1
│ ├─┬ rollup-plugin-node-resolve@3.0.0
│ │ ├─┬ browser-resolve@1.11.2
│ │ │ └── resolve@1.1.7
│ │ ├── builtin-modules@1.1.1
│ │ └── is-module@1.0.0
│ ├── source-map@0.6.1
│ ├─┬ tiny-lr@1.0.5
│ │ ├─┬ body@5.1.0
│ │ │ ├── continuable-cache@0.3.1
│ │ │ ├─┬ error@7.0.2
│ │ │ │ └── string-template@0.2.1
│ │ │ ├─┬ raw-body@1.1.7
│ │ │ │ ├── bytes@1.0.0
│ │ │ │ └── string_decoder@0.10.31
│ │ │ └── safe-json-parse@1.0.1
│ │ ├── debug@2.6.9
│ │ ├─┬ faye-websocket@0.10.0
│ │ │ └─┬ websocket-driver@0.7.0
│ │ │   ├── http-parser-js@0.4.9
│ │ │   └── websocket-extensions@0.1.3
│ │ ├── livereload-js@2.2.2
│ │ └── object-assign@4.1.1
│ ├─┬ tslint@5.8.0
│ │ ├─┬ babel-code-frame@6.26.0
│ │ │ ├─┬ chalk@1.1.3
│ │ │ │ ├── ansi-styles@2.2.1
│ │ │ │ ├─┬ strip-ansi@3.0.1
│ │ │ │ │ └── ansi-regex@2.1.1
│ │ │ │ └── supports-color@2.0.0
│ │ │ ├── esutils@2.0.2
│ │ │ └── js-tokens@3.0.2
│ │ ├── commander@2.12.2
│ │ ├── diff@3.4.0
│ │ └── tsutils@2.13.0
│ ├─┬ tslint-eslint-rules@4.1.1
│ │ ├─┬ doctrine@0.7.2
│ │ │ ├── esutils@1.1.6
│ │ │ └── isarray@0.0.1
│ │ └── tsutils@1.9.1
│ ├─┬ uglify-es@3.2.1
│ │ └── source-map@0.6.1
│ ├─┬ webpack@3.8.1
│ │ ├── acorn@5.2.1
│ │ ├─┬ acorn-dynamic-import@2.0.2
│ │ │ └── acorn@4.0.13
│ │ ├─┬ UNMET PEER DEPENDENCY ajv@5.5.1
│ │ │ ├── co@4.6.0
│ │ │ ├── fast-deep-equal@1.0.0
│ │ │ ├── fast-json-stable-stringify@2.0.0
│ │ │ └── json-schema-traverse@0.3.1
│ │ ├── ajv-keywords@2.1.1
│ │ ├── async@2.6.0
│ │ ├── enhanced-resolve@3.4.1
│ │ ├─┬ escope@3.6.0
│ │ │ ├─┬ es6-map@0.1.5
│ │ │ │ ├── d@1.0.0
│ │ │ │ ├── es5-ext@0.10.37
│ │ │ │ ├── es6-iterator@2.0.3
│ │ │ │ ├── es6-set@0.1.5
│ │ │ │ ├── es6-symbol@3.1.1
│ │ │ │ └── event-emitter@0.3.5
│ │ │ ├── es6-weak-map@2.0.2
│ │ │ ├── esrecurse@4.2.0
│ │ │ └── estraverse@4.2.0

├─┬ rxjs@5.5.2
│ └── symbol-observable@1.1.0
├─┬ sugar@2.0.4
│ └── sugar-core@2.0.4
├─┬ sw-toolbox@3.6.0
│ ├─┬ path-to-regexp@1.7.0
│ │ └── isarray@0.0.1
│ └── serviceworker-cache-polyfill@4.0.0
├── UNMET PEER DEPENDENCY typescript@2.6.1
├── underscore@1.8.3
└── zone.js@0.8.18

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN ionic2-auto-complete@1.5.3-beta requires a peer of @angular/core@^4.0.0 but none was installed.
npm WARN @angular/platform-browser-dynamic@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/platform-browser-dynamic@5.0.1 requires a peer of @angular/common@5.0.1 but none was installed.
npm WARN @angular/compiler-cli@5.0.1 requires a peer of typescript@>=2.4.2 <2.5 but none was installed.
npm WARN @angular/http@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/platform-browser@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/platform-browser@5.0.1 requires a peer of @angular/common@5.0.1 but none was installed.
npm WARN @angular/forms@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/forms@5.0.1 requires a peer of @angular/common@5.0.1 but none was installed.
npm WARN tsickle@0.24.1 requires a peer of typescript@2.4.2 but none was installed.
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none was installed.
</code>```

There are quite a few error messages in this.

Any idea which are relevant and how to correct them?

Also, this is the content of my package.json file, in case that's useful:

```<code>{
    "name": "appName",
    "version": "versionNumber",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "^5.0.1",
        "@angular/compiler": "5.0.1",
        "@angular/compiler-cli": "5.0.1",
        "@angular/core": "^5.0.1",
        "@angular/forms": "5.0.1",
        "@angular/http": "5.0.1",
        "@angular/platform-browser": "5.0.1",
        "@angular/platform-browser-dynamic": "5.0.1",
        "@ionic-native/app-availability": "^4.4.2",
        "@ionic-native/brightness": "^4.2.1",
        "@ionic-native/call-number": "^4.4.2",
        "@ionic-native/clipboard": "^4.4.2",
        "@ionic-native/contacts": "^4.2.1",
        "@ionic-native/core": "^4.4.2",
        "@ionic-native/file": "^4.2.1",
        "@ionic-native/in-app-browser": "^4.4.2",
        "@ionic-native/keyboard": "^4.2.1",
        "@ionic-native/sms": "^4.4.2",
        "@ionic-native/splash-screen": "4.4.2",
        "@ionic-native/status-bar": "4.4.2",
        "@ionic/storage": "2.1.3",
        "@types/jquery": "^3.2.12",
        "angular-elastic": "^2.5.1",
        "angular2-elastic": "^0.13.0",
        "call-number": "^1.0.1",
        "color": "^2.0.1",
        "cordova-android": "^6.2.3",
        "cordova-clipboard": "^1.1.0",
        "cordova-plugin-appavailability": "^0.4.2",
        "cordova-plugin-brightness": "^0.1.5",
        "cordova-plugin-compat": "^1.1.0",
        "cordova-plugin-console": "^1.0.5",
        "cordova-plugin-contacts": "^3.0.0",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-file": "^5.0.0",
        "cordova-plugin-inappbrowser": "^1.7.2",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.2",
        "cordova-plugin-whitelist": "^1.3.1",
        "cordova-sms-plugin": "^0.1.11",
        "ionic": "^3.17.0",
        "ionic-angular": "^3.9.2",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionic2-auto-complete": "^1.5.3-beta",
        "ionicons": "3.0.0",
        "jquery": "^3.2.1",
        "moment": "^2.18.1",
        "mx.ferreyra.callnumber": "~0.0.2",
        "ng-tags-input": "^3.2.0",
        "pouchdb": "^6.3.4",
        "pouchdb-find": "^6.3.4",
        "rxjs": "5.5.2",
        "sugar": "^2.0.4",
        "sw-toolbox": "3.6.0",
        "underscore": "^1.8.3",
        "zone.js": "0.8.18"
    },
    "devDependencies": {
        "@ionic/app-scripts": "^3.1.2",
        "@types/pouchdb": "^6.3.0",
        "@types/pouchdb-find": "^6.3.0",
        "ionic": "3.19.0",
        "typescript": "2.6.1"
    },
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {},
            "cordova-plugin-file": {},
            "cordova-plugin-contacts": {},
            "cordova-plugin-brightness": {},
            "mx.ferreyra.callnumber": {},
            "cordova-clipboard": {},
            "cordova-sms-plugin": {},
            "cordova-plugin-inappbrowser": {},
            "cordova-plugin-appavailability": {}
        },
        "platforms": [
            "android"
        ]
    }
}
</code>```

And this is the error I get when I try building the app:

```<code>$ ionic cordova build android --prod
Running app-scripts build: --prod --platform android --target cordova
[18:55:39]  build prod started ...
[18:55:39]  clean started ...
[18:55:39]  clean finished in 1 ms
[18:55:39]  copy started ...
[18:55:40]  deeplinks started ...
[18:55:40]  deeplinks finished in 327 ms
[18:55:40]  ngc started ...
[18:55:50]  typescript error
            ("mplate [ngTemplateOutlet]="template || defaultTemplate" [ERROR ->][ngOutletContext]=" {attrs:{ data:
            suggestion, keyword: keyword, labelAttribu")

[18:55:50]  typescript error
            ("gestion of suggestions" (tap)="select(suggestion);$event.srcEvent.stopPropagation()"> [ERROR
            ->]<ng-template [ngTemplateOutlet]="template || defaultTemplate" ")

Error: The Angular AoT build failed. See the issues above
    at /path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:237:55
    at step (/path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:32:23)
    at Object.next (/path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:13:53)
    at fulfilled (/path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:4:58)
[18:55:50]  copy finished in 10.71 s
</code>```

答:
Most of them were warnings. So you don't need to worry about those things.

You have done a number of things which were against the Ionic 3.9.2. You must never use the latest angular since the Ionic team has not tested it yet. e.g. You used angular ^5.0.1. You need to follow this official package.json file.And also don't use ^ with angular versions.

Your typescript version too very higher one. You need to follow this:

```<code>"devDependencies": {
    "@ionic/app-scripts": "3.1.4",
    "typescript": "~2.4.2"
  },
</code>```

Use "@ionic/app-scripts": "3.1.4"

After doing all the above changes delete node_modules folder and run npm i

Body:
I'm trying to build my ionic app with --prod flag but I'm getting issues doing it.

After upgrading to ionic 3.18, some time ago, there was some problems and I couldn't run my app anymore. I forgot what were the problems but I solved them somehow with some tweakings in my package.json, if I remember well, and I was able to run the app.

But since that, I can't get it to build with --prod flag (but it works fine without).

Today I was looking into this problem and tried deleting my node_modules and rebuilding it following this advice.
It solved the specific issue there was, but I still cannot build the app.

Here is the result of rebuilding node_modules folder running npm i: (I removed a few lines without any error in the middle, because it was too long to post otherwise.)

npm WARN deprecated cordova-plugin-console@1.1.0: This plugin has been deprecated since it is now included in the latest versions of cordova-ios
npm WARN prefer global node-gyp@3.6.2 should be installed with -g
npm WARN prefer global node-ninja@1.0.2 should be installed with -g

> leveldown@1.5.0 install /path/to/my/app/node_modules/leveldown
> prebuild --install

> node-sass@4.5.3 install /path/to/my/app/node_modules/node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.3/linux-x64-48_binding.node
Download complete .] - :
Binary saved to /path/to/my/app/node_modules/node-sass/vendor/linux-x64-48/binding.node
Caching binary to /home/userName/.npm/node-sass/4.5.3/linux-x64-48_binding.node

> uglifyjs-webpack-plugin@0.4.6 postinstall /path/to/my/app/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js

> node-sass@4.5.3 postinstall /path/to/my/app/node_modules/node-sass
> node scripts/build.js

Binary found at /path/to/my/app/node_modules/node-sass/vendor/linux-x64-48/binding.node
Testing binary
Binary is fine
userName@0.0.1 /path/to/my/app
├─┬ UNMET PEER DEPENDENCY @angular/common@5.0.5
│ └── tslib@1.8.0
├── @angular/compiler@5.0.1
├─┬ @angular/compiler-cli@5.0.1
│ ├─┬ chokidar@1.7.0
│ │ ├─┬ anymatch@1.3.2
│ │ │ ├─┬ micromatch@2.3.11
│ │ │ │ ├─┬ arr-diff@2.0.0
│ │ │ │ │ └── arr-flatten@1.1.0
│ │ │ │ ├── array-unique@0.2.1
│ │ │ │ ├─┬ braces@1.8.5
│ │ │ │ │ ├─┬ expand-range@1.8.2
│ │ │ │ │ │ └─┬ fill-range@2.2.3
│ │ │ │ │ │   ├── is-number@2.1.0
│ │ │ │ │ │   ├── isobject@2.1.0
│ │ │ │ │ │   ├─┬ randomatic@1.1.7
│ │ │ │ │ │   │ ├─┬ is-number@3.0.0
│ │ │ │ │ │   │ │ └── kind-of@3.2.2
│ │ │ │ │ │   │ └── kind-of@4.0.0
│ │ │ │ │ │   └── repeat-string@1.6.1
│ │ │ │ │ ├── preserve@0.2.0
│ │ │ │ │ └── repeat-element@1.1.2
│ │ │ │ ├─┬ expand-brackets@0.1.5
│ │ │ │ │ └── is-posix-bracket@0.1.1
│ │ │ │ ├── extglob@0.3.2
│ │ │ │ ├── filename-regex@2.0.1
│ │ │ │ ├─┬ kind-of@3.2.2
│ │ │ │ │ └── is-buffer@1.1.6
│ │ │ │ ├─┬ object.omit@2.0.1
│ │ │ │ │ ├─┬ for-own@0.1.5
│ │ │ │ │ │ └── for-in@1.0.2
│ │ │ │ │ └── is-extendable@0.1.1
│ │ │ │ ├─┬ parse-glob@3.0.4
│ │ │ │ │ ├── glob-base@0.3.0
│ │ │ │ │ └── is-dotfile@1.0.3
│ │ │ │ └─┬ regex-cache@0.4.4
│ │ │ │   └── is-equal-shallow@0.1.3
│ │ │ └─┬ normalize-path@2.1.1
│ │ │   └── remove-trailing-separator@1.1.0
│ │ ├── async-each@1.0.1
│ │ ├── glob-parent@2.0.0
│ │ ├─┬ is-binary-path@1.0.1
│ │ │ └── binary-extensions@1.11.0
│ │ ├─┬ is-glob@2.0.1
│ │ │ └── is-extglob@1.0.0
│ │ ├── path-is-absolute@1.0.1
│ │ └─┬ readdirp@2.1.0
│ │   ├─┬ readable-stream@2.3.3
│ │   │ └── isarray@1.0.0
│ │   └── set-immediate-shim@1.0.1
│ ├── minimist@1.2.0
│ ├── reflect-metadata@0.1.10
│ ├─┬ tsickle@0.24.1
│ │ ├─┬ mkdirp@0.5.1
│ │ │ └── minimist@0.0.8
│ │ ├── source-map@0.5.7
│ │ └── source-map-support@0.4.18
│ └── UNMET PEER DEPENDENCY typescript@2.4.2
├── UNMET PEER DEPENDENCY @angular/core@5.0.5
├── @angular/forms@5.0.1
├── @angular/http@5.0.1
├── @angular/platform-browser@5.0.1
├── @angular/platform-browser-dynamic@5.0.1
├── @ionic-native/app-availability@4.4.2
├── @ionic-native/brightness@4.4.2
├── @ionic-native/call-number@4.4.2
├── @ionic-native/clipboard@4.4.2
├── @ionic-native/contacts@4.4.2
├── @ionic-native/core@4.4.2
├── @ionic-native/file@4.4.2
├── @ionic-native/in-app-browser@4.4.2
├── @ionic-native/keyboard@4.4.2
├── @ionic-native/sms@4.4.2
├── @ionic-native/splash-screen@4.4.2
├── @ionic-native/status-bar@4.4.2
├─┬ @ionic/app-scripts@3.1.4
│ ├─┬ @angular-devkit/build-optimizer@0.0.33
│ │ ├─┬ loader-utils@1.1.0
│ │ │ ├── big.js@3.2.0
│ │ │ └── emojis-list@2.1.0
│ │ └─┬ webpack-sources@1.1.0
│ │   ├── source-list-map@2.0.0
│ │   └── source-map@0.6.1
│ ├─┬ autoprefixer@7.2.1
│ │ ├─┬ browserslist@2.10.0
│ │ │ └── electron-to-chromium@1.3.28
│ │ ├── caniuse-lite@1.0.30000780
│ │ ├── normalize-range@0.1.2
│ │ ├── num2fraction@1.2.2
│ │ └── postcss-value-parser@3.3.0
│ ├─┬ chalk@2.3.0
│ │ ├── ansi-styles@3.2.0
│ │ ├── escape-string-regexp@1.0.5
│ │ └─┬ supports-color@4.5.0
│ │   └── has-flag@2.0.0
│ ├── clean-css@4.1.9
│ ├─┬ cross-spawn@5.1.0
│ │ ├─┬ lru-cache@4.1.1
│ │ │ ├── pseudomap@1.0.2
│ │ │ └── yallist@2.1.2
│ │ ├─┬ shebang-command@1.2.0
│ │ │ └── shebang-regex@1.0.0
│ │ └─┬ which@1.3.0
│ │   └── isexe@2.0.0
│ ├─┬ express@4.16.2
│ │ ├─┬ accepts@1.3.4
│ │ │ └── negotiator@0.6.1
│ │ ├── array-flatten@1.1.1
│ │ ├─┬ body-parser@1.18.2
│ │ │ ├── bytes@3.0.0
│ │ │ ├── debug@2.6.9
│ │ │ ├─┬ http-errors@1.6.2
│ │ │ │ ├── setprototypeof@1.0.3
│ │ │ │ └── statuses@1.4.0
│ │ │ ├── iconv-lite@0.4.19
│ │ │ └── raw-body@2.3.2
│ │ ├── content-disposition@0.5.2
│ │ ├── content-type@1.0.4
│ │ ├── cookie@0.3.1
│ │ ├── cookie-signature@1.0.6
│ │ ├─┬ debug@2.6.9
│ │ │ └── ms@2.0.0
│ │ ├── depd@1.1.1
│ │ ├── encodeurl@1.0.1
│ │ ├── escape-html@1.0.3
│ │ ├── etag@1.8.1
│ │ ├─┬ finalhandler@1.1.0
│ │ │ ├── debug@2.6.9
│ │ │ ├── statuses@1.3.1
│ │ │ └── unpipe@1.0.0
│ │ ├── fresh@0.5.2
│ │ ├── merge-descriptors@1.0.1
│ │ ├── methods@1.1.2
│ │ ├─┬ on-finished@2.3.0
│ │ │ └── ee-first@1.1.1
│ │ ├── parseurl@1.3.2
│ │ ├── path-to-regexp@0.1.7
│ │ ├─┬ proxy-addr@2.0.2
│ │ │ ├── forwarded@0.1.2
│ │ │ └── ipaddr.js@1.5.2
│ │ ├── qs@6.5.1
│ │ ├── range-parser@1.2.0
│ │ ├── safe-buffer@5.1.1
│ │ ├─┬ send@0.16.1
│ │ │ ├── debug@2.6.9
│ │ │ ├── destroy@1.0.4
│ │ │ ├── mime@1.4.1
│ │ │ └── statuses@1.3.1
│ │ ├── serve-static@1.13.1
│ │ ├── setprototypeof@1.1.0
│ │ ├── statuses@1.3.1
│ │ ├─┬ type-is@1.6.15
│ │ │ └── media-typer@0.3.0
│ │ ├── utils-merge@1.0.1
│ │ └── vary@1.1.2
│ ├─┬ fs-extra@4.0.3
│ │ ├── graceful-fs@4.1.11
│ │ ├── jsonfile@4.0.0
│ │ └── universalify@0.1.1
│ ├─┬ glob@7.1.2
│ │ ├── fs.realpath@1.0.0
│ │ ├─┬ inflight@1.0.6
│ │ │ └── wrappy@1.0.2
│ │ ├─┬ minimatch@3.0.4
│ │ │ └─┬ brace-expansion@1.1.8
│ │ │   ├── balanced-match@1.0.0
│ │ │   └── concat-map@0.0.1
│ │ └── once@1.4.0
│ ├── json-loader@0.5.7
│ ├─┬ node-sass@4.5.3
│ │ ├── async-foreach@0.1.3
│ │ ├─┬ chalk@1.1.3
│ │ │ ├── ansi-styles@2.2.1
│ │ │ ├─┬ has-ansi@2.0.0
│ │ │ │ └── ansi-regex@2.1.1
│ │ │ ├─┬ strip-ansi@3.0.1
│ │ │ │ └── ansi-regex@2.1.1
│ │ │ └── supports-color@2.0.0
│ │ ├── cross-spawn@3.0.1
│ │ ├─┬ gaze@1.1.2
│ │ │ └── globule@1.2.0
│ │ ├── get-stdin@4.0.1
│ │ ├── in-publish@2.0.0
│ │ ├── lodash.assign@4.2.0
│ │ ├── lodash.clonedeep@4.5.0
│ │ ├── lodash.mergewith@4.6.0
│ │ ├─┬ meow@3.7.0
│ │ │ ├─┬ camelcase-keys@2.1.0
│ │ │ │ └── camelcase@2.1.1
│ │ │ ├── decamelize@1.2.0
│ │ │ ├─┬ loud-rejection@1.6.0
│ │ │ │ ├─┬ currently-unhandled@0.4.1
│ │ │ │ │ └── array-find-index@1.0.2
│ │ │ │ └── signal-exit@3.0.2
│ │ │ ├── map-obj@1.0.1
│ │ │ ├─┬ normalize-package-data@2.4.0
│ │ │ │ ├── hosted-git-info@2.5.0
│ │ │ │ ├── is-builtin-module@1.0.0
│ │ │ │ └─┬ validate-npm-package-license@3.0.1
│ │ │ │   ├─┬ spdx-correct@1.0.2
│ │ │ │   │ └── spdx-license-ids@1.2.2
│ │ │ │   └── spdx-expression-parse@1.0.4
│ │ │ ├─┬ read-pkg-up@1.0.1
│ │ │ │ ├─┬ find-up@1.1.2
│ │ │ │ │ ├── path-exists@2.1.0
│ │ │ │ │ └─┬ pinkie-promise@2.0.1
│ │ │ │ │   └── pinkie@2.0.4
│ │ │ │ └─┬ read-pkg@1.1.0
│ │ │ │   ├─┬ load-json-file@1.1.0
│ │ │ │   │ ├─┬ parse-json@2.2.0
│ │ │ │   │ │ └─┬ error-ex@1.3.1
│ │ │ │   │ │   └── is-arrayish@0.2.1
│ │ │ │   │ ├── pify@2.3.0
│ │ │ │   │ └─┬ strip-bom@2.0.0
│ │ │ │   │   └── is-utf8@0.2.1
│ │ │ │   └── path-type@1.1.0
│ │ │ ├─┬ redent@1.0.0
│ │ │ │ ├─┬ indent-string@2.1.0
│ │ │ │ │ └─┬ repeating@2.0.1
│ │ │ │ │   └── is-finite@1.0.2
│ │ │ │ └── strip-indent@1.0.1
│ │ │ └── trim-newlines@1.0.0
│ │ ├── nan@2.4.0
│ │ ├─┬ node-gyp@3.6.2
│ │ │ ├── fstream@1.0.11
│ │ │ ├─┬ nopt@3.0.6
│ │ │ │ └── abbrev@1.1.1
│ │ │ ├─┬ npmlog@2.0.4
│ │ │ │ ├── ansi@0.3.1
│ │ │ │ └─┬ gauge@1.2.7
│ │ │ │   ├── lodash.pad@4.5.1
│ │ │ │   ├── lodash.padend@4.6.1
│ │ │ │   └── lodash.padstart@4.6.1
│ │ │ ├─┬ osenv@0.1.4
│ │ │ │ └── os-tmpdir@1.0.2
│ │ │ ├── semver@5.3.0
│ │ │ └─┬ tar@2.2.1
│ │ │   └── block-stream@0.0.9
│ │ ├─┬ npmlog@4.1.2
│ │ │ ├─┬ are-we-there-yet@1.1.4
│ │ │ │ └── delegates@1.0.0
│ │ │ ├── console-control-strings@1.1.0
│ │ │ ├─┬ gauge@2.7.4
│ │ │ │ ├── aproba@1.2.0
│ │ │ │ ├── has-unicode@2.0.1
│ │ │ │ ├─┬ string-width@1.0.2
│ │ │ │ │ ├── code-point-at@1.1.0
│ │ │ │ │ └─┬ is-fullwidth-code-point@1.0.0
│ │ │ │ │   └── number-is-nan@1.0.1
│ │ │ │ └─┬ wide-align@1.1.2
│ │ │ │   └─┬ string-width@1.0.2
│ │ │ │     ├── is-fullwidth-code-point@1.0.0
│ │ │ │     └─┬ strip-ansi@3.0.1
│ │ │ │       └── ansi-regex@2.1.1
│ │ │ └── set-blocking@2.0.0
│ │ ├─┬ sass-graph@2.2.4
│ │ │ ├─┬ scss-tokenizer@0.2.3
│ │ │ │ ├── js-base64@2.4.0
│ │ │ │ └─┬ source-map@0.4.4
│ │ │ │   └── amdefine@1.0.1
│ │ │ └─┬ yargs@7.1.0
│ │ │   ├── camelcase@3.0.0
│ │ │   ├── os-locale@1.4.0
│ │ │   ├─┬ string-width@1.0.2
│ │ │   │ ├── is-fullwidth-code-point@1.0.0
│ │ │   │ └─┬ strip-ansi@3.0.1
│ │ │   │   └── ansi-regex@2.1.1
│ │ │   ├── which-module@1.0.0
│ │ │   └─┬ yargs-parser@5.0.0
│ │ │     └── camelcase@3.0.0
│ │ └── stdout-stream@1.4.0
│ ├─┬ os-name@2.0.1
│ │ ├── macos-release@1.1.0
│ │ └── win-release@1.1.1
│ ├─┬ postcss@6.0.14
│ │ └── source-map@0.6.1
│ ├── proxy-middleware@0.15.0
│ ├── rollup@0.50.0
│ ├─┬ rollup-plugin-commonjs@8.2.6
│ │ ├── acorn@5.2.1
│ │ ├── estree-walker@0.5.1
│ │ ├─┬ magic-string@0.22.4
│ │ │ └── vlq@0.2.3
│ │ ├─┬ resolve@1.5.0
│ │ │ └── path-parse@1.0.5
│ │ └─┬ rollup-pluginutils@2.0.1
│ │   └── estree-walker@0.3.1
│ ├─┬ rollup-plugin-node-resolve@3.0.0
│ │ ├─┬ browser-resolve@1.11.2
│ │ │ └── resolve@1.1.7
│ │ ├── builtin-modules@1.1.1
│ │ └── is-module@1.0.0
│ ├── source-map@0.6.1
│ ├─┬ tiny-lr@1.0.5
│ │ ├─┬ body@5.1.0
│ │ │ ├── continuable-cache@0.3.1
│ │ │ ├─┬ error@7.0.2
│ │ │ │ └── string-template@0.2.1
│ │ │ ├─┬ raw-body@1.1.7
│ │ │ │ ├── bytes@1.0.0
│ │ │ │ └── string_decoder@0.10.31
│ │ │ └── safe-json-parse@1.0.1
│ │ ├── debug@2.6.9
│ │ ├─┬ faye-websocket@0.10.0
│ │ │ └─┬ websocket-driver@0.7.0
│ │ │   ├── http-parser-js@0.4.9
│ │ │   └── websocket-extensions@0.1.3
│ │ ├── livereload-js@2.2.2
│ │ └── object-assign@4.1.1
│ ├─┬ tslint@5.8.0
│ │ ├─┬ babel-code-frame@6.26.0
│ │ │ ├─┬ chalk@1.1.3
│ │ │ │ ├── ansi-styles@2.2.1
│ │ │ │ ├─┬ strip-ansi@3.0.1
│ │ │ │ │ └── ansi-regex@2.1.1
│ │ │ │ └── supports-color@2.0.0
│ │ │ ├── esutils@2.0.2
│ │ │ └── js-tokens@3.0.2
│ │ ├── commander@2.12.2
│ │ ├── diff@3.4.0
│ │ └── tsutils@2.13.0
│ ├─┬ tslint-eslint-rules@4.1.1
│ │ ├─┬ doctrine@0.7.2
│ │ │ ├── esutils@1.1.6
│ │ │ └── isarray@0.0.1
│ │ └── tsutils@1.9.1
│ ├─┬ uglify-es@3.2.1
│ │ └── source-map@0.6.1
│ ├─┬ webpack@3.8.1
│ │ ├── acorn@5.2.1
│ │ ├─┬ acorn-dynamic-import@2.0.2
│ │ │ └── acorn@4.0.13
│ │ ├─┬ UNMET PEER DEPENDENCY ajv@5.5.1
│ │ │ ├── co@4.6.0
│ │ │ ├── fast-deep-equal@1.0.0
│ │ │ ├── fast-json-stable-stringify@2.0.0
│ │ │ └── json-schema-traverse@0.3.1
│ │ ├── ajv-keywords@2.1.1
│ │ ├── async@2.6.0
│ │ ├── enhanced-resolve@3.4.1
│ │ ├─┬ escope@3.6.0
│ │ │ ├─┬ es6-map@0.1.5
│ │ │ │ ├── d@1.0.0
│ │ │ │ ├── es5-ext@0.10.37
│ │ │ │ ├── es6-iterator@2.0.3
│ │ │ │ ├── es6-set@0.1.5
│ │ │ │ ├── es6-symbol@3.1.1
│ │ │ │ └── event-emitter@0.3.5
│ │ │ ├── es6-weak-map@2.0.2
│ │ │ ├── esrecurse@4.2.0
│ │ │ └── estraverse@4.2.0

├─┬ rxjs@5.5.2
│ └── symbol-observable@1.1.0
├─┬ sugar@2.0.4
│ └── sugar-core@2.0.4
├─┬ sw-toolbox@3.6.0
│ ├─┬ path-to-regexp@1.7.0
│ │ └── isarray@0.0.1
│ └── serviceworker-cache-polyfill@4.0.0
├── UNMET PEER DEPENDENCY typescript@2.6.1
├── underscore@1.8.3
└── zone.js@0.8.18

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN ionic2-auto-complete@1.5.3-beta requires a peer of @angular/core@^4.0.0 but none was installed.
npm WARN @angular/platform-browser-dynamic@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/platform-browser-dynamic@5.0.1 requires a peer of @angular/common@5.0.1 but none was installed.
npm WARN @angular/compiler-cli@5.0.1 requires a peer of typescript@>=2.4.2 <2.5 but none was installed.
npm WARN @angular/http@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/platform-browser@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/platform-browser@5.0.1 requires a peer of @angular/common@5.0.1 but none was installed.
npm WARN @angular/forms@5.0.1 requires a peer of @angular/core@5.0.1 but none was installed.
npm WARN @angular/forms@5.0.1 requires a peer of @angular/common@5.0.1 but none was installed.
npm WARN tsickle@0.24.1 requires a peer of typescript@2.4.2 but none was installed.
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none was installed.

There are quite a few error messages in this.

Any idea which are relevant and how to correct them?

Also, this is the content of my package.json file, in case that's useful:

{
    "name": "appName",
    "version": "versionNumber",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "^5.0.1",
        "@angular/compiler": "5.0.1",
        "@angular/compiler-cli": "5.0.1",
        "@angular/core": "^5.0.1",
        "@angular/forms": "5.0.1",
        "@angular/http": "5.0.1",
        "@angular/platform-browser": "5.0.1",
        "@angular/platform-browser-dynamic": "5.0.1",
        "@ionic-native/app-availability": "^4.4.2",
        "@ionic-native/brightness": "^4.2.1",
        "@ionic-native/call-number": "^4.4.2",
        "@ionic-native/clipboard": "^4.4.2",
        "@ionic-native/contacts": "^4.2.1",
        "@ionic-native/core": "^4.4.2",
        "@ionic-native/file": "^4.2.1",
        "@ionic-native/in-app-browser": "^4.4.2",
        "@ionic-native/keyboard": "^4.2.1",
        "@ionic-native/sms": "^4.4.2",
        "@ionic-native/splash-screen": "4.4.2",
        "@ionic-native/status-bar": "4.4.2",
        "@ionic/storage": "2.1.3",
        "@types/jquery": "^3.2.12",
        "angular-elastic": "^2.5.1",
        "angular2-elastic": "^0.13.0",
        "call-number": "^1.0.1",
        "color": "^2.0.1",
        "cordova-android": "^6.2.3",
        "cordova-clipboard": "^1.1.0",
        "cordova-plugin-appavailability": "^0.4.2",
        "cordova-plugin-brightness": "^0.1.5",
        "cordova-plugin-compat": "^1.1.0",
        "cordova-plugin-console": "^1.0.5",
        "cordova-plugin-contacts": "^3.0.0",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-file": "^5.0.0",
        "cordova-plugin-inappbrowser": "^1.7.2",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.2",
        "cordova-plugin-whitelist": "^1.3.1",
        "cordova-sms-plugin": "^0.1.11",
        "ionic": "^3.17.0",
        "ionic-angular": "^3.9.2",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionic2-auto-complete": "^1.5.3-beta",
        "ionicons": "3.0.0",
        "jquery": "^3.2.1",
        "moment": "^2.18.1",
        "mx.ferreyra.callnumber": "~0.0.2",
        "ng-tags-input": "^3.2.0",
        "pouchdb": "^6.3.4",
        "pouchdb-find": "^6.3.4",
        "rxjs": "5.5.2",
        "sugar": "^2.0.4",
        "sw-toolbox": "3.6.0",
        "underscore": "^1.8.3",
        "zone.js": "0.8.18"
    },
    "devDependencies": {
        "@ionic/app-scripts": "^3.1.2",
        "@types/pouchdb": "^6.3.0",
        "@types/pouchdb-find": "^6.3.0",
        "ionic": "3.19.0",
        "typescript": "2.6.1"
    },
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {},
            "cordova-plugin-file": {},
            "cordova-plugin-contacts": {},
            "cordova-plugin-brightness": {},
            "mx.ferreyra.callnumber": {},
            "cordova-clipboard": {},
            "cordova-sms-plugin": {},
            "cordova-plugin-inappbrowser": {},
            "cordova-plugin-appavailability": {}
        },
        "platforms": [
            "android"
        ]
    }
}

And this is the error I get when I try building the app:

$ ionic cordova build android --prod
Running app-scripts build: --prod --platform android --target cordova
[18:55:39]  build prod started ...
[18:55:39]  clean started ...
[18:55:39]  clean finished in 1 ms
[18:55:39]  copy started ...
[18:55:40]  deeplinks started ...
[18:55:40]  deeplinks finished in 327 ms
[18:55:40]  ngc started ...
[18:55:50]  typescript error
            ("mplate [ngTemplateOutlet]="template || defaultTemplate" [ERROR ->][ngOutletContext]=" {attrs:{ data:
            suggestion, keyword: keyword, labelAttribu")

[18:55:50]  typescript error
            ("gestion of suggestions" (tap)="select(suggestion);$event.srcEvent.stopPropagation()"> [ERROR
            ->]<ng-template [ngTemplateOutlet]="template || defaultTemplate" ")

Error: The Angular AoT build failed. See the issues above
    at /path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:237:55
    at step (/path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:32:23)
    at Object.next (/path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:13:53)
    at fulfilled (/path/to/my/app/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:4:58)
[18:55:50]  copy finished in 10.71 s

Body:
Most of them were warnings. So you don't need to worry about those things.

You have done a number of things which were against the Ionic 3.9.2. You must never use the latest angular since the Ionic team has not tested it yet. e.g. You used angular ^5.0.1. You need to follow this official package.json file.And also don't use ^ with angular versions.

Your typescript version too very higher one. You need to follow this:

"devDependencies": {
    "@ionic/app-scripts": "3.1.4",
    "typescript": "~2.4.2"
  },

Use "@ionic/app-scripts": "3.1.4"

After doing all the above changes delete node_modules folder and run npm i


问:
How to copy std::regex_token_iterator to a std::vector?
The code below fails to copy values from regex_token_iterator to a std::vector; Visual Studio 2015 reports that 'std::copy' with parameters may be unsafe.

Anyone knows how to fix it?

```<code>#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>

int main()
{
    // String to split in words
    std::string line = "dir1\\dir2\\dir3\\dir4";

    // Split the string in words
    std::vector<std::string> to_vector;
    const std::regex ws_re("\\\\");
    std::copy(std::sregex_token_iterator(line.begin(), line.end(), ws_re, -1),
              std::sregex_token_iterator(),
              std::back_insert_iterator<std::vector<std::string>>(to_vector));

    // Display the words
    std::cout << "Words: ";
    std::copy(begin(to_vector), end(to_vector), std::ostream_iterator<std::string>(std::cout, "\n"));
}
</code>```

答:
Here my solution to store the values extracted by regex_token_iterator to a vector:</p>

```<code>#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>

int main()
{
    std::string s("dir1\\dir2\\dir3\\dir4");

    // Split the line in words
    const std::regex reg_exp("\\\\");
    const std::regex_token_iterator<std::string::iterator> end_tokens;
    std::regex_token_iterator<std::string::iterator> it(s.begin(), s.end(), reg_exp, -1);
    std::vector<std::string> to_vector;
    while (it != end_tokens)
    {
        to_vector.emplace_back(*it++);
    }

    // Display the content of the vector
    std::copy(begin(to_vector),
              end(to_vector),
              std::ostream_iterator<std::string>(std::cout, "\n"));

    return 0;
}
</code>```

Body:
The code below fails to copy values from regex_token_iterator to a std::vector; Visual Studio 2015 reports that 'std::copy' with parameters may be unsafe.

Anyone knows how to fix it?

#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>

int main()
{
    // String to split in words
    std::string line = "dir1\\dir2\\dir3\\dir4";

    // Split the string in words
    std::vector<std::string> to_vector;
    const std::regex ws_re("\\\\");
    std::copy(std::sregex_token_iterator(line.begin(), line.end(), ws_re, -1),
              std::sregex_token_iterator(),
              std::back_insert_iterator<std::vector<std::string>>(to_vector));

    // Display the words
    std::cout << "Words: ";
    std::copy(begin(to_vector), end(to_vector), std::ostream_iterator<std::string>(std::cout, "\n"));
}

Body:
Here my solution to store the values extracted by regex_token_iterator to a vector:

#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>

int main()
{
    std::string s("dir1\\dir2\\dir3\\dir4");

    // Split the line in words
    const std::regex reg_exp("\\\\");
    const std::regex_token_iterator<std::string::iterator> end_tokens;
    std::regex_token_iterator<std::string::iterator> it(s.begin(), s.end(), reg_exp, -1);
    std::vector<std::string> to_vector;
    while (it != end_tokens)
    {
        to_vector.emplace_back(*it++);
    }

    // Display the content of the vector
    std::copy(begin(to_vector),
              end(to_vector),
              std::ostream_iterator<std::string>(std::cout, "\n"));

    return 0;
}


问:
Entity Framework Code First - two Foreign Keys from same table not working
I have two foreign Keys from same table defined like this:

```<code>public class OfferTemplate {    ...
 [ForeignKey("CompanyAgentBuyer_CompanyAgentID")]
 [InverseProperty("OfferTemplatesAsBuyer")]
 public virtual CompanyAgent CompanyAgentBuyer { get; set; }

 [ForeignKey("CompanyAgentBroker_CompanyAgentID")]
 [InverseProperty("OfferTemplatesAsBroker")]
 public virtual CompanyAgent CompanyAgentBroker { get; set; }

 public int CompanyAgentBuyer_CompanyAgentID { get; set; }
 public int? CompanyAgentBroker_CompanyAgentID { get; set; }
 ...
}
</code>```

On the model I got this setup:

```<code>modelBuilder.Entity<OfferTemplate>()
            .HasRequired(ca => ca.CompanyAgentBuyer)
            .WithMany(t => t.OfferTemplatesAsBuyer)
            .HasForeignKey(ca => ca.CompanyAgentBuyer_CompanyAgentID)
            .WillCascadeOnDelete(false);

modelBuilder.Entity<OfferTemplate>()
           .HasOptional(ca => ca.CompanyAgentBroker)
           .WithMany(t => t.OfferTemplatesAsBroker)
           .HasForeignKey(ca => ca.CompanyAgentBroker_CompanyAgentID)
           .WillCascadeOnDelete(false);
</code>```

So far everything works, except when I do the query:

```<code>var templates = from user in context.UsersInformation
                            from cTemplate in context.OfferTemplates
                            where user.User.Equals(userID) && cTemplate.Company == user.Company
                            select cTemplate;

var x = templates.FirstOrDefault().CompanyAgentBuyer;
</code>```

While the ID properties (CompanyAgentBuyer_CompanyAgentID & CompanyAgentBroker_CompanyAgentID) are being populated correctly the instance (like in this case x) is not being populated. I tried using Include method but it didn't work either. Any ideas what I am missing?

答:
I end up changing the model to this:

```<code>        modelBuilder.Entity<CompanyAgent>()
            .HasMany(e => e.OfferTemplatesAsBroker)
            .WithOptional(e => e.CompanyAgentBroker)
            .HasForeignKey(e => e.CompanyAgentBroker_CompanyAgentID);

        modelBuilder.Entity<CompanyAgent>()
            .HasMany(e => e.OfferTemplatesAsBuyer)
            .WithRequired(e => e.CompanyAgentBuyer)
            .HasForeignKey(e => e.CompanyAgentBuyer_CompanyAgentID)
            .WillCascadeOnDelete(false);
</code>```

now it is working.

Body:
I have two foreign Keys from same table defined like this:

public class OfferTemplate {    ...
 [ForeignKey("CompanyAgentBuyer_CompanyAgentID")]
 [InverseProperty("OfferTemplatesAsBuyer")]
 public virtual CompanyAgent CompanyAgentBuyer { get; set; }

 [ForeignKey("CompanyAgentBroker_CompanyAgentID")]
 [InverseProperty("OfferTemplatesAsBroker")]
 public virtual CompanyAgent CompanyAgentBroker { get; set; }

 public int CompanyAgentBuyer_CompanyAgentID { get; set; }
 public int? CompanyAgentBroker_CompanyAgentID { get; set; }
 ...
}

On the model I got this setup:

modelBuilder.Entity<OfferTemplate>()
            .HasRequired(ca => ca.CompanyAgentBuyer)
            .WithMany(t => t.OfferTemplatesAsBuyer)
            .HasForeignKey(ca => ca.CompanyAgentBuyer_CompanyAgentID)
            .WillCascadeOnDelete(false);

modelBuilder.Entity<OfferTemplate>()
           .HasOptional(ca => ca.CompanyAgentBroker)
           .WithMany(t => t.OfferTemplatesAsBroker)
           .HasForeignKey(ca => ca.CompanyAgentBroker_CompanyAgentID)
           .WillCascadeOnDelete(false);

So far everything works, except when I do the query:

var templates = from user in context.UsersInformation
                            from cTemplate in context.OfferTemplates
                            where user.User.Equals(userID) && cTemplate.Company == user.Company
                            select cTemplate;

var x = templates.FirstOrDefault().CompanyAgentBuyer;

While the ID properties (CompanyAgentBuyer_CompanyAgentID & CompanyAgentBroker_CompanyAgentID) are being populated correctly the instance (like in this case x) is not being populated. I tried using Include method but it didn't work either. Any ideas what I am missing?

Body:
I end up changing the model to this:

        modelBuilder.Entity<CompanyAgent>()
            .HasMany(e => e.OfferTemplatesAsBroker)
            .WithOptional(e => e.CompanyAgentBroker)
            .HasForeignKey(e => e.CompanyAgentBroker_CompanyAgentID);

        modelBuilder.Entity<CompanyAgent>()
            .HasMany(e => e.OfferTemplatesAsBuyer)
            .WithRequired(e => e.CompanyAgentBuyer)
            .HasForeignKey(e => e.CompanyAgentBuyer_CompanyAgentID)
            .WillCascadeOnDelete(false);

now it is working.


问:
How to make string as an Array Object in JQuery
I have got below string values in a variable.

```<code>var mystring = '{"img_src":"/english/images/spa.jpg",
    "img_title":"Enjoy a refreshing shower at 43,000 feet",
    "img_alt":"Enjoy a refreshing shower at 43,000 feet",
    "img_height":"326",
    "img_width":"980",
    "header":"Enjoy a refreshing shower at 43,000 feet",
    "subheader":"One of many groundbreaking amenities",
    "bg_color":"",
    "url_href":"1"},
     {"img_src":"/english/images/spa1.jpg",
    "img_title":"Enjoy a refreshing shower at 43,000 feet",
    "img_alt":"Enjoy a refreshing shower at 43,000 feet",
    "img_height":"326",
    "img_width":"980",
    "header":"Enjoy a refreshing shower at 43,000 feet",
    "subheader":"One of many groundbreaking amenities",
    "bg_color":"",
    "url_href":"1"}'
</code>```

Now I want to convert this string variable into Array object. So that If I try to access it my function it should behave like an array object. For example.

some code to Convert(mystring) to an Array Object(myArryObject), then I want to pass it to my function like below

```<code>$.fn.liveBanner = function(myArryObject,optional_options)
    {
      //here I want to access my myArryObject as below
      alert(myArryObject[0].img_src) //then it should give "/english/images/spa.jpg"
});
</code>```

Please suggest using JQuery.

EDIT:

I did the changes as suggested by @Deceze, please see below:

```<code>             var myString = "'"+ $("#RotationImages #mainHidden").attr("value")+"'";

    var myArrayobj = jQuery.parseJSON('[' + myString + ']');
    alert(myArrayobj.img_src);
</code>```

the above code is giving below error

```<code>Error: uncaught exception: Invalid JSON:'{"img_src":"/english/images/spa.jpg", "img_title":"Enjoy a refreshing shower at 43,000 feet","img_alt":"Enjoy a refreshing shower at 43,000 feet", "img_height":"326","img_width":"980","header":"Enjoy a refreshing shower at 43,000 feet","subheader":"One of many groundbreaking amenities on the Flight","bg_color":"","url_href":"1"}'
</code>```

答:
As your string only contains the objects inside the array, you have to add the array declaration before you parse it:</p>

```<code>var myArrayobj = jQuery.parseJSON('[' + myString + ']');
</code>```

Body:
I have got below string values in a variable.

var mystring = '{"img_src":"/english/images/spa.jpg",
    "img_title":"Enjoy a refreshing shower at 43,000 feet",
    "img_alt":"Enjoy a refreshing shower at 43,000 feet",
    "img_height":"326",
    "img_width":"980",
    "header":"Enjoy a refreshing shower at 43,000 feet",
    "subheader":"One of many groundbreaking amenities",
    "bg_color":"",
    "url_href":"1"},
     {"img_src":"/english/images/spa1.jpg",
    "img_title":"Enjoy a refreshing shower at 43,000 feet",
    "img_alt":"Enjoy a refreshing shower at 43,000 feet",
    "img_height":"326",
    "img_width":"980",
    "header":"Enjoy a refreshing shower at 43,000 feet",
    "subheader":"One of many groundbreaking amenities",
    "bg_color":"",
    "url_href":"1"}'

Now I want to convert this string variable into Array object. So that If I try to access it my function it should behave like an array object. For example.

some code to Convert(mystring) to an Array Object(myArryObject), then I want to pass it to my function like below

$.fn.liveBanner = function(myArryObject,optional_options)
    {
      //here I want to access my myArryObject as below
      alert(myArryObject[0].img_src) //then it should give "/english/images/spa.jpg"
});

Please suggest using JQuery.

EDIT:

I did the changes as suggested by @Deceze, please see below:

             var myString = "'"+ $("#RotationImages #mainHidden").attr("value")+"'";

    var myArrayobj = jQuery.parseJSON('[' + myString + ']');
    alert(myArrayobj.img_src);

the above code is giving below error

Error: uncaught exception: Invalid JSON:'{"img_src":"/english/images/spa.jpg", "img_title":"Enjoy a refreshing shower at 43,000 feet","img_alt":"Enjoy a refreshing shower at 43,000 feet", "img_height":"326","img_width":"980","header":"Enjoy a refreshing shower at 43,000 feet","subheader":"One of many groundbreaking amenities on the Flight","bg_color":"","url_href":"1"}'

Body:
As your string only contains the objects inside the array, you have to add the array declaration before you parse it:

var myArrayobj = jQuery.parseJSON('[' + myString + ']');


问:
2 elements on left 4 elements on right, space-between using flex
I'm creating a footer that displays inline elements with 2 icons to the left and 4 elements pushed right (buttons + text). This is the closest I've gotten, except the right side is flipped around.

.container {
    width: 100%;
}

.f_col_1 {
    width: 5%;
    float: left;
    background: #ccc;
    border: 1px solid black;
}

.f_col_1  {
    width: 5%;
    float: left;
    background: #ccc;
    border: 1px solid black;
}

.f_col_5 {
    width: 30%;
    display: block;
    background: #ddd;
    text-align: center;
}

.f_col_2 {
    width: 10%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

.f_col_3 {
    width: 20%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

.f_col_2 {
    width: 10%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

.f_col_3 {
    width: 20%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

@media only screen and (max-width: 900px) {
    div[class^="f_col_"]{
        width: 100%;
    }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
    <div class="f_col_1">(1)icon</div>
    <div class="f_col_1">(2) icon</div>
    <div class="f_col_5"></div>
    <div class="f_col_2" >(3)button</div>
    <div class="f_col_3" >(4)555.555.5555 </div>
    <div class="f_col_2" >(5)button</div>
    <div class="f_col_3" >(6)email@internet.com</div>
</div></code>```

It should be... 1-6

I've tried removing floats and putting space-between on center div, but doesn't work. What am I getting wrong? Thanks

答:
Forget the floats and do something like this instead:

.container {
  display: flex; /* displays children inline */
}

.f_col_1  {
  background: #ccc;
  border: 1px solid black;
}

.f_col_2,
.f_col_3 {
  background: #bbb;
  border: 1px solid black;
}

.container > div:nth-child(3) { /* makes a space between the 2nd and 3rd child */
  margin-left: auto;
}

@media screen and (max-width: 900px) {
  .container {
    flex-direction: column; /* stacks children vertically */
  }
  .container > div:nth-child(3) {
    margin-left: initial; /* back to default */
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
  <div class="f_col_1">(1) icon</div>
  <div class="f_col_1">(2) icon</div>
  <div class="f_col_2">(3) button</div>
  <div class="f_col_3">(4) 555.555.5555</div>
  <div class="f_col_2">(5) button</div>
  <div class="f_col_3">(6) email@internet.com</div>
</div></code>```

Body:
I'm creating a footer that displays inline elements with 2 icons to the left and 4 elements pushed right (buttons + text). This is the closest I've gotten, except the right side is flipped around.

.container {
    width: 100%;
}

.f_col_1 {
    width: 5%;
    float: left;
    background: #ccc;
    border: 1px solid black;
}

.f_col_1  {
    width: 5%;
    float: left;
    background: #ccc;
    border: 1px solid black;
}

.f_col_5 {
    width: 30%;
    display: block;
    background: #ddd;
    text-align: center;
}

.f_col_2 {
    width: 10%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

.f_col_3 {
    width: 20%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

.f_col_2 {
    width: 10%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

.f_col_3 {
    width: 20%;
    float: right;
    background: #bbb;
    border: 1px solid black;
}

@media only screen and (max-width: 900px) {
    div[class^="f_col_"]{
        width: 100%;
    }
}

(1)icon

(2) icon

(3)button

(4)555.555.5555

(5)button

(6)email@internet.com

It should be... 1-6

I've tried removing floats and putting space-between on center div, but doesn't work. What am I getting wrong? Thanks

Body:
Forget the floats and do something like this instead:

.container {
  display: flex; /* displays children inline */
}

.f_col_1  {
  background: #ccc;
  border: 1px solid black;
}

.f_col_2,
.f_col_3 {
  background: #bbb;
  border: 1px solid black;
}

.container > div:nth-child(3) { /* makes a space between the 2nd and 3rd child */
  margin-left: auto;
}

@media screen and (max-width: 900px) {
  .container {
    flex-direction: column; /* stacks children vertically */
  }
  .container > div:nth-child(3) {
    margin-left: initial; /* back to default */
  }
}

<div class="container">
  <div class="f_col_1">(1) icon</div>
  <div class="f_col_1">(2) icon</div>
  <div class="f_col_2">(3) button</div>
  <div class="f_col_3">(4) 555.555.5555</div>
  <div class="f_col_2">(5) button</div>
  <div class="f_col_3">(6) email@internet.com</div>
</div>


问:
Doing PUT using Python urllib2
I'm trying to do PUT to REST using urllib2 following the example I found on stackoverflow:

Is there any way to do HTTP PUT in python

I don't understand why I get error an error.

Here's an excerpt of my code:

```<code>import urllib2
import json

content_header = {'Content-type':'application/json',
                 'Accept':'application/vnd.error+json,application/json',
                 'Accept-Version':'1.0'}

baseURL = "http://some/put/url/"

f = open("somefile","r")
data = json.loads(f.read())

request = urllib2.Request(url=baseURL, data=json.dumps(jsonObj), headers=content_header)
request.get_method = lambda: 'PUT' #if I remove this line then the POST works fine.

response = urllib2.urlopen(request)

print response.read()
</code>```

if I remove the PUT option I'm trying to set then it posts it find but it will error out when I try and set get_method to PUT.

To be sure that the REST services aren't causing the issues I tried using cURL to do a PUT and it worked fine.

答:
While aaronfay's answer is good and works, I think that given that there are only 3 HTTP methods other than GET (and you are only worried about PUT), it is clearer and simpler to just define the Request sub-classes per method.

For example:

```<code>class PutRequest(urllib2.Request):
    '''class to handling putting with urllib2'''

    def get_method(self, *args, **kwargs):
        return 'PUT'
</code>```

Then to use:

```<code>request = PutRequest(url, data=json.dumps(data), headers=content_header)
</code>```

Title: Doing PUT using Python urllib2

Body:
I'm trying to do PUT to REST using urllib2 following the example I found on stackoverflow:

Is there any way to do HTTP PUT in python

I don't understand why I get error an error.

Here's an excerpt of my code:

import urllib2
import json

content_header = {'Content-type':'application/json',
                 'Accept':'application/vnd.error+json,application/json',
                 'Accept-Version':'1.0'}

baseURL = "http://some/put/url/"

f = open("somefile","r")
data = json.loads(f.read())

request = urllib2.Request(url=baseURL, data=json.dumps(jsonObj), headers=content_header)
request.get_method = lambda: 'PUT' #if I remove this line then the POST works fine.

response = urllib2.urlopen(request)

print response.read()

if I remove the PUT option I'm trying to set then it posts it find but it will error out when I try and set get_method to PUT.

To be sure that the REST services aren't causing the issues I tried using cURL to do a PUT and it worked fine.

Body:
While aaronfay's answer is good and works, I think that given that there are only 3 HTTP methods other than GET (and you are only worried about PUT), it is clearer and simpler to just define the Request sub-classes per method.

For example:

class PutRequest(urllib2.Request):
    '''class to handling putting with urllib2'''

    def get_method(self, *args, **kwargs):
        return 'PUT'

Then to use:

request = PutRequest(url, data=json.dumps(data), headers=content_header)


问:
Get Folder Size from Windows Command Line
Is it possible in Windows to get a folder's size from the command line without using any 3rd party tool?

I want the same result as you would get when right clicking the folder in the windows explorer → properties.

答:
I guess this would only work if the directory is fairly static and its contents don't change between the execution of the two dir commands. Maybe a way to combine this into one command to avoid that, but this worked for my purpose (I didn't want the full listing; just the summary).

GetDirSummary.bat Script:

```<code>@echo off
rem  get total number of lines from dir output
FOR /F "delims=" %%i IN ('dir /S %1 ^| find "asdfasdfasdf" /C /V') DO set lineCount=%%i
rem  dir summary is always last 3 lines; calculate starting line of summary info
set /a summaryStart="lineCount-3"
rem  now output just the last 3 lines
dir /S %1 | more +%summaryStart%
</code>```

Usage:

GetDirSummary.bat c:\temp

Output:

```<code> Total Files Listed:
          22 File(s)         63,600 bytes
           8 Dir(s)  104,350,330,880 bytes free
</code>```

Body:
I guess this would only work if the directory is fairly static and its contents don't change between the execution of the two dir commands. Maybe a way to combine this into one command to avoid that, but this worked for my purpose (I didn't want the full listing; just the summary).

GetDirSummary.bat Script:

@echo off
rem  get total number of lines from dir output
FOR /F "delims=" %%i IN ('dir /S %1 ^| find "asdfasdfasdf" /C /V') DO set lineCount=%%i
rem  dir summary is always last 3 lines; calculate starting line of summary info
set /a summaryStart="lineCount-3"
rem  now output just the last 3 lines
dir /S %1 | more +%summaryStart%

Usage:

GetDirSummary.bat c:\temp

Output:

 Total Files Listed:
          22 File(s)         63,600 bytes
           8 Dir(s)  104,350,330,880 bytes free


问:
What happens to the task that is initiated if the web api returns the response
I am trying to implement a task in fire and forget manner.

Lets look at the below piece of code.

```<code>public IHttpActionResult Update(int id)
{
   var updatedResult = _updater.update(id);

   // fire and forget a task

   sendEmailToUser();

   return ok();

}

private async Task sendEmailToUser()
{
   var httpclient = new HttpClient();

   // assume the client is initiated with required url and other headers

  await httpclient.postasync("some url");

}
</code>```

Given the above code, can i safely assume that whenever Update endpoint is called, sendEmailToUser task is triggered and will be run to completion ?

答:
No. You should almost never start any background threads in web application. HTTP is suppose to be stateless and the web server was designed with that in mind.

The server might be put into sleep state when there is no incoming request for a set period of time. During that time all the background execution will be halt including the one you had. It might and might not get resume when the next request comes in.

Or when IIS decides to recycle your App domain on a scheduled basis your thread will get killed too.

If you really need background tasks then do that using windows service or run it as a separate console application.

Body:
I am trying to implement a task in fire and forget manner.

Lets look at the below piece of code.

public IHttpActionResult Update(int id)
{
   var updatedResult = _updater.update(id);

   // fire and forget a task

   sendEmailToUser();

   return ok();

}

private async Task sendEmailToUser()
{
   var httpclient = new HttpClient();

   // assume the client is initiated with required url and other headers

  await httpclient.postasync("some url");

}

Given the above code, can i safely assume that whenever Update endpoint is called, sendEmailToUser task is triggered and will be run to completion ?


问:
How to read integers elegantly using C++ stream?
I have a file full of lines in this format:

```<code>1 - 2: 3
</code>```

I want to only load numbers using C++ streams. Whats the most elegant way to do it? I only thought about cin.get() and checikng each char if it is number or not.

答:
Sorry Konrad, but I recommend: never on pain of death, never never never (is that clear enough? :-) read formatted data from a file. Just don't.

There is only one correct way to do input of formatted data: read chunks of characters (typically lines but you can also read fixed length blocks).

Then parse the input text. You're not going to do a cursory check, you going to use a parser that guarantees to catch any formatting error, and report that error in a comprehensible way, take appropriate action (termination, skip the line and continue, whatever).

Separate input (the I/O operation) from parsing.

This advice from decades of experience as a commerical programmer: reading formatted input is for micky mouse proof-of-principal programs. Even if you have exclusive control of the creation of the file, always parse and check and report errors: after all, stuff changes, it may work today but not tomorrow.

I've been writing C++ for decades and I've never read an integer.

Body:
I have a file full of lines in this format:

1 - 2: 3

I want to only load numbers using C++ streams. Whats the most elegant way to do it? I only thought about cin.get() and checikng each char if it is number or not.


问:
Defined component style not working
margin-top style is not being applied to the component. I don't quite understand what I'm missing here.

Home.js

```<code>const BannerSd = styled(Banner)`
    margin-top: 15%;
`;

class Home extends Component {
  render() {
    return(
      <div>
        <BannerSd/>
        <Content/>
      </div>
    );
  }
}

export default Home;
</code>```

Banner.js

```<code>function Banner() {
    return (
        <div>
            <h1>Title</h1>
            <h3>SubTitle</h3>
        </div>
    );
}

export default Banner;
</code>```

答:
You need to pass the className down to the Banner component, as described in the styled-components docs.

function Banner({className}) {
    return (

Title

SubTitle

    );
}

export default Banner;```

Edit: Wrong link

Title: Defined component style not working

Body:
margin-top style is not being applied to the component. I don't quite understand what I'm missing here.

Home.js

const BannerSd = styled(Banner)`
    margin-top: 15%;
`;

class Home extends Component {
  render() {
    return(

        <BannerSd/>
        <Content/>

    );
  }
}

export default Home;

Banner.js

function Banner() {
    return (

Title

SubTitle

    );
}

export default Banner;

Body:
You need to pass the className down to the Banner component, as described in the styled-components docs.

function Banner({className}) {
    return (
        <div className={className}>
            <h1>Title</h1>
            <h3>SubTitle</h3>
        </div>
    );
}

export default Banner;

Edit: Wrong link


问:
Multiple selection ain't working in Phpstorm 8 under Ubuntu
New feature in Phpstorm 8 - multiple selection ain't working under Ubuntu 14.04, however, the hotkey ALT+J does work, but i cannot multiple select using ALT+Mouse left click, i have checked the keymap

```<code>Add or Remove caret is set to ALT+Button1 Click
</code>```

Which seems okay. When i try to hold ALT and left click - nothing happens, i guess it's ubuntu related.

答: Go to File > Settings > Keymap, then enter selection in the input search, then find Select all Ocurrence, then click right and select Add keyboard shortcut and select the combination that you wish, then accept changes and the OK.

Body:
New feature in Phpstorm 8 - multiple selection ain't working under Ubuntu 14.04, however, the hotkey ALT+J does work, but i cannot multiple select using ALT+Mouse left click, i have checked the keymap

Add or Remove caret is set to ALT+Button1 Click

Which seems okay. When i try to hold ALT and left click - nothing happens, i guess it's ubuntu related.


问:
Inserting special character in SQL Server
I have a table that contains these columns:

```<code>Country  Varchar(50)
Currency Nvarchar(10)
</code>```

I want to insert currency (rubble) for country Russia. I inserted currency for India using NCHAR(8377). But I'm not able to insert currency for Russia.

```<code>insert into Currency (country, currency)
values ('Indian Rupee', NCHAR(8377) );

Country      Currency
India         ₹
Russia
</code>```

答:
You can use NCHAR(8381)

```<code>insert into Currency (country, currency)
values ('russian ruble', NCHAR(8381) );
</code>```

Reference : http://www.xe.com/symbols.php

Body:
I have a table that contains these columns:

Country  Varchar(50)
Currency Nvarchar(10)

I want to insert currency (rubble) for country Russia. I inserted currency for India using NCHAR(8377). But I'm not able to insert currency for Russia.

insert into Currency (country, currency)
values ('Indian Rupee', NCHAR(8377) );

Country      Currency
India         ₹
Russia

Body:
You can use NCHAR(8381)

insert into Currency (country, currency)
values ('russian ruble', NCHAR(8381) );

Reference : http://www.xe.com/symbols.php


问:
How does next() method on iterators work?
I have a doubt with the next() method on iterators.  If I have as a part of my code this lines (with arrayOfStrings size = 4):

```<code>Iterator<String> it = arrayOfStrings.iterator(); //arrayOfString is ArrayList<String>

while(it.hasNext()) {
    String e = it.next();
    System.out.println(e);
}
</code>```

At the very first iteration, the iterator starts pointing to element with index 0? or like the "index -1" ?

I ask because as far as I know the next() method returns the next element in the collection.

So, if at the very first iteration the iterator starts at index 0 when next() is invoked, it returns the element at index 1 and I won´t be able to do nothing with the element at index 0?

答: Think of next as a two-step process. First it gets the next item in the iterator, then it increments the pointer to point to the next item. So, when you create a new iterator, it is initialized to return the first item (index 0) in your list.

Body:
I have a doubt with the next() method on iterators.  If I have as a part of my code this lines (with arrayOfStrings size = 4):

Iterator<String> it = arrayOfStrings.iterator(); //arrayOfString is ArrayList<String>

while(it.hasNext()) {
    String e = it.next();
    System.out.println(e);
}

At the very first iteration, the iterator starts pointing to element with index 0? or like the "index -1" ?

I ask because as far as I know the next() method returns the next element in the collection.

So, if at the very first iteration the iterator starts at index 0 when next() is invoked, it returns the element at index 1 and I won´t be able to do nothing with the element at index 0?


问:
How to get the value from Parameterized Test Fixtures?
How to get the TestFixture parameter value as string and pass to Switch statement? I tried but can't solve the issue "Member 'ClassLibrary1.Browsers.browser1' cannot be accessed with an instance reference; qualify it with a type name instead".
Init method should be a static because i used this in another class.

Code here:

```<code>[TestFixture("Chrome")]
public class Browsers
{
    public static IWebDriver webDriver;
    private static string baseURL = "https://www.google.com";
    private static string browser;

    private static string browser1;

    public Browsers(string browser1)
    {
         this.browser1 = browser1;
    }

    public static void Init()
    {
        switch (browser1)
        {
            case "Chrome":
                webDriver = new ChromeDriver();
                break;
            case "IE":
                webDriver = new InternetExplorerDriver();
                break;
            case "Firefox":
                webDriver = new FirefoxDriver();
                break;
        }
        webDriver.Manage().Window.Maximize();
        Goto(baseURL);
    }
    public static string Title
    {
        get { return webDriver.Title; }
    }
    public static IWebDriver getDriver
    {
        get { return webDriver; }
    }
    public static void Goto(string url)
    {
        webDriver.Navigate().GoToUrl(url);
    }
    public static void Close()
    {
        webDriver.Quit();
    }
}
</code>```

答:
As C# is telling you, you can't access an instance member from a static method. The reason for the problem in your case appears to be the fact that Browsers is not actually your test fixture, even though you placed the attribute on it. It looks like a static class containing various utility methods. Is that right?

The correct usage is to place the TestFixtureAttribute on a TestFixture, i.e. a class that contains tests. In that class's constructor, it can save the value of the argument, just as you have done. It can then initiate the correct browser instance either directly or using methods in a utility class.

You haven't explained what you mean by using the static Init method in another class, so I didn't go into that but I'll add to this answer if you explain it.

Body:
How to get the TestFixture parameter value as string and pass to Switch statement? I tried but can't solve the issue "Member 'ClassLibrary1.Browsers.browser1' cannot be accessed with an instance reference; qualify it with a type name instead".
Init method should be a static because i used this in another class.

Code here:

[TestFixture("Chrome")]
public class Browsers
{
    public static IWebDriver webDriver;
    private static string baseURL = "https://www.google.com";
    private static string browser;

    private static string browser1;

    public Browsers(string browser1)
    {
         this.browser1 = browser1;
    }

    public static void Init()
    {
        switch (browser1)
        {
            case "Chrome":
                webDriver = new ChromeDriver();
                break;
            case "IE":
                webDriver = new InternetExplorerDriver();
                break;
            case "Firefox":
                webDriver = new FirefoxDriver();
                break;
        }
        webDriver.Manage().Window.Maximize();
        Goto(baseURL);
    }
    public static string Title
    {
        get { return webDriver.Title; }
    }
    public static IWebDriver getDriver
    {
        get { return webDriver; }
    }
    public static void Goto(string url)
    {
        webDriver.Navigate().GoToUrl(url);
    }
    public static void Close()
    {
        webDriver.Quit();
    }
}


问:
Reason for using bit manipulation in array size

I have recently got a basic idea of bit manipulation, and I was going through a problem where I found this C++ statement:

```<code>int popcount[1<<16];
</code>```

I do have a basic idea of left/right Bit shift, but I would like to know why it is used in array size place.

答:
Unless you find a comment in the code and unless you find out what the intent of popcount is, one can just guess why one writes  1 << 16 instead of, for example, 65536.

A common case could be that you want to count the number of occurrences of a particular id in, for example, a file. If the range of such an id where 16 bits,  then such code could look as follows. The [1<<16] then expresses that you expect a range of not more  than 16 bits:

```<code> int popcounts[1<<16] = { 0 };

 int main() {
    uint16_t id;
    while (myfile >> id) {
      popcounts[id]++;
    }
 }
</code>```

Note that this is more accurate than writing int popcounts[UINT_MAX], because UINT_MAX is guaranteed to be equal or greater than 65536, and it is not guaranteed to be exactly 65536.

Body:
I have recently got a basic idea of bit manipulation, and I was going through a problem where I found this C++ statement:

int popcount[1<<16];

I do have a basic idea of left/right Bit shift, but I would like to know why it is used in array size place.

Body:
Unless you find a comment in the code and unless you find out what the intent of popcount is, one can just guess why one writes  1 << 16 instead of, for example, 65536.

A common case could be that you want to count the number of occurrences of a particular id in, for example, a file. If the range of such an id where 16 bits,  then such code could look as follows. The [1<<16] then expresses that you expect a range of not more  than 16 bits:

 int popcounts[1<<16] = { 0 };

 int main() {
    uint16_t id;
    while (myfile >> id) {
      popcounts[id]++;
    }
 }

Note that this is more accurate than writing int popcounts[UINT_MAX], because UINT_MAX is guaranteed to be equal or greater than 65536, and it is not guaranteed to be exactly 65536.


问:
How to add authorisation logic to the base topic in a Phoenix Channel so that all subtopics gets the same logic
My user_socket have

```<code>defmodule MyappServerWeb.UserSocket do
  use Phoenix.Socket

  ## Channels
  channel "public:login", MyappServerWeb.LoginChannel

  channel "admin:navbar", MyappServerWeb.AdminNavbarChannel
  channel "admin:dash", MyappServerWeb.AdminDashChannel
  channel "admin:user", MyappServerWeb.UserChannel
end
</code>```

Here i have to implement two authorization level, ie, public and admin. All subtopics under these two topic must inherit the same authorization logic i set to the parent topic. How to achieve this? or Am i doing anything wrong? (really new to functional programming)

答:
Usually it can be done using macros to share the same logic among different parts of code. You can make a module in which you write your logic and then in the web.ex file like this

```<code>    def channel do
      quote do
       use Project.module name
      end
   end
</code>```

After that you can use this any where like this use project.web, :module name.

Body:
My user_socket have

defmodule MyappServerWeb.UserSocket do
  use Phoenix.Socket

  ## Channels
  channel "public:login", MyappServerWeb.LoginChannel

  channel "admin:navbar", MyappServerWeb.AdminNavbarChannel
  channel "admin:dash", MyappServerWeb.AdminDashChannel
  channel "admin:user", MyappServerWeb.UserChannel
end

Here i have to implement two authorization level, ie, public and admin. All subtopics under these two topic must inherit the same authorization logic i set to the parent topic. How to achieve this? or Am i doing anything wrong? (really new to functional programming)

Body:
Usually it can be done using macros to share the same logic among different parts of code. You can make a module in which you write your logic and then in the web.ex file like this

    def channel do
      quote do
       use Project.module name
      end
   end

After that you can use this any where like this use project.web, :module name.


问:
Use of JavaScript new Array(n) Declaration
Basic JavaScript question: Since there is no hard limit for arrays as the case with Java (i.e. IndexOutOfBoundsException), what is the use of the declaration where we specify the length property?

```<code>var a = new Array(10);
</code>```

I know it predefines the length and puts "undefined" into those empty spots.  Is that reason enough for having it?

答:
Suppose you want an array of a certain length initialized to a certain value.  This will not work:

```<code>scores = [].fill(0.0, 0, studentCount);
</code>```

It'll just give you an empty array, because fill() will never extend the array beyond its original length.

This will work:

```<code>scores = new Array(studentCount).fill(0.0, 0, studentCount);
</code>```

It'll give you an array of studentCount values initialized to zero.

Body:
Basic JavaScript question: Since there is no hard limit for arrays as the case with Java (i.e. IndexOutOfBoundsException), what is the use of the declaration where we specify the length property?

var a = new Array(10);

I know it predefines the length and puts "undefined" into those empty spots.  Is that reason enough for having it?

Body:
Suppose you want an array of a certain length initialized to a certain value.  This will not work:

scores = [].fill(0.0, 0, studentCount);

It'll just give you an empty array, because fill() will never extend the array beyond its original length.

This will work:

scores = new Array(studentCount).fill(0.0, 0, studentCount);

It'll give you an array of studentCount values initialized to zero.


问:
Unable to install electron using npm
I am trying to install electron but it stucks on > node install.js. I have tried many times and left my laptop on for 2 hours but no success. Then I tried npm install --verbose electron --save-dev so that I could see stats and what is happening in background. And I realized that it's being downloading with only 10kbps or less speed and after sometime it stucks. Can someone please help me? I have searched many times on internet but didn't find any useful answer that's why I am asking a question here. Thanks

答:
Try running (no https):

```<code>npm config set registry http://registry.npmjs.org/
</code>```

It seems that it worked for these guys

Title: Unable to install electron using npm

Body:
Try running (no https):

npm config set registry http://registry.npmjs.org/

It seems that it worked for these guys


问:
Eclipse 3.6 Helios for Ubuntu 10.10
I have ubuntu 10.10 net book edition installed on my dell studio laptop. I downloaded helios for the eclipse site but when I am not able to run it. I have downloaded eclipse 3.5 from synaptic package manager but I am not able to update eclipse 3.5 to eclipse 3.6. Is der any other way to have updated eclipse? Eclipse 3.6 supports HTML 5. </p>

<p>Please let me know, thanks a lot in advance </p>

答:
The Eclipse version available through the official Ubuntu channels is 3.5 and should not be manually upgraded to 3.6.  You probably will not have write permission to do so.

If you must have 3.6 the easiest way is to download the official distribution from eclipse.org, unzip it and run the eclipse binary directly.  This also allows you to fully administer it by yourself with upgrades and extra modules.

Title: Eclipse 3.6 Helios for Ubuntu 10.10

Body:
I have ubuntu 10.10 net book edition installed on my dell studio laptop. I downloaded helios for the eclipse site but when I am not able to run it. I have downloaded eclipse 3.5 from synaptic package manager but I am not able to update eclipse 3.5 to eclipse 3.6. Is der any other way to have updated eclipse? Eclipse 3.6 supports HTML 5.

Please let me know, thanks a lot in advance