问:
Error using akka remoting with artery over docker instances
First of all, sorry for my english. Google translate helps me a lot, haha.

My problem is this:

I have two example projects developed with akka and java: example-remote-client.jar and example-remote-server.jar

I'm using artery serialization, and and i'm trying to send messages from client to server via akka-remoting.

The client actor that does that is:

```<code>public class ClientActor extends AbstractActor {

    public static Props props() {
        return Props.create(ClientActor.class);

    }

    public ClientActor() {
        ActorSelection selection = getContext().system().actorSelection("akka://server@localhost:5001/user/server-process");
        selection.tell(new MessageRequest(), getSelf());
    }

    public Receive createReceive() {
        return receiveBuilder().match(MessageResponse.class, msg -> {
            System.out.println(msg.getMessage());
        }).build();
    }
}
</code>```

My client configuration:

```<code>akka {
  loglevel = "DEBUG"

  actor {
    provider = remote
    allow-java-serialization = off

    serializers {
      java = "akka.serialization.JavaSerializer"
      myown = "serializers.ExampleByteBufSerializer"
    }

    serialization-bindings {
      "java.lang.String" = myown
      "protocol.MessageRequest" = myown
      "protocol.MessageResponse" = myown
      "java.lang.Boolean" = myown
    }

  }

  remote {
    artery {
      enabled = on
      canonical.hostname = "192.168.0.250"     # external (logical) hostname
      canonical.port = 5000                   # external (logical) port

      bind.hostname = "localhost" # internal (bind) hostname
      bind.port = 10000              # internal (bind) port
    }
  }
}
</code>```

The server actor is very dummy, i dont think it is necessary to paste it here. But its configuration is:

```<code>akka {
  loglevel = "DEBUG"

  actor {
    provider = remote
    allow-java-serialization = off

    serializers {
      java = "akka.serialization.JavaSerializer"
      myown = "serializers.ExampleByteBufSerializer"
    }

    serialization-bindings {
      "java.lang.String" = myown
      "protocol.MessageRequest" = myown
      "protocol.MessageResponse" = myown
      "java.lang.Boolean" = myown
    }

  }

  remote {
    artery {
      enabled = on
      canonical.hostname = "192.168.0.250"     # external (logical) hostname
      canonical.port = 5001                   # external (logical) port

      bind.hostname = "localhost" # internal (bind) hostname
      bind.port = 10001              # internal (bind) port
    }
  }
}
</code>```

Both jar are deployed over docker instances running over the same "192.168.0.250 machine", as seen below:

```<code>CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                                            NAMES
d2970bd20371        openjdk:alpine             "sh"                     34 minutes ago      Up 34 minutes       0.0.0.0:5001->10001/tcp                          ex-remoting-server
36a67fea8590        openjdk:alpine             "sh"                     34 minutes ago      Up 34 minutes       0.0.0.0:5000->10000/tcp                          ex-remoting-client
</code>```

The server starts ok, with the following log:

```<code>[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] logger log1-Logging$DefaultLogger started
[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] Default Loggers started
[DEBUG] [07/04/2017 13:46:18.495] [main] [akka.serialization.Serialization(akka://server)] Replacing JavaSerializer with DisabledJavaSerializer, due to `akka.actor.allow-java-serialization = off`.
[INFO] [07/04/2017 13:46:18.628] [main] [akka.remote.artery.ArteryTransport(akka://server)] Started embedded media driver in directory [/dev/shm/aeron-root-server-efd42dec-452d-406c-8d1d-807e0d8ff7fc]
[INFO] [07/04/2017 13:46:18.693] [main] [akka.remote.artery.ArteryTransport(akka://server)] Remoting started; listening on address: [akka://server@192.168.0.250:5001] with UID [-2663186266051514585]
</code>```

But when i try to start client, i get the following error:

```<code>[ERROR] [07/04/2017 14:09:05.250] [client-akka.actor.default-dispatcher-10] [akka://server@192.168.0.250:5001/] swallowing exception during message send
io.aeron.exceptions.RegistrationException: Insufficient usable storage for new log of length=50332096 in /dev/shm (shm)
    at io.aeron.ClientConductor.onError(ClientConductor.java:285)
    at io.aeron.DriverListenerAdapter.onMessage(DriverListenerAdapter.java:79)
    at org.agrona.concurrent.broadcast.CopyBroadcastReceiver.receive(CopyBroadcastReceiver.java:100)
    at io.aeron.DriverListenerAdapter.pollMessage(DriverListenerAdapter.java:59)
    at io.aeron.ClientConductor.doWork(ClientConductor.java:422)
    at io.aeron.ClientConductor.awaitResponse(ClientConductor.java:447)
    at io.aeron.ClientConductor.addPublication(ClientConductor.java:177)
    at io.aeron.Aeron.addPublication(Aeron.java:165)
    at akka.remote.artery.AeronSink$$anon$1.<init>(AeronSink.scala:103)
    at akka.remote.artery.AeronSink.createLogicAndMaterializedValue(AeronSink.scala:100)
    at akka.stream.impl.GraphStageIsland.materializeAtomic(PhasedFusingActorMaterializer.scala:627)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:458)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:420)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:415)
    at akka.stream.scaladsl.RunnableGraph.run(Flow.scala:439)
    at akka.remote.artery.Association.akka$remote$artery$Association$$runOutboundOrdinaryMessagesStream(Association.scala:570)
    at akka.remote.artery.Association.runOutboundStreams(Association.scala:510)
    at akka.remote.artery.Association.associate(Association.scala:502)
    at akka.remote.artery.AssociationRegistry.association(Association.scala:763)
    at akka.remote.artery.ArteryTransport.association(ArteryTransport.scala:932)
    at akka.remote.artery.ArteryTransport.send(ArteryTransport.scala:918)
    at akka.remote.RemoteActorRef.$bang(RemoteActorRefProvider.scala:563)
    at akka.actor.ActorRef.tell(ActorRef.scala:124)
    at akka.actor.ActorSelection$.rec$1(ActorSelection.scala:250)
    at akka.actor.ActorSelection$.deliverSelection(ActorSelection.scala:254)
    at akka.actor.ActorSelection.tell(ActorSelection.scala:45)
    at actors.ClientActor.<init>(ClientActor.java:21)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at akka.util.Reflect$.instantiate(Reflect.scala:44)
    at akka.actor.NoArgsReflectConstructor.produce(IndirectActorProducer.scala:105)
    at akka.actor.Props.newActor(Props.scala:213)
    at akka.actor.ActorCell.newActor(ActorCell.scala:563)
    at akka.actor.ActorCell.create(ActorCell.scala:589)
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:462)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:484)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
    at akka.dispatch.Mailbox.run(Mailbox.scala:223)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
    at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
</code>```

I also try to send message with these "ActorSelection paths":

"akka://server@192.168.0.250:5001/user/server-process"
  "akka://server@localhost:5001/user/server-process"
  "akka://server@192.168.0.250:10001/user/server-process"
  "akka://server@localhost:10001/user/server-process"

but the error still appears.

It is important to clarify, also, that the actor path of the server actor is:

akka://server/user/server-process

What is missing? I'm using akka 2.5.3 version...

Thank's.

答:
I am not quite sure how Akka canonical vs bind addressing works. But my guess is that the bind.hostname is the actual IP or resolved IP by the hostname that it will listen on. In this case, localhost translates to 127.0.0.1, which means the container will only accept connections on 127.0.0.1.

Try setting the bind.hostname to 0.0.0.0. This will allow connections from IP addresses outside the container (from host through port 5001).

Body:
First of all, sorry for my english. Google translate helps me a lot, haha.

My problem is this:

I have two example projects developed with akka and java: example-remote-client.jar and example-remote-server.jar

I'm using artery serialization, and and i'm trying to send messages from client to server via akka-remoting.

The client actor that does that is:

public class ClientActor extends AbstractActor {

    public static Props props() {
        return Props.create(ClientActor.class);

    }

    public ClientActor() {
        ActorSelection selection = getContext().system().actorSelection("akka://server@localhost:5001/user/server-process");
        selection.tell(new MessageRequest(), getSelf());
    }

    public Receive createReceive() {
        return receiveBuilder().match(MessageResponse.class, msg -> {
            System.out.println(msg.getMessage());
        }).build();
    }
}

My client configuration:

akka {
  loglevel = "DEBUG"

  actor {
    provider = remote
    allow-java-serialization = off

    serializers {
      java = "akka.serialization.JavaSerializer"
      myown = "serializers.ExampleByteBufSerializer"
    }

    serialization-bindings {
      "java.lang.String" = myown
      "protocol.MessageRequest" = myown
      "protocol.MessageResponse" = myown
      "java.lang.Boolean" = myown
    }

  }

  remote {
    artery {
      enabled = on
      canonical.hostname = "192.168.0.250"     # external (logical) hostname
      canonical.port = 5000                   # external (logical) port

      bind.hostname = "localhost" # internal (bind) hostname
      bind.port = 10000              # internal (bind) port
    }
  }
}

The server actor is very dummy, i dont think it is necessary to paste it here. But its configuration is:

akka {
  loglevel = "DEBUG"

  actor {
    provider = remote
    allow-java-serialization = off

    serializers {
      java = "akka.serialization.JavaSerializer"
      myown = "serializers.ExampleByteBufSerializer"
    }

    serialization-bindings {
      "java.lang.String" = myown
      "protocol.MessageRequest" = myown
      "protocol.MessageResponse" = myown
      "java.lang.Boolean" = myown
    }

  }

  remote {
    artery {
      enabled = on
      canonical.hostname = "192.168.0.250"     # external (logical) hostname
      canonical.port = 5001                   # external (logical) port

      bind.hostname = "localhost" # internal (bind) hostname
      bind.port = 10001              # internal (bind) port
    }
  }
}

Both jar are deployed over docker instances running over the same "192.168.0.250 machine", as seen below:

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                                            NAMES
d2970bd20371        openjdk:alpine             "sh"                     34 minutes ago      Up 34 minutes       0.0.0.0:5001->10001/tcp                          ex-remoting-server
36a67fea8590        openjdk:alpine             "sh"                     34 minutes ago      Up 34 minutes       0.0.0.0:5000->10000/tcp                          ex-remoting-client

The server starts ok, with the following log:

[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] logger log1-Logging$DefaultLogger started
[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] Default Loggers started
[DEBUG] [07/04/2017 13:46:18.495] [main] [akka.serialization.Serialization(akka://server)] Replacing JavaSerializer with DisabledJavaSerializer, due to `akka.actor.allow-java-serialization = off`.
[INFO] [07/04/2017 13:46:18.628] [main] [akka.remote.artery.ArteryTransport(akka://server)] Started embedded media driver in directory [/dev/shm/aeron-root-server-efd42dec-452d-406c-8d1d-807e0d8ff7fc]
[INFO] [07/04/2017 13:46:18.693] [main] [akka.remote.artery.ArteryTransport(akka://server)] Remoting started; listening on address: [akka://server@192.168.0.250:5001] with UID [-2663186266051514585]

But when i try to start client, i get the following error:

[ERROR] [07/04/2017 14:09:05.250] [client-akka.actor.default-dispatcher-10] [akka://server@192.168.0.250:5001/] swallowing exception during message send
io.aeron.exceptions.RegistrationException: Insufficient usable storage for new log of length=50332096 in /dev/shm (shm)
    at io.aeron.ClientConductor.onError(ClientConductor.java:285)
    at io.aeron.DriverListenerAdapter.onMessage(DriverListenerAdapter.java:79)
    at org.agrona.concurrent.broadcast.CopyBroadcastReceiver.receive(CopyBroadcastReceiver.java:100)
    at io.aeron.DriverListenerAdapter.pollMessage(DriverListenerAdapter.java:59)
    at io.aeron.ClientConductor.doWork(ClientConductor.java:422)
    at io.aeron.ClientConductor.awaitResponse(ClientConductor.java:447)
    at io.aeron.ClientConductor.addPublication(ClientConductor.java:177)
    at io.aeron.Aeron.addPublication(Aeron.java:165)
    at akka.remote.artery.AeronSink$$anon$1.<init>(AeronSink.scala:103)
    at akka.remote.artery.AeronSink.createLogicAndMaterializedValue(AeronSink.scala:100)
    at akka.stream.impl.GraphStageIsland.materializeAtomic(PhasedFusingActorMaterializer.scala:627)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:458)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:420)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:415)
    at akka.stream.scaladsl.RunnableGraph.run(Flow.scala:439)
    at akka.remote.artery.Association.akka$remote$artery$Association$$runOutboundOrdinaryMessagesStream(Association.scala:570)
    at akka.remote.artery.Association.runOutboundStreams(Association.scala:510)
    at akka.remote.artery.Association.associate(Association.scala:502)
    at akka.remote.artery.AssociationRegistry.association(Association.scala:763)
    at akka.remote.artery.ArteryTransport.association(ArteryTransport.scala:932)
    at akka.remote.artery.ArteryTransport.send(ArteryTransport.scala:918)
    at akka.remote.RemoteActorRef.$bang(RemoteActorRefProvider.scala:563)
    at akka.actor.ActorRef.tell(ActorRef.scala:124)
    at akka.actor.ActorSelection$.rec$1(ActorSelection.scala:250)
    at akka.actor.ActorSelection$.deliverSelection(ActorSelection.scala:254)
    at akka.actor.ActorSelection.tell(ActorSelection.scala:45)
    at actors.ClientActor.<init>(ClientActor.java:21)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at akka.util.Reflect$.instantiate(Reflect.scala:44)
    at akka.actor.NoArgsReflectConstructor.produce(IndirectActorProducer.scala:105)
    at akka.actor.Props.newActor(Props.scala:213)
    at akka.actor.ActorCell.newActor(ActorCell.scala:563)
    at akka.actor.ActorCell.create(ActorCell.scala:589)
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:462)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:484)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
    at akka.dispatch.Mailbox.run(Mailbox.scala:223)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
    at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

I also try to send message with these "ActorSelection paths":

"akka://server@192.168.0.250:5001/user/server-process"
  "akka://server@localhost:5001/user/server-process"
  "akka://server@192.168.0.250:10001/user/server-process"
  "akka://server@localhost:10001/user/server-process"

but the error still appears.

It is important to clarify, also, that the actor path of the server actor is:

akka://server/user/server-process

What is missing? I'm using akka 2.5.3 version...

Thank's.


来源: stackexchange

问:
Creating permalinks with Express/MongoDB
Suppose I have the following schemas for a LMS app:

```<code>const CourseSchema = new mongoose.Schema({
    name: { type: String, required: true },
    code: { type: String, required: true, unique: 1, uppercase: 1 }, // ex. CSCA48
    quizzes: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Quiz' }]
});

const QuizSchema = new mongoose.Schema({
    name: { type: String, required: true }, // ex. 1a
    questions: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Question' }]
});

const QuestionSchema = new mongoose.Schema({
    number: { type: String, required: true }, // ex. 4
    question: { type: String, required: true },
    type: { type: String },
    choices: [String],
    answers: [String]
});
</code>```

I built (or tried to build) the app following RESTful API guidelines. For example,

```<code>GET /courses/[ObjectID]
GET /courses/[ObjectID]/quizzes
GET /courses/[ObjectID]/quizzes/[ObjectID]
GET /courses/[ObjectID]/quizzes/[ObjectID]/questions
</code>```

The reason why I used ObjectID was because they are unique and makes it easy to retrieve objects -- particularly with app.param(). For example,

```<code>router.param('courseID', controllers.Course.getCourseByParam);
router.param('quizID', controllers.Quiz.getQuizByParam);
router.param('questionID', controllers.Question.getQuestionByParam);

router.get('/courses', controllers.Course.getCourses);
router.get('/courses/:courseID', controllers.Course.getCourse);
router.get('/courses/:courseID/quizzes', controllers.Quiz.getQuizzes);
router.get('/courses/:courseID/quizzes/:quizID/questions', controllers.Question.getQuestions);
</code>```

But now, I am wondering if there is a way to not use ObjectID in order make the URLs more friendly/readable?

```<code>GET /courses/[code]/quizzes/[name]/questions/[number]

ex. /courses/CSCA48/quizzes/1a/questions/4
</code>```

My biggest concern with this is that, although course code is unique, quiz name and question number are not. For example, /courses/CSCA48/quizzes/1b/questions/4 would be a different question for a different quiz. So, unless I am mistaken, it is not really possible to use app.param(). Therefore I would need to somehow ensure that the quiz belongs to the matched course and then question belongs to the matched quiz.

I am not really looking for code, just a general idea of how I can approach this (or not).

答:
Since the combination [code]-[name]-[number] is unique (and [code] too, which is important), you should be able to run a query that would bring up the correct question:

```<code>Course.findOne({ code : req.params.code })
      .populate({
        path     : 'quizzes',
        match    : { name : req.params.name },
        populate : {
          path  : 'questions',
          match : { number : req.params.number }
        }
      })
</code>```

Alternatively, you could add two fields to QuestionSchema to reflect both the course and the quiz to which the question belongs, in which case you'd only have to run a single query to find the correct question document (population requires 3 queries).

ContentLicense: CC BY-SA 3.0

Body:
Suppose I have the following schemas for a LMS app:

const CourseSchema = new mongoose.Schema({
    name: { type: String, required: true },
    code: { type: String, required: true, unique: 1, uppercase: 1 }, // ex. CSCA48
    quizzes: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Quiz' }]
});

const QuizSchema = new mongoose.Schema({
    name: { type: String, required: true }, // ex. 1a
    questions: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Question' }]
});

const QuestionSchema = new mongoose.Schema({
    number: { type: String, required: true }, // ex. 4
    question: { type: String, required: true },
    type: { type: String },
    choices: [String],
    answers: [String]
});

I built (or tried to build) the app following RESTful API guidelines. For example,

GET /courses/[ObjectID]
GET /courses/[ObjectID]/quizzes
GET /courses/[ObjectID]/quizzes/[ObjectID]
GET /courses/[ObjectID]/quizzes/[ObjectID]/questions

The reason why I used ObjectID was because they are unique and makes it easy to retrieve objects -- particularly with app.param(). For example,

router.param('courseID', controllers.Course.getCourseByParam);
router.param('quizID', controllers.Quiz.getQuizByParam);
router.param('questionID', controllers.Question.getQuestionByParam);

router.get('/courses', controllers.Course.getCourses);
router.get('/courses/:courseID', controllers.Course.getCourse);
router.get('/courses/:courseID/quizzes', controllers.Quiz.getQuizzes);
router.get('/courses/:courseID/quizzes/:quizID/questions', controllers.Question.getQuestions);

But now, I am wondering if there is a way to not use ObjectID in order make the URLs more friendly/readable?

GET /courses/[code]/quizzes/[name]/questions/[number]

ex. /courses/CSCA48/quizzes/1a/questions/4

My biggest concern with this is that, although course code is unique, quiz name and question number are not. For example, /courses/CSCA48/quizzes/1b/questions/4 would be a different question for a different quiz. So, unless I am mistaken, it is not really possible to use app.param(). Therefore I would need to somehow ensure that the quiz belongs to the matched course and then question belongs to the matched quiz.

I am not really looking for code, just a general idea of how I can approach this (or not).

Body:
Since the combination [code]-[name]-[number] is unique (and [code] too, which is important), you should be able to run a query that would bring up the correct question:

Course.findOne({ code : req.params.code })
      .populate({
        path     : 'quizzes',
        match    : { name : req.params.name },
        populate : {
          path  : 'questions',
          match : { number : req.params.number }
        }
      })

Alternatively, you could add two fields to QuestionSchema to reflect both the course and the quiz to which the question belongs, in which case you'd only have to run a single query to find the correct question document (population requires 3 queries).


问:
Content behind Position: fixed is intractable
I have following setup:

```<code><div class="wrapper">
   <div class="element" id="first"></div>
   <div class="element"></div>
   <div class="element"></div>
   <div class="element"></div>
...
</div>
</code>```

so wrapper is set to overflow-x: auto and content that overflows it is horizontally scrollable. #first div has fixed position and more styling applied, but essentially it is always visible and other divs scroll behind it, like this:

issue here is that I'm using drag and drop functionality which works fine, but once I try to drop stuff on a fixed div and if it has content behind it, the drag and drop happens to that content. Basically feels like I'm interacting with stuff behind fixed div even though it is in front. I know fixed elements are out of the flow and maybe this is whats causing it? But I can't figure out how to make content behind that div stay behind it.

答: Try plaing with ay pointer-events: none; in CSS

Body:
I have following setup:

...

so wrapper is set to overflow-x: auto and content that overflows it is horizontally scrollable. #first div has fixed position and more styling applied, but essentially it is always visible and other divs scroll behind it, like this:

issue here is that I'm using drag and drop functionality which works fine, but once I try to drop stuff on a fixed div and if it has content behind it, the drag and drop happens to that content. Basically feels like I'm interacting with stuff behind fixed div even though it is in front. I know fixed elements are out of the flow and maybe this is whats causing it? But I can't figure out how to make content behind that div stay behind it.


问:
Why latest .net 4.7 adds an invalid configsection to my web.config?
I am having an issue with an asp.net app where the web.config is updated and reloaded dynamically.

The following code is used to save the appsettings section in web.config:

```<code>     public static void SetWebConfigValue(string keyValue, string value, bool isDefault)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

                AppSettingsSection appSettings = config.AppSettings;

                KeyValueConfigurationCollection settings = appSettings.Settings;

                if (KeyExists(settings.AllKeys, keyValue))
                {
                    settings.Remove(keyValue);
                }

                if (!isDefault) settings.Add(keyValue, value);

                config.Save(ConfigurationSaveMode.Modified, true);
            }
        }
</code>```

This code works just fine when I deploy the web app using on a machine with the .net 4.0 runtime. However, on a machine with the  .net 4.7 runtime installed, an extra (empty) <System.Windows.Forms.ApplicationConfigurationSection /> is added to web.config. Since this setting cannot be empty, this crashes the web app when the web.config is reloaded.

Edit: Question: why does the latest .net 4.7 adds an invalid configsection to my web.config?

Edit 2: the following issue has been created: https://github.com/Microsoft/dotnet/issues/435

答:
We ran into this as well.

I think it looks like Microsoft missed the backwards compatibility here between .Net 4.7 and earlier versions.

You didn't really pose this as a question, but what we ended up doing was reading the config file as a string after saving it, then we removed the offending section with a string replacement and saved the string down to file again. It's not pretty but it gets the job done.

Body:
I am having an issue with an asp.net app where the web.config is updated and reloaded dynamically.

The following code is used to save the appsettings section in web.config:

     public static void SetWebConfigValue(string keyValue, string value, bool isDefault)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

                AppSettingsSection appSettings = config.AppSettings;

                KeyValueConfigurationCollection settings = appSettings.Settings;

                if (KeyExists(settings.AllKeys, keyValue))
                {
                    settings.Remove(keyValue);
                }

                if (!isDefault) settings.Add(keyValue, value);

                config.Save(ConfigurationSaveMode.Modified, true);
            }
        }

