问:
Pygame: Other way of checking mouse button up
I'm creating a game via a game class setup like this:

```<code>class Game:
   def __init__(self)

   def new(self)
       run()

   def events(self)

   def update(self)

   def draw(self)

   def run(self)
       while True:
           events()
           update()
           draw()

g = Game()
while g.isrunning:
    g.new()
</code>```

Rough sketch of the template. Also probably need to tell I'm working with sprites, created from another class.

I first wanted a sprite to be removed when you click on it so in the update function i checked:

```<code>self.mouseState = pygame.mouse.get_pressed()
if (sprite.rect.collidepoint(pygame.mouse.get_pos()) and self.mouseState[0]):
    sprite.kill()
</code>```

this works and made me happy. But now i want it to happen when you RELEASE the mousebutton. I know you can check MOUSEBUTTONUP in the events function via "for event in pygame.event.get():" but with the way my template works i can't call that in the game loop (the update function) right?

答:
You can just iterate over the sprite group if a MOUSEBUTTONUP event appears and then kill the sprite if it collides with the event.pos or pygame.mouse.get_pos().

```<code>import pygame as pg

class Player(pg.sprite.Sprite):

    def __init__(self, pos):
        super().__init__()
        self.image = pg.Surface((30, 50))
        self.image.fill(pg.Color('dodgerblue2'))
        self.rect = self.image.get_rect(center=pos)

class Game:

    def __init__(self):
        self.screen = pg.display.set_mode((640, 480))
        self.clock = pg.time.Clock()
        self.all_sprites = pg.sprite.Group(Player((200, 200)), Player((400, 200)))
        self.done = False

    def run(self):
        while not self.done:
            self.handle_events()
            self.run_logic()
            self.draw()
            self.clock.tick(30)

    def handle_events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                self.done = True
            elif event.type == pg.MOUSEBUTTONUP:
                if event.button == 1:  # Left mouse button.
                    for sprite in self.all_sprites:
                        if sprite.rect.collidepoint(event.pos):
                            sprite.kill()

    def run_logic(self):
        self.all_sprites.update()

    def draw(self):
        self.screen.fill((30, 30, 30))
        self.all_sprites.draw(self.screen)
        pg.display.flip()

if __name__ == '__main__':
    pg.init()
    Game().run()
    pg.quit()
</code>```

Body:
I'm creating a game via a game class setup like this:

class Game:
   def __init__(self)

   def new(self)
       run()

   def events(self)

   def update(self)

   def draw(self)

   def run(self)
       while True:
           events()
           update()
           draw()

g = Game()
while g.isrunning:
    g.new()

Rough sketch of the template. Also probably need to tell I'm working with sprites, created from another class.

I first wanted a sprite to be removed when you click on it so in the update function i checked:

self.mouseState = pygame.mouse.get_pressed()
if (sprite.rect.collidepoint(pygame.mouse.get_pos()) and self.mouseState[0]):
    sprite.kill()

this works and made me happy. But now i want it to happen when you RELEASE the mousebutton. I know you can check MOUSEBUTTONUP in the events function via "for event in pygame.event.get():" but with the way my template works i can't call that in the game loop (the update function) right?

Body:
You can just iterate over the sprite group if a MOUSEBUTTONUP event appears and then kill the sprite if it collides with the event.pos or pygame.mouse.get_pos().

import pygame as pg

class Player(pg.sprite.Sprite):

    def __init__(self, pos):
        super().__init__()
        self.image = pg.Surface((30, 50))
        self.image.fill(pg.Color('dodgerblue2'))
        self.rect = self.image.get_rect(center=pos)

class Game:

    def __init__(self):
        self.screen = pg.display.set_mode((640, 480))
        self.clock = pg.time.Clock()
        self.all_sprites = pg.sprite.Group(Player((200, 200)), Player((400, 200)))
        self.done = False

    def run(self):
        while not self.done:
            self.handle_events()
            self.run_logic()
            self.draw()
            self.clock.tick(30)

    def handle_events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                self.done = True
            elif event.type == pg.MOUSEBUTTONUP:
                if event.button == 1:  # Left mouse button.
                    for sprite in self.all_sprites:
                        if sprite.rect.collidepoint(event.pos):
                            sprite.kill()

    def run_logic(self):
        self.all_sprites.update()

    def draw(self):
        self.screen.fill((30, 30, 30))
        self.all_sprites.draw(self.screen)
        pg.display.flip()

if __name__ == '__main__':
    pg.init()
    Game().run()
    pg.quit()


来源: stackexchange

问:
Find all elements that start with 'button-'
I am using Selenium to try and get all ID elements that that start with "button-". What I have tried so far was to use regex to match the "button-" but I get an error stating that TypeError: Object of type 'SRE_Pattern' is not JSON serializable. My code so far is:

```<code>all_btns = self.driver.find_elements_by_id(re.compile('^button-?'))
</code>```

But as mentioned that raises an error. What is the appropriate way of getting all elements when you don't know the full ID, class, css selector etc.?

答:
You could use find_element_by_xpath and starts-with:

```<code>find_elements_by_xpath('//*[starts-with(@id, "button-")]')
</code>```

//* will match any elements

[starts-with(@id, "button-")] will filter the elements with a property id that starts with button-

ContentLicense: CC BY-SA 3.0

Body:
I am using Selenium to try and get all ID elements that that start with "button-". What I have tried so far was to use regex to match the "button-" but I get an error stating that TypeError: Object of type 'SRE_Pattern' is not JSON serializable. My code so far is:

all_btns = self.driver.find_elements_by_id(re.compile('^button-?'))

But as mentioned that raises an error. What is the appropriate way of getting all elements when you don't know the full ID, class, css selector etc.?

Body:
You could use find_element_by_xpath and starts-with:

find_elements_by_xpath('//*[starts-with(@id, "button-")]')

//* will match any elements

[starts-with(@id, "button-")] will filter the elements with a property id that starts with button-


问:
Laravel 5 - how to retrieve results from table for every date, even if entries do not exist
I have a table named daily_data that has a date field.  I would like to be able, through the Query Builder interface, return a result for every row in a range of dates, even if there is no entry for a given date (return null values in those cases)

From digging around, one suggestion seems to be generating a dynamic list of dates in the range, and then doing a join with the table.  This seems like a fairly nice way to solve the problem, but I can not find any examples of this in Laravel.  I would prefer to have the full set of results returned from Query Builder rather than having to loop through the results in PHP, detecting/adding empty fields after the query.

If there is a better way to achieve this with Laravel/Query Builder, I would gladly hear it.

In the meantime, I found this code for generating a range of dates on SqlFiddle: http://sqlfiddle.com/#!9/38f7db/92.  It does what it claims to, and I did adapt it to work in Laravel.  It is basically everything contained in the DB::select below.  Here is my attempt to combine it with a join to get the results I'm looking for:

```<code>    $dates = DB::select(DB::raw(
        'SELECT a.Date as Date FROM
          (SELECT "2017-11-15" - INTERVAL (a.a + (10 * b.a)) DAY AS Date
           FROM
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3
              UNION ALL SELECT 4
              UNION ALL SELECT 5
              UNION ALL SELECT 6
              UNION ALL SELECT 7
              UNION ALL SELECT 8
              UNION ALL SELECT 9) AS a CROSS
           JOIN
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3) AS b) a
        where a.Date between "2017-11-01" and "2017-11-15"'))
        ->leftJoin(
            'daily_data',
            function($join) {
                $join->on("Date", "=", "daily_data.date");
            }
        );
</code>```

I get the error:

[2017-11-16 01:23:16] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function leftJoin() on array

I can understand that this doesn't work as using DB::table would...but is there a different way to accomplish what I am trying to do here?

I have verified that the part of the query generating the dates does work in returning an appropriate list of dates.  (see below for the code, basically the same as above without the join, and the output it gives).

```<code>   $dates = DB::select(DB::raw(
        'SELECT a.Date as Date FROM
          (SELECT "2017-11-15" - INTERVAL (a.a + (10 * b.a)) DAY AS Date
           FROM
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3
              UNION ALL SELECT 4
              UNION ALL SELECT 5
              UNION ALL SELECT 6
              UNION ALL SELECT 7
              UNION ALL SELECT 8
              UNION ALL SELECT 9) AS a CROSS
           JOIN
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3) AS b) a
        where a.Date between "2017-11-01" and "2017-11-15" '));
</code>```

and the output... (a list of dates between 2017-11-01 and 2017-11-15):

```<code>[0] => stdClass Object
    (
        [Date] => 2017-11-15
    )
[1] => stdClass Object
    (
        [Date] => 2017-11-05
    )
[2] => stdClass Object
    (
        [Date] => 2017-11-14
    )
...
</code>```

)

(I know its not ordered but I am sure I can fix that, just trying to get the basic idea down for now)

Thanks in advance for any pointers.

答:
You can try this raw query instead of using leftJoin() method     </p>

