问:
How to make my random generated div appear inside container div?
HTML

```<code>    <div id="container">
        <div id="wrapper">

        </div>
        <span id = "waveNum">Current Wave: 0</span>
        <input type = "button" value = "Start Game" onclick = "startGame()"></input>
    </div>

    <script src="https://code.jquery.com/jquery-2.1.3.js"></script>
    <script src="main.js"></script>
  </body>
</code>```

Javascript

```<code>var keyArray = [];
var currentWave = 1;

var player;
var player2;
function initiate(){
    player = new createPlayer(150,50,"player1","relative","blue");
    player2 = new createPlayer(150,0,"player2","relative","green");
}

function startGame() {
    point();
}

function createPlayer(l,t,id,pos,color){
    this.speed = 3;
    this.width = 25;
    this.height = 25;
    this.left = l;
    this.top = t;
    this.id = id;
    this.model = $("<div id=" + id + "/>")
        .css({"backgroundColor":color,"height":this.height,"width":this.width,
            "left":this.left,"top":this.top,"position":pos})

  $('#wrapper').append($(this.model));
}

function point(){
  leftP = parseInt(Math.random()*970);
  topP = parseInt(Math.random()*580);
  $points = $("<div class=point/>")
    .css({"backgroundColor":"yellow","height":"10px","width":"10px","left":0,
        "top":0,"position":"relative"})
  $('#wrapper').append($points)
}

function update(){
  //left
    if(keyArray[65]){
        var newLeft = parseInt(player.left)-player.speed+"px"
        player.left = newLeft;
        document.getElementById(player.id).style.left = newLeft;
    }
    //right
    if(keyArray[68]){
        var newLeft = parseInt(player.left)+player.speed+"px"
        player.left = newLeft;
        document.getElementById(player.id).style.left = newLeft;
    }
    //up
    if(keyArray[87]){
        var newTop = parseInt(player.top)-player.speed+"px"
        player.top = newTop;
        document.getElementById(player.id).style.top = newTop;
    }
    //down
    if(keyArray[83]){
        var newTop = parseInt(player.top)+player.speed+"px"
        player.top = newTop;
        document.getElementById(player.id).style.top = newTop;
    }

  //player2
    //left
    if(keyArray[37]){
        var newLeft = parseInt(player2.left)-player2.speed+"px"
        player2.left = newLeft;
        document.getElementById(player2.id).style.left = newLeft;
    }
    //right
    if(keyArray[39]){
        var newLeft = parseInt(player2.left)+player2.speed+"px"
        player2.left = newLeft;
        document.getElementById(player2.id).style.left = newLeft;
    }
    //up
    if(keyArray[38]){
        var newTop = parseInt(player2.top)-player2.speed+"px"
        player2.top = newTop;
        document.getElementById(player2.id).style.top = newTop;
    }
    //down
    if(keyArray[40]){
        var newTop = parseInt(player2.top)+player2.speed+"px"
        player2.top = newTop;
        document.getElementById(player2.id).style.top = newTop;
    }
    blockade();
    requestAnimationFrame(update);
}

function blockade(){
    var elemLeft = parseInt($('#wrapper').css('left'));
    var elemWidth = parseInt($('#wrapper').css('width'));
    var elemTop= parseInt($('#wrapper').css('height'));
  //blocks players from moving outside of game
    if(parseInt(player.left) + player.width >= elemLeft+elemWidth){
        player.left = elemWidth - player.width - 2;
    }
    if(parseInt(player.top) + player.height >= elemTop){
        player.top = elemTop - player.height - 2;
    }
    if(parseInt(player.top) < 3){
        player.top = 3;
    }
    if(parseInt(player.left) < 3){
        player.left = 3;
    }
    if(parseInt(player2.left) + player2.width >= elemLeft+elemWidth){
        player2.left = elemWidth - player2.width - 2;
    }
    if(parseInt(player2.top) + player2.height >= elemTop){
        player2.top = elemTop - player2.height - 2;
    }
    if(parseInt(player2.top) < 3){
        player2.top = 3;
    }
    if(parseInt(player2.left) < 3){
        player2.left = 3;
    }
}

window.onkeydown = function(page){
    keyArray[page.keyCode] = page.type === 'keydown';
}
    window.onkeyup = function(page){
        keyArray[page.keyCode] = page.type === 'keydown'
}
</code>```

CSS

```<code>html, body {margin: 0; height: 100%; overflow: hidden}

#container{
    width:80%;
    height:60%;
    display: block;
    text-align:center;
    margin: 0 auto;
}
#wrapper{
    left:0px;
    width:1000px; /* 100% */
    height:600px;
    border:1px solid lime;
    margin:0 auto;
    background-color:black;
}

#player1, .point {
    float: left;
    clear: both;
}
body{
    background-color:black;
}
#waveNum{
    color:white;
    font-size:200%;
}

.point {
    overflow: auto;
}
</code>```

So currently I need my point() function to generate a random div within the
 which it is but after a few different spawns, does not stay within the wrapper div eventually. It seems like the container of the point() seems to be shifting down. The more that is generated the more often it appears to the bottom and outside of the container.

Eventually my idea is for all of them to have the same top and left original positions in that way I could use my player and player2 to touch them (match left and top positions) and make them disappear like they are being collected like points. I also cant get them to have the same origin point. I think these issues might be related

答:
You can use to make appeared specific div</p>

```<code>z-index: 0
</code>```

Body:
HTML

        Current Wave: 0
        <input type = "button" value = "Start Game" onclick = "startGame()"></input>

Javascript

var keyArray = [];
var currentWave = 1;

var player;
var player2;
function initiate(){
    player = new createPlayer(150,50,"player1","relative","blue");
    player2 = new createPlayer(150,0,"player2","relative","green");
}

function startGame() {
    point();
}

function createPlayer(l,t,id,pos,color){
    this.speed = 3;
    this.width = 25;
    this.height = 25;
    this.left = l;
    this.top = t;
    this.id = id;
    this.model = $("
")
        .css({"backgroundColor":color,"height":this.height,"width":this.width,
            "left":this.left,"top":this.top,"position":pos})

  $('#wrapper').append($(this.model));
}

function point(){
  leftP = parseInt(Math.random()*970);
  topP = parseInt(Math.random()*580);
  $points = $("
")
    .css({"backgroundColor":"yellow","height":"10px","width":"10px","left":0,
        "top":0,"position":"relative"})
  $('#wrapper').append($points)
}

function update(){
  //left
    if(keyArray[65]){
        var newLeft = parseInt(player.left)-player.speed+"px"
        player.left = newLeft;
        document.getElementById(player.id).style.left = newLeft;
    }
    //right
    if(keyArray[68]){
        var newLeft = parseInt(player.left)+player.speed+"px"
        player.left = newLeft;
        document.getElementById(player.id).style.left = newLeft;
    }
    //up
    if(keyArray[87]){
        var newTop = parseInt(player.top)-player.speed+"px"
        player.top = newTop;
        document.getElementById(player.id).style.top = newTop;
    }
    //down
    if(keyArray[83]){
        var newTop = parseInt(player.top)+player.speed+"px"
        player.top = newTop;
        document.getElementById(player.id).style.top = newTop;
    }

  //player2
    //left
    if(keyArray[37]){
        var newLeft = parseInt(player2.left)-player2.speed+"px"
        player2.left = newLeft;
        document.getElementById(player2.id).style.left = newLeft;
    }
    //right
    if(keyArray[39]){
        var newLeft = parseInt(player2.left)+player2.speed+"px"
        player2.left = newLeft;
        document.getElementById(player2.id).style.left = newLeft;
    }
    //up
    if(keyArray[38]){
        var newTop = parseInt(player2.top)-player2.speed+"px"
        player2.top = newTop;
        document.getElementById(player2.id).style.top = newTop;
    }
    //down
    if(keyArray[40]){
        var newTop = parseInt(player2.top)+player2.speed+"px"
        player2.top = newTop;
        document.getElementById(player2.id).style.top = newTop;
    }
    blockade();
    requestAnimationFrame(update);
}

function blockade(){
    var elemLeft = parseInt($('#wrapper').css('left'));
    var elemWidth = parseInt($('#wrapper').css('width'));
    var elemTop= parseInt($('#wrapper').css('height'));
  //blocks players from moving outside of game
    if(parseInt(player.left) + player.width >= elemLeft+elemWidth){
        player.left = elemWidth - player.width - 2;
    }
    if(parseInt(player.top) + player.height >= elemTop){
        player.top = elemTop - player.height - 2;
    }
    if(parseInt(player.top) < 3){
        player.top = 3;
    }
    if(parseInt(player.left) < 3){
        player.left = 3;
    }
    if(parseInt(player2.left) + player2.width >= elemLeft+elemWidth){
        player2.left = elemWidth - player2.width - 2;
    }
    if(parseInt(player2.top) + player2.height >= elemTop){
        player2.top = elemTop - player2.height - 2;
    }
    if(parseInt(player2.top) < 3){
        player2.top = 3;
    }
    if(parseInt(player2.left) < 3){
        player2.left = 3;
    }
}

window.onkeydown = function(page){
    keyArray[page.keyCode] = page.type === 'keydown';
}
    window.onkeyup = function(page){
        keyArray[page.keyCode] = page.type === 'keydown'
}

CSS

html, body {margin: 0; height: 100%; overflow: hidden}

#container{
    width:80%;
    height:60%;
    display: block;
    text-align:center;
    margin: 0 auto;
}
#wrapper{
    left:0px;
    width:1000px; /* 100% */
    height:600px;
    border:1px solid lime;
    margin:0 auto;
    background-color:black;
}

#player1, .point {
    float: left;
    clear: both;
}
body{
    background-color:black;
}
#waveNum{
    color:white;
    font-size:200%;
}

.point {
    overflow: auto;
}

So currently I need my point() function to generate a random div within the
 which it is but after a few different spawns, does not stay within the wrapper div eventually. It seems like the container of the point() seems to be shifting down. The more that is generated the more often it appears to the bottom and outside of the container.

Eventually my idea is for all of them to have the same top and left original positions in that way I could use my player and player2 to touch them (match left and top positions) and make them disappear like they are being collected like points. I also cant get them to have the same origin point. I think these issues might be related

Body:
You can use to make appeared specific div

z-index: 0


来源: stackexchange

问:
How to build dagger itself
The dagger project uses bazel.build system to build. I have installed bazel on Fedora, it runs and builds the project but apparently dagger has Java 1.8 code, and bazel targets java 7.

There is a build_def.bzl file and java target version is defined like so:

SOURCE_7_TARGET_7 = ["-source 1.7 -target 1.7"]

changing it to

SOURCE_7_TARGET_7 = ["-source 1.8 -target 1.8"]

does not help. Both master and rc11 branches fail to build because of the same error (java compiler complains about target version 1.7 not supporting lambda and method reference). There is no guide for building dagger on the wiki or project page and I'm unfamiliar with bazel. I wonder if something like retrolambda must be added to the build runtime path but it doesn't seem easy with bazel.

Sample output:

```<code>$> bazel build :all

INFO: Found 8 targets...
ERROR: /home/user/dagger/java/dagger/internal/codegen/BUILD:44:1: Building java/dagger/internal/codegen/libcodegen.jar (116 source files) failed: java failed: error executing command external/local_jdk/bin/java -Xbootclasspath/p:external/bazel_tools/third_party/java/jdk/langtools/javac-9-dev-r4023-2.jar -XX:+TieredCompilation '-XX:TieredStopAtLevel=1' -jar ... (remaining 2 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
java/dagger/internal/codegen/AbstractComponentWriter.java:612: error: method references are not supported in -source 1.7
  (use -source 8 or higher to enable method references)
java/dagger/internal/codegen/AnnotationExpression.java:80: error: lambda expressions are not supported in -source 1.7
  (use -source 8 or higher to enable lambda expressions)
java/dagger/internal/codegen/AnnotationSpecs.java:41: error: method references are not supported in -source 1.7
  (use -source 8 or higher to enable method references)

# Rest of output removed for brevity, the error above repeats for many more files.
</code>```

答:
I had wrong version of bazel installed. Building is as simple as running:

```<code>bazel build :all
</code>```

I already had Oracle JDK 8 installed on my machine (Fedora) and downloaded this release of bazel (bazel-0.5.0-without-jdk-installer-linux-x86_64.sh).

ContentLicense: CC BY-SA 3.0

Title: How to build dagger itself

Body:
The dagger project uses bazel.build system to build. I have installed bazel on Fedora, it runs and builds the project but apparently dagger has Java 1.8 code, and bazel targets java 7.

