问:
A suitable PC for Visual Studio 2010 programming
I'm planning on buying a new PC for programming under Visual Studio 2010. My main other usages are:

Programming under Microsoft Visual Studio.

Running VMWare Virtual Machines.

Probably multi-monitor (if my budget lets me buy an extra one)

Here are my questions:

Do I need to purchase a high performance display adapter considering my usage described above? or a medium-range one will suffice? In general, I'd like to know how much a display adapter could affect my usages?

Which CPU could perform better? Core i7, Core 2 Quad, AMD?  I have a limited budget but I really need a good performance and buying a good CPU/MB/RAM is my first priority.

答: Another thing to look for is drive speed.  Visual Studio does a lot of writing and reading to disk so get the fastest you can.  SSD is ideal.</p>


来源: stackexchange

问:
Swift ios check if remote push notifications are enabled in ios9 and ios10
How can I check if the user has enabled remote notifications on ios 9 or ios 10?

If the user has not allowed or clicked No I want to toggle a message asking if they want to enable notifications.

答:
@Rajat's answer is not enough.

isRegisteredForRemoteNotifications is that your app has connected to APNS and get device token, this can be for silent push notification

currentUserNotificationSettings is for user permissions, without this, there is no alert, banner or sound push notification delivered to the app

Here is the check

```<code>static var isPushNotificationEnabled: Bool {
  guard let settings = UIApplication.shared.currentUserNotificationSettings
    else {
      return false
  }

  return UIApplication.shared.isRegisteredForRemoteNotifications
    && !settings.types.isEmpty
}
</code>```

For iOS 10, instead of checking for currentUserNotificationSettings, you should use UserNotifications framework

```<code>center.getNotificationSettings(completionHandler: { settings in
  switch settings.authorizationStatus {
  case .authorized, .provisional:
    print("authorized")
  case .denied:
    print("denied")
  case .notDetermined:
    print("not determined, ask user for permission now")
  }
})

</code>```

Push notification can be delivered to our apps in many ways, and we can ask for that

```<code>UNUserNotificationCenter.current()
  .requestAuthorization(options: [.alert, .sound, .badge])
</code>```

User can go to Settings app and turn off any of those at any time, so it's best to check for that in the settings object

```<code>open class UNNotificationSettings : NSObject, NSCopying, NSSecureCoding {

    open var authorizationStatus: UNAuthorizationStatus { get }

    open var soundSetting: UNNotificationSetting { get }

    open var badgeSetting: UNNotificationSetting { get }

    open var alertSetting: UNNotificationSetting { get }

    open var notificationCenterSetting: UNNotificationSetting { get }
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
@Rajat's answer is not enough.

isRegisteredForRemoteNotifications is that your app has connected to APNS and get device token, this can be for silent push notification

currentUserNotificationSettings is for user permissions, without this, there is no alert, banner or sound push notification delivered to the app

Here is the check

static var isPushNotificationEnabled: Bool {
  guard let settings = UIApplication.shared.currentUserNotificationSettings
    else {
      return false
  }

  return UIApplication.shared.isRegisteredForRemoteNotifications
    && !settings.types.isEmpty
}

For iOS 10, instead of checking for currentUserNotificationSettings, you should use UserNotifications framework

center.getNotificationSettings(completionHandler: { settings in
  switch settings.authorizationStatus {
  case .authorized, .provisional:
    print("authorized")
  case .denied:
    print("denied")
  case .notDetermined:
    print("not determined, ask user for permission now")
  }
})

Push notification can be delivered to our apps in many ways, and we can ask for that

UNUserNotificationCenter.current()
  .requestAuthorization(options: [.alert, .sound, .badge])

User can go to Settings app and turn off any of those at any time, so it's best to check for that in the settings object

open class UNNotificationSettings : NSObject, NSCopying, NSSecureCoding {

    open var authorizationStatus: UNAuthorizationStatus { get }

    open var soundSetting: UNNotificationSetting { get }

    open var badgeSetting: UNNotificationSetting { get }

    open var alertSetting: UNNotificationSetting { get }

    open var notificationCenterSetting: UNNotificationSetting { get }
}

ContentLicense: CC BY-SA 4.0


问:
MPAndroidChart: Entry data is null when refreshing marker view content
I am using MPAndroidChart in order to create a grouped bars chart. Everything is fine but I am not able to display a MarkerView properly.

I'd like to show some information in the MarkerView depending on entry index, but I just can retrieve x or y values.

refreshContent method

```<code>@Override
public void refreshContent(Entry e, Highlight highlight) {
        Log.d("MARKER", "x:" + e.getX() + " | y:" + e.getY()
                + " | hx:" + highlight.getX() + " | hy:" + highlight.getY()
                + " | dataindex:" + highlight.getDataIndex()
                + " | datasetindex:" + highlight.getDataSetIndex());
        super.refreshContent(e, highlight);
}
</code>```

This is my log output:

```<code>x:2.7349997 | y:65.0 | hx:2.7349997 | hy:65.0 | dataindex:1 | datasetindex:1
</code>```

Dataindex is always 1 no matter which bar I tap. Datasetindex shows correct value depending on index within group bar.

I realized I can use getData() method from Entry, so I used another constructor for each BarEntry:

```<code>new BarEntry(x, y, "extraData");
</code>```

however, e.getData() is null in refreshContent.

What am I doing wrong?

答:
The trick was on my chart because is composed by a bar chart and a line chart. So, when I tap a point in my chart I am receiving refreshContent event because of a tap in my line chart. Then, if I set the data object in for each line chart entry, now it is received on refreshContent method. However my solution was to disable highlighting to line data set:

```<code>lineDataSet.setHighlightEnabled(false);
</code>```

This way every tap on chart belongs always to bar chart.

Body:
I am using MPAndroidChart in order to create a grouped bars chart. Everything is fine but I am not able to display a MarkerView properly.

I'd like to show some information in the MarkerView depending on entry index, but I just can retrieve x or y values.

refreshContent method

@Override
public void refreshContent(Entry e, Highlight highlight) {
        Log.d("MARKER", "x:" + e.getX() + " | y:" + e.getY()
                + " | hx:" + highlight.getX() + " | hy:" + highlight.getY()
                + " | dataindex:" + highlight.getDataIndex()
                + " | datasetindex:" + highlight.getDataSetIndex());
        super.refreshContent(e, highlight);
}

This is my log output:

x:2.7349997 | y:65.0 | hx:2.7349997 | hy:65.0 | dataindex:1 | datasetindex:1

Dataindex is always 1 no matter which bar I tap. Datasetindex shows correct value depending on index within group bar.

I realized I can use getData() method from Entry, so I used another constructor for each BarEntry:

new BarEntry(x, y, "extraData");

however, e.getData() is null in refreshContent.

What am I doing wrong?

Body:
The trick was on my chart because is composed by a bar chart and a line chart. So, when I tap a point in my chart I am receiving refreshContent event because of a tap in my line chart. Then, if I set the data object in for each line chart entry, now it is received on refreshContent method. However my solution was to disable highlighting to line data set:

lineDataSet.setHighlightEnabled(false);

This way every tap on chart belongs always to bar chart.


问:
Wrapped method ends up in the 'false' block as but direct function call doesn't
Note: I come from a Python / PHP related background and don't have too much experience with C.

I'm currently writing a PHP extension that needs to check if another module is loaded, for this I've copied and pasted the following snippet of code throughout my extension:

```<code>#include "php.h"

const char* name = "hash";

if (zend_hash_str_exists(&module_registry, name, sizeof(name) - 1)) {
    return; // Doesn't end up here, module is loaded
}

// Returns true and thus ends up here
</code>```

I decided to put this into it's own method to make my code a lot more clean, however whenever I do this, the method seems to return FALSE or NULL. This is the method I'm using:

```<code>#include "php.h"

zend_bool extension_module_exists(const char* name)
{
    return zend_hash_str_exists(&module_registry, name, sizeof(name) - 1);
}

const char* name = "hash";