```<code>$dates = DB::select(DB::raw('
    SELECT a.Date AS DATE
    FROM
    (
        SELECT "2017-11-15" - INTERVAL (a.a + (10 * b.a)) DAY AS DATE
        FROM
        (
            SELECT 0 AS a UNION ALL
            SELECT 1 UNION ALL
            SELECT 2 UNION ALL
            SELECT 3 UNION ALL
            SELECT 4 UNION ALL
            SELECT 5 UNION ALL
            SELECT 6 UNION ALL
            SELECT 7 UNION ALL
            SELECT 8 UNION ALL
            SELECT 9) AS a CROSS
            JOIN
            (
                SELECT 0 AS a UNION ALL
                SELECT 1 UNION ALL
                SELECT 2 UNION ALL
                SELECT 3
            ) AS b
        ) a
    LEFT JOIN daily_data c ON a.Date=c.date
    WHERE a.Date BETWEEN "2017-11-01" AND "2017-11-15"
    ORDER BY a.Date'));
</code>```

Body:
I have a table named daily_data that has a date field.  I would like to be able, through the Query Builder interface, return a result for every row in a range of dates, even if there is no entry for a given date (return null values in those cases)

From digging around, one suggestion seems to be generating a dynamic list of dates in the range, and then doing a join with the table.  This seems like a fairly nice way to solve the problem, but I can not find any examples of this in Laravel.  I would prefer to have the full set of results returned from Query Builder rather than having to loop through the results in PHP, detecting/adding empty fields after the query.

If there is a better way to achieve this with Laravel/Query Builder, I would gladly hear it.

In the meantime, I found this code for generating a range of dates on SqlFiddle: http://sqlfiddle.com/#!9/38f7db/92.  It does what it claims to, and I did adapt it to work in Laravel.  It is basically everything contained in the DB::select below.  Here is my attempt to combine it with a join to get the results I'm looking for:

    $dates = DB::select(DB::raw(
        'SELECT a.Date as Date FROM
          (SELECT "2017-11-15" - INTERVAL (a.a + (10 * b.a)) DAY AS Date
           FROM
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3
              UNION ALL SELECT 4
              UNION ALL SELECT 5
              UNION ALL SELECT 6
              UNION ALL SELECT 7
              UNION ALL SELECT 8
              UNION ALL SELECT 9) AS a CROSS
           JOIN
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3) AS b) a
        where a.Date between "2017-11-01" and "2017-11-15"'))
        ->leftJoin(
            'daily_data',
            function($join) {
                $join->on("Date", "=", "daily_data.date");
            }
        );

I get the error:

[2017-11-16 01:23:16] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function leftJoin() on array

I can understand that this doesn't work as using DB::table would...but is there a different way to accomplish what I am trying to do here?

I have verified that the part of the query generating the dates does work in returning an appropriate list of dates.  (see below for the code, basically the same as above without the join, and the output it gives).

   $dates = DB::select(DB::raw(
        'SELECT a.Date as Date FROM
          (SELECT "2017-11-15" - INTERVAL (a.a + (10 * b.a)) DAY AS Date
           FROM
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3
              UNION ALL SELECT 4
              UNION ALL SELECT 5
              UNION ALL SELECT 6
              UNION ALL SELECT 7
              UNION ALL SELECT 8
              UNION ALL SELECT 9) AS a CROSS
           JOIN
             (SELECT 0 AS a
              UNION ALL SELECT 1
              UNION ALL SELECT 2
              UNION ALL SELECT 3) AS b) a
        where a.Date between "2017-11-01" and "2017-11-15" '));

and the output... (a list of dates between 2017-11-01 and 2017-11-15):

[0] => stdClass Object
    (
        [Date] => 2017-11-15
    )
[1] => stdClass Object
    (
        [Date] => 2017-11-05
    )
[2] => stdClass Object
    (
        [Date] => 2017-11-14
    )
...

)

(I know its not ordered but I am sure I can fix that, just trying to get the basic idea down for now)

Thanks in advance for any pointers.

Body:
You can try this raw query instead of using leftJoin() method