There is a build_def.bzl file and java target version is defined like so:

SOURCE_7_TARGET_7 = ["-source 1.7 -target 1.7"]

changing it to

SOURCE_7_TARGET_7 = ["-source 1.8 -target 1.8"]

does not help. Both master and rc11 branches fail to build because of the same error (java compiler complains about target version 1.7 not supporting lambda and method reference). There is no guide for building dagger on the wiki or project page and I'm unfamiliar with bazel. I wonder if something like retrolambda must be added to the build runtime path but it doesn't seem easy with bazel.

Sample output:

$> bazel build :all

INFO: Found 8 targets...
ERROR: /home/user/dagger/java/dagger/internal/codegen/BUILD:44:1: Building java/dagger/internal/codegen/libcodegen.jar (116 source files) failed: java failed: error executing command external/local_jdk/bin/java -Xbootclasspath/p:external/bazel_tools/third_party/java/jdk/langtools/javac-9-dev-r4023-2.jar -XX:+TieredCompilation '-XX:TieredStopAtLevel=1' -jar ... (remaining 2 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
java/dagger/internal/codegen/AbstractComponentWriter.java:612: error: method references are not supported in -source 1.7
  (use -source 8 or higher to enable method references)
java/dagger/internal/codegen/AnnotationExpression.java:80: error: lambda expressions are not supported in -source 1.7
  (use -source 8 or higher to enable lambda expressions)
java/dagger/internal/codegen/AnnotationSpecs.java:41: error: method references are not supported in -source 1.7
  (use -source 8 or higher to enable method references)

# Rest of output removed for brevity, the error above repeats for many more files.

Body:
I had wrong version of bazel installed. Building is as simple as running:

bazel build :all

I already had Oracle JDK 8 installed on my machine (Fedora) and downloaded this release of bazel (bazel-0.5.0-without-jdk-installer-linux-x86_64.sh).


问:
Unable to use ADC on atmega328
I am trying to make a proximity sensor using ATmega328P. I am using the onboard ADC to convert the voltage value and if it is higher than the ambient, an LED is lit.

The voltage that is being sensed is according to this circuit:

In the circuit, the VOUT is going to ADC channel 3 and should be sensed (think of the led on the right as the IR Sensor).

When the program starts, it senses 30 readings and takes their average to be used as the ambient setting. If any subsequent measurement is higher than this value, the LED should be lit.

But the LED does not light even if I place my hand above the sensor.

I have tested with just the LED to see if the IR sensor is ok. It is ok by the way.

The code for the microcontroller is as follows:

/*
 * Proximity Sensor IR.c
 *
 * Created: 6/3/2017 2:35:33 PM
 * Author : Rishav
 */

#include <avr/io.h>
#include <stdio.h>

#define F_CPU 16000000UL
#include <util/delay.h>

int calibration()
{
    unsigned int sum = 0;

    for (int i=0; i<30; i++)
        {
            ADCSRA |= (1<<ADSC);
            while(!(ADCSRA & (1<<ADIF)));

            ADCSRA |= (1<<ADIF);

            sum += (ADCH<<8)|ADCL;
        }

    return (sum/30);
}

int main(void)
{
    unsigned int val = 0;

    ADMUX |= (0<<REFS1)|(1<<REFS0)|(0<<MUX3)|(0<<MUX2)|(1<<MUX1)|(1<<MUX0);     //setting the multiplexer to ADC3
    ADCSRA |= (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

    DDRB = 0b00000010;

    DDRD |= (1<<PCINT22);
    PORTD |= (1<<PCINT22);

    int calib_value = calibration();

    while (1)
    {
        ADCSRA |= (1<<ADSC);
        while(!(ADCSRA & (1<<ADIF)));

        val = (ADCH<<8)|ADCL;

        ADCSRA |= (1<<ADIF);

        if (val > calib_value)
            PORTB = 0b00000010;
    }
}
```

I think there is some problem in the code. Please help.

答:
Some things that come to mind when looking at your code:

You are really not completely initializing the ADMUX and ADCSRA registers - everything you put in there is just 'ORed'-in. (ADLAR in ADMUX is not in a defined state, for example, ADCSRA has even more undefined bits).

After setting the reference voltage source in the ADMUX register, you are supposed to wait for the chip to switch, but don't. Most probably, your first measurement in calibration will be way off. The simplest way to address this is to do one first measurement whose result you simply ignore. (or wait some ms after you have set up ADC).

You are supposed to always read ADCL before ADCH (the AVR locks the ADC for writing further results to the result register when ADCL is read until ADCH is read as well). Your current code has an undefined read order of those 2 registers.

Title: Unable to use ADC on atmega328

Body:
I am trying to make a proximity sensor using ATmega328P. I am using the onboard ADC to convert the voltage value and if it is higher than the ambient, an LED is lit.

The voltage that is being sensed is according to this circuit:

In the circuit, the VOUT is going to ADC channel 3 and should be sensed (think of the led on the right as the IR Sensor).

When the program starts, it senses 30 readings and takes their average to be used as the ambient setting. If any subsequent measurement is higher than this value, the LED should be lit.

But the LED does not light even if I place my hand above the sensor.

I have tested with just the LED to see if the IR sensor is ok. It is ok by the way.

The code for the microcontroller is as follows:

/*
 * Proximity Sensor IR.c
 *
 * Created: 6/3/2017 2:35:33 PM
 * Author : Rishav
 */

#include <avr/io.h>
#include <stdio.h>

#define F_CPU 16000000UL
#include <util/delay.h>

int calibration()
{
    unsigned int sum = 0;

    for (int i=0; i<30; i++)
        {
            ADCSRA |= (1<<ADSC);
            while(!(ADCSRA & (1<<ADIF)));

            ADCSRA |= (1<<ADIF);

            sum += (ADCH<<8)|ADCL;
        }

    return (sum/30);
}

int main(void)
{
    unsigned int val = 0;

    ADMUX |= (0<<REFS1)|(1<<REFS0)|(0<<MUX3)|(0<<MUX2)|(1<<MUX1)|(1<<MUX0);     //setting the multiplexer to ADC3
    ADCSRA |= (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

    DDRB = 0b00000010;

    DDRD |= (1<<PCINT22);
    PORTD |= (1<<PCINT22);

    int calib_value = calibration();

    while (1)
    {
        ADCSRA |= (1<<ADSC);
        while(!(ADCSRA & (1<<ADIF)));

        val = (ADCH<<8)|ADCL;

        ADCSRA |= (1<<ADIF);

        if (val > calib_value)
            PORTB = 0b00000010;
    }
}

I think there is some problem in the code. Please help.


问:
Why does my Facebook Like button create a brand new Facebook page?
I'm trying to integrate Facebook into a site I'm developing, I have created a Facebook Page for the business & a Facebook app too - I am very confused with the documentation & terminology that Facebook uses.

I am using FBML to add a Recommend button to the footer of my site so that users can recommend that particular page but when I click on it, it creates a brand new Facebook page for that URI & seemingly ignores all the facebook & open graph metatag info.

FYI, these are the metatags that I'm using:

```<code><meta property="og:title" content="My Page title"/>
<meta property="og:type" content="company"/>
<meta property="og:url" content="http://mysite.com/"/>
<meta property="og:image" content="http://mysiteimage.jpg"/>
<meta property="og:site_name" content="My Site Name"/>
<meta property="fb:admins" content="My_FB_Admin_ID"/>
<meta property="fb:page_id" content="My_FB_Page_ID" />
<meta property="fb:app_id" content="My_FB_App_ID" />
<meta property="og:description" content="Desctiption of page"/>
</code>```

This is the FBML I'm using:

```<code><fb:like width="940" action="recommend" font="lucida grande"></fb:like>
</code>```

This is the Facebook Javascript SDK code I'm adding to each page before the  tag (it is only being added once per page):

```<code><div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({appId: 'My_FB_App_ID', status: true, cookie: true,
        xfbml: true});
    };
    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
</script>
</code>```

Does anyone have any idea what the heck I should be doing? Should I be using an app as the fan page or the page I'm already using??

I would also really like to be able to 'Like/Recommend' the actual Facebook page from the site, is this possible?

Many thanks in advance.

Zander

答:
The issue has to do with the meta property og:type. Anything other than article like a video/audio etc.  will create a new Facebook Page on the open social graph.

If you set og:type to article, or remove it altogether, the issue will go away.

I hope that helps.

ContentLicense: CC BY-SA 2.5

Body:
I'm trying to integrate Facebook into a site I'm developing, I have created a Facebook Page for the business & a Facebook app too - I am very confused with the documentation & terminology that Facebook uses.

I am using FBML to add a Recommend button to the footer of my site so that users can recommend that particular page but when I click on it, it creates a brand new Facebook page for that URI & seemingly ignores all the facebook & open graph metatag info.

FYI, these are the metatags that I'm using:

<meta property="og:title" content="My Page title"/>
<meta property="og:type" content="company"/>
<meta property="og:url" content="http://mysite.com/"/>
<meta property="og:image" content="http://mysiteimage.jpg"/>
<meta property="og:site_name" content="My Site Name"/>
<meta property="fb:admins" content="My_FB_Admin_ID"/>
<meta property="fb:page_id" content="My_FB_Page_ID" />
<meta property="fb:app_id" content="My_FB_App_ID" />
<meta property="og:description" content="Desctiption of page"/>

This is the FBML I'm using:

<fb:like width="940" action="recommend" font="lucida grande"></fb:like>

This is the Facebook Javascript SDK code I'm adding to each page before the  tag (it is only being added once per page):

Does anyone have any idea what the heck I should be doing? Should I be using an app as the fan page or the page I'm already using??

I would also really like to be able to 'Like/Recommend' the actual Facebook page from the site, is this possible?

Many thanks in advance.

Zander


问:
Scanf with format specifier and input mismatch
Passing characters to a scanf with a %d specifier resulted in random numbers all around 32,760. I am using the GCC available with Ubuntu 16.04.
My guess is, obviously, that this is unspecified behavior. But any idea as to what's going on under the hood?

Here is the rather obvious code for aforementioned objective:

```<code>#include <stdio.h>

void main() {
  int n;
  scanf("%d", &n);
  printf("\n%d", n);
}
</code>```

The input supplied was repeatedly the letter 'a' followed by pressing an Enter to terminate terminal talk. The results for the first three runs were : 32765, 32764, 32767.

In response to some helpful suggestions, I've thus figured that scanf doesn't initialize n. But it does something.
Consider this code:

```<code>#include<stdio.h>
int main() {
    int i;
    for(i=0; i<10; i++)
    {
        int n;
        printf("%d", n);
    }
}
</code>```

This gives me a row of ten zeroes for the output.
I'm flummoxed. The question probably isn't interesting, I get it. But I just can't not stop wondering why. I still can't rule out the effect of scanf because of this.

答:
I changed your program to

```<code>#include <stdio.h>

int main() {
  int n;
  printf("%d\n", n);
  scanf("%d", &n);
  printf("%d\n", n);
}
</code>```

When I run it with the input "a", it prints

```<code>32767
32767
</code>```

So whatever is causing n to start out with the bit pattern for 32767, it is not anything that scanf is doing.

At one level this is interesting, perhaps even fascinating: despite the fact I'm using a very different system (clang-600.0.57 under MacOS 10.9.5), I got a remarkably similar result.  But no matter how intriguing this is, I'm not going to waste time trying to figure out why, because it'd be hard, and it wouldn't teach me anything useful about writing proper programs.  It's just some random, meaningless coincidence.

Body:
Passing characters to a scanf with a %d specifier resulted in random numbers all around 32,760. I am using the GCC available with Ubuntu 16.04.
My guess is, obviously, that this is unspecified behavior. But any idea as to what's going on under the hood?

Here is the rather obvious code for aforementioned objective:

#include <stdio.h>

void main() {
  int n;
  scanf("%d", &n);
  printf("\n%d", n);
}

The input supplied was repeatedly the letter 'a' followed by pressing an Enter to terminate terminal talk. The results for the first three runs were : 32765, 32764, 32767.

In response to some helpful suggestions, I've thus figured that scanf doesn't initialize n. But it does something.
Consider this code:

#include<stdio.h>
int main() {
    int i;
    for(i=0; i<10; i++)
    {
        int n;
        printf("%d", n);
    }
}

This gives me a row of ten zeroes for the output.
I'm flummoxed. The question probably isn't interesting, I get it. But I just can't not stop wondering why. I still can't rule out the effect of scanf because of this.

Body:
I changed your program to

#include <stdio.h>

int main() {
  int n;
  printf("%d\n", n);
  scanf("%d", &n);
  printf("%d\n", n);
}

When I run it with the input "a", it prints

32767
32767

So whatever is causing n to start out with the bit pattern for 32767, it is not anything that scanf is doing.

At one level this is interesting, perhaps even fascinating: despite the fact I'm using a very different system (clang-600.0.57 under MacOS 10.9.5), I got a remarkably similar result.  But no matter how intriguing this is, I'm not going to waste time trying to figure out why, because it'd be hard, and it wouldn't teach me anything useful about writing proper programs.  It's just some random, meaningless coincidence.


问:
Weird colors in XCode Interface Builder?
I have really weird problem with colors in interface builder. I set a color on one UI element, for example UIView, and then I want the same color on UIButton...but when I try to do so, colors are often different - I mean little bit different tone, not absolutely different color. How is this even possible ??? I've tried to use RGB sliders, and other sliders, also that color picker tool... Only thing that helps me sometimes is, when I create new UI element. Anybody had the same problem and knows what's going on ?</p>

答:
I solved this issue using "Device RGB" instead "Generic RGB".
See the image:


问:
New Facebook like button HTML validation
After adding the new facebook like button on my page, it's no longer validates using XHTML strict standard.  The two errors I come across are:

All of the meta property tags say that there is no attribute property;

All of the variables used in the like button line are listed that there are no attributes for it.  The line is as follows:

<fb:like href="http://www.pampamanta.org" layout="button_count" show_faces="false" width="120" action="like" font="arial" colorscheme="light"></fb:like>

答:
@Eric I hope you eventually found what you were looking for.

Twitter integration has its difficulties if you want to empower developers to validate irrespective of XHTML Strict 1.0 or HTML5. Facebook, on the other hand, is down right impossible with its custom FBML tags.

On our last project my friend Jason and I knew two things for certain:

We were going to validate XHTML Strict 1.0 using Facebook's Like Button

We were not going to add Technical Debt by fudging our DOCTYPE or xmlns

The solution is to use a flexible, asynchronous JavaScript module. Thankfully, we had some help and guidance along the way: http://techoctave.com/c7/posts/40-xhtml-strict-tweet-button-and-facebook-like-button


问:
Script to Find Copies of Files in Powershell
I am trying to make a script in PowerShell that analyzes recursevily a directory and gets all hashes MD5 from all files and from all files inside any directories inside the 1st one given.

After that, I want to compare all the hashes between each other to see which one is a copy, and then give an option to delete these copies or not.

At the moment I have this:

```<code>$UserInput=Read-Host
Get-ChildItem -Path $UserInput -Recurse
$someFilePath = $UserInput
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($someFilePath)))
$hash
</code>```

The main problem is in the hash part, that I get an error in calling the "ReadAllBytes".

I also am doubting if creating an array so when I compare the hashes, if they are equal, put the copies in an array, so then deleting them is "easier".

What do you think? (I am also not sure if I am using right the "SomeFilePath", MD5 nor Hash).

答:
Try this:</p>

```<code>$fileHashes = Get-ChildItem -Path $myFilePath -Recurse -File | Get-Filehash -Algorithm MD5
$doubles = $fileHashes | Group hash | ? {$_.count -gt 1} | % {$_.Group}