This code works just fine when I deploy the web app using on a machine with the .net 4.0 runtime. However, on a machine with the  .net 4.7 runtime installed, an extra (empty) <System.Windows.Forms.ApplicationConfigurationSection /> is added to web.config. Since this setting cannot be empty, this crashes the web app when the web.config is reloaded.

Edit: Question: why does the latest .net 4.7 adds an invalid configsection to my web.config?

Edit 2: the following issue has been created: https://github.com/Microsoft/dotnet/issues/435


问:
Access SQL appears to be treating date as dd/mm/yyyy?
I have a table in MS Access which holds staff details (tblStaff):

```<code>| Employee Number |  Employee Name |  Dept     |
------------------------------------------------
|     205147      |   Joe Bloggs   |  IT       |
|     205442      |   John Doe     |  Accounts |
</code>```

I refresh this table with new data weekly and if any records have changed (e.g. changed dept) then they are archived in another table (tblArchiveStaff) along with the dates that that record was valid from and to.

```<code>| Employee Number |  Employee Name |  Dept     | DateFrom | DateTo   |
----------------------------------------------------------------------
|     205147      |   Joe Bloggs   |  HR       | 03/01/16 | 01/06/17 |
</code>```

I am trying to write a query that will select records from either of these tables based on which ones were valid for a given date

We can assume that records in tblStaff are valid from the dateTo + 1 of the last entry for that employee in tblArchiveStaff, or from 03 Jan 16 if they have no archived records.

So far I have come up with the below query into which I have hardcoded the date condition of #07/01/2017#:

```<code>SELECT [Employee Number], [Dept], DateFrom, DateTo
FROM

     (
      SELECT ts.[Employee Number], ts.[Dept], nz(ta2.DateTo,#01/02/16#)+1 AS DateFrom, date() AS DateTo
      FROM tblStaff ts LEFT JOIN tblArchiveStaff ta2 ON ts.[Employee Number] = ta2.[Employee Number]

      UNION ALL

      SELECT ta.[Employee Number], ta.[Dept], ta.DateFrom, ta.DateTo
      FROM tblArchiveStaff ta

     ) AS tblUnion

WHERE #07/01/2017# BETWEEN DateFrom AND DateTo;
</code>```