$dates = DB::select(DB::raw('
    SELECT a.Date AS DATE
    FROM
    (
        SELECT "2017-11-15" - INTERVAL (a.a + (10 * b.a)) DAY AS DATE
        FROM
        (
            SELECT 0 AS a UNION ALL
            SELECT 1 UNION ALL
            SELECT 2 UNION ALL
            SELECT 3 UNION ALL
            SELECT 4 UNION ALL
            SELECT 5 UNION ALL
            SELECT 6 UNION ALL
            SELECT 7 UNION ALL
            SELECT 8 UNION ALL
            SELECT 9) AS a CROSS
            JOIN
            (
                SELECT 0 AS a UNION ALL
                SELECT 1 UNION ALL
                SELECT 2 UNION ALL
                SELECT 3
            ) AS b
        ) a
    LEFT JOIN daily_data c ON a.Date=c.date
    WHERE a.Date BETWEEN "2017-11-01" AND "2017-11-15"
    ORDER BY a.Date'));


问:
Failed to load resource: the server responded with a status of 404 (Not Found) Unable to resolve this issue
I am getting this error. I tried all the combinations of the paths of directories but every time I am getting following errors.

```<code>Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/dist/styles.css
Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/styles/branding.css
Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/dist/styles.css
Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/styles/branding.css
</code>```

I have made an index.html which is requesting swaggerindex.html in which following scripts and stylesheets are present.

bundle.js

branding.js

styles.css

branding.css

Here is the code snippet of swaggerindex.html

<link rel="stylesheet" href="../myapp/dist/styles.css">
    <link rel="stylesheet" href="../myapp/styles/branding.css">

Sending the content from swagger index

    ```
</div>
</div>
</p>

<p>Here is the screenshot of the directory structure</p>

```myapp
  |--index.html
  |--swaggerindex.html
  |--dist //directory containing styles.css and bundle.js
       |--styles.css
       |--bundle.js
  |--scripts //directory
       |--branding.js
  |--styles //directory
       |--branding.css
```

for more clarification of directory structure you can visit to
github link of the directory structure

Note: This doesnot contain dist folder but it is created when we build it in local machine

Note: I have changed the name of index.html file to swaggerindex.html

答:
Inside the root folder of your angular2 project, note the naming, it has to be in this form "project-name"

Step1: ng install
Step2: ng build --prod
Step3: step2 will produce a "dist" folder inside your project's root directory
Step4: go inside "dist" folder, and take note of the full path
Step5: create a VHOST like this:

    ServerAdmin someone@somewhere.com
    DocumentRoot "full\path\to\dist\directory"
    ServerName projectname

```<code>ProxyRequests Off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass /enterprise-sa/ http://127.0.0.1:8001/enterprise-sa/
ProxyPassReverse /enterprise-sa/ http://127.0.0.1:8001/enterprise-sa/
<Location />
    Order allow,deny
    Allow from all
</Location>
</code>```

Step6: add an entry in /etc/hosts file
       XXX.X.X.X  projectname

restart apache/nginx

Body:
I am getting this error. I tried all the combinations of the paths of directories but every time I am getting following errors.

Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/dist/styles.css
Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/styles/branding.css
Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/dist/styles.css
Failed to load resource: the server responded with a status of 404 (Not Found)   http://localhost:3000/myapp/styles/branding.css

I have made an index.html which is requesting swaggerindex.html in which following scripts and stylesheets are present.

bundle.js

branding.js

styles.css

branding.css

Here is the code snippet of swaggerindex.html

<link rel="stylesheet" href="../myapp/dist/styles.css">
    <link rel="stylesheet" href="../myapp/styles/branding.css">

Sending the content from swagger index

Here is the screenshot of the directory structure

myapp
  |--index.html
  |--swaggerindex.html
  |--dist //directory containing styles.css and bundle.js
       |--styles.css
       |--bundle.js
  |--scripts //directory
       |--branding.js
  |--styles //directory
       |--branding.css

for more clarification of directory structure you can visit to
github link of the directory structure

Note: This doesnot contain dist folder but it is created when we build it in local machine

Note: I have changed the name of index.html file to swaggerindex.html

Body:
Inside the root folder of your angular2 project, note the naming, it has to be in this form "project-name"

Step1: ng install
Step2: ng build --prod
Step3: step2 will produce a "dist" folder inside your project's root directory
Step4: go inside "dist" folder, and take note of the full path
Step5: create a VHOST like this:

    ServerAdmin someone@somewhere.com
    DocumentRoot "full\path\to\dist\directory"
    ServerName projectname

ProxyRequests Off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass /enterprise-sa/ http://127.0.0.1:8001/enterprise-sa/
ProxyPassReverse /enterprise-sa/ http://127.0.0.1:8001/enterprise-sa/
<Location />
    Order allow,deny
    Allow from all
</Location>

Step6: add an entry in /etc/hosts file
       XXX.X.X.X  projectname

restart apache/nginx


问:
potential leak at CFStringRef while getting phone number from contacts
I am getting phone number from the address book for that i am using this code.

```<code>- (IBAction)contacts {

    ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
    peoplePickerController.peoplePickerDelegate = self;
    [self presentModalViewController:peoplePickerController animated:NO];
    [peoplePickerController release];

}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonPhoneProperty) {
    ABMultiValueRef phonenumbers = ABRecordCopyValue(person, property);
    CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(phonenumbers, identifier);

    NSString *aNSString = (NSString *)phonenumberselected;
    if ([share_toadd length] == 0) {
        [share_toadd appendString:aNSString];
    }
    else {
        [share_toadd appendString:@","];
        [share_toadd appendString:aNSString];
    }

    share_textfield.text = share_toadd;
    // Return to the main view controller.
    [ self dismissModalViewControllerAnimated:YES ];
    return NO;

    [share_textfield release];
}
return YES;
</code>```

}

but i am getting potential leak at CFStringRef

```<code> Potential leak of an object allocated on line 1126

 Call to function 'ABRecordCopyValue' returns a Core Foundation object with a +1 retain count (owning reference)

 Object allocated on line 1126 is no longer referenced after this point and has a retain count of +1 (object leaked)
</code>```

can any one pls help me.

how can i resolve it.

答: You should call CFRelease(phonenumbersselected) when you're done using the object.</p>

ContentLicense: CC BY-SA 2.5

Body:
I am getting phone number from the address book for that i am using this code.

- (IBAction)contacts {

    ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
    peoplePickerController.peoplePickerDelegate = self;
    [self presentModalViewController:peoplePickerController animated:NO];
    [peoplePickerController release];

}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonPhoneProperty) {
    ABMultiValueRef phonenumbers = ABRecordCopyValue(person, property);
    CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(phonenumbers, identifier);

    NSString *aNSString = (NSString *)phonenumberselected;
    if ([share_toadd length] == 0) {
        [share_toadd appendString:aNSString];
    }
    else {
        [share_toadd appendString:@","];
        [share_toadd appendString:aNSString];
    }

    share_textfield.text = share_toadd;
    // Return to the main view controller.
    [ self dismissModalViewControllerAnimated:YES ];
    return NO;

    [share_textfield release];
}
return YES;

}

but i am getting potential leak at CFStringRef

 Potential leak of an object allocated on line 1126

 Call to function 'ABRecordCopyValue' returns a Core Foundation object with a +1 retain count (owning reference)

 Object allocated on line 1126 is no longer referenced after this point and has a retain count of +1 (object leaked)

can any one pls help me.

how can i resolve it.


答:
Here's another option, using IF(expr1,expr2,expr3) and then taking the Sum().</p>

```<code>SELECT
    SUM(IF(Side-1-Length > Side-2-Length, Side-1-Length, Side-2-Length))
FROM TableA
WHERE DateEnd >= '2017-11-10';
</code>```

Title: sum all of greatest value of two fields mysql

Body:
I was trying to get all the greatest value in the table. Let say i have table named TableA and here is the attributes
My Current query is below which is only display one row. So the value that i want to get is sum of all the greatest value of all data.

SELECT GREATEST(MAX(Side-1-Length), MAX(Side-2-Length)) from TableA where DateEnd >='2017-11-10';

Below is my TableA

+---------+--------------+--------------+--------------+
| Id      | Side-1-Length| Side-2-Length|    DateEnd   |
+---------+--------------+--------------+--------------+
| 64      |      22      |      21      | 2011-11-14   |
| 187     |      32      |      26      | 2011-11-15   |
| 325     |      12      |      18      | 2011-11-15   |
| 389     |      41      |      36      | 2011-11-16   |
| 495     |      62      |      41      | 2011-11-14   |
+---------+--------------+--------------+--------------+

The Query that i want to display will output something like below table

+---------+--------------+--------------+
| Id      | Side-Greates |    DateEnd   |
+---------+--------------+--------------+
| 64      |      22      | 2011-11-14   |
| 187     |      32      | 2011-11-15   |
| 325     |      18      | 2011-11-15   |
| 389     |      41      | 2011-11-16   |
| 495     |      62      | 2011-11-14   |
+---------+--------------+--------------+

And WIll sum up all the Side-Greates value

+---------+
| Sum     |
+---------+
| 175     |
+---------+

Body:
Here's another option, using IF(expr1,expr2,expr3) and then taking the Sum().

SELECT
    SUM(IF(Side-1-Length > Side-2-Length, Side-1-Length, Side-2-Length))
FROM TableA
WHERE DateEnd >= '2017-11-10';


问:
Most efficient way to find the index of the only '1' bit in a char variable (in C)
This is an interview question:

You are given a char variable named ch, when you know that it represents a number that in its binary form, only one of its eight bits will be equal to '1'. I.E. , the only possible values for ch are: 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80.

Given the variable ch, I need to write the most efficient code to get the index of that '1' bit. For example: if ch == 0x1 -> result is 0. if ch == 0x4 -> result is 2.

The obvious way is to use switch-case, but I need something more efficient.

Is there any bit manipulation you can do here for efficient implementation?

答:
Some architectures contain efficient (single instruction) implementation of popcount, available in C-compilers through intrinsics or __builtin_popcount().

If this is the case, it will be hard to beat popcount(x - 1), which will first convert the single set bit (1 << n) to a run of bits from (1 << (n-1)) .. 1, or 0 when x==1, then count the number of ones, which is the index of the original n.

Some comments point out ”Bit Scan Forward”, however, at least in x86 architectures that is inferior to popcount. Always know your HW...


问:
Error Loading Large CSV into Google BigQuery
Getting an Error on loading a large CSV into bigquery. Everywhere I read online I see that there is a 5gb size limit on zipped files but no limits on CSV.

BigQuery error in load operation: Error processing job 'bqjob_r3016bbfad3037f_0000015cea1a1eff_1': Input CSV files are not splittable and
at least one of the files is larger than the maximum allowed size. Size is: 24686861596. Max allowed size is: 4294967296.

答:
Try this:

Turn off quoting

Set separating character to a non occurring character.

bq help load:

```<code>--quote: Quote character to use to enclose records. Default is ". To indicate no quote character at all, use an empty string.
-F,--field_delimiter: The character that indicates the boundary between columns in the input file. "\t" and "tab" are accepted names for tab.
</code>```

This will import each CSV line to a one column table. Split afterwards within BigQuery (with REGEXP_EXTRACT(), SPLIT(), or JavaScript UDF).

Body:
Try this:

Turn off quoting

Set separating character to a non occurring character.

bq help load:

--quote: Quote character to use to enclose records. Default is ". To indicate no quote character at all, use an empty string.
-F,--field_delimiter: The character that indicates the boundary between columns in the input file. "\t" and "tab" are accepted names for tab.

This will import each CSV line to a one column table. Split afterwards within BigQuery (with REGEXP_EXTRACT(), SPLIT(), or JavaScript UDF).


问:
cannot get option values after updating option
This code works fine:

```<code>$("#day option").click(function () {
    daySelected = $("#day select").val();
});
</code>```

But after this function:

```<code>$("#month option").click(function () {
    $("#day select").html("<option value='default'>Day</option>");
    for (var i = 1; i <= daysNum; i++) {
        $("#day select").append("<option value='" + i + "'>" + i + "</option>");
    }
    if (parseInt(daySelected) > daysNum) {
        $("#day select").val(String(daysNum));
    } else {
        $("#day select").val(daySelected);
    }
});
</code>```

my daySelected variable won't change its value anymore when I click $("#day option").

答:
I think because jQuery click function is used for already exists element.

So when you clear and recreate option element, click event not attach to it.

I guess you can use on function like this.

```<code>$("#day").on('click', 'option', function () {
    daySelected = $("#day select").val();
});
</code>```

Hope this help.

Body:
This code works fine:

$("#day option").click(function () {
    daySelected = $("#day select").val();
});

But after this function:

$("#month option").click(function () {
    $("#day select").html("<option value='default'>Day</option>");
    for (var i = 1; i <= daysNum; i++) {
        $("#day select").append("<option value='" + i + "'>" + i + "</option>");
    }
    if (parseInt(daySelected) > daysNum) {
        $("#day select").val(String(daysNum));
    } else {
        $("#day select").val(daySelected);
    }
});

my daySelected variable won't change its value anymore when I click $("#day option").

Body:
I think because jQuery click function is used for already exists element.

So when you clear and recreate option element, click event not attach to it.

I guess you can use on function like this.

$("#day").on('click', 'option', function () {
    daySelected = $("#day select").val();
});

Hope this help.


问:
Log4jConfigurer Alternative
I see that the class org.springframework.util.Log4jConfigurer is deprecated, but I could not find which class should be used as a replacement.
Specifically, I need Log4jConfigurer.initLogging.

Does anybody know which class/method I should use?

Thanks.

答:
Only needed for non-default log4j initialization, for example with a custom config location or a refresh interval. By default, log4j will simply read its configuration from a log4j.properties or log4j.xml file in the root of the classpath.

```<code>String prop = System.getProperty("log4j.configuration");
if (prop == null) prop = "log4j.properties";
URL log4jConfig = Loader.getResource(prop);
if (log4jConfig.getProtocol().equalsIgnoreCase("file")){
    PropertyConfigurator.configureAndWatch(log4jConfig.getFile().substring(1), 10000);
}else{
    // cannot monitor if file changed because URL is not a file
}
</code>```

Check this link.

Title: Log4jConfigurer Alternative

Body:
Only needed for non-default log4j initialization, for example with a custom config location or a refresh interval. By default, log4j will simply read its configuration from a log4j.properties or log4j.xml file in the root of the classpath.

String prop = System.getProperty("log4j.configuration");
if (prop == null) prop = "log4j.properties";
URL log4jConfig = Loader.getResource(prop);
if (log4jConfig.getProtocol().equalsIgnoreCase("file")){
    PropertyConfigurator.configureAndWatch(log4jConfig.getFile().substring(1), 10000);
}else{
    // cannot monitor if file changed because URL is not a file
}

Check this link.


问:
On checked - adding image instead of checkbox (Angular 4/Ionic 3)
I'm trying to replace the checkbox with an image. This image will change based on css class whether or not it's checked. Adding a class doesn't work on change of checked because it changes all of the icons in the column. I'm using ion-checkbox for my checkbox. Doing ion-checkbox:checked does not work either in css.

A look at the images below I would like to replace the pin icon with the checkbox and when it's checked the class changes the icon to a red color and changes one of them, not all.

HTML

```<code><tr *ngFor="let object of array">
  <td>
     <fa name="map-marker" [ngClass]="pinIcon ? 'unclick-pin' : 'click-pin'"></fa>
     <ion-checkbox (ionChange)="selectTwo(object, $event.checked)"></ion-checkbox>
  </td>
</tr>
</code>```

TS

```<code>selectTwo(object, isChecked: boolean){
    this.pinIcon = !this.pinIcon;
}
</code>```

 .

答:
The issue with your code is, you are using single variable for all checkbox, and on ionChange you are changing that variable , so it will change all the checkbox.

Here it is, Change your code as below and it will work

Template side :

```<code><tr *ngFor="let object of array">
  <td>
     <fa name="map-marker" [ngClass]="object.pinIcon ? 'unclick-pin' : 'click-pin'"></fa>
     <ion-checkbox (ionChange)="selectTwo(object, $event.checked)"></ion-checkbox>
  </td>
</tr>
</code>```

Component side :

```<code>selectTwo(object, isChecked: boolean){
    object.pinIcon = isChecked;
}
</code>```

Body:
I'm trying to replace the checkbox with an image. This image will change based on css class whether or not it's checked. Adding a class doesn't work on change of checked because it changes all of the icons in the column. I'm using ion-checkbox for my checkbox. Doing ion-checkbox:checked does not work either in css.

A look at the images below I would like to replace the pin icon with the checkbox and when it's checked the class changes the icon to a red color and changes one of them, not all.

HTML

     <fa name="map-marker" [ngClass]="pinIcon ? 'unclick-pin' : 'click-pin'"></fa>
     <ion-checkbox (ionChange)="selectTwo(object, $event.checked)"></ion-checkbox>

TS

selectTwo(object, isChecked: boolean){
    this.pinIcon = !this.pinIcon;
}

 .

Body:
The issue with your code is, you are using single variable for all checkbox, and on ionChange you are changing that variable , so it will change all the checkbox.

Here it is, Change your code as below and it will work

Template side :

<tr *ngFor="let object of array">
  <td>
     <fa name="map-marker" [ngClass]="object.pinIcon ? 'unclick-pin' : 'click-pin'"></fa>
     <ion-checkbox (ionChange)="selectTwo(object, $event.checked)"></ion-checkbox>
  </td>
</tr>

Component side :

selectTwo(object, isChecked: boolean){
    object.pinIcon = isChecked;
}


问:
Slow vagrant box, how to improve this?
We've built a vagrant box for our development box and we are facing some latency issues.

Issues:

Assetic:watch is being slow

Overall application access in (app_dev.php) is slow

Using "find" command in the shared folder on the vagrant box is super slow

About the box:

Running on virtualbox (running on both Mac and Linux)

LAMP env (ubuntu)

Big code base (10K+ files)

Symfony 2 application

Things done to improve perfs:

Use of NTFS (using bindfs)

Vagrant configs:

config.vm.synced_folder "#{folder['source']}", "/mnt/vagrant-#{i}",
  id: "#{i}", type: 'nfs', mount_options: ['rw', 'vers=3', 'tcp', 'fsc'
  ,'actimeo=2']

Move cache and logs out of the shared folder (AppKernel update)

We can clearly see that any time a file from the shared folder is accessed the "bindfs" process is eating a lot of cpu.

First of all is that normal? I was expecting vagrant to copy files on the box an whenever those files were being accessed things were done locally.

We can see that the box itself works fine as when accessing cache data (outside of shared folder) things are going fast enough so what can I do to improve the box performances and avoid those latency issue?

答:
Late to the game. For newcomers there are 2 plugins which will increase the speed of the vagrant box right of the bat.

vagrant-cachier

Installation
Make sure you have Vagrant 1.4+ and run: vagrant plugin install vagrant-cachier

Vagrant-faster

```<code>vagrant plugin install vagrant-faster
</code>```

I'm also using MySQL-tuner-perl which is quite good for MySQL fine tuning.

I hope it helps

Title: Slow vagrant box, how to improve this?

Body:
Late to the game. For newcomers there are 2 plugins which will increase the speed of the vagrant box right of the bat.

vagrant-cachier

Installation
Make sure you have Vagrant 1.4+ and run: vagrant plugin install vagrant-cachier

Vagrant-faster

vagrant plugin install vagrant-faster

I'm also using MySQL-tuner-perl which is quite good for MySQL fine tuning.

I hope it helps


问:
SQL - Get average count GROUP BY months
Let's say I have the following structure:

```<code>Ticket |date_created       |date_removed

ticket1|2015-05-14 15:08:65|2015-05-11 10:50:11
</code>```

I'm trying to find the average count of date_removed minus date_created, and then group by months.

Here's what I have so far:

```<code>select AVG(DATEDIFF(day, date_created, date_resolved)) AS 'avg_days' from
my_table
</code>```

gives me the avg number of days for the entire query.
How would I go about grouping by months as well?

I've tried the following:

```<code>select AVG(DATEDIFF(day, date_created, date_resolved)) AS 'avg_days',
MONTH(date_created) AS 'month' from my_table
</code>```

but got the error:

```<code>Incorrect parameter count in the call to native function 'DATEDIFF'
</code>```

答:
Did you try to convert to date format instead of work with datetime?</p>

```<code>select AVG(DATEDIFF(day, convert(date,date_created,102),convert(date,date_removed,102)) )
from table
</code>```

Title: SQL - Get average count GROUP BY months

Body:
Let's say I have the following structure:

Ticket |date_created       |date_removed

ticket1|2015-05-14 15:08:65|2015-05-11 10:50:11

I'm trying to find the average count of date_removed minus date_created, and then group by months.

Here's what I have so far:

select AVG(DATEDIFF(day, date_created, date_resolved)) AS 'avg_days' from
my_table

gives me the avg number of days for the entire query.
How would I go about grouping by months as well?

I've tried the following:

select AVG(DATEDIFF(day, date_created, date_resolved)) AS 'avg_days',
MONTH(date_created) AS 'month' from my_table

but got the error:

Incorrect parameter count in the call to native function 'DATEDIFF'

Body:
Did you try to convert to date format instead of work with datetime?

select AVG(DATEDIFF(day, convert(date,date_created,102),convert(date,date_removed,102)) )
from table


问:
How to preview a part of a large pandas DataFrame, in iPython notebook?
I am just getting started with pandas in the IPython Notebook and encountering the following problem: When a DataFrame read from a CSV file is small, the IPython Notebook displays it in a nice table view. When the DataFrame is large, something like this is ouput:

```<code>In [27]:

evaluation = readCSV("evaluation_MO_without_VNS_quality.csv").filter(["solver", "instance", "runtime", "objective"])

In [37]:

evaluation

Out[37]:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 333 entries, 0 to 332
Data columns:
solver       333  non-null values
instance     333  non-null values
runtime      333  non-null values
objective    333  non-null values
dtypes: int64(1), object(3)
</code>```

I would like to see a small portion of the data frame as a table just to make sure it is in the right format. What options do I have?

答:
In Python pandas provide head() and tail() to print head and tail data respectively.</p>

```<code>import pandas as pd
train = pd.read_csv('file_name')
train.head() # it will print 5 head row data as default value is 5
train.head(n) # it will print n head row data
train.tail() #it will print 5 tail row data as default value is 5
train.tail(n) #it will print n tail row data
</code>```

Body:
I am just getting started with pandas in the IPython Notebook and encountering the following problem: When a DataFrame read from a CSV file is small, the IPython Notebook displays it in a nice table view. When the DataFrame is large, something like this is ouput:

In [27]:

evaluation = readCSV("evaluation_MO_without_VNS_quality.csv").filter(["solver", "instance", "runtime", "objective"])

In [37]:

evaluation

Out[37]:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 333 entries, 0 to 332
Data columns:
solver       333  non-null values
instance     333  non-null values
runtime      333  non-null values
objective    333  non-null values
dtypes: int64(1), object(3)

I would like to see a small portion of the data frame as a table just to make sure it is in the right format. What options do I have?

Body:
In Python pandas provide head() and tail() to print head and tail data respectively.

import pandas as pd
train = pd.read_csv('file_name')
train.head() # it will print 5 head row data as default value is 5
train.head(n) # it will print n head row data
train.tail() #it will print 5 tail row data as default value is 5
train.tail(n) #it will print n tail row data


问:
How to integrate the Android Support Repository in an IBM MobileFirst Platform 7.1 project using Eclipse
I'm working in an IBM MobileFirst 7.1 project using Eclipse Mars but when I'm trying to deploy my app in a device, the app stops and the error is related to android/support/v4/view/GestureDetectorCompat class. I'm using the support library 19 because this is a jar file, however if I want to use the 25 or 26 alpha I can't find the way to convert the .aar file to .jar and keep working with Eclipse IDE.

Is any way to work with a support library updated with this configuration?

答: As a quick fix, you can extract the .aar file which will contain the classes.jar which you can use in Eclipse. </p>


问:
TreeMap Key, Value pair exists, but .get(Key) returns the value as null
I have this code (below) that when I print the treemap, I can clearly see the key,value pairs. Every key has a value (no null values in the output). When I get the first key, it will give me the key, but when I try to get the value based on the key, it will return null.

```<code>TreeMap<String, Double> cosinesimilarityvalues = simvalfordoc.returnsortedcosinesimilarityvalues();
System.out.println(cosinesimilarityvalues);
String topkey = cosinesimilarityvalues.firstKey();
System.out.println(topkey);
Double topvalue = cosinesimilarityvalues.get(topkey);
System.out.println(topvalue);
topones.put(topkey, topvalue);
</code>```

Here is part of an output :

```<code>{article04_C9,article08_C12=0.0, article04_C9,article18_C10=0.0, article04_C9,article07_C1=0.0, article04_C9,article03_C10=0.0, article04_C9,article01_C10=0.0, article04_C9,article07_C10=0.0, article04_C9,article17_C10=0.0, article04_C9,article10_C10=0.0, article04_C9,article05_C10=0.0, article04_C9,article11_C10=0.0, article04_C9,article02_C10=0.0, article04_C9,article13_C10=0.0, article04_C9,article02_C13=5.676594773265355E-4, article04_C9,article02_C11=6.228132014119322E-4, article04_C9,article06_C10=6.732460014209593E-4, article04_C9,article12_C10=0.0011438670619737105, article04_C9,article03_C3=0.0011907203907551985, article04_C9,article03_C11=0.0012323612320990097}
</code>```

So I should be getting article04_C9,article08_C12 as firstKey() (which I do)
but when I go to retrieve the value associated with that key, it returns null.

Here is the code that I'm using to populate the treemap

```<code>HashMap<String, Double> cosinesimilarityvalues = new HashMap<String, Double>();
TreeMap<String, Double> sortedcosinesimilarityvalues = new TreeMap<String, Double>();
public void comparecosinesimilarityvalues(List<tfidfvalues> matrix, tfidfvalues currentvector) {
    String articlename = currentvector.returnarticlename();
    String foldername = currentvector.returnfoldername();
    ArrayList<Double> tfidfval = currentvector.returntfidfvaluesforrow();
    articlefolder = articlename+ "_" + foldername;
    CosineSimilarity calculator = new CosineSimilarity();
    for(int i = 0; i < matrix.size(); i++) {
        String compvectorarticlename = matrix.get(i).returnarticlename();
        String compvectorfoldername = matrix.get(i).returnfoldername();
        ArrayList<Double> compvector = matrix.get(i).returntfidfvaluesforrow();

        Double cosinesimilarity = calculator.CosineSimilarityCalc(tfidfval, compvector);

        String comparingwhat = compvectorarticlename + "_" + compvectorfoldername;

        String comparingthese = articlefolder + "," + comparingwhat;
        cosinesimilarityvalues.put(comparingthese, cosinesimilarity);
    }

    Iterator<Map.Entry<String, Double>> iterator = cosinesimilarityvalues.entrySet().iterator();
    while(iterator.hasNext()) {
        Map.Entry<String, Double> entry = iterator.next();
        if((entry.getValue() > 0.989 && entry.getValue() < 1) || entry.getValue() > 1) {
            iterator.remove();
        }
    }

    sortedcosinesimilarityvalues = sortMapByValue(cosinesimilarityvalues);
}

public TreeMap<String, Double> returnsortedcosinesimilarityvalues() {
    return sortedcosinesimilarityvalues;
}
</code>```

Here is the function I am using to sort by value...if that helps

from : https://www.programcreek.com/2013/03/java-sort-map-by-value/

```<code>class ValueComparator implements Comparator<String>{

    HashMap<String, Double> map = new HashMap<String, Double>();

    public ValueComparator(HashMap<String, Double> map){
        this.map.putAll(map);
    }

    @Override
    public int compare(String s1, String s2) {
        if(map.get(s1) >= map.get(s2)){
            return 1;
        }else{
            return -1;
        }
    }
}

public TreeMap<String, Double> sortMapByValue(HashMap<String, Double> map){
    Comparator<String> comparator = new ValueComparator(map);
    //TreeMap is a map sorted by its keys.
    //The comparator is used to sort the TreeMap by keys.
    TreeMap<String, Double> result = new TreeMap<String, Double>(comparator);
    result.putAll(map);
    return result;
}
</code>```

I'm not sure what I'm doing wrong. Please help!

Thanks!

UPDATE

I was able to retrieve the top key and top value via

```<code>Map.Entry<String, Double> entry1 = cosinesimilarityvalues.firstEntry();
String topkey = entry1.getKey();
Double topvalue = entry1.getValue();
</code>```

but I have no idea why this works and the other method does not work.
Although my code now works, I wish I could find out what the difference is!

答:
Sorry not able to post comment in the question yet so have to post here as an answer. Maybe you can try first to copy the whole string to the get input to see if you still get null

```<code>Double topvalue = cosinesimilarityvalues.get(“article04_C9,article08_C12”);
</code>```

I find out the problem is with your overriden compare method for custom Comparator. The below replicates your issue

```<code>    import java.util.Comparator;
import java.util.TreeMap;
public class MyTreeMapComparator {
    public static void main(String a[]){
        //the treemap sorts by key
        TreeMap<String, String> hm = new TreeMap<String, String>(new MyComp());
         //add key-value pair to TreeMap
         hm.put("java", "language");
         hm.put("computer", "machine");
         hm.put("india","country");
         hm.put("mango","fruit");
         System.out.println(hm.get("java"));
     }
}
class MyComp implements Comparator<String>{
    @Override
    public int compare(String str1, String str2) {
        if (str1.compareTo(str2) >= 0) {return 1;}
        else {return -1;}
    }
}
</code>```

Then if you change to this then it works fine

```<code>    import java.util.Comparator;
import java.util.TreeMap;
public class MyTreeMapComparator {
    public static void main(String a[]){
        //the treemap sorts by key
        TreeMap<String, String> hm = new TreeMap<String, String>(new MyComp());
         //add key-value pair to TreeMap
         hm.put("java", "language");
         hm.put("computer", "machine");
         hm.put("india","country");
         hm.put("mango","fruit");
         System.out.println(hm.get("java"));
     }
}
class MyComp implements Comparator<String>{
    @Override
    public int compare(String str1, String str2) {
        if (str1.compareTo(str2) == 0) {return 0;}
        else if (str1.compareTo(str2) > 0) {return 1;}
        else {return -1;}
    }
}
</code>```

Body:
I have this code (below) that when I print the treemap, I can clearly see the key,value pairs. Every key has a value (no null values in the output). When I get the first key, it will give me the key, but when I try to get the value based on the key, it will return null.

TreeMap<String, Double> cosinesimilarityvalues = simvalfordoc.returnsortedcosinesimilarityvalues();
System.out.println(cosinesimilarityvalues);
String topkey = cosinesimilarityvalues.firstKey();
System.out.println(topkey);
Double topvalue = cosinesimilarityvalues.get(topkey);
System.out.println(topvalue);
topones.put(topkey, topvalue);

Here is part of an output :

{article04_C9,article08_C12=0.0, article04_C9,article18_C10=0.0, article04_C9,article07_C1=0.0, article04_C9,article03_C10=0.0, article04_C9,article01_C10=0.0, article04_C9,article07_C10=0.0, article04_C9,article17_C10=0.0, article04_C9,article10_C10=0.0, article04_C9,article05_C10=0.0, article04_C9,article11_C10=0.0, article04_C9,article02_C10=0.0, article04_C9,article13_C10=0.0, article04_C9,article02_C13=5.676594773265355E-4, article04_C9,article02_C11=6.228132014119322E-4, article04_C9,article06_C10=6.732460014209593E-4, article04_C9,article12_C10=0.0011438670619737105, article04_C9,article03_C3=0.0011907203907551985, article04_C9,article03_C11=0.0012323612320990097}

So I should be getting article04_C9,article08_C12 as firstKey() (which I do)
but when I go to retrieve the value associated with that key, it returns null.

Here is the code that I'm using to populate the treemap

HashMap<String, Double> cosinesimilarityvalues = new HashMap<String, Double>();
TreeMap<String, Double> sortedcosinesimilarityvalues = new TreeMap<String, Double>();
public void comparecosinesimilarityvalues(List<tfidfvalues> matrix, tfidfvalues currentvector) {
    String articlename = currentvector.returnarticlename();
    String foldername = currentvector.returnfoldername();
    ArrayList<Double> tfidfval = currentvector.returntfidfvaluesforrow();
    articlefolder = articlename+ "_" + foldername;
    CosineSimilarity calculator = new CosineSimilarity();
    for(int i = 0; i < matrix.size(); i++) {
        String compvectorarticlename = matrix.get(i).returnarticlename();
        String compvectorfoldername = matrix.get(i).returnfoldername();
        ArrayList<Double> compvector = matrix.get(i).returntfidfvaluesforrow();

        Double cosinesimilarity = calculator.CosineSimilarityCalc(tfidfval, compvector);

        String comparingwhat = compvectorarticlename + "_" + compvectorfoldername;

        String comparingthese = articlefolder + "," + comparingwhat;
        cosinesimilarityvalues.put(comparingthese, cosinesimilarity);
    }

    Iterator<Map.Entry<String, Double>> iterator = cosinesimilarityvalues.entrySet().iterator();
    while(iterator.hasNext()) {
        Map.Entry<String, Double> entry = iterator.next();
        if((entry.getValue() > 0.989 && entry.getValue() < 1) || entry.getValue() > 1) {
            iterator.remove();
        }
    }

    sortedcosinesimilarityvalues = sortMapByValue(cosinesimilarityvalues);
}

public TreeMap<String, Double> returnsortedcosinesimilarityvalues() {
    return sortedcosinesimilarityvalues;
}

Here is the function I am using to sort by value...if that helps

from : https://www.programcreek.com/2013/03/java-sort-map-by-value/

class ValueComparator implements Comparator<String>{

    HashMap<String, Double> map = new HashMap<String, Double>();

    public ValueComparator(HashMap<String, Double> map){
        this.map.putAll(map);
    }

    @Override
    public int compare(String s1, String s2) {
        if(map.get(s1) >= map.get(s2)){
            return 1;
        }else{
            return -1;
        }
    }
}

public TreeMap<String, Double> sortMapByValue(HashMap<String, Double> map){
    Comparator<String> comparator = new ValueComparator(map);
    //TreeMap is a map sorted by its keys.
    //The comparator is used to sort the TreeMap by keys.
    TreeMap<String, Double> result = new TreeMap<String, Double>(comparator);
    result.putAll(map);
    return result;
}

I'm not sure what I'm doing wrong. Please help!

Thanks!

UPDATE

I was able to retrieve the top key and top value via

Map.Entry<String, Double> entry1 = cosinesimilarityvalues.firstEntry();
String topkey = entry1.getKey();
Double topvalue = entry1.getValue();

but I have no idea why this works and the other method does not work.
Although my code now works, I wish I could find out what the difference is!

Body:
Sorry not able to post comment in the question yet so have to post here as an answer. Maybe you can try first to copy the whole string to the get input to see if you still get null

Double topvalue = cosinesimilarityvalues.get(“article04_C9,article08_C12”);

I find out the problem is with your overriden compare method for custom Comparator. The below replicates your issue

    import java.util.Comparator;
import java.util.TreeMap;
public class MyTreeMapComparator {
    public static void main(String a[]){
        //the treemap sorts by key
        TreeMap<String, String> hm = new TreeMap<String, String>(new MyComp());
         //add key-value pair to TreeMap
         hm.put("java", "language");
         hm.put("computer", "machine");
         hm.put("india","country");
         hm.put("mango","fruit");
         System.out.println(hm.get("java"));
     }
}
class MyComp implements Comparator<String>{
    @Override
    public int compare(String str1, String str2) {
        if (str1.compareTo(str2) >= 0) {return 1;}
        else {return -1;}
    }
}

Then if you change to this then it works fine

    import java.util.Comparator;
import java.util.TreeMap;
public class MyTreeMapComparator {
    public static void main(String a[]){
        //the treemap sorts by key
        TreeMap<String, String> hm = new TreeMap<String, String>(new MyComp());
         //add key-value pair to TreeMap
         hm.put("java", "language");
         hm.put("computer", "machine");
         hm.put("india","country");
         hm.put("mango","fruit");
         System.out.println(hm.get("java"));
     }
}
class MyComp implements Comparator<String>{
    @Override
    public int compare(String str1, String str2) {
        if (str1.compareTo(str2) == 0) {return 0;}
        else if (str1.compareTo(str2) > 0) {return 1;}
        else {return -1;}
    }
}


问:
searching multiple keyword and print out matched keyword with several field in logs
example log (sample.log)

```<code>11:00:00 INFO KOREA AAABB DDDRR
11:00:01 INFO SWEDEN TYTY PLO
11:00:02 INFO US OIILL OTLTOL
11:00:03 INFO NORTHKOREA OTL
</code>```

KEYWORDs (multiple)
    "KOREA", "OTL"

What I want as a result

```<code>11:00:00 KOREA
11:00:02 OTL
11:00:03 KOREA OTL
</code>```

I'm just thinking by using awk fuction.
But I failed....

```<code># $val_1 = KOREA
# $val_2 = OTL

# awk /$val_1|$val_2/'print{$1, $val_1, $val_2}' sample.log
</code>```

答:
```<code>$ cat infile
11:00:00 INFO KOREA AAABB DDDRR
11:00:01 INFO SWEDEN TYTY PLO
11:00:02 INFO US OIILL OTLTOL
11:00:03 INFO NORTHKOREA OTL

$ awk -v search='KOREA|OTL' '{f=$1; s="";while(match($0,search)){s=(s?s OFS:"") substr($0,RSTART,RLENGTH);$0=substr($0,RSTART+RLENGTH)}if(s)print f,s}' infile
11:00:00 KOREA
11:00:02 OTL
11:00:03 KOREA OTL
</code>```

Better Readable:

```<code>awk -v search='KOREA|OTL' '{
            f=$1;
            s="";
            while(match($0,search))
            {
                s  = (s?s OFS:"") substr($0,RSTART,RLENGTH);
                $0 = substr($0,RSTART+RLENGTH)
            }
            if(s)
               print f,s
            }
            ' infile