foreach($item in $doubles) {
  Write-Output $item
}
</code>```

Body:
I am trying to make a script in PowerShell that analyzes recursevily a directory and gets all hashes MD5 from all files and from all files inside any directories inside the 1st one given.

After that, I want to compare all the hashes between each other to see which one is a copy, and then give an option to delete these copies or not.

At the moment I have this:

$UserInput=Read-Host
Get-ChildItem -Path $UserInput -Recurse
$someFilePath = $UserInput
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($someFilePath)))
$hash

The main problem is in the hash part, that I get an error in calling the "ReadAllBytes".

I also am doubting if creating an array so when I compare the hashes, if they are equal, put the copies in an array, so then deleting them is "easier".

What do you think? (I am also not sure if I am using right the "SomeFilePath", MD5 nor Hash).

Body:
Try this:

$fileHashes = Get-ChildItem -Path $myFilePath -Recurse -File | Get-Filehash -Algorithm MD5
$doubles = $fileHashes | Group hash | ? {$_.count -gt 1} | % {$_.Group}

foreach($item in $doubles) {
  Write-Output $item
}


问:
Simple DIV float / stack issue (fixed right, flexible left, media rule)
I am almost there, but looks like one property is missing or wrong.

I want to embed two iFrames:
- left side: a youtube video (witdh flexible)
- right side: a youtube live chat (fixed width 200px)

The @media rule already works. However for the desktop view the second div (chat) stays below the first div (video), whereas it should be on the same line. This is the problem I can't solve. Can somebody be as kind and tell me the trick to bring the chat next to the video?

http://jsbin.com/waxaxa/1/edit?html,css,output

```<code>.wrapper {
 border : 2px dotted #ccc; padding: 2px;
}

.wrapper div {
width: 100%;
 min-height: 200px;
 padding: 10px;
 -webkit-box-sizing: border-box;
 -moz-box-sizing: border-box;
 box-sizing: border-box;
 float: left;
 overflow: hidden;
}

#video { background-color: red; float:none; width:auto;}
#chat { background-color: gray;position: }

@media screen and (min-width: 600px) {
   .wrapper {
    height: auto;width: auto; overflow: hidden; // clearing
   }
   #video {float:none; margin-right: 200px;}
   #chat { width: 200px; float: right; }
}
</code>```

Thanks for any help on this.

答:
Change Code Like This :

.wrapper {
 border : 2px dotted #ccc; padding: 2px;
 width: 100%;
 overflow: auto;
}

.wrapper div {
   width: 100%;
    min-height: 200px;
   padding: 10px;
   -webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
   box-sizing: border-box;
}

#chat {
 background-color: gray;
  width: 20%;
        float: right;
}

#video {
 background-color: red;
 width: 80%;
 float: left;
}

@media screen and (max-width: 600px) {
   #chat,#video {
    float: none;
    width: 100%;

   }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrapper">
    <div id="video">video</div>
    <div id="chat">chat</div>
</div></code>```

Body:
I am almost there, but looks like one property is missing or wrong.

I want to embed two iFrames:
- left side: a youtube video (witdh flexible)
- right side: a youtube live chat (fixed width 200px)

The @media rule already works. However for the desktop view the second div (chat) stays below the first div (video), whereas it should be on the same line. This is the problem I can't solve. Can somebody be as kind and tell me the trick to bring the chat next to the video?

http://jsbin.com/waxaxa/1/edit?html,css,output

.wrapper {
 border : 2px dotted #ccc; padding: 2px;
}

.wrapper div {
width: 100%;
 min-height: 200px;
 padding: 10px;
 -webkit-box-sizing: border-box;
 -moz-box-sizing: border-box;
 box-sizing: border-box;
 float: left;
 overflow: hidden;
}

#video { background-color: red; float:none; width:auto;}
#chat { background-color: gray;position: }

@media screen and (min-width: 600px) {
   .wrapper {
    height: auto;width: auto; overflow: hidden; // clearing
   }
   #video {float:none; margin-right: 200px;}
   #chat { width: 200px; float: right; }
}

Thanks for any help on this.

Body:
Change Code Like This :

.wrapper {
 border : 2px dotted #ccc; padding: 2px;
 width: 100%;
 overflow: auto;
}

.wrapper div {
   width: 100%;
    min-height: 200px;
   padding: 10px;
   -webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
   box-sizing: border-box;
}

#chat {
 background-color: gray;
  width: 20%;
        float: right;
}

#video {
 background-color: red;
 width: 80%;
 float: left;
}

@media screen and (max-width: 600px) {
   #chat,#video {
    float: none;
    width: 100%;

   }
}

<div class="wrapper">
    <div id="video">video</div>
    <div id="chat">chat</div>
</div>


问:
How do you find a particular piece of functionality in a large codebase?
I was fascinated by the "press Tab to search site" feature in chromium, so naturally I wanted to see how exactly it was implemented in code.

A little background for anybody who aren't familiar with this. After navigating to some site, say wikipedia, and doing a search, chromium remembers the name of the query variable and will let you press tab and search the site directly from the address bar. Neat!

Problem is the codebase for chromium is huge and I've had no luck in finding the method/function that handles this.

How do you approach a large codebase when you are looking for the implementation of a particular piece of functionality? Any tricks for narrowing it down? Preferably it should not require building the software with debug symbols and following the flow through the program.

答:
A test coverage tool is a good way to do this.  They tell you what part of an application
is exercised by a test.

Instrument the application to collect test coverage.  Execute the functionality you care about.  Record what is executed.  Execute something similar, but not the same as the functionality you want.   Record this.  Take the set difference over the coverage.  The diff selects code involved in the functionality of interest, excluding code which is common to similar functionality.


问:
How to select a Top 1 from another Top-selection?
In my database I'm filtering my records using a Top 101. My goal is to get the last Id which is being returned in my filtered list.

Is there a way to get this in a single statement for use in my SQL Command?

```<code>SELECT TOP 101 Id FROM Messages WHERE Validation = 2 AND Shown > 0 ORDER BY Id DESC
</code>```

And from this list I need the last entry.

How can I get this in a single query?

Thank you.

答:
```<code>SELECT TOP 1 temp.Id
from (SELECT TOP 101 Messages.Id FROM Messages WHERE Validation = 2 AND Shown > 0 ORDER BY Messages.Id ASC) as temp
</code>```

Body:
In my database I'm filtering my records using a Top 101. My goal is to get the last Id which is being returned in my filtered list.

Is there a way to get this in a single statement for use in my SQL Command?

SELECT TOP 101 Id FROM Messages WHERE Validation = 2 AND Shown > 0 ORDER BY Id DESC

And from this list I need the last entry.

How can I get this in a single query?

Thank you.


问:
Why color in button not same as example from website
I am building a web site with Bootstrap. I've noticed that the color of the various buttons on my website are paler than those on bootstrap's website.

An example from website.

On my website.

What is different?

答:
OK. I got an answer.

in resources\assets\sass\_variables.scss. They have

Just change

```<code>// Brands
$brand-primary: #3097D1;
$brand-info: #8eb4cb;
$brand-success: #2ab27b;
$brand-warning: #cbb956;
$brand-danger: #bf5329;
</code>```

To this.

```<code>// Brands
$brand-primary: #337ab7;
$brand-info: #5bc0de;
$brand-success: #5cb85c;
$brand-warning: #ec971f;
$brand-danger: #d9534f;
</code>```

Body:
OK. I got an answer.

in resources\assets\sass\_variables.scss. They have

Just change

// Brands
$brand-primary: #3097D1;
$brand-info: #8eb4cb;
$brand-success: #2ab27b;
$brand-warning: #cbb956;
$brand-danger: #bf5329;

To this.

// Brands
$brand-primary: #337ab7;
$brand-info: #5bc0de;
$brand-success: #5cb85c;
$brand-warning: #ec971f;
$brand-danger: #d9534f;


问:
Instant Payment Notification (IPN)
I have more than one website that I want to use IPN with. However, there is only one notification URL to edit in this feature? So how it is possible to support mult-website? </p>

答:
You can pass in the notification url on the initial post to PayPal (assuming the NVP integration) using the parameter: notify_url
You many have the ability to pass in the notification url in other implementations.

The setting in PayPal, is the default one I think.

Title: Instant Payment Notification (IPN)


问:
Podcast search API
Is there any podcast directory search API out there apart from the iTunes search API? I have looked around but could not find anything useful. Can I use feedburner for this? Is there a search API for feedburner too? </p>

答: I was just looking for the same thing, and found Digital Podcast Search Service. I haven't tried using it yet.</p>

Title: Podcast search API


问:
libserial undefined reference to symbol
I compiled libserial-0.6.0rc2 from source in Ubuntu 16.04 and am now trying to compile a simple test program:

```<code>#include <SerialStream.h>
#include <iostream>
using namespace LibSerial;
int main(int argc, char** argv)
{
    SerialStream serial_port;
    serial_port.Open("/dev/ttyS0");
    serial_port.SetBaudRate( SerialStreamBuf::BAUD_9600 );
    serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 );
    serial_port.SetParity( SerialStreamBuf::PARITY_EVEN );
    serial_port.SetNumOfStopBits(1);

    serial_port.write( "s", 1 ) ;
}
</code>```

I'm getting the following error:

```<code>karl@karl-T430u:~/scan/arduino$ gcc *.cpp -Wl,-
rpath -Wl,/usr/local/lib -L/usr/local/lib -lserial
/usr/bin/ld: /tmp/ccT3ucCm.o: undefined reference to symbol
'_ZNSaIcED1Ev@@GLIBCXX_3.4'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO
missing from command line
collect2: error: ld returned 1 exit status
</code>```

It took me a while to compile libserial as there was apparently a required dependency on SIP which I didn't know about. I can build the examples using the provided makefile but I am not able to build my own examples with the installed libraries. Does anyone have any ideas?

答:
You are attempting to compile and link a C++ program with the C compiler driver
gcc. C and C++ are different languages. gcc does not by default link the Standard C++ library, libstdc++,
so you have an undefined reference error to a symbol _ZNSaIcED1Ev (demangled
= std::allocator<char>::~allocator()) that is defined in that library.

To compile and link C++ programs use the C++ compiler driver, g++.

Title: libserial undefined reference to symbol

Body:
I compiled libserial-0.6.0rc2 from source in Ubuntu 16.04 and am now trying to compile a simple test program:

#include <SerialStream.h>
#include <iostream>
using namespace LibSerial;
int main(int argc, char** argv)
{
    SerialStream serial_port;
    serial_port.Open("/dev/ttyS0");
    serial_port.SetBaudRate( SerialStreamBuf::BAUD_9600 );
    serial_port.SetCharSize( SerialStreamBuf::CHAR_SIZE_8 );
    serial_port.SetParity( SerialStreamBuf::PARITY_EVEN );
    serial_port.SetNumOfStopBits(1);

    serial_port.write( "s", 1 ) ;
}

I'm getting the following error:

karl@karl-T430u:~/scan/arduino$ gcc *.cpp -Wl,-
rpath -Wl,/usr/local/lib -L/usr/local/lib -lserial
/usr/bin/ld: /tmp/ccT3ucCm.o: undefined reference to symbol
'_ZNSaIcED1Ev@@GLIBCXX_3.4'
//usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO
missing from command line
collect2: error: ld returned 1 exit status

It took me a while to compile libserial as there was apparently a required dependency on SIP which I didn't know about. I can build the examples using the provided makefile but I am not able to build my own examples with the installed libraries. Does anyone have any ideas?


问:
"This database file is not compatible with the current instance of SQL Server"
I am currently reading through a book about MVVM and I need to use the Northwind database for the next section. Unfortunately, when I try to add Northwind to my project, I get the following error:

"An error occurred while connecting to the database. The database might be unavailable. An exception of type 'Microsoft.Data.ConnectionUI.SqlDatabaseFileUpgradeRequiredException' occurred. The error message is: 'This database file is not compatible with the current instance of SQL Server.'"

I haven't installed an SQL Server, just Visual Studio 2012. The book instructs me to add the .MDF file to the project, set it as an Entity Data Model, and then to generate from database. It's on the next screen where I get the error. I use NORTHWND.MDF as the data connection and the entity connection string is as follows:

metadata=res:///Model1.csdl|res:///Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\NORTHWND.MDF;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"

In the book, this reads:

metadata=res:///Model1.csdl|res:///Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;UserInstance=True"

I have tried using both data sources and neither work.

Also of note, the sample code that goes along with the book doesn't work either. It compiles and launches, but in the server explorer, NORTHWND.MDF has an 'x' in the icon and upon launch none of the data is there.

When I attempt to upgrade the database, I get an error saying:

"Database '...\NORTHWND.MDF' cannot be upgraded because its non-release version (539) is not supported by this version of SQL Server. You cannot open a database that is incompatible with this version of sqlservr.exe. You must re-create the database..."

If anybody could give me any tips on how to get this working, I would certainly appreciate it.

答:
If we are trying to attach .mdf file in SQL Express mode in our development project and while adding .mdf file in App_Data folder we are getting exception like below :

```<code>"The database file is not compatible with the current instance of sql server...."
</code>```

Then we can go to Server explorer window → go to Data connections → go to "your database" → right click on Modify connection → check the Data sources and Database file name, then use windows Authentication and press OK.

It works for me.

Body:
If we are trying to attach .mdf file in SQL Express mode in our development project and while adding .mdf file in App_Data folder we are getting exception like below :

"The database file is not compatible with the current instance of sql server...."

Then we can go to Server explorer window → go to Data connections → go to "your database" → right click on Modify connection → check the Data sources and Database file name, then use windows Authentication and press OK.

It works for me.


问:
how redirect back after login and logout - laravel 5
Now after login or logout I am forwarded to the homepage.

in this article  have read that
I can define redirection path in Auth Controller

```<code>protected $redirectPath = '/';
</code>```

I can also change this line in Middleware RedirectIfAuthenticated.php:

```<code>return new RedirectResponse(url('/'));
</code>```

But my goal is to

either login by AJAX

or, after login or logout, redirect back to the page where I have pressed the button.

Both answers highly appreciated.

Thx.

答:
For anyone who have to redirect user back to the page where they clicked the  button for a protected page that redirected back to login. Here is my simple approach to it.

First on your nav, menu or whatever, your href value would be something like this:

```<code><a href="{{auth::check() ? url('protected-page') : url('signin').'?redirect_to=post-request'}}"> Some Page </a>
</code>```

What this simply do is, if your user is not logged in, its uses the lgin page as url, which simply cut off the need to redirect and adds the current page they are in which would be the page they would redirected back after login as a get param to the login url. Unlike using sessions to retrieve http_referer which would be wrong if user were redirected back to login due to validation error, this would stick around on your url.

Example of login url may be  http://localhost:2008/signin?redirect_to=protected-page

Then simply after login you would just check if get param redirected_to is available then redirect user back to that page or a default page if its not available as a get a param, probably your home or dashboard maybe, an example below might help.

```<code>$data = $request->all();
$referer =  $data['redirect_to'] ? url($data['redirect_to']) : url('/');
if($allowAccess) return redirect($referer);
</code>```

I hope this helps someone!

Body:
Now after login or logout I am forwarded to the homepage.

in this article  have read that
I can define redirection path in Auth Controller

protected $redirectPath = '/';

I can also change this line in Middleware RedirectIfAuthenticated.php:

return new RedirectResponse(url('/'));

But my goal is to

either login by AJAX

or, after login or logout, redirect back to the page where I have pressed the button.

Both answers highly appreciated.

Thx.

Body:
For anyone who have to redirect user back to the page where they clicked the  button for a protected page that redirected back to login. Here is my simple approach to it.

First on your nav, menu or whatever, your href value would be something like this:

<a href="{{auth::check() ? url('protected-page') : url('signin').'?redirect_to=post-request'}}"> Some Page </a>

What this simply do is, if your user is not logged in, its uses the lgin page as url, which simply cut off the need to redirect and adds the current page they are in which would be the page they would redirected back after login as a get param to the login url. Unlike using sessions to retrieve http_referer which would be wrong if user were redirected back to login due to validation error, this would stick around on your url.

Example of login url may be  http://localhost:2008/signin?redirect_to=protected-page

Then simply after login you would just check if get param redirected_to is available then redirect user back to that page or a default page if its not available as a get a param, probably your home or dashboard maybe, an example below might help.

$data = $request->all();
$referer =  $data['redirect_to'] ? url($data['redirect_to']) : url('/');
if($allowAccess) return redirect($referer);

I hope this helps someone!


问:
How does dplyr's select helper function everything() differ from copying?
What is the use case for

```<code>select(iris, everything())
</code>```

as opposed to e.g. just copying the data.frame?

答:
Another example use case:

```<code># Moves the variable Petal.Length to the end
select(iris, -Petal.Length, everything())
</code>```