As I understand it the above query should return records valid on July 1st 2017 which would be both records in tblStaff, it is however returning the record in tblArchiveStaff. It is almost like it is treating the date condition as 7 January which would mean it is formatted dd/mm/yyyy which I thought was impossible.

Can anyone explain this please?

答:
Standard date flipping errors.  Try to always use neutral date formats in your code like

d MMM yyyy

1 Jul 2017 (viable but not recommended because of language differences)

or

yyyy-MM-dd

2017-07-01 (recommended, will work everywhere)

Body:
I have a table in MS Access which holds staff details (tblStaff):

| Employee Number |  Employee Name |  Dept     |
------------------------------------------------
|     205147      |   Joe Bloggs   |  IT       |
|     205442      |   John Doe     |  Accounts |

I refresh this table with new data weekly and if any records have changed (e.g. changed dept) then they are archived in another table (tblArchiveStaff) along with the dates that that record was valid from and to.

| Employee Number |  Employee Name |  Dept     | DateFrom | DateTo   |
----------------------------------------------------------------------
|     205147      |   Joe Bloggs   |  HR       | 03/01/16 | 01/06/17 |

I am trying to write a query that will select records from either of these tables based on which ones were valid for a given date

We can assume that records in tblStaff are valid from the dateTo + 1 of the last entry for that employee in tblArchiveStaff, or from 03 Jan 16 if they have no archived records.

So far I have come up with the below query into which I have hardcoded the date condition of #07/01/2017#:

SELECT [Employee Number], [Dept], DateFrom, DateTo
FROM

     (
      SELECT ts.[Employee Number], ts.[Dept], nz(ta2.DateTo,#01/02/16#)+1 AS DateFrom, date() AS DateTo
      FROM tblStaff ts LEFT JOIN tblArchiveStaff ta2 ON ts.[Employee Number] = ta2.[Employee Number]

      UNION ALL

      SELECT ta.[Employee Number], ta.[Dept], ta.DateFrom, ta.DateTo
      FROM tblArchiveStaff ta

     ) AS tblUnion

WHERE #07/01/2017# BETWEEN DateFrom AND DateTo;

As I understand it the above query should return records valid on July 1st 2017 which would be both records in tblStaff, it is however returning the record in tblArchiveStaff. It is almost like it is treating the date condition as 7 January which would mean it is formatted dd/mm/yyyy which I thought was impossible.

Can anyone explain this please?


问:
How to get indirect groups of an AD user? - C#
I'm using DirectorySearcher to get the groups of an AD user in which he is a member of using the 'memberof' property. But according to this msdn page the 'memberof' property only returns the direct groups in which the user is a member. How can I get the indirect groups of the user too.

For ex.

```<code>Group A -> User X, User Y, Group B
Group B -> User Z
Group C -> User Z
</code>```

I want to get the result as Group A, Group B, Group C for the user Z since he is an indirect user of Group A.

Update

Okie. I've followed this codeproject article to get the groups recursively. But still the builtin group 'Domain Users' is missing from the list. So does that mean Built in groups wont appear in the directory searcher?

答: You have to define your own method of iterating through the direct groups until you reach the common root for all. You will need to perform an LDAP query against each group and use the same memberOf attribute to determine which groups that group belongs to. This can be time intensive, particularly if the groups are numerous and laid out web-like.

ContentLicense: CC BY-SA 2.5

Body:
I'm using DirectorySearcher to get the groups of an AD user in which he is a member of using the 'memberof' property. But according to this msdn page the 'memberof' property only returns the direct groups in which the user is a member. How can I get the indirect groups of the user too.

For ex.

Group A -> User X, User Y, Group B
Group B -> User Z
Group C -> User Z

I want to get the result as Group A, Group B, Group C for the user Z since he is an indirect user of Group A.

Update

Okie. I've followed this codeproject article to get the groups recursively. But still the builtin group 'Domain Users' is missing from the list. So does that mean Built in groups wont appear in the directory searcher?


问:
Content Slider Pure CSS
I have code below for a content slider using HTML, CSS and JQuery. Is it possible to get exactly what I have now but using pure CSS only? If its not possible with pure CSS is it possible to do with Vanilla JavaScript with no JQuery? Anything helps, cheers.

$(function(){
        var scroller = $('#scroller div.innerScrollArea');
        var scrollerContent = scroller.children('ul');
        scrollerContent.children().clone().appendTo(scrollerContent);
        var curX = 0;
        scrollerContent.children().each(function(){
            var $this = $(this);
            $this.css('left', curX);
            curX += $this.outerWidth(true);
        });
        var fullW = curX / 2;
        var viewportW = scroller.width();

        // Scrolling speed management
        var controller = {curSpeed:0, fullSpeed:2};
        var $controller = $(controller);
        var tweenToNewSpeed = function(newSpeed, duration)
        {
            if (duration === undefined)
                duration = 600;
            $controller.stop(true).animate({curSpeed:newSpeed}, duration);
        };

        // Pause on hover
        scroller.hover(function(){
            tweenToNewSpeed(0);
        }, function(){
            tweenToNewSpeed(controller.fullSpeed);
        });

        // Scrolling management; start the automatical scrolling
        var doScroll = function()
        {
            var curX = scroller.scrollLeft();
            var newX = curX + controller.curSpeed;
            if (newX > fullW*2 - viewportW)
                newX -= fullW;
            scroller.scrollLeft(newX);
        };
        setInterval(doScroll, 40);
        tweenToNewSpeed(controller.fullSpeed);
    });```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#scroller {
  position: absolute;
}

#scroller .innerScrollArea {
  overflow: hidden;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

#scroller ul {
  padding: 0;
  position: relative;
}

#scroller li {
  padding: 0;
  list-style-type: none;
  position: absolute;
}
.circle {
  width: 250px;
  height: 250px;
  position: relative;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border-radius: 50%;
  background-color:transparent;
  border-style:solid;
  border-width:9px;
  border-color:#006850;
}

.circle-text {
  color: #1f497d;
  font-family:Verdana;
  font-size: 20.5px;
  text-align: center;
  width: 200px;
  top: 90px;
  left: 10%;
  bottom: 0;
  position: absolute;
  z-index: 99;
}

.arrow {
  width:300px;
  height:80px;
}

.flipimage {
  width:300px;
  height:80px;
  -moz-transform: scaleY(-1);
    -webkit-transform: scaleY(-1);
    -o-transform: scaleY(-1);
    transform: scaleY(-1);
    -ms-filter: fliph; /*IE*/
    filter: fliph; /*IE*/
}

.everything {
  /*transform: scale(0.6);
}</code>```

        HR Connect
Service
Representative

Employee
Relations
Specialist

       Employee
Relations
Manager

Director, Employee
Relations &
Well-Being

```

答:
You may use animation , but to keep the whole thing sliding for ever, you will need to clone (or make a redundant copy in HTML)  at least of the elements that you see at first in the slider . Else, it would behave as a marquee , living a blank space untill everything slides off the box.

Example below:

/* all position:absolute removed */
#scroller {
overflow:hidden;
}

#scroller .innerScrollArea {

}

#scroller ul {
  padding: 0;
  position: relative;
  display:flex;/* UPDATE */
}

#scroller li {
  padding: 0;
  list-style-type: none;
}
.circle {
  width: 250px;
  height: 250px;
  position: relative;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border-radius: 50%;
  background-color:transparent;
  border-style:solid;
  border-width:9px;
  border-color:#006850;
}

.circle-text {
  color: #1f497d;
  font-family:Verdana;
  font-size: 20.5px;
  text-align: center;
  width: 200px;
  top: 90px;
  left: 10%;
  bottom: 0;
  position: absolute;
  z-index: 99;
}

.arrow {
  width:300px;
  height:80px;
}

.flipimage {
  width:300px;
  height:80px;
  -moz-transform: scaleY(-1);
    -webkit-transform: scaleY(-1);
    -o-transform: scaleY(-1);
    transform: scaleY(-1);
    -ms-filter: fliph; /*IE*/
    filter: fliph; /*IE*/
}

/* UPDATE  for animation */
ul {
  animation: slidli 9s infinite linear;
}
ul:hover {
  animation-play-state:paused;
}
@keyframes slidli {
  100% {
    transform:translatex(-133.5%);/* this is to be update to the content with to see every element slide once untill copies/clone comes back at same spot */
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="everything">
  <div id="scroller" style="width: 900px; height: 470px; margin: 0 auto;">
    <div class="innerScrollArea">
      <ul>
        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              HR Connect<br/>Service<br/>Representative
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Specialist
            </div>
          </div>
        </li>
        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Manager
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Director, Employee<br/>Relations &<br/>Well-Being
            </div>
          </div>
        </li>
        <!-- from here it is a copy of the previous elements . 3 of them might have been enough -->

        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              HR Connect<br/>Service<br/>Representative
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Specialist
            </div>
          </div>
        </li>
        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Manager
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Director, Employee<br/>Relations &<br/>Well-Being
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</div></code>```

Notice: I used the flex model and droppped the absolute positionning. Main parent can be in absolute if you do need it, children do not.

Title: Content Slider Pure CSS

Body:
I have code below for a content slider using HTML, CSS and JQuery. Is it possible to get exactly what I have now but using pure CSS only? If its not possible with pure CSS is it possible to do with Vanilla JavaScript with no JQuery? Anything helps, cheers.

$(function(){
        var scroller = $('#scroller div.innerScrollArea');
        var scrollerContent = scroller.children('ul');
        scrollerContent.children().clone().appendTo(scrollerContent);
        var curX = 0;
        scrollerContent.children().each(function(){
            var $this = $(this);
            $this.css('left', curX);
            curX += $this.outerWidth(true);
        });
        var fullW = curX / 2;
        var viewportW = scroller.width();

        // Scrolling speed management
        var controller = {curSpeed:0, fullSpeed:2};
        var $controller = $(controller);
        var tweenToNewSpeed = function(newSpeed, duration)
        {
            if (duration === undefined)
                duration = 600;
            $controller.stop(true).animate({curSpeed:newSpeed}, duration);
        };

        // Pause on hover
        scroller.hover(function(){
            tweenToNewSpeed(0);
        }, function(){
            tweenToNewSpeed(controller.fullSpeed);
        });

        // Scrolling management; start the automatical scrolling
        var doScroll = function()
        {
            var curX = scroller.scrollLeft();
            var newX = curX + controller.curSpeed;
            if (newX > fullW*2 - viewportW)
                newX -= fullW;
            scroller.scrollLeft(newX);
        };
        setInterval(doScroll, 40);
        tweenToNewSpeed(controller.fullSpeed);
    });

#scroller {
  position: absolute;
}