</code>```

Body:
example log (sample.log)

11:00:00 INFO KOREA AAABB DDDRR
11:00:01 INFO SWEDEN TYTY PLO
11:00:02 INFO US OIILL OTLTOL
11:00:03 INFO NORTHKOREA OTL

KEYWORDs (multiple)
    "KOREA", "OTL"

What I want as a result

11:00:00 KOREA
11:00:02 OTL
11:00:03 KOREA OTL

I'm just thinking by using awk fuction.
But I failed....

# $val_1 = KOREA
# $val_2 = OTL

# awk /$val_1|$val_2/'print{$1, $val_1, $val_2}' sample.log

Body:
$ cat infile
11:00:00 INFO KOREA AAABB DDDRR
11:00:01 INFO SWEDEN TYTY PLO
11:00:02 INFO US OIILL OTLTOL
11:00:03 INFO NORTHKOREA OTL

$ awk -v search='KOREA|OTL' '{f=$1; s="";while(match($0,search)){s=(s?s OFS:"") substr($0,RSTART,RLENGTH);$0=substr($0,RSTART+RLENGTH)}if(s)print f,s}' infile
11:00:00 KOREA
11:00:02 OTL
11:00:03 KOREA OTL

Better Readable:

awk -v search='KOREA|OTL' '{
            f=$1;
            s="";
            while(match($0,search))
            {
                s  = (s?s OFS:"") substr($0,RSTART,RLENGTH);
                $0 = substr($0,RSTART+RLENGTH)
            }
            if(s)
               print f,s
            }
            ' infile


问:
Apache conditional logging regex (pcre)
I have the following for conditional:

```<code>SetEnvIf X-Forwarded-For ".*, (.+)$" log-format-combinedio-xff-multiple-ips XFF-LAST-IP=$1
SetEnvIf X-Forwarded-For "[^,]+" log-format-combinedio-xff-single-ip
SetEnvIf X-Forwarded-For "^$" log-format-combinedio
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-multiple-ips env=log-format-combinedio-xff-multiple-ips
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-single-ip env=log-format-combinedio-xff-single-ip
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio env=log-format-combinedio
</code>```

However, when I send a request with the X-Forwarded-For header set to a comma-separated list of IPs (more than one) it sets BOTH enivronment variables log-format-combinedio-xff-multiple-ips and log-format-combinedio-xff-single-ip and so I get it logged twice.

Any ideas how to fix this?

答:
In the second condition (to match a single IP), if you add a check for the beginning (^) and end ($) of the string to create the following regex, it won't match multiple comma separated values.

```<code>^[^,]+$
</code>```

It means: from the beginning to the end of the string, match a sequence of non-comma characters.

Title: Apache conditional logging regex (pcre)

Body:
I have the following for conditional:

SetEnvIf X-Forwarded-For ".*, (.+)$" log-format-combinedio-xff-multiple-ips XFF-LAST-IP=$1
SetEnvIf X-Forwarded-For "[^,]+" log-format-combinedio-xff-single-ip
SetEnvIf X-Forwarded-For "^$" log-format-combinedio
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-multiple-ips env=log-format-combinedio-xff-multiple-ips
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-single-ip env=log-format-combinedio-xff-single-ip
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio env=log-format-combinedio

However, when I send a request with the X-Forwarded-For header set to a comma-separated list of IPs (more than one) it sets BOTH enivronment variables log-format-combinedio-xff-multiple-ips and log-format-combinedio-xff-single-ip and so I get it logged twice.

Any ideas how to fix this?

Body:
In the second condition (to match a single IP), if you add a check for the beginning (^) and end ($) of the string to create the following regex, it won't match multiple comma separated values.

^[^,]+$

It means: from the beginning to the end of the string, match a sequence of non-comma characters.


问:
Install Ruby Using RVM on Virtual Machine Running Debian Failed Silently
I've successfully installed a Debian guest operating system on a Vista host using VirtualBox. I'm trying to follow this tutorial(http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you) to install RVM and Ruby. It appears to install ruby successfully, but the terminal will not recognise ruby at all.

Here is the terminal output:

```<code>user@debian:~$ rvm install 1.9.2
/home/user/.rvm/rubies/ruby-1.9.2-p136, this may take a while depending on your cpu(s)...