if (extension_module_exists(name) == false) {
    return; // Now I end up here
}
</code>```

Could someone give me an indication of what I might be doing wrong?
Thank you.

答:
I don't think your first version works, either, as it is shown here. Chances are you have

```<code>const char name[] = "hash";
</code>```

instead of

```<code>const char* name = "hash";
</code>```

The code is wrong because sizeof() does something different than you seem to expect. It returns the actual storage size of its argument, and if this argument is a pointer, the size returned is the size of the pointer, not that of the object it points to.

For the length of a string, there's the function strlen() in string.h, you should use this instead of sizeof().

Example:

```<code>zend_bool extension_module_exists(const char* name)
{
    return zend_hash_str_exists(&module_registry, name, strlen(name));
}
</code>```

Note this comes with a little overhead, as strlen() must scan its argument to find the first 0-byte, which marks the end of a string in C.

That being said, you should probably think about restructuring your module to only once check for the other extension and save the result in a variable.

Body:
Note: I come from a Python / PHP related background and don't have too much experience with C.

I'm currently writing a PHP extension that needs to check if another module is loaded, for this I've copied and pasted the following snippet of code throughout my extension:

#include "php.h"

const char* name = "hash";

if (zend_hash_str_exists(&module_registry, name, sizeof(name) - 1)) {
    return; // Doesn't end up here, module is loaded
}

// Returns true and thus ends up here

I decided to put this into it's own method to make my code a lot more clean, however whenever I do this, the method seems to return FALSE or NULL. This is the method I'm using:

#include "php.h"

zend_bool extension_module_exists(const char* name)
{
    return zend_hash_str_exists(&module_registry, name, sizeof(name) - 1);
}

const char* name = "hash";

if (extension_module_exists(name) == false) {
    return; // Now I end up here
}

Could someone give me an indication of what I might be doing wrong?
Thank you.

Body:
I don't think your first version works, either, as it is shown here. Chances are you have

const char name[] = "hash";

instead of

const char* name = "hash";

The code is wrong because sizeof() does something different than you seem to expect. It returns the actual storage size of its argument, and if this argument is a pointer, the size returned is the size of the pointer, not that of the object it points to.

For the length of a string, there's the function strlen() in string.h, you should use this instead of sizeof().

Example:

zend_bool extension_module_exists(const char* name)
{
    return zend_hash_str_exists(&module_registry, name, strlen(name));
}

Note this comes with a little overhead, as strlen() must scan its argument to find the first 0-byte, which marks the end of a string in C.

That being said, you should probably think about restructuring your module to only once check for the other extension and save the result in a variable.


问:
How to read NSData into clientside made in java
I create an iOS server using GCDAsyncSocket and Client is created using Java language. When I sent data in form of NSDAta it can be read by SocketTester(application for testing client connection) but it cannot be completely read at java end .

```<code>static void   recorderServerClient() throws  IOException{
    int port =9892;
        clientSocket = new Socket("localhost", port);
        System.out.print("Connected to localhost"+port);

        while (true){
        InputStream inputStream = clientSocket.getInputStream();
        try {
            Thread.sleep(3000);
            }
         catch (InterruptedException e) {
            e.printStackTrace();
        }/*fetch data with help of output stream and write it with help of PrintWriter */
      PrintWriter printWriterObj = new PrintWriter(clientSocket.getOutputStream());
          printWriterObj.println();
            printWriterObj.flush();
           /*created an array for now static and assign some memory */              byte[] buffer = new byte[1000000];
            int read;
            while((read = inputStream.read(buffer)) != -1) {
                String output = new String(buffer, 0, read);
               System.out.print(output);
                System.out.flush();
            }
        }
        */
</code>```

}

I want to get data length sent through ios server.and create buffer accordingly.Can any one help me out?

答:
```<code>import java.io.*;
import java.net.Socket;

public class SocketDemo {
    public static void main(String args[]) throws Exception {

        Socket socket = new Socket("localhost", 2100);
        System.out.println("Connected");

        DataInputStream ins = new DataInputStream(socket.getInputStream());
        DataOutputStream  out = new DataOutputStream(socket.getOutputStream());
        System.out.println("opened OutputStreams");

        System.out.println(readResponse(ins));
        Thread.sleep(100);
        out.write("ss 1\n".getBytes());//send command
        out.flush();
        System.out.println("sent command");
        Thread.sleep(3000);//important to wait for the server to response
        System.out.println(readResponse(ins));
        socket.close();
        System.out.println("Connection to the server closed");
    }

    private static String readResponse(InputStream in) throws IOException {
        byte[] buf = new byte[1024];//1k
        StringBuilder sb = new StringBuilder();
        while (in.available() > 0) {//server is waiting for client once it sent all data
            int pos  = in.read(buf);
            String s = new String(buf, 0, pos);
            sb.append(s);
            //System.out.println("reading data..." + pos + " s>>>" + s.getBytes() + "available?" +  ins.available());
            //System.out.print(pos + " ? " + (char) pos);
        }
        return sb.toString();
    }
}
</code>```

Body:
I create an iOS server using GCDAsyncSocket and Client is created using Java language. When I sent data in form of NSDAta it can be read by SocketTester(application for testing client connection) but it cannot be completely read at java end .

static void   recorderServerClient() throws  IOException{
    int port =9892;
        clientSocket = new Socket("localhost", port);
        System.out.print("Connected to localhost"+port);

        while (true){
        InputStream inputStream = clientSocket.getInputStream();
        try {
            Thread.sleep(3000);
            }
         catch (InterruptedException e) {
            e.printStackTrace();
        }/*fetch data with help of output stream and write it with help of PrintWriter */
      PrintWriter printWriterObj = new PrintWriter(clientSocket.getOutputStream());
          printWriterObj.println();
            printWriterObj.flush();
           /*created an array for now static and assign some memory */              byte[] buffer = new byte[1000000];
            int read;
            while((read = inputStream.read(buffer)) != -1) {
                String output = new String(buffer, 0, read);
               System.out.print(output);
                System.out.flush();
            }
        }
        */

}

I want to get data length sent through ios server.and create buffer accordingly.Can any one help me out?


问:
sql : how to find duplicates rows?
i got a table users (id,first_name,last_name,...)
i want to find duplicate users in that table (users which has the same first_name AND the same last_name).

let's say my data is :

```<code> 1;bill;campton
 2;sarah;connor
 3;bill;campton
</code>```

i need to get

```<code>  1;bill;campton;3;bill;campton
</code>```

i dont want to get

```<code>  1;bill;campton;3;bill;campton
  3;bill;campton;1;bill;campton
</code>```

How could i do that?
I use SQL Server 2005

thank you

答:
Given the output format you said you wanted, this works:

```<code>select
  o.id,
  o.firstname,
  o.lastname,
  d.id,
  d.firstname,
  d.lastname
from
  users o
  join users d on d.firstname = o.firstname and d.lastname = o.lastname and o.id < d.id
</code>```

Note that if you have more than one duplicate that you will get results that you probably don't want, and so SQLMenace's solution is probably much better overall.

ContentLicense: CC BY-SA 2.5

Title: sql : how to find duplicates rows?

Body:
i got a table users (id,first_name,last_name,...)
i want to find duplicate users in that table (users which has the same first_name AND the same last_name).

let's say my data is :

 1;bill;campton
 2;sarah;connor
 3;bill;campton

i need to get

  1;bill;campton;3;bill;campton

i dont want to get

  1;bill;campton;3;bill;campton
  3;bill;campton;1;bill;campton

How could i do that?
I use SQL Server 2005

thank you

Body:
Given the output format you said you wanted, this works:

select
  o.id,
  o.firstname,
  o.lastname,
  d.id,
  d.firstname,
  d.lastname
from
  users o
  join users d on d.firstname = o.firstname and d.lastname = o.lastname and o.id < d.id

Note that if you have more than one duplicate that you will get results that you probably don't want, and so SQLMenace's solution is probably much better overall.


问:
Angular2 refresh router-outlet
I'm working on a CRM and I have a select box in the header which allows the user to change the current user,
In addition, the main content is inside the router-outlet.

When the user select another user I want to refresh the page but only the router-outlet so the info will be for the new user

I saw that other CRMs just redirect the user to the dashboard / index page,
but I want to keep the user on the same page.

答:
You should have a function in a service

```<code>import {Subject} from 'rxjs/Subject';

onUserChange= new Subject<void>();

userChange(): void {
    this.http.post('')
        .map()
        .subscribe((data: UserChangeResponse) => {
             this.onUserChange.next();
        })
}
</code>```

And In component you can use it in ngOnInit

```<code>serviceReference.onUserChange.subscribe(() => {

     // use can call get users method or anything

});
</code>```

Title: Angular2 refresh router-outlet

Body:
You should have a function in a service

import {Subject} from 'rxjs/Subject';

onUserChange= new Subject<void>();

userChange(): void {
    this.http.post('')
        .map()
        .subscribe((data: UserChangeResponse) => {
             this.onUserChange.next();
        })
}

And In component you can use it in ngOnInit

serviceReference.onUserChange.subscribe(() => {

     // use can call get users method or anything

});


问:
How does the prime numbers example from the Kotlin Coroutines documentation work?
I'm going through the coroutines documentation for Kotlin and was following along pretty well until this example.  I'm having a really difficult time understanding how it's calculating when it finds a prime number, and specifically how the return from the filter function is both being returned and assigned to cur, as well as still producing numbers from the numbersFrom method.

I've added debugging statements to try and follow the various coroutines that are running, but I'm still lost on the logical flow of when it starts new coroutines and receives numbers from others.

https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#prime-numbers-with-pipeline

The code:

```<code>fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")

fun main(args: Array<String>) = runBlocking<Unit> {
    var cur = numbersFrom(context, 2)
    for (i in 1..10) {
        val prime = cur.receive()
        println(prime)
        cur = filter(context, cur, prime)
    }
}

fun numbersFrom(context: CoroutineContext, start: Int) = produce<Int>(context) {
       var x = start
    while (true) {
        log("NumbersFrom Send: ${x}")
        send(x++)
    } // infinite stream of integers from start
}

fun filter(context: CoroutineContext, numbers: ReceiveChannel<Int>, prime: Int) = produce<Int>(context) {
    for (x in numbers) {
        log("filter ${x}, prime ${prime}")
        if (x % prime != 0) {
            send(x)
        }
    }
}
</code>```

Outout:

```<code>[main @coroutine#2] NumbersFrom Send: 2
[main @coroutine#2] NumbersFrom Send: 3
2
[main @coroutine#3] filter 3, prime 2
[main @coroutine#2] NumbersFrom Send: 4
[main @coroutine#2] NumbersFrom Send: 5
3
[main @coroutine#3] filter 4, prime 2
[main @coroutine#3] filter 5, prime 2
[main @coroutine#4] filter 5, prime 3
[main @coroutine#2] NumbersFrom Send: 6
[main @coroutine#3] filter 6, prime 2
5
[main @coroutine#2] NumbersFrom Send: 7
[main @coroutine#2] NumbersFrom Send: 8
[main @coroutine#3] filter 7, prime 2
[main @coroutine#3] filter 8, prime 2
[main @coroutine#4] filter 7, prime 3
[main @coroutine#2] NumbersFrom Send: 9
[main @coroutine#2] NumbersFrom Send: 10
[main @coroutine#5] filter 7, prime 5
[main @coroutine#3] filter 9, prime 2
[main @coroutine#3] filter 10, prime 2
7
[main @coroutine#4] filter 9, prime 3
[main @coroutine#2] NumbersFrom Send: 11
[main @coroutine#2] NumbersFrom Send: 12
[main @coroutine#3] filter 11, prime 2
[main @coroutine#3] filter 12, prime 2
[main @coroutine#4] filter 11, prime 3
[main @coroutine#2] NumbersFrom Send: 13
[main @coroutine#2] NumbersFrom Send: 14
[main @coroutine#5] filter 11, prime 5
[main @coroutine#3] filter 13, prime 2
[main @coroutine#3] filter 14, prime 2
[main @coroutine#6] filter 11, prime 7
[main @coroutine#4] filter 13, prime 3
[main @coroutine#2] NumbersFrom Send: 15
[main @coroutine#2] NumbersFrom Send: 16
11
[main @coroutine#5] filter 13, prime 5
[main @coroutine#3] filter 15, prime 2
[main @coroutine#3] filter 16, prime 2
[main @coroutine#6] filter 13, prime 7
[main @coroutine#4] filter 15, prime 3
[main @coroutine#2] NumbersFrom Send: 17
[main @coroutine#2] NumbersFrom Send: 18
[main @coroutine#7] filter 13, prime 11
[main @coroutine#3] filter 17, prime 2
[main @coroutine#3] filter 18, prime 2
13
[main @coroutine#4] filter 17, prime 3
[main @coroutine#2] NumbersFrom Send: 19
[main @coroutine#2] NumbersFrom Send: 20
[main @coroutine#5] filter 17, prime 5
[main @coroutine#3] filter 19, prime 2
[main @coroutine#3] filter 20, prime 2
[main @coroutine#6] filter 17, prime 7
[main @coroutine#4] filter 19, prime 3
[main @coroutine#2] NumbersFrom Send: 21
[main @coroutine#2] NumbersFrom Send: 22
[main @coroutine#7] filter 17, prime 11
[main @coroutine#5] filter 19, prime 5
[main @coroutine#3] filter 21, prime 2
[main @coroutine#3] filter 22, prime 2
[main @coroutine#8] filter 17, prime 13
[main @coroutine#6] filter 19, prime 7
[main @coroutine#4] filter 21, prime 3
[main @coroutine#2] NumbersFrom Send: 23
[main @coroutine#2] NumbersFrom Send: 24
17
[main @coroutine#7] filter 19, prime 11
[main @coroutine#3] filter 23, prime 2
[main @coroutine#3] filter 24, prime 2
[main @coroutine#8] filter 19, prime 13
[main @coroutine#4] filter 23, prime 3
[main @coroutine#2] NumbersFrom Send: 25
[main @coroutine#2] NumbersFrom Send: 26
[main @coroutine#9] filter 19, prime 17
[main @coroutine#5] filter 23, prime 5
[main @coroutine#3] filter 25, prime 2
[main @coroutine#3] filter 26, prime 2
19
[main @coroutine#6] filter 23, prime 7
[main @coroutine#4] filter 25, prime 3
[main @coroutine#2] NumbersFrom Send: 27
[main @coroutine#2] NumbersFrom Send: 28
[main @coroutine#7] filter 23, prime 11
[main @coroutine#5] filter 25, prime 5
[main @coroutine#3] filter 27, prime 2
[main @coroutine#3] filter 28, prime 2
[main @coroutine#8] filter 23, prime 13
[main @coroutine#4] filter 27, prime 3
[main @coroutine#2] NumbersFrom Send: 29
[main @coroutine#2] NumbersFrom Send: 30
[main @coroutine#9] filter 23, prime 17
[main @coroutine#3] filter 29, prime 2
[main @coroutine#3] filter 30, prime 2
[main @coroutine#10] filter 23, prime 19
[main @coroutine#4] filter 29, prime 3
[main @coroutine#2] NumbersFrom Send: 31
[main @coroutine#2] NumbersFrom Send: 32
23
[main @coroutine#5] filter 29, prime 5
[main @coroutine#3] filter 31, prime 2
[main @coroutine#3] filter 32, prime 2
[main @coroutine#6] filter 29, prime 7
[main @coroutine#4] filter 31, prime 3
[main @coroutine#2] NumbersFrom Send: 33
[main @coroutine#2] NumbersFrom Send: 34
[main @coroutine#7] filter 29, prime 11
[main @coroutine#5] filter 31, prime 5
[main @coroutine#3] filter 33, prime 2
[main @coroutine#3] filter 34, prime 2
[main @coroutine#8] filter 29, prime 13
[main @coroutine#6] filter 31, prime 7
[main @coroutine#4] filter 33, prime 3
[main @coroutine#2] NumbersFrom Send: 35
[main @coroutine#2] NumbersFrom Send: 36
[main @coroutine#9] filter 29, prime 17
[main @coroutine#7] filter 31, prime 11
[main @coroutine#3] filter 35, prime 2
[main @coroutine#3] filter 36, prime 2
[main @coroutine#10] filter 29, prime 19
[main @coroutine#8] filter 31, prime 13
[main @coroutine#4] filter 35, prime 3
[main @coroutine#2] NumbersFrom Send: 37
[main @coroutine#2] NumbersFrom Send: 38
[main @coroutine#11] filter 29, prime 23
[main @coroutine#9] filter 31, prime 17
[main @coroutine#5] filter 35, prime 5
[main @coroutine#3] filter 37, prime 2
[main @coroutine#3] filter 38, prime 2
29
[main @coroutine#10] filter 31, prime 19
[main @coroutine#4] filter 37, prime 3
[main @coroutine#2] NumbersFrom Send: 39
</code>```

答:
Make sure you understand the logic of Sieve of Eratosthenes algorithm.

Look at the animation: filter(2) is shown in red color.
filter(3) is green,
filter(5) is blue, etc.

Body:
I'm going through the coroutines documentation for Kotlin and was following along pretty well until this example.  I'm having a really difficult time understanding how it's calculating when it finds a prime number, and specifically how the return from the filter function is both being returned and assigned to cur, as well as still producing numbers from the numbersFrom method.

I've added debugging statements to try and follow the various coroutines that are running, but I'm still lost on the logical flow of when it starts new coroutines and receives numbers from others.

https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#prime-numbers-with-pipeline

The code:

fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")

fun main(args: Array<String>) = runBlocking<Unit> {
    var cur = numbersFrom(context, 2)
    for (i in 1..10) {
        val prime = cur.receive()
        println(prime)
        cur = filter(context, cur, prime)
    }
}

fun numbersFrom(context: CoroutineContext, start: Int) = produce<Int>(context) {
       var x = start
    while (true) {
        log("NumbersFrom Send: ${x}")
        send(x++)
    } // infinite stream of integers from start
}

fun filter(context: CoroutineContext, numbers: ReceiveChannel<Int>, prime: Int) = produce<Int>(context) {
    for (x in numbers) {
        log("filter ${x}, prime ${prime}")
        if (x % prime != 0) {
            send(x)
        }
    }
}

Outout:

[main @coroutine#2] NumbersFrom Send: 2
[main @coroutine#2] NumbersFrom Send: 3
2
[main @coroutine#3] filter 3, prime 2
[main @coroutine#2] NumbersFrom Send: 4
[main @coroutine#2] NumbersFrom Send: 5
3
[main @coroutine#3] filter 4, prime 2
[main @coroutine#3] filter 5, prime 2
[main @coroutine#4] filter 5, prime 3
[main @coroutine#2] NumbersFrom Send: 6
[main @coroutine#3] filter 6, prime 2
5
[main @coroutine#2] NumbersFrom Send: 7
[main @coroutine#2] NumbersFrom Send: 8
[main @coroutine#3] filter 7, prime 2
[main @coroutine#3] filter 8, prime 2
[main @coroutine#4] filter 7, prime 3
[main @coroutine#2] NumbersFrom Send: 9
[main @coroutine#2] NumbersFrom Send: 10
[main @coroutine#5] filter 7, prime 5
[main @coroutine#3] filter 9, prime 2
[main @coroutine#3] filter 10, prime 2
7
[main @coroutine#4] filter 9, prime 3
[main @coroutine#2] NumbersFrom Send: 11
[main @coroutine#2] NumbersFrom Send: 12
[main @coroutine#3] filter 11, prime 2
[main @coroutine#3] filter 12, prime 2
[main @coroutine#4] filter 11, prime 3
[main @coroutine#2] NumbersFrom Send: 13
[main @coroutine#2] NumbersFrom Send: 14
[main @coroutine#5] filter 11, prime 5
[main @coroutine#3] filter 13, prime 2
[main @coroutine#3] filter 14, prime 2
[main @coroutine#6] filter 11, prime 7
[main @coroutine#4] filter 13, prime 3
[main @coroutine#2] NumbersFrom Send: 15
[main @coroutine#2] NumbersFrom Send: 16
11
[main @coroutine#5] filter 13, prime 5
[main @coroutine#3] filter 15, prime 2
[main @coroutine#3] filter 16, prime 2
[main @coroutine#6] filter 13, prime 7
[main @coroutine#4] filter 15, prime 3
[main @coroutine#2] NumbersFrom Send: 17
[main @coroutine#2] NumbersFrom Send: 18
[main @coroutine#7] filter 13, prime 11
[main @coroutine#3] filter 17, prime 2
[main @coroutine#3] filter 18, prime 2
13
[main @coroutine#4] filter 17, prime 3
[main @coroutine#2] NumbersFrom Send: 19
[main @coroutine#2] NumbersFrom Send: 20
[main @coroutine#5] filter 17, prime 5
[main @coroutine#3] filter 19, prime 2
[main @coroutine#3] filter 20, prime 2
[main @coroutine#6] filter 17, prime 7
[main @coroutine#4] filter 19, prime 3
[main @coroutine#2] NumbersFrom Send: 21
[main @coroutine#2] NumbersFrom Send: 22
[main @coroutine#7] filter 17, prime 11
[main @coroutine#5] filter 19, prime 5
[main @coroutine#3] filter 21, prime 2
[main @coroutine#3] filter 22, prime 2
[main @coroutine#8] filter 17, prime 13
[main @coroutine#6] filter 19, prime 7
[main @coroutine#4] filter 21, prime 3
[main @coroutine#2] NumbersFrom Send: 23
[main @coroutine#2] NumbersFrom Send: 24
17
[main @coroutine#7] filter 19, prime 11
[main @coroutine#3] filter 23, prime 2
[main @coroutine#3] filter 24, prime 2
[main @coroutine#8] filter 19, prime 13
[main @coroutine#4] filter 23, prime 3
[main @coroutine#2] NumbersFrom Send: 25
[main @coroutine#2] NumbersFrom Send: 26
[main @coroutine#9] filter 19, prime 17
[main @coroutine#5] filter 23, prime 5
[main @coroutine#3] filter 25, prime 2
[main @coroutine#3] filter 26, prime 2
19
[main @coroutine#6] filter 23, prime 7
[main @coroutine#4] filter 25, prime 3
[main @coroutine#2] NumbersFrom Send: 27
[main @coroutine#2] NumbersFrom Send: 28
[main @coroutine#7] filter 23, prime 11
[main @coroutine#5] filter 25, prime 5
[main @coroutine#3] filter 27, prime 2
[main @coroutine#3] filter 28, prime 2
[main @coroutine#8] filter 23, prime 13
[main @coroutine#4] filter 27, prime 3
[main @coroutine#2] NumbersFrom Send: 29
[main @coroutine#2] NumbersFrom Send: 30
[main @coroutine#9] filter 23, prime 17
[main @coroutine#3] filter 29, prime 2
[main @coroutine#3] filter 30, prime 2
[main @coroutine#10] filter 23, prime 19
[main @coroutine#4] filter 29, prime 3
[main @coroutine#2] NumbersFrom Send: 31
[main @coroutine#2] NumbersFrom Send: 32
23
[main @coroutine#5] filter 29, prime 5
[main @coroutine#3] filter 31, prime 2
[main @coroutine#3] filter 32, prime 2
[main @coroutine#6] filter 29, prime 7
[main @coroutine#4] filter 31, prime 3
[main @coroutine#2] NumbersFrom Send: 33
[main @coroutine#2] NumbersFrom Send: 34
[main @coroutine#7] filter 29, prime 11
[main @coroutine#5] filter 31, prime 5
[main @coroutine#3] filter 33, prime 2
[main @coroutine#3] filter 34, prime 2
[main @coroutine#8] filter 29, prime 13
[main @coroutine#6] filter 31, prime 7
[main @coroutine#4] filter 33, prime 3
[main @coroutine#2] NumbersFrom Send: 35
[main @coroutine#2] NumbersFrom Send: 36
[main @coroutine#9] filter 29, prime 17
[main @coroutine#7] filter 31, prime 11
[main @coroutine#3] filter 35, prime 2
[main @coroutine#3] filter 36, prime 2
[main @coroutine#10] filter 29, prime 19
[main @coroutine#8] filter 31, prime 13
[main @coroutine#4] filter 35, prime 3
[main @coroutine#2] NumbersFrom Send: 37
[main @coroutine#2] NumbersFrom Send: 38
[main @coroutine#11] filter 29, prime 23
[main @coroutine#9] filter 31, prime 17
[main @coroutine#5] filter 35, prime 5
[main @coroutine#3] filter 37, prime 2
[main @coroutine#3] filter 38, prime 2
29
[main @coroutine#10] filter 31, prime 19
[main @coroutine#4] filter 37, prime 3
[main @coroutine#2] NumbersFrom Send: 39


问:
How to change an HTML class with JavaScript using getElementsByClassName
How to change a class with Javascript using getElementsByClassName. I got it to work a little but it won't change the class one at the time bet only do it one time to.

I click the button to change css class it do it on all the div and I can do it more in one time.

Here is my Code

```<code>function Button_Color(Show_This) {
    var x = document.getElementById("Color_box");
    var i;
    var Show_This;

    if (Show_This == 1)
    {
        var d = document.getElementsByClassName("id_blue");
        d[0].className = "hid";

        var o = document.getElementsByClassName("id_red");
        o[0].className = " uhid";
    }
    if (Show_This == 2) {

            var d = document.getElementsByClassName("id_blue");
        d[0].className = "hid";

        var o = document.getElementsByClassName("id_red");
        o[0].className = " uhid";
    }

}
</code>```

Here is a like to show you how it looks now with html css js
https://jsfiddle.net/ee51o5h5/1/

I want it to show red only when you click the little red one and blue only when you click the little blue one.

i am dyslexic and from a non-english speaking country so sorry for any miss up.

答:
i try this :

```<code><body>

    <section class="section-button-box">
        <div class="box-button box-color01" onClick="Button_Color(1);">
        </div>

        <div class="box-button box-color02" onClick="Button_Color(2);">
        </div>

    </section>

    <section class="section-color-box" id="Color_box">

        <div class="main-color id_blue">
            <div class="box-size box-color01">
            </div>
        </div>

        <div class="main-color id_red">
            <div class="box-size box-color02">
            </div>
        </div>

        <div class="main-color id_blue">
            <div class="box-size box-color01">
            </div>
        </div>

        <div class="main-color id_red">
              <div class="box-size box-color02">
              </div>
        </div>

    </section>

</body>
</code>```

JS:

```<code>/*|  Blue box  |*/
    function Button_Color(Show_This) {
        var x = document.getElementById("Color_box");
        var i;
        var Show_This;
            var list = document.getElementsByClassName("main-color");
        for(var i = 0 ; i < list.length; i ++ ){
            if (Show_This == 1)
        {
                console.log(list[i].classList.contains("id_blue"));
            if(list[i].classList.contains("id_blue")){
                list[i].classList.add("uhid");
              list[i].classList.remove("hid");
            }
            if(list[i].classList.contains("id_red")){
                list[i].classList.add("hid");
              list[i].classList.remove("uhid");
            }
        }
        if (Show_This == 2) {
                console.log(list[i].classList.contains("id_blue"));
            if(list[i].classList.contains("id_blue")){
                list[i].classList.add("hid");
              list[i].classList.remove("uhid");
            }
            if(list[i].classList.contains("id_red")){
                list[i].classList.add("uhid");
              list[i].classList.remove("hid");
            }
        }
        }
    }
</code>```

and css :

```<code>/*|  Button Box  |*/
.section-button-box{
    height:100px;
    width:100%;
    background-color:aqua;
}
.box-button{
    height:50px;
    width:50px;
    float:left;
}

/*|  Color Box  |*/
.section-color-box{
    height:300px;
    background-color:#c1c1c1;
    width:100%;
}
.box-size{
    height:100px;
    width:100px;
    float:left;
}
.box-color01{
    background-color:blue;
}
.box-color02{
    background-color:red;
}

.hid , .hid .box-size {
    height:0px;
    width:0px;
}
.uhid{
    height:100px;
    width:100px;
}
</code>```

i add something to your code . Hope to sovle your issue.

Body:
How to change a class with Javascript using getElementsByClassName. I got it to work a little but it won't change the class one at the time bet only do it one time to.

I click the button to change css class it do it on all the div and I can do it more in one time.

Here is my Code

function Button_Color(Show_This) {
    var x = document.getElementById("Color_box");
    var i;
    var Show_This;

    if (Show_This == 1)
    {
        var d = document.getElementsByClassName("id_blue");
        d[0].className = "hid";

        var o = document.getElementsByClassName("id_red");
        o[0].className = " uhid";
    }
    if (Show_This == 2) {

            var d = document.getElementsByClassName("id_blue");
        d[0].className = "hid";

        var o = document.getElementsByClassName("id_red");
        o[0].className = " uhid";
    }

}

Here is a like to show you how it looks now with html css js
https://jsfiddle.net/ee51o5h5/1/

I want it to show red only when you click the little red one and blue only when you click the little blue one.

i am dyslexic and from a non-english speaking country so sorry for any miss up.

Body:
i try this :

<body>

    <section class="section-button-box">
        <div class="box-button box-color01" onClick="Button_Color(1);">
        </div>

        <div class="box-button box-color02" onClick="Button_Color(2);">
        </div>

    </section>

    <section class="section-color-box" id="Color_box">

        <div class="main-color id_blue">
            <div class="box-size box-color01">
            </div>
        </div>

        <div class="main-color id_red">
            <div class="box-size box-color02">
            </div>
        </div>

        <div class="main-color id_blue">
            <div class="box-size box-color01">
            </div>
        </div>

        <div class="main-color id_red">
              <div class="box-size box-color02">
              </div>
        </div>

    </section>

</body>

JS:

/*|  Blue box  |*/
    function Button_Color(Show_This) {
        var x = document.getElementById("Color_box");
        var i;
        var Show_This;
            var list = document.getElementsByClassName("main-color");
        for(var i = 0 ; i < list.length; i ++ ){
            if (Show_This == 1)
        {
                console.log(list[i].classList.contains("id_blue"));
            if(list[i].classList.contains("id_blue")){
                list[i].classList.add("uhid");
              list[i].classList.remove("hid");
            }
            if(list[i].classList.contains("id_red")){
                list[i].classList.add("hid");
              list[i].classList.remove("uhid");
            }
        }
        if (Show_This == 2) {
                console.log(list[i].classList.contains("id_blue"));
            if(list[i].classList.contains("id_blue")){
                list[i].classList.add("hid");
              list[i].classList.remove("uhid");
            }
            if(list[i].classList.contains("id_red")){
                list[i].classList.add("uhid");
              list[i].classList.remove("hid");
            }
        }
        }
    }

and css :

/*|  Button Box  |*/
.section-button-box{
    height:100px;
    width:100%;
    background-color:aqua;
}
.box-button{
    height:50px;
    width:50px;
    float:left;
}

/*|  Color Box  |*/
.section-color-box{
    height:300px;
    background-color:#c1c1c1;
    width:100%;
}
.box-size{
    height:100px;
    width:100px;
    float:left;
}
.box-color01{
    background-color:blue;
}
.box-color02{
    background-color:red;
}

.hid , .hid .box-size {
    height:0px;
    width:0px;
}
.uhid{
    height:100px;
    width:100px;
}

i add something to your code . Hope to sovle your issue.


问:
How to create two-column unique key constrain with HBM mapping?
I have a hibernate mapping:

```
<properties name="lrt_bps_bpr_acs_uk" unique="true">
    <many-to-one name="activitySummary" column="bps_acs_id" class="xyz.ActivitySummary"
    unique-key="lrt_bps_bpr_acs_uk"/>
    <many-to-one name="bestPractice" column="bps_bpr_id" class="xyz.BestPractice"
        unique-key="lrt_bps_bpr_acs_uk"/>
</properties>
```

I expected that hibernate would create unique constraint on database for this mapping. Nothing like that happened however.

What am I doing wrong?

答:
What's the actual DDL that Hibernate is generating? What would be the DDL if you remove the unique-key parameters? What's the Hibernate version?

From the documentation, it seems you are doing it correctly:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-properties

Body:
I have a hibernate mapping:

<properties name="lrt_bps_bpr_acs_uk" unique="true">
    <many-to-one name="activitySummary" column="bps_acs_id" class="xyz.ActivitySummary"
    unique-key="lrt_bps_bpr_acs_uk"/>
    <many-to-one name="bestPractice" column="bps_bpr_id" class="xyz.BestPractice"
        unique-key="lrt_bps_bpr_acs_uk"/>
</properties>

I expected that hibernate would create unique constraint on database for this mapping. Nothing like that happened however.

What am I doing wrong?


问:
bind ng-click to a css class
Can we bind ng-click to a CSS class?

I have loads of s to bind and check if they are clicked then fire the click of the label in it, in order to give a maximum clickable area for touch devices.

I have done something like below.

var myApp = angular.module("myApp", [])
  .controller("myController", ["$scope", "$timeout", function myController($scope, $timeout) {
    $scope.checkRadio = function checkRadio($event) {
      $timeout(function() {
        angular.element($event.target).find("label").trigger('click');
      }, 100);
    };
  }]);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.invisible-radio {
  position: absolute;
  display: inline;
  opacity: 0;
  width: 0;
  margin: 0;
  -webkit-appearance: none;
  overflow: hidden;
}

.custom-radio-label {
  display: inline-block;
  position: relative;
  padding-left: 20px;
  vertical-align: text-top;
  line-height: 20px;
  cursor: pointer;
  border-style: solid;
  border-width: 0;
}

.custom-radio-label::before {
  border-color: #7f7f7f;
  border-radius: 50%;
  background-color: #fff;
  border-width: 2px;
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  border-style: solid;
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
}

.invisible-radio:checked+.custom-radio-label::after {
  background-color: #337ab7;
  border-radius: 50%;
  top: 5px;
  left: 5px;
  content: "";
  width: 12px;
  height: 12px;
  position: absolute;
}</code>```

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

      Option 1
      Option 2

        <input id="option1" type="radio" class="invisible-radio" name="option" value="0" ng-model="model.Option" required />

        <input id="option2" type="radio" class="invisible-radio" name="option" value="1" ng-model="model.Option" required />

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

<p>But it seems overkill to go and decorate 100s of <code><td></code>s with <code>ng-click</code> attribute.</p>

<p>I am thinking if it is possible to bind <code>ng-click</code> to a common class that all my <code><td></code>s share.</p>

<p>It is certainly possible to do it with <code>jQuery</code> as below.</p>

```$(".someclassOnMyTD").click($event) {
   $event.target.find("label").click();
}
```

But I am looking for an Angular way here. A directive possibly.

答:
Actually that is what a  for.

```<code><td>
  <label for="option1">
    <input id="option1" type="radio" class="invisible-radio" name="option" value="0" ng-model="model.Option" required />
    <label class="custom-radio-label" for="option1"></label>
  </label>
</td>
</code>```

You might need to tinker with the CSS a little so it fills the area of its parent td

Title: bind ng-click to a css class

Body:
Can we bind ng-click to a CSS class?

I have loads of s to bind and check if they are clicked then fire the click of the label in it, in order to give a maximum clickable area for touch devices.

I have done something like below.

var myApp = angular.module("myApp", [])
  .controller("myController", ["$scope", "$timeout", function myController($scope, $timeout) {
    $scope.checkRadio = function checkRadio($event) {
      $timeout(function() {
        angular.element($event.target).find("label").trigger('click');
      }, 100);
    };
  }]);

.invisible-radio {
  position: absolute;
  display: inline;
  opacity: 0;
  width: 0;
  margin: 0;
  -webkit-appearance: none;
  overflow: hidden;
}

.custom-radio-label {
  display: inline-block;
  position: relative;
  padding-left: 20px;
  vertical-align: text-top;
  line-height: 20px;
  cursor: pointer;
  border-style: solid;
  border-width: 0;
}

.custom-radio-label::before {
  border-color: #7f7f7f;
  border-radius: 50%;
  background-color: #fff;
  border-width: 2px;
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  border-style: solid;
  -webkit-box-sizing: content-box;
  -moz-box-sizing: content-box;
  box-sizing: content-box;
}

.invisible-radio:checked+.custom-radio-label::after {
  background-color: #337ab7;
  border-radius: 50%;
  top: 5px;
  left: 5px;
  content: "";
  width: 12px;
  height: 12px;
  position: absolute;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

      Option 1
      Option 2

        <input id="option1" type="radio" class="invisible-radio" name="option" value="0" ng-model="model.Option" required />

        <input id="option2" type="radio" class="invisible-radio" name="option" value="1" ng-model="model.Option" required />

But it seems overkill to go and decorate 100s of s with ng-click attribute.

I am thinking if it is possible to bind ng-click to a common class that all my s share.

It is certainly possible to do it with jQuery as below.

$(".someclassOnMyTD").click($event) {
   $event.target.find("label").click();
}

But I am looking for an Angular way here. A directive possibly.

Body:
Actually that is what a <label> for.

<td>
  <label for="option1">
    <input id="option1" type="radio" class="invisible-radio" name="option" value="0" ng-model="model.Option" required />
    <label class="custom-radio-label" for="option1"></label>
  </label>
</td>

You might need to tinker with the CSS a little so it fills the area of its parent td


问:
table rows and cells are broken
I have the following styling and HTML, but when it displays, the table appears broken (all the table rows and cells are broken). I'm not sure why; how can I fix it?

the tbody need have this size: height: calc(100vh - 130px);

the red line defines the size of the table.

edit: my tbody need have scroll and the thead need be fixed.

jsfiddle: https://jsfiddle.net/zuxq2gr0/11/

.col-lg-12 {
  border: 1px solid red;
}

tbody {
  display: block;
  overflow-y: scroll;
  height: calc(100vh - 130px);
}

tbody > tr {
  display: table;
  width: 100%;
}```

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

          test
          test
          test
          test
          test

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          <compose view="./-box.html"></compose>

```

答:
To fix the broken cells

You need to remove display:block from tbody and remove display:table from tr element.

```<code>.col-lg-12 {
  border:1px solid red;
}
tbody {
    overflow-y: scroll;
    height: calc(100vh - 130px);
    width: 100%;
}

tbody > tr {
  width: 100%;
}
</code>```

See fiddle: https://jsfiddle.net/zuxq2gr0/15/

Making a sticky header

The sticky header depends on the browser support you need.
Easiest way to do it would be with position: sticky, see at work in this fiddle: https://jsfiddle.net/zuxq2gr0/17/
That only works in modern browsers though, needs prefixes and doesn't work in either IE or Edge (refer to CanIUse: https://caniuse.com/#search=sticky). There might be good polyfills out there, but I haven't tried any.

You could use position: fixed, but then you need to know all your heights and so on. Refer to this codepen: https://codepen.io/tjvantoll/pen/JEKIu

Other than that you'll probably need to use a javascript. There are quite a few tutorials out there that cover javascript sticky headers. I haven't tried them, but here's one from Codedrops. There are also some SO questions concerning this topic, e.g.:

Table header to stay fixed at the top when user scrolls it out of view with jQuery

HTML table headers always visible at top of window when viewing a large table

Title: table rows and cells are broken

Body:
I have the following styling and HTML, but when it displays, the table appears broken (all the table rows and cells are broken). I'm not sure why; how can I fix it?

the tbody need have this size: height: calc(100vh - 130px);

the red line defines the size of the table.

edit: my tbody need have scroll and the thead need be fixed.

jsfiddle: https://jsfiddle.net/zuxq2gr0/11/

.col-lg-12 {
  border: 1px solid red;
}

tbody {
  display: block;
  overflow-y: scroll;
  height: calc(100vh - 130px);
}

tbody > tr {
  display: table;
  width: 100%;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

          test
          test
          test
          test
          test

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          test
          test
          test

              <select id="selectbasic" name="selectbasic" class="form-control col-lg-6 col-md-6 col-sm-6">
                <option value="" selected=""></option>
                <option value="-action"> Action</option>
              </select>

          <compose view="./-box.html"></compose>

Body:
To fix the broken cells

You need to remove display:block from tbody and remove display:table from tr element.

.col-lg-12 {
  border:1px solid red;
}
tbody {
    overflow-y: scroll;
    height: calc(100vh - 130px);
    width: 100%;
}

tbody > tr {
  width: 100%;
}

See fiddle: https://jsfiddle.net/zuxq2gr0/15/

Making a sticky header

The sticky header depends on the browser support you need.
Easiest way to do it would be with position: sticky, see at work in this fiddle: https://jsfiddle.net/zuxq2gr0/17/
That only works in modern browsers though, needs prefixes and doesn't work in either IE or Edge (refer to CanIUse: https://caniuse.com/#search=sticky). There might be good polyfills out there, but I haven't tried any.

You could use position: fixed, but then you need to know all your heights and so on. Refer to this codepen: https://codepen.io/tjvantoll/pen/JEKIu

Other than that you'll probably need to use a javascript. There are quite a few tutorials out there that cover javascript sticky headers. I haven't tried them, but here's one from Codedrops. There are also some SO questions concerning this topic, e.g.:

Table header to stay fixed at the top when user scrolls it out of view with jQuery

HTML table headers always visible at top of window when viewing a large table


问:
positioning problem with uisplitviewcontroller in left view
i got a little problem, when launching my splitview in landscape, there is a little black space above my left view controller:

after rotating my ipad to portrait and switching back to landscape, the space is gone.

if i load the uitableviewcontroller directly into the left view, and not in a navigationcontroller, it works fine:

any ideas why this is happening ??

```<code>// Produkte
    self.produkteMainTableVC = [[produkteMainTableViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *produkteMainNavigationController = [[UINavigationController alloc] initWithRootViewController:self.produkteMainTableVC];
    self.produkteDetailVC = [[produkteDetailViewController alloc] initWithNibName:@"produkteDetailViewController" bundle:nil];
    self.produkteSplitVC = [[UISplitViewController alloc] init];

    self.produkteSplitVC.delegate = self.produkteDetailVC;
    self.produkteMainTableVC.produkteDetailVC = produkteDetailVC;
    [self.produkteSplitVC setViewControllers:[NSArray arrayWithObjects:produkteMainNavigationController,self.produkteDetailVC,nil]];
</code>```

thanks for all help!

edit:
its exactly 20px like the statusbar. does that help anyone?

edit2:

doing something like this:

```<code>if(self.navigationController.navigationBar.frame.origin.y >= 20.0) {

        self.navigationController.navigationBar.frame = CGRectMake(self.navigationController.navigationBar.frame.origin.x, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
    }
</code>```

results that:

a little improvement i would say. but i have no idea how to stick my tableview underneath the navigationbar.

答: UINavigationController has a nasty habit of shifting its contents down by 20px, depending where you place it.  I'm guessing it's doing it here because your split view controller is inside of a tabbar controller, and Apple has not blessed this type of arrangement.</p>

Body:
i got a little problem, when launching my splitview in landscape, there is a little black space above my left view controller:

after rotating my ipad to portrait and switching back to landscape, the space is gone.

if i load the uitableviewcontroller directly into the left view, and not in a navigationcontroller, it works fine:

any ideas why this is happening ??

// Produkte
    self.produkteMainTableVC = [[produkteMainTableViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *produkteMainNavigationController = [[UINavigationController alloc] initWithRootViewController:self.produkteMainTableVC];
    self.produkteDetailVC = [[produkteDetailViewController alloc] initWithNibName:@"produkteDetailViewController" bundle:nil];
    self.produkteSplitVC = [[UISplitViewController alloc] init];

    self.produkteSplitVC.delegate = self.produkteDetailVC;
    self.produkteMainTableVC.produkteDetailVC = produkteDetailVC;
    [self.produkteSplitVC setViewControllers:[NSArray arrayWithObjects:produkteMainNavigationController,self.produkteDetailVC,nil]];

thanks for all help!

edit:
its exactly 20px like the statusbar. does that help anyone?

edit2:

doing something like this:

if(self.navigationController.navigationBar.frame.origin.y >= 20.0) {

        self.navigationController.navigationBar.frame = CGRectMake(self.navigationController.navigationBar.frame.origin.x, 0.0, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height);
    }

results that:

a little improvement i would say. but i have no idea how to stick my tableview underneath the navigationbar.


问:
Adding pre_build command to add_jar cmake
I'm trying to add a pre_build command to my jar in CMake. Apparently add_jar does not support this options. Is there any way to do something similar?</p>

答:
I solved the issue, I just had to use the output param at add_custom_command. Basically I wanted to generate some java file and add it to my jar. Here's the steps what I've done:   </p>

```<code>add_library(MyLib ${SRC})

add_custom_command(
    OUTPUT "${PATH}/${file}.java"
    COMMAND ${ANDROID_HOME}/build-tools/22.0.1/aidl "${PATH}/${file}.aidl" "${PATH}/${file}.java"
)

add_jar(MyLib_java
        SOURCES ${JAVA_SRC} "${PATH}/${file}.java"
        OUTPUT_DIR ${CMAKE_BINARY_DIR}/lib
        )

add_dependencies(MyLib_java MyLib)
</code>```

Body:
I solved the issue, I just had to use the output param at add_custom_command. Basically I wanted to generate some java file and add it to my jar. Here's the steps what I've done:

add_library(MyLib ${SRC})

add_custom_command(
    OUTPUT "${PATH}/${file}.java"
    COMMAND ${ANDROID_HOME}/build-tools/22.0.1/aidl "${PATH}/${file}.aidl" "${PATH}/${file}.java"
)

add_jar(MyLib_java
        SOURCES ${JAVA_SRC} "${PATH}/${file}.java"
        OUTPUT_DIR ${CMAKE_BINARY_DIR}/lib
        )

add_dependencies(MyLib_java MyLib)


问:
How to align 2 tables (left and center) inside a div?
I want to center one table inside a div and have another table floating to the left of the first one.
My desired result would look something like this:

```[ (Left Table)     (Center table)               ]```

But with my current HTML and CSS (seen below) I get this result:

```[ (Left Table)           (Center table)         ]```

The problem here being that it floats the first table to the left and centers the second table in the remaining space.

This is the code:

#wrapper {
  text-align: center;
  width: 500px;
  border: 1px solid black;
}

#left {
  float:left;
}

#center {
  margin: 0 auto;
}

td {
  border: 1px solid black;
  width: 100px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="wrapper">
  <table id="left">
    <tr>
      <td>
        Left
      </td>
    </tr>
  </table>

  <table id="center">
    <tr>
      <td>
        Center
      </td>
    </tr>
  </table>
</div></code>```

Any help on how to fix it?

答:
Try setting #wrapper to position: relative; and #left to position: absolute; left: 0;

#wrapper {
  text-align: center;
  background-color: skyblue;
  text-align: left;
  position: relative;
}
table {
  border: 1px solid black;
}
#left {
  background-color: red;
  position: absolute;
  left: 0;
}
#center {
  background-color: yellow;
  margin: 0 auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="wrapper">
  <table id="left">
    <tr>
      <td>Left Table</td>
    </tr>
  </table>
  <table id="center">
    <tr>
      <td>Center Table</td>
    </tr>
  </table>
</div></code>```

Body:
I want to center one table inside a div and have another table floating to the left of the first one.
My desired result would look something like this:

[ (Left Table)     (Center table)               ]

But with my current HTML and CSS (seen below) I get this result:

[ (Left Table)           (Center table)         ]

The problem here being that it floats the first table to the left and centers the second table in the remaining space.

This is the code:

#wrapper {
  text-align: center;
  width: 500px;
  border: 1px solid black;
}

#left {
  float:left;
}

#center {
  margin: 0 auto;
}

td {
  border: 1px solid black;
  width: 100px;
}

        Left

        Center

Any help on how to fix it?

Body:
Try setting #wrapper to position: relative; and #left to position: absolute; left: 0;

#wrapper {
  text-align: center;
  background-color: skyblue;
  text-align: left;
  position: relative;
}
table {
  border: 1px solid black;
}
#left {
  background-color: red;
  position: absolute;
  left: 0;
}
#center {
  background-color: yellow;
  margin: 0 auto;
}

<div id="wrapper">
  <table id="left">
    <tr>
      <td>Left Table</td>
    </tr>
  </table>
  <table id="center">
    <tr>
      <td>Center Table</td>
    </tr>
  </table>
</div>


问:
Make post REST API calls using Angular2
I am new to Angular2 and I'm trying to use the Ionic2 framework to build a mobile hybrid app.

I need to make a POST call to a REST based API and I'm unable to do so.

Can anyone suggest me in the direction to get the same done

答:
Below is the sample for post request which is same in both in Angular 2 and Ionic 2. read more docs also.

```<code> registerUser(registration: RegistrationTO): Promise<String> {
    let headers = new Headers();
    let body = JSON.stringify(
      {
        "userName": registration.userId,
        "emailId": registration.emailId,
        "userId": registration.userId,
        "facultyCode": registration.facultyCode
      }
    );
    headers.append('Content-Type', 'application/json');
    let params:URLSearchParams = new URLSearchParams();
    let requestOption: RequestOptionsArgs =
      {search: params,  headers: headers };
    return this.http
      .post(RegistrationUrl, body, requestOption)
      .toPromise()
      .then(res => res.json().userTO.msg)
      .catch(this.handleError);
  }
</code>```

call the function like this

```<code>this.loginService.registerUser(this.registration).then((msg)=>{console.log(msg)});
</code>```

Title: Make post REST API calls using Angular2

Body:
Below is the sample for post request which is same in both in Angular 2 and Ionic 2. read more docs also.

 registerUser(registration: RegistrationTO): Promise<String> {
    let headers = new Headers();
    let body = JSON.stringify(
      {
        "userName": registration.userId,
        "emailId": registration.emailId,
        "userId": registration.userId,
        "facultyCode": registration.facultyCode
      }
    );
    headers.append('Content-Type', 'application/json');
    let params:URLSearchParams = new URLSearchParams();
    let requestOption: RequestOptionsArgs =
      {search: params,  headers: headers };
    return this.http
      .post(RegistrationUrl, body, requestOption)
      .toPromise()
      .then(res => res.json().userTO.msg)
      .catch(this.handleError);
  }

call the function like this

this.loginService.registerUser(this.registration).then((msg)=>{console.log(msg)});


问:
C++ generate random number based on mathematical equations.
I have three positive integers

distance1

distance2

distnace3

that sum up to 100.

distance1 + distance2 + distance3 = 100 (EQ1)

I have  additional information that

20 < distance2 < 90 (EQ2) and

distance1 + distance3 > 8 (EQ3)

I need in C++ to calculate fast three positive random values for distance1, distance2 and distance3 in order to support the equations EQ1, EQ2 and EQ3.

My first approach was to do the following

```<code>    std::list<...> solutions;
    //i for distance1, j for distance2, z for distance3
    for (int i = 1; i < 101; i++) {

       for (int j = 1; j < 101; j++)  {

           for (int z = 1; z < 101; z++)  {

              evaluate if i, j, z satisfy EQ1, EQ2,EQ3
              if ( evaluate == true )
                solutions.push_back(...i,j,z...); //pseudocode

           }
       }

    }
// when all iterations are finished select a random from std::<list>
</code>```

Any better approach to do this? Is there any library that can help? Is this the correct way to perform combinations?

答:
First note that you only need two random numbers per trial, since the third is constrained by their having to sum to 100.

Second note, if distance2 is less than 90, and the sum is 100, then distance1 + distance3 must be 11 or more. So EQ3 must hold if EQ2 holds.

Sampling using Mersenne Twister (in the absence of any other information) is probably the best way, and reject combinations that don't satisfy the constraints. To get started, sample distance1 and distance2 between [0, 100] regardless of efficiency and improve if necessary but take absolutely exquisite care that you don't introduce statistical bias in reducing the number of rejected combinations (and that is the hard bit).

Note that Mersenne Twister has been part of the C++ Standard since C++11: to get things started use something like

```<code>#include <random>
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_int_distribution<int> uni(0, 100);
auto random_integer = uni(rng);
</code>```

Body:
I have three positive integers

distance1

distance2

distnace3

that sum up to 100.

distance1 + distance2 + distance3 = 100 (EQ1)

I have  additional information that

20 < distance2 < 90 (EQ2) and

distance1 + distance3 > 8 (EQ3)

I need in C++ to calculate fast three positive random values for distance1, distance2 and distance3 in order to support the equations EQ1, EQ2 and EQ3.

My first approach was to do the following

    std::list<...> solutions;
    //i for distance1, j for distance2, z for distance3
    for (int i = 1; i < 101; i++) {

       for (int j = 1; j < 101; j++)  {

           for (int z = 1; z < 101; z++)  {

              evaluate if i, j, z satisfy EQ1, EQ2,EQ3
              if ( evaluate == true )
                solutions.push_back(...i,j,z...); //pseudocode

           }
       }

    }
// when all iterations are finished select a random from std::<list>

Any better approach to do this? Is there any library that can help? Is this the correct way to perform combinations?

Body:
First note that you only need two random numbers per trial, since the third is constrained by their having to sum to 100.

Second note, if distance2 is less than 90, and the sum is 100, then distance1 + distance3 must be 11 or more. So EQ3 must hold if EQ2 holds.

Sampling using Mersenne Twister (in the absence of any other information) is probably the best way, and reject combinations that don't satisfy the constraints. To get started, sample distance1 and distance2 between [0, 100] regardless of efficiency and improve if necessary but take absolutely exquisite care that you don't introduce statistical bias in reducing the number of rejected combinations (and that is the hard bit).

Note that Mersenne Twister has been part of the C++ Standard since C++11: to get things started use something like

#include <random>
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_int_distribution<int> uni(0, 100);
auto random_integer = uni(rng);


问:
Why we add 2 directories path in Python in Windows environment variable
Why we add 2  directory path in windows environment variableC:\Python27\;C:\Python27\Scripts\ ?

Is C:\Python27\ is not sufficient ?

Any helpful answer will be appreciated !

答: sys does not do a recursive lookup because that is wasteful. Explicitly specify the complete path to ONLY the directories/sub-directories you want to include in your PATH, and python will only look for modules to import there.


答:
Pick a random value for distance2 in the appropriate range.

Pick a random value for distance1 in the appropriate range (based on the value of distance2).

Calculate distance3.

Title: C++ generate random number based on mathematical equations.


问:
Theory: Compression algorithm that makes some files smaller but none bigger?
I came across this question;

"A lossless compression algorithm claims to guarantee to make some files smaller and no files larger.

Is this;

a) Impossible

b) Possible but may run for an indeterminate amount of time,

c) Possible for compression factor 2 or less,

d) Possible for any compression factor?"

I'm leaning towards (a), but couldn't give a solid explanation as to why. (I'll list the thoughts a friend and I came up with as a possible answer)

答:
e) Possible

...with some restrictions.

I recently came across Shoco, a string compression library for small strings. I was reminded of this question when reading this claim:

...the most remarkable property of shoco is that the compressed size will never exceed the size of your input string, provided it is plain ASCII.

If you are sure that the input data is plain ASCII, your out buffer for only needs to be as large as the input string

http://ed-von-schleck.github.io/shoco/#how-it-works


问:
Select from inherited table
I have this inheritance in my database and I need to use a SELECT query and INSERT query to it.

I can't seem to pull this off.

It's about the Item and it's inheritances.

答:
This could be helpful?

```<code>INSERT INTO table2
SELECT *
FROM table1
WHERE condition;
</code>```

I don't know if i've understood your question but, you want to insert some values into a table selecting from an another table.

Title: Select from inherited table

Body:
This could be helpful?

INSERT INTO table2
SELECT *
FROM table1
WHERE condition;

I don't know if i've understood your question but, you want to insert some values into a table selecting from an another table.


问:
R Shiny in Memory Application or noSQL
I am running a tiny web app using R's shiny framework. The tool doesn't do that much. It's just filtering data frames with given parameters from the UI.
The problem I have now is the following. If a user is accessing the app via http it takes a long time to start the App. Since the data, which I load in the global.R, is pretty big (~5GB). After an initial start, the App is running smooth, also when re-accessing within a given time (the app seems to be completely in memory, for some minutes).
Since I got enough memory available, and my data doesn't change by user interaction, I am asking myself if I could keep the complete App in memory. Is it possible to force this? My server is running centOS 6. Also the problem isn't the file system, hard disk, etc. - I created a ram disk to load the data from, but the performance increase is marginal. So the bottle neck seems to be R, when processing the data.

Now I got two ideas, which may overcome the problem.

Just as I mentioned, is it possible to keep the complete app in memory?

Don't save the Data as R objects, instead use a fast noSQL DB e.g. Redis wich is in memory

May one of you has some experience when loading bigger data. I would be thankful if could get a discussion going. If it is possible, I would like to avoid external software, like Redis, to keep everything as simple as possible.

With all the best,

Mario

答:
I have no experience with noSQL databases, but here is how I am combining shiny with an Oracle database to speed up my apps:

User inputs are passed to an sql query which is sent to the extremly fast database, and only the output of this query is read into R. In many cases (especially if the sql involves a group by statement) this reduces the number of observations to be read from several millions to a few hundreds. Hence, data loading becomes very fast.

In the example below users first select questionnaires and the date range. This generate an sql statement which filters the relevant observations and counts frequencies of answers per question and questionnaire. These frequencies are read into R and displayed as a datatable in the shiny app.

```<code>library(shiny)
library(ROracle)
library(DT)

drv <- dbDriver("Oracle")
con <-dbConnect(drv, username = "...", password = '...', dbname = "...")

query <- 'select distinct questionnaire from ... order by questionnaire'
questionnaire.list <- dbGetQuery(con, query)$questionnaire

ui <- fluidPage(
      selectInput('questionnaire_inp','Questionnaire',
                  choices=questionnaire.list,selected=questionnaire.list,multiple=T),
      dateRangeInput("daterange_inp", "Date range",
                     start='2016-01-01', end=Sys.Date()),
      dataTableOutput('tbl')
)

server <- function(input, output) {

  output$tbl <- renderDataTable({
    query <- paste0(
        "select questionnaire, question, answer, count(*) from ...
        where title in (", paste0(shQuote(input$questionnaire_inp), collapse=","), ")
        and date between to_date('", input$daterange_inp[1] ,"','YYYY-MM-DD')
        and to_date ('", input$daterange_inp[1] ,"','YYYY-MM-DD')
        group by questionnaire, question, answer")
    dt <- dbGetQuery(con, query)
    datatable(dt)

  })

shinyApp(ui = ui, server = server)
</code>```

Title: R Shiny in Memory Application or noSQL

Body:
I have no experience with noSQL databases, but here is how I am combining shiny with an Oracle database to speed up my apps:

User inputs are passed to an sql query which is sent to the extremly fast database, and only the output of this query is read into R. In many cases (especially if the sql involves a group by statement) this reduces the number of observations to be read from several millions to a few hundreds. Hence, data loading becomes very fast.

In the example below users first select questionnaires and the date range. This generate an sql statement which filters the relevant observations and counts frequencies of answers per question and questionnaire. These frequencies are read into R and displayed as a datatable in the shiny app.

library(shiny)
library(ROracle)
library(DT)

drv <- dbDriver("Oracle")
con <-dbConnect(drv, username = "...", password = '...', dbname = "...")

query <- 'select distinct questionnaire from ... order by questionnaire'
questionnaire.list <- dbGetQuery(con, query)$questionnaire

ui <- fluidPage(
      selectInput('questionnaire_inp','Questionnaire',
                  choices=questionnaire.list,selected=questionnaire.list,multiple=T),
      dateRangeInput("daterange_inp", "Date range",
                     start='2016-01-01', end=Sys.Date()),
      dataTableOutput('tbl')
)

server <- function(input, output) {

  output$tbl <- renderDataTable({
    query <- paste0(
        "select questionnaire, question, answer, count(*) from ...
        where title in (", paste0(shQuote(input$questionnaire_inp), collapse=","), ")
        and date between to_date('", input$daterange_inp[1] ,"','YYYY-MM-DD')
        and to_date ('", input$daterange_inp[1] ,"','YYYY-MM-DD')
        group by questionnaire, question, answer")
    dt <- dbGetQuery(con, query)
    datatable(dt)

  })

shinyApp(ui = ui, server = server)