#scroller .innerScrollArea {
  overflow: hidden;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

#scroller ul {
  padding: 0;
  position: relative;
}

#scroller li {
  padding: 0;
  list-style-type: none;
  position: absolute;
}
.circle {
  width: 250px;
  height: 250px;
  position: relative;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border-radius: 50%;
  background-color:transparent;
  border-style:solid;
  border-width:9px;
  border-color:#006850;
}

.circle-text {
  color: #1f497d;
  font-family:Verdana;
  font-size: 20.5px;
  text-align: center;
  width: 200px;
  top: 90px;
  left: 10%;
  bottom: 0;
  position: absolute;
  z-index: 99;
}

.arrow {
  width:300px;
  height:80px;
}

.flipimage {
  width:300px;
  height:80px;
  -moz-transform: scaleY(-1);
    -webkit-transform: scaleY(-1);
    -o-transform: scaleY(-1);
    transform: scaleY(-1);
    -ms-filter: fliph; /*IE*/
    filter: fliph; /*IE*/
}

.everything {
  /*transform: scale(0.6);
}

        HR Connect
Service
Representative

Employee
Relations
Specialist

       Employee
Relations
Manager

Director, Employee
Relations &
Well-Being

Body:
You may use animation , but to keep the whole thing sliding for ever, you will need to clone (or make a redundant copy in HTML)  at least of the elements that you see at first in the slider . Else, it would behave as a marquee , living a blank space untill everything slides off the box.

Example below:

/* all position:absolute removed */
#scroller {
overflow:hidden;
}

#scroller .innerScrollArea {

}

#scroller ul {
  padding: 0;
  position: relative;
  display:flex;/* UPDATE */
}

#scroller li {
  padding: 0;
  list-style-type: none;
}
.circle {
  width: 250px;
  height: 250px;
  position: relative;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  border-radius: 50%;
  background-color:transparent;
  border-style:solid;
  border-width:9px;
  border-color:#006850;
}

.circle-text {
  color: #1f497d;
  font-family:Verdana;
  font-size: 20.5px;
  text-align: center;
  width: 200px;
  top: 90px;
  left: 10%;
  bottom: 0;
  position: absolute;
  z-index: 99;
}

.arrow {
  width:300px;
  height:80px;
}

.flipimage {
  width:300px;
  height:80px;
  -moz-transform: scaleY(-1);
    -webkit-transform: scaleY(-1);
    -o-transform: scaleY(-1);
    transform: scaleY(-1);
    -ms-filter: fliph; /*IE*/
    filter: fliph; /*IE*/
}

/* UPDATE  for animation */
ul {
  animation: slidli 9s infinite linear;
}
ul:hover {
  animation-play-state:paused;
}
@keyframes slidli {
  100% {
    transform:translatex(-133.5%);/* this is to be update to the content with to see every element slide once untill copies/clone comes back at same spot */
  }
}

<div class="everything">
  <div id="scroller" style="width: 900px; height: 470px; margin: 0 auto;">
    <div class="innerScrollArea">
      <ul>
        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              HR Connect<br/>Service<br/>Representative
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Specialist
            </div>
          </div>
        </li>
        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Manager
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Director, Employee<br/>Relations &<br/>Well-Being
            </div>
          </div>
        </li>
        <!-- from here it is a copy of the previous elements . 3 of them might have been enough -->

        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              HR Connect<br/>Service<br/>Representative
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Specialist
            </div>
          </div>
        </li>
        <li>
          <br style="line-height:89px;" />
          <div class="circle">
            <div class="circle-text">
              Employee<br/>Relations<br/>Manager
            </div>
          </div>
          <img class="flipimage" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
        </li>
        <li>
          <img class="arrow" src="http://res.cloudinary.com/djxai1v1e/image/upload/v1499182382/testarrow_png6fn.png">
          <div class="circle">
            <div class="circle-text">
              Director, Employee<br/>Relations &<br/>Well-Being
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</div>

Notice: I used the flex model and droppped the absolute positionning. Main parent can be in absolute if you do need it, children do not.


问:
Express any odd number greater than 5 as the sum of 3 primes
For a given odd number n I want to efficiently compute 3 primes whose sum is equal to n. If there are multiple solutions then I want the one with the smallest primes (I want 2+2+17=21 instead of 3+5+13=21)

This is always possible forn>5.

My current approach is to reduce the problem to computing 2 primes whose sum is equal to n-3 and then I simply output the 2 computed primes and 3 since they obviously sum up to n. I choose 3 since it is the smallest odd prime and when I subtract it from n I get an even number, therefore it should be part of every solution I'm looking for. I'm using this to compute the sum of 2 primes, it works if n is even which it is in my case (since I subtracted 3 from an odd n).

My approach doesn't work since there are solutions without a 3 as a summand (41=2+2+37).

Is there a straightforward approach which I'm missing?

答: First test whether n-4 is prime.  If so, your answer is {2, 2, n-4}.  Otherwise, your original approach will work.  You'll never use just one 2 because your sum would be even.</p>


问:
Error: Current componentRef is different for cached componentRef
I'm developing a NativeScript Angular 2 application.

I have a ListView that contains a bunch of objects. Tapping one of these objects opens up a new Component. After I press the back button to go back to the list and press on another object in the list, I get the following error:

How can I fix this?

```<code>CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1091:24: ERROR Error: Uncaught (in promise): Error: Current componentRef is different for cached componentRef
    deactivate@file:///app/tns_modules/nativescript-angular/router/page-router-outlet.js:105:32 [angular]
    deactiveRouteAndOutlet@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4578:30 [angular]
    deactiveRouteAndItsChildren@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4538:40 [angular]
    deactivateRoutes@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4467:49 [angular]
    file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4429:35 [angular]
    forEach@[native code] [angular]
    deactivateChildRoutes@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4428:36 [angular]
    activate@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4415:35 [angular]
    file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4034:30 [angular]
    file:///app/tns_modules/rxjs/Observable.js:110:25 [angular]
    __tryOrSetError@file:///app/tns_modules/rxjs/Subscriber.js:247:20 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:187:42 [angular]
    _next@file:///app/tns_modules/rxjs/Subscriber.js:125:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/reduce.js:119:34 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyComplete@file:///app/tns_modules/rxjs/operator/every.js:53:30 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/every.js:70:28 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyComplete@file:///app/tns_modules/rxjs/operator/every.js:53:30 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/every.js:70:28 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]
</code>```