ruby-1.9.2-p136 - #fetching
ruby-1.9.2-p136 - #downloading ruby-1.9.2-p136, this may take a while depending on your connection...
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
100 8612k  100 8612k    0     0   200k      0  0:00:42  0:00:42 --:--:--  328k
ruby-1.9.2-p136 - #extracting ruby-1.9.2-p136 to /home/user/.rvm/src/ruby-1.9.2-p136
ruby-1.9.2-p136 - #extracted to /home/user/.rvm/src/ruby-1.9.2-p136
ruby-1.9.2-p136 - #configuring
ruby-1.9.2-p136 - #compiling
ruby-1.9.2-p136 - #installing
ruby-1.9.2-p136 - updating #rubygems for /home/user/.rvm/gems/ruby-1.9.2-p136@global
ruby-1.9.2-p136 - updating #rubygems for /home/user/.rvm/gems/ruby-1.9.2-p136
ruby-1.9.2-p136 - adjusting #shebangs for (gem).
ruby-1.9.2-p136 - #importing default gemsets (/home/user/.rvm/gemsets/)
Install of ruby-1.9.2-p136 - #complete
user@debian:~$ ruby -v
bash: ruby: command not found
</code>```

I have no idea what went wrong or how to proceed here. I'd appreciate any insight anyone could offer.

Thanks

答: Try rvm use 1.9.2. Right now it's probably defaulting to the system ruby, and if you don't have a system ruby, well, it's defaulting to nothing.

Body:
I've successfully installed a Debian guest operating system on a Vista host using VirtualBox. I'm trying to follow this tutorial(http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you) to install RVM and Ruby. It appears to install ruby successfully, but the terminal will not recognise ruby at all.

Here is the terminal output:

user@debian:~$ rvm install 1.9.2
/home/user/.rvm/rubies/ruby-1.9.2-p136, this may take a while depending on your cpu(s)...

ruby-1.9.2-p136 - #fetching
ruby-1.9.2-p136 - #downloading ruby-1.9.2-p136, this may take a while depending on your connection...
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
100 8612k  100 8612k    0     0   200k      0  0:00:42  0:00:42 --:--:--  328k
ruby-1.9.2-p136 - #extracting ruby-1.9.2-p136 to /home/user/.rvm/src/ruby-1.9.2-p136
ruby-1.9.2-p136 - #extracted to /home/user/.rvm/src/ruby-1.9.2-p136
ruby-1.9.2-p136 - #configuring
ruby-1.9.2-p136 - #compiling
ruby-1.9.2-p136 - #installing
ruby-1.9.2-p136 - updating #rubygems for /home/user/.rvm/gems/ruby-1.9.2-p136@global
ruby-1.9.2-p136 - updating #rubygems for /home/user/.rvm/gems/ruby-1.9.2-p136
ruby-1.9.2-p136 - adjusting #shebangs for (gem).
ruby-1.9.2-p136 - #importing default gemsets (/home/user/.rvm/gemsets/)
Install of ruby-1.9.2-p136 - #complete
user@debian:~$ ruby -v
bash: ruby: command not found

I have no idea what went wrong or how to proceed here. I'd appreciate any insight anyone could offer.

Thanks


问:
Nothing is being detected in Tensorflow Object detection API
I'm trying to implement Tensorflow object detection API sample. I am following sentdex videos for getting started. The sample code runs perfectly, it also shows the images which are used for testing the results, but no boundaries around detected objects are shown. Just the plane image is displayed without any errors.

I'm using this code: This Github link.

This is my result after running the sample code.

another image without any detection.

What I'm missing here? The code is included in above link and there is no error logs.

Results of box, score, classes, num in that order.

```<code>  [[[ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.20880508  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.20934391  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.20880508  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]]]
[[ 0.03587547  0.02224986  0.0186467   0.01096812  0.01003207  0.00654409
   0.00633549  0.00534311  0.0049596   0.00410213  0.00362371  0.00339186
   0.00308251  0.00303347  0.00293389  0.00277099  0.00269575  0.00266825
   0.00263925  0.00263331  0.00258657  0.00240822  0.0022581   0.00186967
   0.00184311  0.00180467  0.00177475  0.00173655  0.00172811  0.00171935
   0.00171891  0.00170288  0.00163755  0.00162967  0.00160273  0.00156545
   0.00153615  0.00140941  0.00132407  0.00131524  0.0013105   0.00129431
   0.0012582   0.0012553   0.00122365  0.00119186  0.00115651  0.00115186
   0.00112369  0.00107097  0.00105805  0.00104338  0.00102719  0.00102337
   0.00100349  0.00097762  0.00096851  0.00092741  0.00088506  0.00087696
   0.0008734   0.00084826  0.00084135  0.00083513  0.00083398  0.00082068
   0.00080583  0.00078979  0.00078059  0.00077476  0.00075448  0.00074426
   0.00074421  0.00070195  0.00068741  0.00068138  0.00067262  0.00067125
   0.00067033  0.00066035  0.00064729  0.00064205  0.00061964  0.00061794
   0.00060835  0.00060465  0.00059548  0.00059479  0.00059461  0.00059436
   0.00059426  0.00059411  0.00059406  0.00059392  0.00059365  0.00059351
   0.00059191  0.00058798  0.00058682  0.00058148]]