(I saw it here: https://stackoverflow.com/a/30472217/4663008)

Either way, both Gregor's answer and mine are confusing to me - I would have expected Species to be duplicated in Gregor's example or removed in my example. e.g. if you try something more complicated based on the previous two examples, it doesn't work:

```<code>> dplyr::select(iris, Petal.Width, -Petal.Length, everything())
    Petal.Width Sepal.Length Sepal.Width Petal.Length    Species
1           0.2          5.1         3.5          1.4     setosa
2           0.2          4.9         3.0          1.4     setosa
3           0.2          4.7         3.2          1.3     setosa
</code>```

Update:
After a quick response from hadley on github, I found out that there is a special behaviour using everything() combined with a negative in the first position in select() that will start select() off with all the variables and then everything() draws them back out again. A negative variable in non-first positions do not work as one might expect.

I agree that the negative variable in first position and the everything() select_helper function needs to be better explained in the documentation

Update 2: the documentation for ?select has now been updated to state "Positive values select variables; negative values to drop variables. If the first expression is negative, select() will automatically start with all variables."

Body:
What is the use case for

select(iris, everything())

as opposed to e.g. just copying the data.frame?

Body:
Another example use case:

# Moves the variable Petal.Length to the end
select(iris, -Petal.Length, everything())

(I saw it here: https://stackoverflow.com/a/30472217/4663008)

Either way, both Gregor's answer and mine are confusing to me - I would have expected Species to be duplicated in Gregor's example or removed in my example. e.g. if you try something more complicated based on the previous two examples, it doesn't work:

> dplyr::select(iris, Petal.Width, -Petal.Length, everything())
    Petal.Width Sepal.Length Sepal.Width Petal.Length    Species
1           0.2          5.1         3.5          1.4     setosa
2           0.2          4.9         3.0          1.4     setosa
3           0.2          4.7         3.2          1.3     setosa

Update:
After a quick response from hadley on github, I found out that there is a special behaviour using everything() combined with a negative in the first position in select() that will start select() off with all the variables and then everything() draws them back out again. A negative variable in non-first positions do not work as one might expect.

I agree that the negative variable in first position and the everything() select_helper function needs to be better explained in the documentation

Update 2: the documentation for ?select has now been updated to state "Positive values select variables; negative values to drop variables. If the first expression is negative, select() will automatically start with all variables."

ContentLicense: CC BY-SA 4.0


问:
Xcode 6 Interface Builder - color picker oddity/bug?
I've recently been tearing my hair out over trying to set the same background color for views styled using Interface Builder, and views styled programatically using [UIColor colorWithRed: green: blue: alpha:].  Despite setting the same RGB values, the views styled in IB were a slightly different color shade to those styled in code.

I finally realised it was to do with color spaces - when I examined the views in IB using the color picker, it showed the color space was set to 'sRGB' rather than the default of 'Generic RGB' which UIColor uses.  I never changed the color space setting myself.  I then realised what is happening is that when you manually type in the RGB values in the color picker, it changes the color space to 'sRGB' without you knowing therefore giving a different color.  However if you use the mouse to drag the slider bars to change the values then the color space remains at 'Generic RGB' and all is well.

Is this a bug, or am I misunderstanding the color picker?  I'm using Xcode 6.1.

答:
A solution is to use "Device RGB" and not "Generic RGB".
<img src="https://i.stack.imgur.com/Fr1OQ.png" alt="enter image description here"> </p>


问:
How to navigate the JSON hierarchy with PHP?
I am building a weather application that decodes a JSON file (found here: http://api.openweathermap.org/data/2.5/forecast?q=Helsinki&appid=77f5e3fbc99649054660f82f871220f4&units=metric)

The problem I am running into is navigating the JSON file in my PHP code to correctly select the tempature.

I need to do list->1->main->temp but this pulls up a number error in PHP. How do I correctly set the navigation?

```<code>echo "<form id='searchform' method='POST' action='https://projekt2-sofiamusick.c9users.io/wordpress/prognos/'>
Search: <input type='text' name='searchquery' placeholder='Search the forum' />
<input class='sendbutton_search' type='submit' name='search' value='>>' />
</form>";

if (isset($_POST['search'])){

$cityz = $_POST['searchquery'];
echo "<br>";
echo "<div id=apithing>";
$data = file_get_contents("http://api.openweathermap.org/data/2.5/forecast?q=$cityz&appid=77f5e3fbc99649054660f82f871220f4&units=metric");
$jsonObject = json_decode($data, JSON_NUMERIC_CHECK);
json_encode( array( 'list' => (int)$jsonObject ) );
$list = $jsonObject->list;
$number = $jsonObject->'1';
$mains = $jsonObject->main;
echo $mains;
</code>```

答:
You can achieve it like this

```<code>$data = file_get_contents("http://api.openweathermap.org/data/2.5/forecast?q=Helsinki&appid=77f5e3fbc99649054660f82f871220f4&units=metric");
$jsonObject = json_decode($data);
if($jsonObject->cod == '200' && count($jsonObject->list) > 0){
  foreach ($jsonObject->list as $jlk => $jlv) {
    $dt = $jlv->dt;
    $main = $jlv->main;
    // your rest of logic
  }
}
</code>```

If you want you can see your data like this:

```<code>  echo '```';
  var_dump($jsonObject);
  echo '```';
  die;
</code>```

Where you will see object, means you have to use "->" to access, and where you see array there use key of array to fetch that value.

Please feel free to ask, if any other doubt.

Body:
I am building a weather application that decodes a JSON file (found here: http://api.openweathermap.org/data/2.5/forecast?q=Helsinki&appid=77f5e3fbc99649054660f82f871220f4&units=metric)

The problem I am running into is navigating the JSON file in my PHP code to correctly select the tempature.

I need to do list->1->main->temp but this pulls up a number error in PHP. How do I correctly set the navigation?

echo "<form id='searchform' method='POST' action='https://projekt2-sofiamusick.c9users.io/wordpress/prognos/'>
Search: <input type='text' name='searchquery' placeholder='Search the forum' />
<input class='sendbutton_search' type='submit' name='search' value='>>' />
</form>";

if (isset($_POST['search'])){

$cityz = $_POST['searchquery'];
echo "
";
echo "
";
$data = file_get_contents("http://api.openweathermap.org/data/2.5/forecast?q=$cityz&appid=77f5e3fbc99649054660f82f871220f4&units=metric");
$jsonObject = json_decode($data, JSON_NUMERIC_CHECK);
json_encode( array( 'list' => (int)$jsonObject ) );
$list = $jsonObject->list;
$number = $jsonObject->'1';
$mains = $jsonObject->main;
echo $mains;

Body:
You can achieve it like this

$data = file_get_contents("http://api.openweathermap.org/data/2.5/forecast?q=Helsinki&appid=77f5e3fbc99649054660f82f871220f4&units=metric");
$jsonObject = json_decode($data);
if($jsonObject->cod == '200' && count($jsonObject->list) > 0){
  foreach ($jsonObject->list as $jlk => $jlv) {
    $dt = $jlv->dt;
    $main = $jlv->main;
    // your rest of logic
  }
}

If you want you can see your data like this:

  echo '<pre>';
  var_dump($jsonObject);
  echo '</pre>';
  die;

Where you will see object, means you have to use "->" to access, and where you see array there use key of array to fetch that value.

Please feel free to ask, if any other doubt.


问:
Sending instructions to a thread which is waiting for TCP?
I'm trying to understand multi-threading in TCP so I'm coding a basic telnet text "router".

using ReadLine() each thread using a TCP listener will wait for input from the telnet client and then respond based on the text which is sent. I have this working with multiple threads and multiple telnet clients.

I want to conditionally send messages to all threads.
For example, if the text sent from any one thread is "Alert!" then I want every thread for connected clients to execute WriteLine("Alert!")

Does this make sense?
My problem is that I don't know how to make one thread raise an event in another thread.

答:
You need to look at a Event Broker pattern. Basically you would have one object with an event that all your threads subscribe to. It will also have a method that can be called which will invoke the event. It maybe sounds complicated, but its fairly simple.

Example code is here http://msforge.net/blogs/paki/archive/2007/11/20/EventBroker-implementation-in-C_2300_-full-source-code.aspx.


问:
Angular 2 dependency injection - A service is injected in some components but not in all
I am working to an Angular 2 application which has only one module with several services registered as providers at bootstrap. The application has also several components in the same module which are using these services.

All components are receiving the services using DI (services are declared as parameters in construtor).

The problem that I am facing is: the same service is correctly injected in some components but in other no.

I checked the Injector object for the components where the injection fails and the services instances are within the Injector object. What it fails is the searching with the Injector.get() method. The token provided as parameter is different from the token stored in the Injector dictionary. I am not able to find out why because I am using the class name of the service and the token is automatically generated by the Javascript engine from this class name.

I tried to use OpaqueTokens to control the injection and, again, even if I am using the same opaque token, when Injector.get() method is called, the token provided by argument is considered different from the token stored by injector.

A short fragment from the code looks like

myservice.service.ts

```<code>import { OpaqueToken } from '@angular/core'

export const BACKEND = new OpaqueToken('backend');
</code>```

app.module.ts

```<code>import { BACKEND } from 'myservice.service'
...
providers: [{ provide: BACKEND, useValue: "TestValue" }]
</code>```

mycomponent.component.ts

```<code>import { Component, Inject } from '@angular/core'
import { BACKEND } from 'myservice.service'

@Component(
{
selector:'mycomponent'
templateUrl: ...
})
export class MyComponent
{
  constructor(@Inject(BACKEND) config: string) {
    console.info(JSON.stringify(config));
  }
}
</code>```

This injection with BACKEND token works for some components but for other not (the empty {} object is injected). I tried to debug the Javascript code in browser and it looks like the Injector is called with a different token than the token from dictionary (they are looking the same, with the same name 'backend' but still different and === returns false).

Note: I am using Angular 2.4.2, Typescript 2.1 with 'commonjs' modules and 'node' module resolution. systemjs is used as module loader.

Please, can you provide some ideeas about how to fix this?

Thanks,

答:
Do you have various declarations of providers from different modules/components? For every declaration inside the providers array, angular will create a new instance of these services.

Do you have included the parentheses in the @Injectable decorator? https://angular.io/docs/ts/latest/guide/dependency-injection.html#!#injectable

Body:
I am working to an Angular 2 application which has only one module with several services registered as providers at bootstrap. The application has also several components in the same module which are using these services.

All components are receiving the services using DI (services are declared as parameters in construtor).

The problem that I am facing is: the same service is correctly injected in some components but in other no.

I checked the Injector object for the components where the injection fails and the services instances are within the Injector object. What it fails is the searching with the Injector.get() method. The token provided as parameter is different from the token stored in the Injector dictionary. I am not able to find out why because I am using the class name of the service and the token is automatically generated by the Javascript engine from this class name.

I tried to use OpaqueTokens to control the injection and, again, even if I am using the same opaque token, when Injector.get() method is called, the token provided by argument is considered different from the token stored by injector.

A short fragment from the code looks like

myservice.service.ts

import { OpaqueToken } from '@angular/core'

export const BACKEND = new OpaqueToken('backend');

app.module.ts

import { BACKEND } from 'myservice.service'
...
providers: [{ provide: BACKEND, useValue: "TestValue" }]

mycomponent.component.ts

import { Component, Inject } from '@angular/core'
import { BACKEND } from 'myservice.service'

@Component(
{
selector:'mycomponent'
templateUrl: ...
})
export class MyComponent
{
  constructor(@Inject(BACKEND) config: string) {
    console.info(JSON.stringify(config));
  }
}

This injection with BACKEND token works for some components but for other not (the empty {} object is injected). I tried to debug the Javascript code in browser and it looks like the Injector is called with a different token than the token from dictionary (they are looking the same, with the same name 'backend' but still different and === returns false).

Note: I am using Angular 2.4.2, Typescript 2.1 with 'commonjs' modules and 'node' module resolution. systemjs is used as module loader.

Please, can you provide some ideeas about how to fix this?

Thanks,


问:
Unresolved import Template when building Rocket handlebars example
I am unable to get the Rocket handlebars example
to work. These are my Cargo.toml dependencies:

```<code>[dependencies]
rocket = "*"
rocket_codegen = "*"
rocket_contrib = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"
</code>```

The errors:

error[E0432]: unresolved import `rocket_contrib::Template`
  --> src\main.rs:29:5
   |
29 | use rocket_contrib::Template;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no `Template` in the root

error[E0599]: no method named `attach` found for type `rocket::Rocket` in the current scope
  --> src\main.rs:62:10
   |
62 |         .attach(Template::fairing())
   |          ^^^^^^
```

<p>The first error looks for <code>Template</code> and can't find it. In the git repo of the example, it doesn't exist. How is it possible that the example works? I am sure that the Rust code in my main.rs is ok, it's the same as in the example. I think it's only a dependency problem.</p>

<p>I changed my Cargo.toml to:</p>

```[dependencies]
rocket = "*"
rocket_codegen = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"

[dependencies.rocket_contrib]
version = "*"
features = ["handlebars_templates"]
```

<p>Now I get these errors:</p>

<pre class="lang-none prettyprint-override"><code>error[E0599]: no method named `attach` found for type `rocket::Rocket` in the current scope
  --> src\main.rs:62:10
   |
62 |         .attach(Template::fairing())
   |          ^^^^^^

error[E0599]: no associated item named `fairing` found for type `rocket_contrib::Template` in the current scope
  --> src\main.rs:62:17
   |
62 |         .attach(Template::fairing())
   |                 ^^^^^^^^^^^^^^^^^
</code>```

答:
You are missing the handlebars_templates feature. You can see this in the example's Cargo.toml:

[dependencies.rocket_contrib]
version = "*" # Not a good idea to use * as version
features = ["handlebars_templates"]
```

Body:
I am unable to get the Rocket handlebars example
to work. These are my Cargo.toml dependencies:

[dependencies]
rocket = "*"
rocket_codegen = "*"
rocket_contrib = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"

The errors:

error[E0432]: unresolved import `rocket_contrib::Template`
  --> src\main.rs:29:5
   |
29 | use rocket_contrib::Template;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no `Template` in the root

error[E0599]: no method named `attach` found for type `rocket::Rocket` in the current scope
  --> src\main.rs:62:10
   |
62 |         .attach(Template::fairing())
   |          ^^^^^^

The first error looks for Template and can't find it. In the git repo of the example, it doesn't exist. How is it possible that the example works? I am sure that the Rust code in my main.rs is ok, it's the same as in the example. I think it's only a dependency problem.

I changed my Cargo.toml to:

[dependencies]
rocket = "*"
rocket_codegen = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"

[dependencies.rocket_contrib]
version = "*"
features = ["handlebars_templates"]

Now I get these errors:

error[E0599]: no method named `attach` found for type `rocket::Rocket` in the current scope
  --> src\main.rs:62:10
   |
62 |         .attach(Template::fairing())
   |          ^^^^^^

error[E0599]: no associated item named `fairing` found for type `rocket_contrib::Template` in the current scope
  --> src\main.rs:62:17
   |
62 |         .attach(Template::fairing())
   |                 ^^^^^^^^^^^^^^^^^


问:
Objective-c - get count elements of an array
I'm an Objective-C rookie, and I want to get the elements count of an array of chars. I managed to find only this way:

```<code>@autoreleasepool {

    char parola[30];
    int c;

    NSLog(@"Write word:");
    scanf("%c",&parola[30]);

    c = sizeof(parola)/sizeof(parola[0]);
    NSLog(@"The word has %i letters",c);

}
return 0;
</code>```

The problem is that it gives me the length I specified in the array declaration, not the elements count.
Any idea?

答:
You have a few errors there.

You want the user to input a "word", i.e. a string. Then don't use %c, which only scans one character, but %s instead, which scans one string (note that that can mean that the user also enters spaces, or more than 29 characters).

You store beyond the array. The array is declared as

```<code>char parola[30];
</code>```

That means it can be indexed with values 0 .. 29. But your &parola[30] points beyond the array (at index 30, which does not "exist"). That is not what you want. Do this:

```<code>scanf("%s", parola);
</code>```

And hope that the user doesn't enter more than 29 characters.

The length of the string can then be found using

```<code>c = strlen(parola);
</code>```

So this becomes:

```<code>@autoreleasepool {
    char parola[30];
    unsigned long c;

    NSLog(@"Write word:");
    scanf("%s", parola);

    c = strlen(parola);
    NSLog(@"The word has %ld letters", c);

}
return 0;
</code>```

Instead of NSLog, you can also use printf:

```<code>    printf("Write word: ");
</code>```

and

```<code>    printf("The word has %ld letters\n", c);
</code>```

That will look cleaner, as NSLog() always shows these extra infos, like

```<code>2017-06-04 12:37:25.758802+0200 SOTest[4718:2690388]
</code>```

And that is, IMO, plain ugly. Good for a log, but not good for clean screen output. The output now becomes:

```<code>Write word: Tesla
The word has 5 letters
Program ended with exit code: 0
</code>```

Body:
I'm an Objective-C rookie, and I want to get the elements count of an array of chars. I managed to find only this way:

@autoreleasepool {

    char parola[30];
    int c;

    NSLog(@"Write word:");
    scanf("%c",&parola[30]);

    c = sizeof(parola)/sizeof(parola[0]);
    NSLog(@"The word has %i letters",c);

}
return 0;

The problem is that it gives me the length I specified in the array declaration, not the elements count.
Any idea?

Body:
You have a few errors there.

You want the user to input a "word", i.e. a string. Then don't use %c, which only scans one character, but %s instead, which scans one string (note that that can mean that the user also enters spaces, or more than 29 characters).

You store beyond the array. The array is declared as

char parola[30];

That means it can be indexed with values 0 .. 29. But your &parola[30] points beyond the array (at index 30, which does not "exist"). That is not what you want. Do this:

scanf("%s", parola);

And hope that the user doesn't enter more than 29 characters.

The length of the string can then be found using

c = strlen(parola);

So this becomes:

@autoreleasepool {
    char parola[30];
    unsigned long c;

    NSLog(@"Write word:");
    scanf("%s", parola);

    c = strlen(parola);
    NSLog(@"The word has %ld letters", c);

}
return 0;

Instead of NSLog, you can also use printf:

    printf("Write word: ");

and

    printf("The word has %ld letters\n", c);

That will look cleaner, as NSLog() always shows these extra infos, like

2017-06-04 12:37:25.758802+0200 SOTest[4718:2690388]

And that is, IMO, plain ugly. Good for a log, but not good for clean screen output. The output now becomes:

Write word: Tesla
The word has 5 letters
Program ended with exit code: 0


问:
Can't get Svg to show up in react-native with react-native-svg or Svg/expo
I am not sure exactly why this is not showing up. I suspect maybe it has to do with the transform?

```<code><Svg.G id="startup" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd" transform="translate(135.000000, 76.000000)">
</code>```

But I really don't know... I'm seeing "invalid prop transform"

As I copied SVG code form sketch, suspect I'm having similar trouble to this issue:

https://github.com/react-native-community/react-native-svg/issues/205

Code is below. Any ideas?

```<code>import React from 'react';
import { Svg } from 'expo';

const RocketSvg = () => {
    return (
        <Svg width="108px" height="128px" viewBox="135 76 108 128" version="1.1">
            <Svg.G id="startup" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd" transform="translate(135.000000, 76.000000)">
                <Svg.Ellipse id="Oval" fill="#DCDDDE" cx="54" cy="75" rx="52" ry="51"></Svg.Ellipse>
                <Svg.Path d="M81.764,76.608 C79.316,75.5 75.758,74.198 72,73.81 L72,61.414 C77.408,64.05 80.866,70.118 81.764,76.608 Z" id="Shape" fill="#FFFFFF"></Svg.Path>
                <Svg.Path d="M26.236,76.608 C27.134,70.118 30.592,64.052 36,61.412 L36,73.804 C32.242,74.194 28.682,75.498 26.236,76.608 Z" id="Shape" fill="#FFFFFF"></Svg.Path>
                <Svg.Path d="M40,76 L40,42 C40,37.68 40.562,33.678 41.448,30 L66.556,30 C67.44,33.676 68,37.676 68,42 L68,76 L66,76 L42,76 L40,76 Z" id="Shape" fill="#FFFFFF"></Svg.Path>
                <Svg.Polygon id="Shape" fill="#FFFFFF" points="46 84 46 80 62 80 62 84 60 84 48 84"></Svg.Polygon>
                <Svg.Path d="M70,78 L70,42 C70,18 54,2 54,2 L54,78 L70,78 Z" id="Shape" fill="#DCDDDE"></Svg.Path>
                <Svg.Circle id="Oval" fill="#53B7E8" cx="54" cy="42" r="6"></Svg.Circle>
                <Svg.Path d="M98.8,100.76 C96.66,104.34 94.04,107.7 90.96,110.78 C88.58,113.16 86.02,115.26 83.32,117.08 C65.74,129.02 42.46,128.98 24.92,116.96 C22.28,115.18 19.78,113.12 17.44,110.78 C14.26,107.6 11.56,104.1 9.38,100.4 C11.4,96.6 15.4,94 20,94 C25.48,94 30.1,97.7 31.54,102.74 C33.3,99.9 36.42,98 40,98 C44.84,98 48.88,101.44 49.8,106 L50,106 L50,86 L58,86 L58,106 L58.2,106 C59.12,101.44 63.16,98 68,98 C71.58,98 74.7,99.9 76.46,102.74 C77.88,97.7 82.5,94 88,94 C92.74,94 96.84,96.76 98.8,100.76 Z" id="Shape" fill="#FFD768"></Svg.Path>
                <Svg.Rect id="Rectangle-path" fill="#DCDDDE" x="54" y="80" width="8" height="4"></Svg.Rect>
                <Svg.Path d="M91.414,36.586 L90,35.172 L87.172,38 L88.586,39.414 C98.67,49.5 104,61.458 104,74 C104,82.056 102.096,89.812 98.522,96.778 C95.9,93.776 92.12,92 88,92 C82.948,92 78.354,94.752 75.894,98.988 C73.742,97.08 70.96,96 68,96 C64.966,96 62.144,97.148 60,99.062 L60,88 L66,88 L66,80 L72,80 L72,77.844 C77.584,78.546 82.886,81.664 82.966,81.714 L86,83.538 L86,80 C86,70.238 80.864,60.222 72,57.052 L72,42 C72,17.454 56.092,2.09 55.414,1.414 L54,0 L52.586,1.414 C51.908,2.09 36,17.454 36,42 L36,57.052 C27.136,60.222 22,70.238 22,80 L22.002,83.538 L25.034,81.714 C25.116,81.664 30.418,78.542 36,77.842 L36,80 L42,80 L42,88 L48,88 L48,99.062 C45.856,97.148 43.034,96 40,96 C37.036,96 34.252,97.082 32.1,98.994 C29.628,94.754 25.036,92 20,92 C15.91,92 12.116,93.794 9.486,96.794 C5.906,89.824 4,82.06 4,73.998 C4,61.458 9.33,49.5 19.414,39.414 L20.828,38 L18,35.172 L16.586,36.586 C5.736,47.438 0,60.376 0,73.998 C0,88.424 5.618,101.984 15.816,112.184 C26.344,122.71 40.172,128 54,128 C67.828,128 81.656,122.71 92.184,112.184 C102.382,101.984 108,88.424 108,74 C108,60.376 102.264,47.438 91.414,36.586 Z M81.764,76.608 C79.316,75.5 75.758,74.198 72,73.81 L72,61.414 C77.408,64.05 80.866,70.118 81.764,76.608 Z M54.002,5.824 C56.604,8.896 62.168,15.912 65.444,26 L42.566,26 C45.844,15.928 51.404,8.902 54.002,5.824 Z M26.236,76.608 C27.134,70.118 30.592,64.052 36,61.412 L36,73.804 C32.242,74.194 28.682,75.498 26.236,76.608 Z M40,76 L40,42 C40,37.68 40.562,33.678 41.448,30 L66.556,30 C67.44,33.676 68,37.676 68,42 L68,76 L66,76 L42,76 L40,76 Z M46,84 L46,80 L62,80 L62,84 L60,84 L48,84 L46,84 Z M89.356,109.356 C69.86,128.85 38.14,128.85 18.646,109.356 C15.952,106.662 13.616,103.706 11.634,100.558 C13.48,97.732 16.598,96 20,96 C24.436,96 28.39,98.998 29.618,103.29 L30.86,107.638 L33.24,103.794 C34.712,101.418 37.24,100 40,100 C43.794,100 47.092,102.69 47.838,106.394 L48.164,108 L52,108 L52,88 L56,88 L56,108 L59.836,108 L60.16,106.394 C60.908,102.69 64.206,100 68,100 C70.76,100 73.288,101.418 74.76,103.792 L77.154,107.656 L78.386,103.282 C79.592,98.994 83.546,96 88,96 C91.426,96 94.528,97.718 96.372,100.55 C94.39,103.7 92.052,106.658 89.356,109.356 Z" id="Shape" fill="#0C3847"></Svg.Path>
                <Svg.Path d="M54,34 C49.588,34 46,37.588 46,42 C46,46.412 49.588,50 54,50 C58.412,50 62,46.412 62,42 C62,37.588 58.412,34 54,34 Z M54,46 C51.794,46 50,44.206 50,42 C50,39.794 51.794,38 54,38 C56.206,38 58,39.794 58,42 C58,44.206 56.206,46 54,46 Z" id="Shape" fill="#0C3847"></Svg.Path>
                <Svg.Polygon id="Shape" fill="#0C3847" points="78 16 82 16 82 12 86 12 86 8 82 8 82 4 78 4 78 8 74 8 74 12 78 12"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="14 26 18 26 18 22 22 22 22 18 18 18 18 14 14 14 14 18 10 18 10 22 14 22"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="96 32 100 32 100 28 104 28 104 24 100 24 100 20 96 20 96 24 92 24 92 28 96 28"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="84 46 84 48 82 48 82 52 84 52 84 54 88 54 88 52 90 52 90 48 88 48 88 46"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="26 44 30 44 30 42 32 42 32 38 30 38 30 36 26 36 26 38 24 38 24 42 26 42"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="26 8 30 8 30 6 32 6 32 2 30 2 30 0 26 0 26 2 24 2 24 6 26 6"></Svg.Polygon>
                <Svg.Path d="M54.002,5.824 C56.604,8.896 62.168,15.912 65.444,26 L42.566,26 C45.844,15.928 51.404,8.902 54.002,5.824 Z" id="Shape" fill="#F37053"></Svg.Path>*/}
            </Svg.G>
        </Svg>
    );
}
</code>```

Body:
I am not sure exactly why this is not showing up. I suspect maybe it has to do with the transform?

<Svg.G id="startup" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd" transform="translate(135.000000, 76.000000)">

But I really don't know... I'm seeing "invalid prop transform"

As I copied SVG code form sketch, suspect I'm having similar trouble to this issue:

https://github.com/react-native-community/react-native-svg/issues/205

Code is below. Any ideas?

import React from 'react';
import { Svg } from 'expo';

const RocketSvg = () => {
    return (
        <Svg width="108px" height="128px" viewBox="135 76 108 128" version="1.1">
            <Svg.G id="startup" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd" transform="translate(135.000000, 76.000000)">
                <Svg.Ellipse id="Oval" fill="#DCDDDE" cx="54" cy="75" rx="52" ry="51"></Svg.Ellipse>
                <Svg.Path d="M81.764,76.608 C79.316,75.5 75.758,74.198 72,73.81 L72,61.414 C77.408,64.05 80.866,70.118 81.764,76.608 Z" id="Shape" fill="#FFFFFF"></Svg.Path>
                <Svg.Path d="M26.236,76.608 C27.134,70.118 30.592,64.052 36,61.412 L36,73.804 C32.242,74.194 28.682,75.498 26.236,76.608 Z" id="Shape" fill="#FFFFFF"></Svg.Path>
                <Svg.Path d="M40,76 L40,42 C40,37.68 40.562,33.678 41.448,30 L66.556,30 C67.44,33.676 68,37.676 68,42 L68,76 L66,76 L42,76 L40,76 Z" id="Shape" fill="#FFFFFF"></Svg.Path>
                <Svg.Polygon id="Shape" fill="#FFFFFF" points="46 84 46 80 62 80 62 84 60 84 48 84"></Svg.Polygon>
                <Svg.Path d="M70,78 L70,42 C70,18 54,2 54,2 L54,78 L70,78 Z" id="Shape" fill="#DCDDDE"></Svg.Path>
                <Svg.Circle id="Oval" fill="#53B7E8" cx="54" cy="42" r="6"></Svg.Circle>
                <Svg.Path d="M98.8,100.76 C96.66,104.34 94.04,107.7 90.96,110.78 C88.58,113.16 86.02,115.26 83.32,117.08 C65.74,129.02 42.46,128.98 24.92,116.96 C22.28,115.18 19.78,113.12 17.44,110.78 C14.26,107.6 11.56,104.1 9.38,100.4 C11.4,96.6 15.4,94 20,94 C25.48,94 30.1,97.7 31.54,102.74 C33.3,99.9 36.42,98 40,98 C44.84,98 48.88,101.44 49.8,106 L50,106 L50,86 L58,86 L58,106 L58.2,106 C59.12,101.44 63.16,98 68,98 C71.58,98 74.7,99.9 76.46,102.74 C77.88,97.7 82.5,94 88,94 C92.74,94 96.84,96.76 98.8,100.76 Z" id="Shape" fill="#FFD768"></Svg.Path>
                <Svg.Rect id="Rectangle-path" fill="#DCDDDE" x="54" y="80" width="8" height="4"></Svg.Rect>
                <Svg.Path d="M91.414,36.586 L90,35.172 L87.172,38 L88.586,39.414 C98.67,49.5 104,61.458 104,74 C104,82.056 102.096,89.812 98.522,96.778 C95.9,93.776 92.12,92 88,92 C82.948,92 78.354,94.752 75.894,98.988 C73.742,97.08 70.96,96 68,96 C64.966,96 62.144,97.148 60,99.062 L60,88 L66,88 L66,80 L72,80 L72,77.844 C77.584,78.546 82.886,81.664 82.966,81.714 L86,83.538 L86,80 C86,70.238 80.864,60.222 72,57.052 L72,42 C72,17.454 56.092,2.09 55.414,1.414 L54,0 L52.586,1.414 C51.908,2.09 36,17.454 36,42 L36,57.052 C27.136,60.222 22,70.238 22,80 L22.002,83.538 L25.034,81.714 C25.116,81.664 30.418,78.542 36,77.842 L36,80 L42,80 L42,88 L48,88 L48,99.062 C45.856,97.148 43.034,96 40,96 C37.036,96 34.252,97.082 32.1,98.994 C29.628,94.754 25.036,92 20,92 C15.91,92 12.116,93.794 9.486,96.794 C5.906,89.824 4,82.06 4,73.998 C4,61.458 9.33,49.5 19.414,39.414 L20.828,38 L18,35.172 L16.586,36.586 C5.736,47.438 0,60.376 0,73.998 C0,88.424 5.618,101.984 15.816,112.184 C26.344,122.71 40.172,128 54,128 C67.828,128 81.656,122.71 92.184,112.184 C102.382,101.984 108,88.424 108,74 C108,60.376 102.264,47.438 91.414,36.586 Z M81.764,76.608 C79.316,75.5 75.758,74.198 72,73.81 L72,61.414 C77.408,64.05 80.866,70.118 81.764,76.608 Z M54.002,5.824 C56.604,8.896 62.168,15.912 65.444,26 L42.566,26 C45.844,15.928 51.404,8.902 54.002,5.824 Z M26.236,76.608 C27.134,70.118 30.592,64.052 36,61.412 L36,73.804 C32.242,74.194 28.682,75.498 26.236,76.608 Z M40,76 L40,42 C40,37.68 40.562,33.678 41.448,30 L66.556,30 C67.44,33.676 68,37.676 68,42 L68,76 L66,76 L42,76 L40,76 Z M46,84 L46,80 L62,80 L62,84 L60,84 L48,84 L46,84 Z M89.356,109.356 C69.86,128.85 38.14,128.85 18.646,109.356 C15.952,106.662 13.616,103.706 11.634,100.558 C13.48,97.732 16.598,96 20,96 C24.436,96 28.39,98.998 29.618,103.29 L30.86,107.638 L33.24,103.794 C34.712,101.418 37.24,100 40,100 C43.794,100 47.092,102.69 47.838,106.394 L48.164,108 L52,108 L52,88 L56,88 L56,108 L59.836,108 L60.16,106.394 C60.908,102.69 64.206,100 68,100 C70.76,100 73.288,101.418 74.76,103.792 L77.154,107.656 L78.386,103.282 C79.592,98.994 83.546,96 88,96 C91.426,96 94.528,97.718 96.372,100.55 C94.39,103.7 92.052,106.658 89.356,109.356 Z" id="Shape" fill="#0C3847"></Svg.Path>
                <Svg.Path d="M54,34 C49.588,34 46,37.588 46,42 C46,46.412 49.588,50 54,50 C58.412,50 62,46.412 62,42 C62,37.588 58.412,34 54,34 Z M54,46 C51.794,46 50,44.206 50,42 C50,39.794 51.794,38 54,38 C56.206,38 58,39.794 58,42 C58,44.206 56.206,46 54,46 Z" id="Shape" fill="#0C3847"></Svg.Path>
                <Svg.Polygon id="Shape" fill="#0C3847" points="78 16 82 16 82 12 86 12 86 8 82 8 82 4 78 4 78 8 74 8 74 12 78 12"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="14 26 18 26 18 22 22 22 22 18 18 18 18 14 14 14 14 18 10 18 10 22 14 22"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="96 32 100 32 100 28 104 28 104 24 100 24 100 20 96 20 96 24 92 24 92 28 96 28"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="84 46 84 48 82 48 82 52 84 52 84 54 88 54 88 52 90 52 90 48 88 48 88 46"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="26 44 30 44 30 42 32 42 32 38 30 38 30 36 26 36 26 38 24 38 24 42 26 42"></Svg.Polygon>
                <Svg.Polygon id="Shape" fill="#0C3847" points="26 8 30 8 30 6 32 6 32 2 30 2 30 0 26 0 26 2 24 2 24 6 26 6"></Svg.Polygon>
                <Svg.Path d="M54.002,5.824 C56.604,8.896 62.168,15.912 65.444,26 L42.566,26 C45.844,15.928 51.404,8.902 54.002,5.824 Z" id="Shape" fill="#F37053"></Svg.Path>*/}
            </Svg.G>
        </Svg>
    );
}

Body:
Answer Regards Tranform

transform propType is not currently support as part of react-native-svg (4th June 2017)

However you can use x and y props instead:

<Svg.G x="135.000000" y="76.000000" id="startup" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">

Fix for SVG

However the SVG you pasted does still not seem to render.

I first converted it back to SVG and re-exported with Sketch.

// logo.svg

<?xml version="1.0" encoding="UTF-8"?>
<svg width="108px" height="128px" viewBox="0 0 108 128" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 44.1 (41455) - http://www.bohemiancoding.com/sketch -->
    <title>Slice 1</title>
    <desc>Created with Sketch.</desc>
    <defs></defs>
    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="so" fill-rule="nonzero">
            <ellipse id="Oval" fill="#DCDDDE" cx="54" cy="75" rx="52" ry="51"></ellipse>
            <path d="M81.764,76.608 C79.316,75.5 75.758,74.198 72,73.81 L72,61.414 C77.408,64.05 80.866,70.118 81.764,76.608 Z" id="Shape" fill="#FFFFFF"></path>
            <path d="M26.236,76.608 C27.134,70.118 30.592,64.052 36,61.412 L36,73.804 C32.242,74.194 28.682,75.498 26.236,76.608 Z" id="Shape" fill="#FFFFFF"></path>
            <path d="M40,76 L40,42 C40,37.68 40.562,33.678 41.448,30 L66.556,30 C67.44,33.676 68,37.676 68,42 L68,76 L66,76 L42,76 L40,76 Z" id="Shape" fill="#FFFFFF"></path>
            <polygon id="Shape" fill="#FFFFFF" points="46 84 46 80 62 80 62 84 60 84 48 84"></polygon>
            <path d="M70,78 L70,42 C70,18 54,2 54,2 L54,78 L70,78 Z" id="Shape" fill="#DCDDDE"></path>
            <circle id="Oval" fill="#53B7E8" cx="54" cy="42" r="6"></circle>
            <path d="M98.8,100.76 C96.66,104.34 94.04,107.7 90.96,110.78 C88.58,113.16 86.02,115.26 83.32,117.08 C65.74,129.02 42.46,128.98 24.92,116.96 C22.28,115.18 19.78,113.12 17.44,110.78 C14.26,107.6 11.56,104.1 9.38,100.4 C11.4,96.6 15.4,94 20,94 C25.48,94 30.1,97.7 31.54,102.74 C33.3,99.9 36.42,98 40,98 C44.84,98 48.88,101.44 49.8,106 L50,106 L50,86 L58,86 L58,106 L58.2,106 C59.12,101.44 63.16,98 68,98 C71.58,98 74.7,99.9 76.46,102.74 C77.88,97.7 82.5,94 88,94 C92.74,94 96.84,96.76 98.8,100.76 Z" id="Shape" fill="#FFD768"></path>
            <rect id="Rectangle-path" fill="#DCDDDE" x="54" y="80" width="8" height="4"></rect>
            <path d="M91.414,36.586 L90,35.172 L87.172,38 L88.586,39.414 C98.67,49.5 104,61.458 104,74 C104,82.056 102.096,89.812 98.522,96.778 C95.9,93.776 92.12,92 88,92 C82.948,92 78.354,94.752 75.894,98.988 C73.742,97.08 70.96,96 68,96 C64.966,96 62.144,97.148 60,99.062 L60,88 L66,88 L66,80 L72,80 L72,77.844 C77.584,78.546 82.886,81.664 82.966,81.714 L86,83.538 L86,80 C86,70.238 80.864,60.222 72,57.052 L72,42 C72,17.454 56.092,2.09 55.414,1.414 L54,0 L52.586,1.414 C51.908,2.09 36,17.454 36,42 L36,57.052 C27.136,60.222 22,70.238 22,80 L22.002,83.538 L25.034,81.714 C25.116,81.664 30.418,78.542 36,77.842 L36,80 L42,80 L42,88 L48,88 L48,99.062 C45.856,97.148 43.034,96 40,96 C37.036,96 34.252,97.082 32.1,98.994 C29.628,94.754 25.036,92 20,92 C15.91,92 12.116,93.794 9.486,96.794 C5.906,89.824 4,82.06 4,73.998 C4,61.458 9.33,49.5 19.414,39.414 L20.828,38 L18,35.172 L16.586,36.586 C5.736,47.438 0,60.376 0,73.998 C0,88.424 5.618,101.984 15.816,112.184 C26.344,122.71 40.172,128 54,128 C67.828,128 81.656,122.71 92.184,112.184 C102.382,101.984 108,88.424 108,74 C108,60.376 102.264,47.438 91.414,36.586 Z M81.764,76.608 C79.316,75.5 75.758,74.198 72,73.81 L72,61.414 C77.408,64.05 80.866,70.118 81.764,76.608 Z M54.002,5.824 C56.604,8.896 62.168,15.912 65.444,26 L42.566,26 C45.844,15.928 51.404,8.902 54.002,5.824 Z M26.236,76.608 C27.134,70.118 30.592,64.052 36,61.412 L36,73.804 C32.242,74.194 28.682,75.498 26.236,76.608 Z M40,76 L40,42 C40,37.68 40.562,33.678 41.448,30 L66.556,30 C67.44,33.676 68,37.676 68,42 L68,76 L66,76 L42,76 L40,76 Z M46,84 L46,80 L62,80 L62,84 L60,84 L48,84 L46,84 Z M89.356,109.356 C69.86,128.85 38.14,128.85 18.646,109.356 C15.952,106.662 13.616,103.706 11.634,100.558 C13.48,97.732 16.598,96 20,96 C24.436,96 28.39,98.998 29.618,103.29 L30.86,107.638 L33.24,103.794 C34.712,101.418 37.24,100 40,100 C43.794,100 47.092,102.69 47.838,106.394 L48.164,108 L52,108 L52,88 L56,88 L56,108 L59.836,108 L60.16,106.394 C60.908,102.69 64.206,100 68,100 C70.76,100 73.288,101.418 74.76,103.792 L77.154,107.656 L78.386,103.282 C79.592,98.994 83.546,96 88,96 C91.426,96 94.528,97.718 96.372,100.55 C94.39,103.7 92.052,106.658 89.356,109.356 Z" id="Shape" fill="#0C3847"></path>
            <path d="M54,34 C49.588,34 46,37.588 46,42 C46,46.412 49.588,50 54,50 C58.412,50 62,46.412 62,42 C62,37.588 58.412,34 54,34 Z M54,46 C51.794,46 50,44.206 50,42 C50,39.794 51.794,38 54,38 C56.206,38 58,39.794 58,42 C58,44.206 56.206,46 54,46 Z" id="Shape" fill="#0C3847"></path>
            <polygon id="Shape" fill="#0C3847" points="78 16 82 16 82 12 86 12 86 8 82 8 82 4 78 4 78 8 74 8 74 12 78 12"></polygon>
            <polygon id="Shape" fill="#0C3847" points="14 26 18 26 18 22 22 22 22 18 18 18 18 14 14 14 14 18 10 18 10 22 14 22"></polygon>
            <polygon id="Shape" fill="#0C3847" points="96 32 100 32 100 28 104 28 104 24 100 24 100 20 96 20 96 24 92 24 92 28 96 28"></polygon>
            <polygon id="Shape" fill="#0C3847" points="84 46 84 48 82 48 82 52 84 52 84 54 88 54 88 52 90 52 90 48 88 48 88 46"></polygon>
            <polygon id="Shape" fill="#0C3847" points="26 44 30 44 30 42 32 42 32 38 30 38 30 36 26 36 26 38 24 38 24 42 26 42"></polygon>
            <polygon id="Shape" fill="#0C3847" points="26 8 30 8 30 6 32 6 32 2 30 2 30 0 26 0 26 2 24 2 24 6 26 6"></polygon>
            <path d="M54.002,5.824 C56.604,8.896 62.168,15.912 65.444,26 L42.566,26 C45.844,15.928 51.404,8.902 54.002,5.824 Z" id="Shape" fill="#F37053"></path>
        </g>
    </g>
</svg>

Then I used msvgc to convert it to a react-native-svg compatible component. Lastly made changes so with works with import { Svg } from 'expo'. You'll notice that there is no longer a transform anyway so your original question is not needed.

// Logo.js

import React from 'react'
import { Svg } from 'expo'

const logo = props => (
  <Svg width={props.width || 108} height={props.height || 128} viewBox="0 0 108 128">
    <Svg.G fillRule="nonzero" fill="none">
      <Svg.Ellipse fill="#DCDDDE" cx="54" cy="75" rx="52" ry="51"></Svg.Ellipse>
      <Svg.Path d="M81.764 76.608C79.316 75.5 75.758 74.198 72 73.81V61.414c5.408 2.636 8.866 8.704 9.764 15.194zM26.236 76.608c.898-6.49 4.356-12.556 9.764-15.196v12.392c-3.758.39-7.318 1.694-9.764 2.804zM40 76V42c0-4.32.562-8.322 1.448-12h25.108A51.108 51.108 0 0 1 68 42v34H40zM46 84v-4h16v4H48z" fill="#FFF"></Svg.Path>
      <Svg.Path d="M70 78V42C70 18 54 2 54 2v76h16z" fill="#DCDDDE"></Svg.Path>
      <Svg.Circle fill="#53B7E8" cx="54" cy="42" r="6"></Svg.Circle>
      <Svg.Path d="M98.8 100.76a51.654 51.654 0 0 1-7.84 10.02 51.539 51.539 0 0 1-7.64 6.3c-17.58 11.94-40.86 11.9-58.4-.12a50.5 50.5 0 0 1-7.48-6.18 52.123 52.123 0 0 1-8.06-10.38C11.4 96.6 15.4 94 20 94c5.48 0 10.1 3.7 11.54 8.74C33.3 99.9 36.42 98 40 98a10 10 0 0 1 9.8 8h.2V86h8v20h.2a10 10 0 0 1 9.8-8c3.58 0 6.7 1.9 8.46 4.74C77.88 97.7 82.5 94 88 94c4.74 0 8.84 2.76 10.8 6.76z" fill="#FFD768"></Svg.Path>
      <Svg.Path fill="#DCDDDE" d="M54 80h8v4h-8z"></Svg.Path>
      <Svg.Path d="M91.414 36.586L90 35.172 87.172 38l1.414 1.414C98.67 49.5 104 61.458 104 74c0 8.056-1.904 15.812-5.478 22.778A13.905 13.905 0 0 0 88 92c-5.052 0-9.646 2.752-12.106 6.988A11.857 11.857 0 0 0 68 96a12.009 12.009 0 0 0-8 3.062V88h6v-8h6v-2.156c5.584.702 10.886 3.82 10.966 3.87L86 83.538V80c0-9.762-5.136-19.778-14-22.948V42C72 17.454 56.092 2.09 55.414 1.414L54 0l-1.414 1.414C51.908 2.09 36 17.454 36 42v15.052C27.136 60.222 22 70.238 22 80l.002 3.538 3.032-1.824c.082-.05 5.384-3.172 10.966-3.872V80h6v8h6v11.062A12.009 12.009 0 0 0 40 96a11.85 11.85 0 0 0-7.9 2.994C29.628 94.754 25.036 92 20 92c-4.09 0-7.884 1.794-10.514 4.794C5.906 89.824 4 82.06 4 73.998 4 61.458 9.33 49.5 19.414 39.414L20.828 38 18 35.172l-1.414 1.414C5.736 47.438 0 60.376 0 73.998c0 14.426 5.618 27.986 15.816 38.186C26.344 122.71 40.172 128 54 128c13.828 0 27.656-5.29 38.184-15.816C102.382 101.984 108 88.424 108 74c0-13.624-5.736-26.562-16.586-37.414zm-9.65 40.022C79.316 75.5 75.758 74.198 72 73.81V61.414c5.408 2.636 8.866 8.704 9.764 15.194zM54.002 5.824C56.604 8.896 62.168 15.912 65.444 26H42.566c3.278-10.072 8.838-17.098 11.436-20.176zM26.236 76.608c.898-6.49 4.356-12.556 9.764-15.196v12.392c-3.758.39-7.318 1.694-9.764 2.804zM40 76V42c0-4.32.562-8.322 1.448-12h25.108A51.108 51.108 0 0 1 68 42v34H40zm6 8v-4h16v4H46zm43.356 25.356c-19.496 19.494-51.216 19.494-70.71 0a50.398 50.398 0 0 1-7.012-8.798C13.48 97.732 16.598 96 20 96c4.436 0 8.39 2.998 9.618 7.29l1.242 4.348 2.38-3.844c1.472-2.376 4-3.794 6.76-3.794 3.794 0 7.092 2.69 7.838 6.394l.326 1.606H52V88h4v20h3.836l.324-1.606C60.908 102.69 64.206 100 68 100c2.76 0 5.288 1.418 6.76 3.792l2.394 3.864 1.232-4.374C79.592 98.994 83.546 96 88 96c3.426 0 6.528 1.718 8.372 4.55a50.456 50.456 0 0 1-7.016 8.806z" fill="#0C3847"></Svg.Path>
      <Svg.Path d="M54 34c-4.412 0-8 3.588-8 8s3.588 8 8 8 8-3.588 8-8-3.588-8-8-8zm0 12c-2.206 0-4-1.794-4-4s1.794-4 4-4 4 1.794 4 4-1.794 4-4 4zM78 16h4v-4h4V8h-4V4h-4v4h-4v4h4zM14 26h4v-4h4v-4h-4v-4h-4v4h-4v4h4zM96 32h4v-4h4v-4h-4v-4h-4v4h-4v4h4zM84 46v2h-2v4h2v2h4v-2h2v-4h-2v-2zM26 44h4v-2h2v-4h-2v-2h-4v2h-2v4h2zM26 8h4V6h2V2h-2V0h-4v2h-2v4h2z" fill="#0C3847"></Svg.Path>
      <Svg.Path d="M54.002 5.824C56.604 8.896 62.168 15.912 65.444 26H42.566c3.278-10.072 8.838-17.098 11.436-20.176z" fill="#F37053"></Svg.Path>
    </Svg.G>
  </Svg>
)

export default logo


问:
Counting numbers of even numbers and odd numbers in java array
I have a program that reads a list of integers, and then display the number of even numbers and odd numbers. We assume that the input ends with 0. Here is the sample run of the program.

Input numbers: 1 2 3 4 5 6 7 8 9 0

Odd: 5    Even: 4

However, my result is
Odd: 5 and Even: 5.

The problem is that 0 is counted as an even number. This is my code

```<code>public class Q75 {
    public static void main(String[] args){
        java.util.Scanner input = new java.util.Scanner (System.in);
        double [] numbers = new double[10];
        System.out.print("Enter numbers: ");
        for(int i = 0;i<numbers.length;i++){
            numbers[i] = input.nextDouble();
        }

        int Evens = 0;
        int Odd = 0;

        for(int i = 0;i<numbers.length;i++){
            if(numbers[i]%2 == 0){
                Evens++;
            }else{
                Odd++;
            }
        }
        System.out.println("The number of odd numbers: " + Odd);
        System.out.println("The number of even numbers: " + Evens);
    }

}
</code>```

答:
Just don't check the last element: Use i < numbers.length - 1

```<code>for(int i = 0;i < numbers.length - 1; i++) {
        //
}
</code>```

Body:
I have a program that reads a list of integers, and then display the number of even numbers and odd numbers. We assume that the input ends with 0. Here is the sample run of the program.

Input numbers: 1 2 3 4 5 6 7 8 9 0

Odd: 5    Even: 4

However, my result is
Odd: 5 and Even: 5.

The problem is that 0 is counted as an even number. This is my code

public class Q75 {
    public static void main(String[] args){
        java.util.Scanner input = new java.util.Scanner (System.in);
        double [] numbers = new double[10];
        System.out.print("Enter numbers: ");
        for(int i = 0;i<numbers.length;i++){
            numbers[i] = input.nextDouble();
        }

        int Evens = 0;
        int Odd = 0;

        for(int i = 0;i<numbers.length;i++){
            if(numbers[i]%2 == 0){
                Evens++;
            }else{
                Odd++;
            }
        }
        System.out.println("The number of odd numbers: " + Odd);
        System.out.println("The number of even numbers: " + Evens);
    }

}

Body:
Just don't check the last element: Use i < numbers.length - 1

for(int i = 0;i < numbers.length - 1; i++) {
        //
}


问:
Why Tokyo Tyrant so slow
I have follow situation tyrant server lunched on freebsd host, like this:

ttserver -uas -log /data/tyrant/1.log -sid 1 -thnum 8 -tout 5 /data/tyrant/data/1.tct

And i try to communicate this server on windows from python and pyrant-0.3.5: like this:

```<code>
import pyrant;
import time;

t = pyrant.Tyrant(host="192.168.0.220", port=1978);
tbegin = time.time();

for i in xrange(4000000):
  if i and ((i % 10000) == 0):
    print time.time() - tbegin;
    tbegin = time.time();

  t[i] = {"text": "ruslan text", "value": i};
</code>```

and have i think very slow performance about 5-6 per 10,000 records. But if i start this code on the same machine like server(ttserver). Performance are good - about 0.5 sec per 10,000 records

What i must do to workaround this problem?

答: you can tracert www.ttserver.com and look at the latency from your native host to the remote server. maybe it's the cause.</p>

Title: Why Tokyo Tyrant so slow

Body:
I have follow situation tyrant server lunched on freebsd host, like this:

ttserver -uas -log /data/tyrant/1.log -sid 1 -thnum 8 -tout 5 /data/tyrant/data/1.tct

And i try to communicate this server on windows from python and pyrant-0.3.5: like this:

import pyrant;
import time;

t = pyrant.Tyrant(host="192.168.0.220", port=1978);
tbegin = time.time();

for i in xrange(4000000):
  if i and ((i % 10000) == 0):
    print time.time() - tbegin;
    tbegin = time.time();

  t[i] = {"text": "ruslan text", "value": i};

and have i think very slow performance about 5-6 per 10,000 records. But if i start this code on the same machine like server(ttserver). Performance are good - about 0.5 sec per 10,000 records

What i must do to workaround this problem?


问:
Angular2: how bind to select multiple
I'm able to bind using ngModel for a single select but I would like to bind an array to the multiple selected options.  When I attempt this I get the error

Cannot find a differ supporting object 'xxx' in 'myModelProperty'

My Code

<select multiple [(ngModel)]="myModelProperty">
    <option *ngFor="#item of myOptions" [value]="item.value">{{item.name}}</option>
</select>
```

答:
Why all those complicate answers about simple question.

If you in advance have options which have to be selected, you can do it simply this way :

This code is good :

HTML

```<code><select multiple [(ngModel)]="myModelProperty">
    <option *ngFor="#item of myOptions" [value]="item.value">{{item.name}}</option>
</select>
</code>```

ANGULAR

```<code>myModelProperty: any;
myModelProperty = ['YOUR_VALUE', 'YOUR_VALUE'];
</code>```

or if you have string, you can parse it

```<code>myModelProperty: any;
myModelProperty = string.split(',');
</code>```

So, all you have to done is that [(ngModel)] from select tag, have to be initialized in angular part with some array of values which correspond to [value] from option tag

This will automatically select one or more options depends on values from array.

Title: Angular2: how bind to select multiple

Body:
Why all those complicate answers about simple question.

If you in advance have options which have to be selected, you can do it simply this way :

This code is good :

HTML

<select multiple [(ngModel)]="myModelProperty">
    <option *ngFor="#item of myOptions" [value]="item.value">{{item.name}}</option>
</select>

ANGULAR

myModelProperty: any;
myModelProperty = ['YOUR_VALUE', 'YOUR_VALUE'];

or if you have string, you can parse it

myModelProperty: any;
myModelProperty = string.split(',');

So, all you have to done is that [(ngModel)] from select tag, have to be initialized in angular part with some array of values which correspond to [value] from option tag

This will automatically select one or more options depends on values from array.