```

答: I had this error because the details page was referencing a object property in the actionbar... (looks like it was not instantiated at the time the action bar got rendered) Hope it helps</p>

Body:
I'm developing a NativeScript Angular 2 application.

I have a ListView that contains a bunch of objects. Tapping one of these objects opens up a new Component. After I press the back button to go back to the list and press on another object in the list, I get the following error:

How can I fix this?

CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1091:24: ERROR Error: Uncaught (in promise): Error: Current componentRef is different for cached componentRef
    deactivate@file:///app/tns_modules/nativescript-angular/router/page-router-outlet.js:105:32 [angular]
    deactiveRouteAndOutlet@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4578:30 [angular]
    deactiveRouteAndItsChildren@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4538:40 [angular]
    deactivateRoutes@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4467:49 [angular]
    file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4429:35 [angular]
    forEach@[native code] [angular]
    deactivateChildRoutes@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4428:36 [angular]
    activate@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4415:35 [angular]
    file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4034:30 [angular]
    file:///app/tns_modules/rxjs/Observable.js:110:25 [angular]
    __tryOrSetError@file:///app/tns_modules/rxjs/Subscriber.js:247:20 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:187:42 [angular]
    _next@file:///app/tns_modules/rxjs/Subscriber.js:125:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/reduce.js:119:34 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyComplete@file:///app/tns_modules/rxjs/operator/every.js:53:30 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/every.js:70:28 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyComplete@file:///app/tns_modules/rxjs/operator/every.js:53:30 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/every.js:70:28 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]

```


问:
Reset checkbox to initial status
As you may know, Reset buttons in a form can not reset checkboxes to their initial status. How can I make that happen either with javascript or PHP or jquery or ...?

Here is the code I have:

```<code><form method="POST">
<input type="text" name="name" id="name" value="default value" required >
<input type="checkbox" name="group[]" id="checkbox1" value="0" checked>
<input type="checkbox" name="group[]" id="checkbox2" value="1" >
<button type="reset"> Reset </button>
<button type="submit"> Submit </button>
</form>
</code>```

答:
Iterate over all your input elements and uncheck the ones which are checked.

```<code>var allInputs = $( ":input" );

for(var i = 0; i < allInputs.length; i++) {

   if( $( 'input[type="checkbox"]:checked' ) )
      $( this ).prop('checked', false);
}
</code>```

Or as James pointed out, this could be done in one line like this:

```<code>$( 'input[type="checkbox"]' ).prop('checked', false);
</code>```

Title: Reset checkbox to initial status

Body:
As you may know, Reset buttons in a form can not reset checkboxes to their initial status. How can I make that happen either with javascript or PHP or jquery or ...?

Here is the code I have:

<form method="POST">
<input type="text" name="name" id="name" value="default value" required >
<input type="checkbox" name="group[]" id="checkbox1" value="0" checked>
<input type="checkbox" name="group[]" id="checkbox2" value="1" >
<button type="reset"> Reset </button>
<button type="submit"> Submit </button>
</form>

Body:
Iterate over all your input elements and uncheck the ones which are checked.

var allInputs = $( ":input" );

for(var i = 0; i < allInputs.length; i++) {

   if( $( 'input[type="checkbox"]:checked' ) )
      $( this ).prop('checked', false);
}

Or as James pointed out, this could be done in one line like this:

$( 'input[type="checkbox"]' ).prop('checked', false);


问:
Attendance reader with iBeacon/eddystone and raspberry
I'm a bit confused. I explain to you my project, I would like to make a "reader" by using beacon technology (ibeacon for apple, eddystone for android) using a raspberry pi 3. The smatphone application sends an acknowledgment code when passing the person. The raspberry marks and updates an online database. I wanted to ask, first of all can this be done? My problem is to realize the beacon transmission, then for the app and the database I have no problems. I tried using bluez but I can not detect the phone. Is there any online tutorial that could help me? Thanks</p>

答:
If you are looking to use the phone to emit a beacon transmission and then use the Raspberry Pi 3 to detect the beacon, then yes, this is possible.  I put together a tutorial on how to use the Android Things to detect beacons on the Raspberry Pi 3.

The problem with using BlueZ for beacon detection is that it is simply not stable on the Raspberry Pi, and will freeze up and stop detecting requiring a reboot.


问:
Google Maps in Internet Explorer
Kind of stuck here. I am adding a very simple google map to my webpage, and using the basic javascript API to do so. Everything works fine in chrome, but with internet explorer it works occasionally. The error that comes up is:

SCRIPT5022: InvalidValueError: initMap is not a function  js, line 102
  character 390

the error refers to the call to google maps API, not in my js.

```<code><!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  <title>Under Construction</title>
  <link rel="shortcut icon" href="images/betterlogo.ico" type="image/x-icon">

  <!-- Bootstrap -->
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/animate.css">
  <link rel="stylesheet" href="css/thumbnails.css">
  <link rel="stylesheet" href="css/main.css">

  <!-- JS -->

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->
<script src='js/device.min.js'></script>
</head>
</code>```

```<code>      <div class="col-md-6 col-sm-12 col-xs-12">
        <div class="container-fluid">
          <div id="map-canvas"></div>
        </div>
      </div>
</code>```

<--some more code filler that nobody needs to see,-->

```<code><!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.ui.accordion.min.js"></script>
<script src="js/wow.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDFmJX1o4ocAPluAPlDWlh-VX_35iwc23o&libraries=places&callback=initMap" async defer></script>
<script src="js/main.js"></script>
</code>```

and my javascript:

```<code>function initMap() {
  var myLatLng = {lat:40.4917507, lng:-74.2971267};
  var map = new google.maps.Map(document.getElementById('map-canvas'),{
  center: myLatLng,
  zoom: 15
  });
  var marker = new google.maps.Marker({
    position: myLatLng,
    map:map,
    title:"abc"
  });

  google.maps.event.addDomListener(window, "resize", function(){
    var center=map.getCenter();
    google.maps.event.trigger(map, "resize");
    map.setCenter(center);
  })
}
</code>```

答: I was getting the same error as above, but the marked answer didn't help. If anyone is getting the initMap error only on Internet explorer it could be because you are using JavaScript that is too modern for Internet Explorer including 'template literals' and 'arrow functions'. I went through my code and replaced them with older code which removed this error. Hopefully that will save someone the hours of debugging I went through...

Title: Google Maps in Internet Explorer

Body:
Kind of stuck here. I am adding a very simple google map to my webpage, and using the basic javascript API to do so. Everything works fine in chrome, but with internet explorer it works occasionally. The error that comes up is:

SCRIPT5022: InvalidValueError: initMap is not a function  js, line 102
  character 390

the error refers to the call to google maps API, not in my js.

<!DOCTYPE html>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>Under Construction</title>
  <link rel="shortcut icon" href="images/betterlogo.ico" type="image/x-icon">

  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="css/animate.css">
  <link rel="stylesheet" href="css/thumbnails.css">
  <link rel="stylesheet" href="css/main.css">

<--some more code filler that nobody needs to see,-->

and my javascript:

function initMap() {
  var myLatLng = {lat:40.4917507, lng:-74.2971267};
  var map = new google.maps.Map(document.getElementById('map-canvas'),{
  center: myLatLng,
  zoom: 15
  });
  var marker = new google.maps.Marker({
    position: myLatLng,
    map:map,
    title:"abc"
  });

  google.maps.event.addDomListener(window, "resize", function(){
    var center=map.getCenter();
    google.maps.event.trigger(map, "resize");
    map.setCenter(center);
  })
}


问:
Why does Foundation recommend adding a tabindex="0" to main content?
In Foundation's docs on creating skip links, they recommend adding tabindex="0" to the element that represents the main content to skip to. I'm a bit confused as to why they would say that. As far as I can see, this results in an extra element receiving focus when tabbing through the document, even though there's not really anything to do with that element focused.

Is the reason perhaps compatibility with older browsers that don't support anchoring to ids? Or is there another reason?

Update: It should soon no longer say the above anymore, but that's because I changed it in response to the answers here :P

答: Usually the main content is given an id which a skip link uses to jump the user's focus to the main content. However, this straight forward approach doesn't work in Internet Explorer 9. You need to set the focus to the main content using javascript focus(). And tabindex=0 is used to make an element that is not inherently capable of receiving focus, focusable.


问:
How to you get the address of an element in an std::string in C++?
For example, i have the following string :

```<code>std::string s = "Hello, World!"
</code>```

I want the address of the last element of s which is '!'.

I tried the following code, but it does not seem to output what I want it to.

```<code>std::cout << &s[s.length() - 1];
</code>```