[[  1.   1.  18.  32.  62.  60.  63.  67.  61.  49.  31.  84.  50.  54.
   15.  44.  44.  49.  31.  56.  88.  28.  88.  52.  17.  32.  38.  75.
    3.  33.  48.  59.  35.  57.  47.  51.  19.  27.  72.   4.  84.   6.
   55.  20.  58.  65.  61.  82.  42.  34.  40.  21.  43.  64.  39.  62.
   36.  22.  79.  46.  16.  40.  41.  77.  16.  48.  78.  77.  89.  86.
   27.   8.  87.   5.  25.  70.  80.  76.  75.  67.  65.  37.   2.   9.
   73.  63.  29.  30.  69.  66.  68.  26.  71.  12.  45.  83.  13.  85.
   74.  23.]]
[ 100.]
[[[ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.00784111  0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]]]
[[ 0.01044297  0.0098214   0.00942165  0.00846471  0.00613666  0.00398615
   0.00357754  0.0030054   0.00255861  0.00236574  0.00232631  0.00220291
   0.00185227  0.0016354   0.0015979   0.00145072  0.00143661  0.00141369
   0.00122685  0.00118978  0.00108457  0.00104251  0.00099215  0.00096401
   0.0008708   0.00084773  0.00080484  0.00078507  0.00078378  0.00076876
   0.00072774  0.00071732  0.00071348  0.00070812  0.00069253  0.0006762
   0.00067269  0.00059905  0.00059367  0.000588    0.00056114  0.0005504
   0.00051472  0.00051057  0.00050973  0.00048486  0.00047297  0.00046204
   0.00044787  0.00043259  0.00042987  0.00042673  0.00041978  0.00040494
   0.00040087  0.00039576  0.00039059  0.00037274  0.00036831  0.00036417
   0.00036119  0.00034645  0.00034479  0.00034078  0.00033771  0.00033605
   0.0003333   0.0003304   0.0003294   0.00032326  0.00031787  0.00031773
   0.00031748  0.00031741  0.00031732  0.00031729  0.00031724  0.00031722
   0.00031717  0.00031708  0.00031702  0.00031579  0.00030416  0.00030222
   0.00029739  0.00029726  0.00028289  0.0002653   0.00026325  0.00024584
   0.00024221  0.00024156  0.00023911  0.00023335  0.00021619  0.0002001
   0.00019127  0.00018342  0.00017273  0.00015509]]
[[ 38.   1.   1.  16.  25.  38.  64.  24.  49.  56.  20.   3.  28.   2.
   48.  19.  21.  62.  50.   6.   8.   7.  67.  18.  35.  53.  39.  55.
   15.  57.  72.  52.  10.   5.  42.  43.  76.  22.  82.   4.  61.  23.
   17.  16.  87.  62.  51.  60.  36.  58.  59.  33.  31.  54.  70.  11.
   40.  79.  31.   9.  41.  77.  80.  34.  90.  89.  73.  13.  84.  32.
   63.  29.  30.  69.  66.  68.  26.  71.  12.  45.  83.  14.  44.  78.
   85.  46.  47.  19.  65.  74.  37.  27.  63.  88.  28.  81.  86.  75.
   27.  18.]]
[ 100.]
</code>```

EDIT: As per suggested answers, it is working when we use faster_rcnn_resnet101_coco_2017_11_08 model. But it is more accurate and that's why slower. I want this application with high speed because I'm going to use it in real time (on webcam) object detection. So I need to use faster model (ssd_mobilenet_v1_coco_2017_11_08)

答:
The problem is from the model: 'ssd_mobilenet_v1_coco_2017_11_08'

Solution: change to an differrent version 'ssd_mobilenet_v1_coco_11_06_2017' (this model type is the fastest one, change to other model types will make it slower and not the thing that you want)

Just change 1 line of code:

```<code># What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'
</code>```

When I use your code, nothing is shown but when I replace it with my previous experiment model 'ssd_mobilenet_v1_coco_11_06_2017' it works fine

Body:
I'm trying to implement Tensorflow object detection API sample. I am following sentdex videos for getting started. The sample code runs perfectly, it also shows the images which are used for testing the results, but no boundaries around detected objects are shown. Just the plane image is displayed without any errors.

I'm using this code: This Github link.

This is my result after running the sample code.

another image without any detection.

What I'm missing here? The code is included in above link and there is no error logs.

Results of box, score, classes, num in that order.

  [[[ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.20880508  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.20934391  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.20880508  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.74907303  0.14624023  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]]]
[[ 0.03587547  0.02224986  0.0186467   0.01096812  0.01003207  0.00654409
   0.00633549  0.00534311  0.0049596   0.00410213  0.00362371  0.00339186
   0.00308251  0.00303347  0.00293389  0.00277099  0.00269575  0.00266825
   0.00263925  0.00263331  0.00258657  0.00240822  0.0022581   0.00186967
   0.00184311  0.00180467  0.00177475  0.00173655  0.00172811  0.00171935
   0.00171891  0.00170288  0.00163755  0.00162967  0.00160273  0.00156545
   0.00153615  0.00140941  0.00132407  0.00131524  0.0013105   0.00129431
   0.0012582   0.0012553   0.00122365  0.00119186  0.00115651  0.00115186
   0.00112369  0.00107097  0.00105805  0.00104338  0.00102719  0.00102337
   0.00100349  0.00097762  0.00096851  0.00092741  0.00088506  0.00087696
   0.0008734   0.00084826  0.00084135  0.00083513  0.00083398  0.00082068
   0.00080583  0.00078979  0.00078059  0.00077476  0.00075448  0.00074426
   0.00074421  0.00070195  0.00068741  0.00068138  0.00067262  0.00067125
   0.00067033  0.00066035  0.00064729  0.00064205  0.00061964  0.00061794
   0.00060835  0.00060465  0.00059548  0.00059479  0.00059461  0.00059436
   0.00059426  0.00059411  0.00059406  0.00059392  0.00059365  0.00059351
   0.00059191  0.00058798  0.00058682  0.00058148]]
[[  1.   1.  18.  32.  62.  60.  63.  67.  61.  49.  31.  84.  50.  54.
   15.  44.  44.  49.  31.  56.  88.  28.  88.  52.  17.  32.  38.  75.
    3.  33.  48.  59.  35.  57.  47.  51.  19.  27.  72.   4.  84.   6.
   55.  20.  58.  65.  61.  82.  42.  34.  40.  21.  43.  64.  39.  62.
   36.  22.  79.  46.  16.  40.  41.  77.  16.  48.  78.  77.  89.  86.
   27.   8.  87.   5.  25.  70.  80.  76.  75.  67.  65.  37.   2.   9.
   73.  63.  29.  30.  69.  66.  68.  26.  71.  12.  45.  83.  13.  85.
   74.  23.]]
[ 100.]
[[[ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.00784111  0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.          1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]
  [ 0.          0.68494415  1.          1.        ]]]
[[ 0.01044297  0.0098214   0.00942165  0.00846471  0.00613666  0.00398615
   0.00357754  0.0030054   0.00255861  0.00236574  0.00232631  0.00220291
   0.00185227  0.0016354   0.0015979   0.00145072  0.00143661  0.00141369
   0.00122685  0.00118978  0.00108457  0.00104251  0.00099215  0.00096401
   0.0008708   0.00084773  0.00080484  0.00078507  0.00078378  0.00076876
   0.00072774  0.00071732  0.00071348  0.00070812  0.00069253  0.0006762
   0.00067269  0.00059905  0.00059367  0.000588    0.00056114  0.0005504
   0.00051472  0.00051057  0.00050973  0.00048486  0.00047297  0.00046204
   0.00044787  0.00043259  0.00042987  0.00042673  0.00041978  0.00040494
   0.00040087  0.00039576  0.00039059  0.00037274  0.00036831  0.00036417
   0.00036119  0.00034645  0.00034479  0.00034078  0.00033771  0.00033605
   0.0003333   0.0003304   0.0003294   0.00032326  0.00031787  0.00031773
   0.00031748  0.00031741  0.00031732  0.00031729  0.00031724  0.00031722
   0.00031717  0.00031708  0.00031702  0.00031579  0.00030416  0.00030222
   0.00029739  0.00029726  0.00028289  0.0002653   0.00026325  0.00024584
   0.00024221  0.00024156  0.00023911  0.00023335  0.00021619  0.0002001
   0.00019127  0.00018342  0.00017273  0.00015509]]
[[ 38.   1.   1.  16.  25.  38.  64.  24.  49.  56.  20.   3.  28.   2.
   48.  19.  21.  62.  50.   6.   8.   7.  67.  18.  35.  53.  39.  55.
   15.  57.  72.  52.  10.   5.  42.  43.  76.  22.  82.   4.  61.  23.
   17.  16.  87.  62.  51.  60.  36.  58.  59.  33.  31.  54.  70.  11.
   40.  79.  31.   9.  41.  77.  80.  34.  90.  89.  73.  13.  84.  32.
   63.  29.  30.  69.  66.  68.  26.  71.  12.  45.  83.  14.  44.  78.
   85.  46.  47.  19.  65.  74.  37.  27.  63.  88.  28.  81.  86.  75.
   27.  18.]]
[ 100.]

EDIT: As per suggested answers, it is working when we use faster_rcnn_resnet101_coco_2017_11_08 model. But it is more accurate and that's why slower. I want this application with high speed because I'm going to use it in real time (on webcam) object detection. So I need to use faster model (ssd_mobilenet_v1_coco_2017_11_08)

Body:
The problem is from the model: 'ssd_mobilenet_v1_coco_2017_11_08'

Solution: change to an differrent version 'ssd_mobilenet_v1_coco_11_06_2017' (this model type is the fastest one, change to other model types will make it slower and not the thing that you want)

Just change 1 line of code:

# What model to download.
MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017'

When I use your code, nothing is shown but when I replace it with my previous experiment model 'ssd_mobilenet_v1_coco_11_06_2017' it works fine


答:
Ok I figured it out and posting here in case it helps anyone else:

The regex for the second SetEnvIfshould be:

```<code>SetEnvIf X-Forwarded-For "^[^,]+$" log-format-combinedio-xff-single-ip
</code>```

This will basically only match strings that DO NOT have a comma in them (as in a single IP).

So the full solution is something like this:

```<code>SetEnvIf X-Forwarded-For ".*, (.+)$" log-format-combinedio-xff-multiple-ips XFF-LAST-IP=$1
SetEnvIf X-Forwarded-For "^[^,]+$" log-format-combinedio-xff-single-ip
SetEnvIf X-Forwarded-For "^$" log-format-combinedio
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-multiple-ips env=log-format-combinedio-xff-multiple-ips
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-single-ip env=log-format-combinedio-xff-single-ip
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio env=log-format-combinedio
</code>```

Title: Apache conditional logging regex (pcre)

Body:
Ok I figured it out and posting here in case it helps anyone else:

The regex for the second SetEnvIfshould be:

SetEnvIf X-Forwarded-For "^[^,]+$" log-format-combinedio-xff-single-ip

This will basically only match strings that DO NOT have a comma in them (as in a single IP).

So the full solution is something like this:

SetEnvIf X-Forwarded-For ".*, (.+)$" log-format-combinedio-xff-multiple-ips XFF-LAST-IP=$1
SetEnvIf X-Forwarded-For "^[^,]+$" log-format-combinedio-xff-single-ip
SetEnvIf X-Forwarded-For "^$" log-format-combinedio
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-multiple-ips env=log-format-combinedio-xff-multiple-ips
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio-xff-single-ip env=log-format-combinedio-xff-single-ip
CustomLog "|/usr/bin/rotatelogs -f /var/log/apache2/access_log.%Y%m%d%H%M%S 604800" combinedio env=log-format-combinedio


问:
JPA @Id @GeneratedValue annotations vs DB primary key?
I have an app accessing an existing MySQL DB utilizing JDBC and am converting to JPA.  My DB is already setup with primary keys which are auto generated.  Do I need to annotate my entity classes w/ @Id, @GeneratedValue... when this is already defined in the DB?  Will the annotations override / conflict with the DB primary key / indexes already defined?</p>

答:
I assume you are using autonumbers in MySQL and these are autogenerated.

The following code will do what you require:

```<code>@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "table_id")
</code>```

Notice the GenerationType.IDENTITY strategy? This tells JPA to use the autogenerated database values.

Body:
I assume you are using autonumbers in MySQL and these are autogenerated.

The following code will do what you require:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "table_id")

Notice the GenerationType.IDENTITY strategy? This tells JPA to use the autogenerated database values.