That outputs '!' not it's address, the same happens with s.back()

Is it because of the formatting caused by std::cout or  is the problem elsewhere?

Basically I want a function that outputs the address of the last (and if possible, the first) element in a string.

答:
Currently, you're using the overload of operator<< that takes a const char* as input. It treats the input as a null-terminated C string.

If you cast to (const void*) the problem will go away:

```<code>std::cout << (const void*)(&s[s.length() - 1]);
</code>```

Body:
For example, i have the following string :

std::string s = "Hello, World!"

I want the address of the last element of s which is '!'.

I tried the following code, but it does not seem to output what I want it to.

std::cout << &s[s.length() - 1];

That outputs '!' not it's address, the same happens with s.back()

Is it because of the formatting caused by std::cout or  is the problem elsewhere?

Basically I want a function that outputs the address of the last (and if possible, the first) element in a string.

Body:
Currently, you're using the overload of operator<< that takes a const char* as input. It treats the input as a null-terminated C string.

If you cast to (const void*) the problem will go away:

std::cout << (const void*)(&s[s.length() - 1]);


答:
```<code>auto address_back = &s.back();
auto address_front = &s.front();

cout << static_cast<void*>(address_back) << endl;
cout << static_cast<void*>(address_front) << endl;
</code>```

Title: How to you get the address of an element in an std::string in C++?


问:
Windows NodeJS: always get either "Error: ENOENT: no such file or directory, open" or "Error: EACCES: permission denied, open"
Here is my code:

```<code>var fs = require('fs');
var util = require('util');
var logFile = fs.createWriteStream('C:/text.txt', { flags: 'a' });
// Or 'w' to truncate the file every time the process starts.
var logStdout = process.stdout;

console.log = function () {
logFile.write(util.format.apply(null, arguments) + '\n');
logStdout.write(util.format.apply(null, arguments) + '\n');
}
console.error = console.log;
</code>```

No matter what I type instead of "C:/text.txt" I either get

Error: ENOENT: no such file or directory, open

or

Error: EACCES: permission denied, open

I tried everything such as "run as administrator" and "elevate", but when it's not the second error message, it's the first one; and when it's not the first one, it's the second one.

I'm soooo confused

答:
For windows it's better to use \\ in the path to avoid some problems.

```<code>C:\\text.txt
</code>```

This path I use to include pdftk.exe:

```<code>C:\\PDFtk\\bin\\pdftk.exe
</code>```

Body:
Here is my code:

var fs = require('fs');
var util = require('util');
var logFile = fs.createWriteStream('C:/text.txt', { flags: 'a' });
// Or 'w' to truncate the file every time the process starts.
var logStdout = process.stdout;

console.log = function () {
logFile.write(util.format.apply(null, arguments) + '\n');
logStdout.write(util.format.apply(null, arguments) + '\n');
}
console.error = console.log;

No matter what I type instead of "C:/text.txt" I either get

Error: ENOENT: no such file or directory, open

or

Error: EACCES: permission denied, open

I tried everything such as "run as administrator" and "elevate", but when it's not the second error message, it's the first one; and when it's not the first one, it's the second one.

I'm soooo confused

Body:
For windows it's better to use \\ in the path to avoid some problems.

C:\\text.txt

This path I use to include pdftk.exe:

C:\\PDFtk\\bin\\pdftk.exe


问:
Reading JSON Array Values in Python / Flask
I have the following JSON data the I need to read in Flask:

```<code>{
"NewList":[
    {
        "key" : "myvalue1",
        "value" : "value1"
    },
    {
        "key" : "myvalue2",
        "value" : "value2"
    },
    {
        "key" : "myvalu3",
        "value" : "value4"
    }
]
}
</code>```

And I'm having trouble doing so. The code I currently have is as follows:

```<code>@app.route('/dataread', methods=['GET', 'POST'])
def dataread():
    if(request.json):
            myvalue1 = request.json['NewList']['myvalue1']
            return str(myvalue1)
        else:
            return 'nothing'
</code>```

But it isn't working. I'm getting the following error:

KeyError: 'NewList'

I know my syntax must be wrong but I can't figure how to fix it. I'm sorry for such a newb question. Please can you help.

Thanks.

答:
I wasn't sure which part of this you were having an issue with so I did it long hand. It's obviously not ideal but should be easily understandable.But I would echo the comment above that you should start by printing exactly what you got in. May not be a complete match. </p>

<p>The dictionary is a set of lists of dictionaries so you end up walking the set for each one.  </p>

```<code>dict = {
"NewList":[
    {
        "key" : "myvalue1",
        "value" : "value1"
    },
    {
        "key" : "myvalue2",
        "value" : "value2"
    },
    {
        "key" : "myvalu3",
        "value" : "value4"
    }
]
}

for firstkey, big_list in dict.items():
    print('print dict: ' + str(firstkey))
    for pair in big_list:
        print('print sets in dict: ' + str(pair))
        nextdict = pair
        for nextkey, small_list in nextdict.items():
            print('print each: ' + str(nextkey)+ '->' + str(small_list))
            #address each one
            print('pull just data: ' + str(nextdict[nextkey]))

"""
results
print dict: NewList
print sets in dict: {'key': 'myvalue1', 'value': 'value1'}
print each: key->myvalue1
pull just data: myvalue1
print each: value->value1
pull just data: value1
print sets in dict: {'key': 'myvalue2', 'value': 'value2'}
print each: key->myvalue2
pull just data: myvalue2
print each: value->value2
pull just data: value2
print sets in dict: {'key': 'myvalu3', 'value': 'value4'}
print each: key->myvalu3
pull just data: myvalu3
print each: value->value4
pull just data: value4
"""
</code>```

Body:
I have the following JSON data the I need to read in Flask:

{
"NewList":[
    {
        "key" : "myvalue1",
        "value" : "value1"
    },
    {
        "key" : "myvalue2",
        "value" : "value2"
    },
    {
        "key" : "myvalu3",
        "value" : "value4"
    }
]
}

And I'm having trouble doing so. The code I currently have is as follows:

@app.route('/dataread', methods=['GET', 'POST'])
def dataread():
    if(request.json):
            myvalue1 = request.json['NewList']['myvalue1']
            return str(myvalue1)
        else:
            return 'nothing'

But it isn't working. I'm getting the following error:

KeyError: 'NewList'

I know my syntax must be wrong but I can't figure how to fix it. I'm sorry for such a newb question. Please can you help.

Thanks.

Body:
I wasn't sure which part of this you were having an issue with so I did it long hand. It's obviously not ideal but should be easily understandable.But I would echo the comment above that you should start by printing exactly what you got in. May not be a complete match.

The dictionary is a set of lists of dictionaries so you end up walking the set for each one.

dict = {
"NewList":[
    {
        "key" : "myvalue1",
        "value" : "value1"
    },
    {
        "key" : "myvalue2",
        "value" : "value2"
    },
    {
        "key" : "myvalu3",
        "value" : "value4"
    }
]
}

for firstkey, big_list in dict.items():
    print('print dict: ' + str(firstkey))
    for pair in big_list:
        print('print sets in dict: ' + str(pair))
        nextdict = pair
        for nextkey, small_list in nextdict.items():
            print('print each: ' + str(nextkey)+ '->' + str(small_list))
            #address each one
            print('pull just data: ' + str(nextdict[nextkey]))

"""
results
print dict: NewList
print sets in dict: {'key': 'myvalue1', 'value': 'value1'}
print each: key->myvalue1
pull just data: myvalue1
print each: value->value1
pull just data: value1
print sets in dict: {'key': 'myvalue2', 'value': 'value2'}
print each: key->myvalue2
pull just data: myvalue2
print each: value->value2
pull just data: value2
print sets in dict: {'key': 'myvalu3', 'value': 'value4'}
print each: key->myvalu3
pull just data: myvalu3
print each: value->value4
pull just data: value4
"""


问:
Pass NTLM with Postman
Is there a way to pass Windows Authentication with postman?

I have added this in header but still 401 Unauthorized.

```<code>Authorization: NTLM TkFcYWRtaW46dGVzdA==
</code>```

As suggested by this link. I've encrypted as Unicode (UTF-16, little-endian) but of no use.

Any Ideas?

答:
You can also change internet options and set Logon to:
Automatic logon with current user name and password

taken from:
https://sysadminspot.com/windows/google-chrome-and-ntlm-auto-logon-using-windows-authentication/

if the website uses https you can add it to Trusted Sites and set it there, otherwise you can add it to local intranet sites and set Custom level... there.

Open internet options:

Click Custom level... and scroll to bottom:

Title: Pass NTLM with Postman

Body:
Is there a way to pass Windows Authentication with postman?

I have added this in header but still 401 Unauthorized.

Authorization: NTLM TkFcYWRtaW46dGVzdA==

As suggested by this link. I've encrypted as Unicode (UTF-16, little-endian) but of no use.

Any Ideas?


问:
Find all combinations in arraylist recursively
I'm completely lost on this. I can do this iteratively, but recursion is new to me. If I'm given an arraylist with 1, 2, 3 inside of it, the total possible combos with repeats is 27.

111, 112, 113, 121, 122, 123, etc...

how can I find this recursively? I'd show my code but I'm not even close to getting the concept...

答:
Bit late to this party, & sorry, it's in c#, but hey, it's similar to Java. Everything here seems a bit complicated, so here's a function which is pretty simple, which should be easy to translate to Java -</p>

```<code>    public static List<List<T>> Permutations<T>(List<T> list)
    {
        List<List<T>> result = new List<List<T>>();

        for (int i = 0; i < list.Count(); i++)
        {
            T initialValue = list[i];
            List<T> clonedList = list.Where((item, index) => { return index != i; }).ToList(); // proper copy, less the initialValue item

            // here's where the recursion happens, but only if there are at least 2 items left in the list
            List<List<T>> permutations = clonedList.Count > 0 ? Permutations(clonedList) : new List<List<T>> { new List<T>() };

            foreach (List<T> permutation in permutations)
            {
                List<T> combined = new List<T> { initialValue };
                combined.AddRange(permutation);

                result.Add(combined);
            }
        }

        return result;
    }
</code>```

Body:
Bit late to this party, & sorry, it's in c#, but hey, it's similar to Java. Everything here seems a bit complicated, so here's a function which is pretty simple, which should be easy to translate to Java -

    public static List<List<T>> Permutations<T>(List<T> list)
    {
        List<List<T>> result = new List<List<T>>();

        for (int i = 0; i < list.Count(); i++)
        {
            T initialValue = list[i];
            List<T> clonedList = list.Where((item, index) => { return index != i; }).ToList(); // proper copy, less the initialValue item

            // here's where the recursion happens, but only if there are at least 2 items left in the list
            List<List<T>> permutations = clonedList.Count > 0 ? Permutations(clonedList) : new List<List<T>> { new List<T>() };

            foreach (List<T> permutation in permutations)
            {
                List<T> combined = new List<T> { initialValue };
                combined.AddRange(permutation);

                result.Add(combined);
            }
        }

        return result;
    }


问:
SystemVerilog & RegEx: "\d" is not recognized as a character class
I'm trying to use regular expressions in SystemVerilog. The character class "\d" (a digit) seems not to work, while other character classes like "\w", "\s"  work fine. I tried with SVLIB and UVM, same behavior.

To reproduce I wrote the code below. The code does nothing but test "1" against regex "\d" and "\w" using UVM and SVLIB.

```<code>module SandBox;

import svlib_pkg::*;
import uvm_pkg::*;

initial
begin

Str myString;
Regex regex;

string testString;
string reString;

testString = "1";
reString = "\\d";

myString = Str::create(testString);
regex = Regex::create();
regex.setRE(reString);

$display("-------------------------------------");
$display("test string: %s", testString);
$display("regex: %s", reString);

if (regex.test(myString)) begin

    $display("SVLIB Test passed!");

end

if (!uvm_re_match(reString, testString)) begin

    $display("UVM Test passed!");

end

testString = "1";
reString = "\\w";

myString = Str::create(testString);
regex = Regex::create();
regex.setRE(reString);

$display("-------------------------------------");
$display("test string: %s", testString);
$display("regex: %s", reString);

if (regex.test(myString)) begin

    $display("SVLIB Test passed!");

end

if (!uvm_re_match(reString, testString)) begin

    $display("UVM Test passed!");

end

end

endmodule
</code>```

I have the following output:

```<code>-------------------------------------
test string: 1
regex: \d
-------------------------------------
test string: 1
regex: \w
SVLIB Test passed!
UVM Test passed!
</code>```

What is the reason for this behavior? The underlying system? Something in SV syntax?

答:
According to the svlib User Guide and Programmer's Reference:

svlib uses the "extended
  regular expression" dialect of the C library's POSIX-compliant regular expression subsystem,
  and you can find full details of how to write regular expressions in this dialect by consulting
  the man-page man 7 regex or any of the numerous online regular expression tutorials. The
  regex dialect of svlib is in almost all respects the same as that used by the Unix/Linux
  command egrep.

The POSIX regular expressions standard (man 7 regexp), in turn, defines the available character classes as follows:

Within a bracket expression, the name of a character class enclosed in "[:" and ":]" stands for the list of all characters belonging to that class.  Standard character class names are:

```<code>alnum   digit   punct
alpha   graph   space
blank   lower   upper
cntrl   print   xdigit
</code>```

So, the digits characters class has to be specified as:

```<code>[[:digit:]]
</code>```

using the canonical syntax.

The \d, \w or \s are a so called Shorthand Character Classes, which are not defined by the POSIX standard, so their availability depends on the Regexp
engine implementation you are using.

Some regexp engines choose to implement all of them, others (e.g. sed or grep, only implement a subset, not including \d.

The svlib implementation is claimed to be egrep compatible, and egrep does not support \d.

Body:
I'm trying to use regular expressions in SystemVerilog. The character class "\d" (a digit) seems not to work, while other character classes like "\w", "\s"  work fine. I tried with SVLIB and UVM, same behavior.

To reproduce I wrote the code below. The code does nothing but test "1" against regex "\d" and "\w" using UVM and SVLIB.

module SandBox;

import svlib_pkg::*;
import uvm_pkg::*;

initial
begin

Str myString;
Regex regex;

string testString;
string reString;

testString = "1";
reString = "\\d";

myString = Str::create(testString);
regex = Regex::create();
regex.setRE(reString);

$display("-------------------------------------");
$display("test string: %s", testString);
$display("regex: %s", reString);

if (regex.test(myString)) begin

    $display("SVLIB Test passed!");

end

if (!uvm_re_match(reString, testString)) begin

    $display("UVM Test passed!");

end

testString = "1";
reString = "\\w";

myString = Str::create(testString);
regex = Regex::create();
regex.setRE(reString);

$display("-------------------------------------");
$display("test string: %s", testString);
$display("regex: %s", reString);

if (regex.test(myString)) begin

    $display("SVLIB Test passed!");

end

if (!uvm_re_match(reString, testString)) begin

    $display("UVM Test passed!");

end

end

endmodule

I have the following output:

-------------------------------------
test string: 1
regex: \d
-------------------------------------
test string: 1
regex: \w
SVLIB Test passed!
UVM Test passed!

What is the reason for this behavior? The underlying system? Something in SV syntax?

Body:
According to the svlib User Guide and Programmer's Reference:

svlib uses the "extended
  regular expression" dialect of the C library's POSIX-compliant regular expression subsystem,
  and you can find full details of how to write regular expressions in this dialect by consulting
  the man-page man 7 regex or any of the numerous online regular expression tutorials. The
  regex dialect of svlib is in almost all respects the same as that used by the Unix/Linux
  command egrep.

The POSIX regular expressions standard (man 7 regexp), in turn, defines the available character classes as follows:

Within a bracket expression, the name of a character class enclosed in "[:" and ":]" stands for the list of all characters belonging to that class.  Standard character class names are:

alnum   digit   punct
alpha   graph   space
blank   lower   upper
cntrl   print   xdigit

So, the digits characters class has to be specified as:

[[:digit:]]

using the canonical syntax.

The \d, \w or \s are a so called Shorthand Character Classes, which are not defined by the POSIX standard, so their availability depends on the Regexp
engine implementation you are using.

Some regexp engines choose to implement all of them, others (e.g. sed or grep, only implement a subset, not including \d.

The svlib implementation is claimed to be egrep compatible, and egrep does not support \d.


问:
vim using gf option with env variable
I often use gf in vim to open files. Often these file paths use environment variables.
I am using tcl shell to launch some scripts.  When the environment variable is used without ::env (option which is necessary for env for tcl), vim has no trouble understanding it. But when it does contain, vim is unable to use the environment variable value.

This works for gf:

$hello/bla.tcl

This does NOT work for gf:

$::env(hello)/bla.tcl

答:
If there are spaces before and after the file name, you can do with</p>

```<code>viWgf
</code>```

Title: vim using gf option with env variable

Body:
If there are spaces before and after the file name, you can do with

viWgf