问:
Can't start `dockerd` in dev container with wsl2
I'm trying to set up a dev-container in VS code that is able to run docker-compose and spin up some containers. I'm using Windows, so using wsl2 (and have docker desktop installed). I am able to install docker in the dev-container and it runs, but am unable to start up dockerd. I've checked a lot of different articles/questions on the internet, but haven't been able to figure it out.

This is what my container is based on in the dev-container Dockerfile:

```<code>ARG VARIANT="3.10-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
RUN curl -fsSL https://get.docker.com | sh
</code>```

I try running

```<code>sudo dockerd --iptables=false --debug
</code>```

and i get

```<code>INFO[2022-12-11T04:11:09.085898954Z] Starting up
DEBU[2022-12-11T04:11:09.086390079Z] Listener created for HTTP on unix (/var/run/docker.sock)
DEBU[2022-12-11T04:11:09.086417341Z] Containerd not running, starting daemon managed containerd
INFO[2022-12-11T04:11:09.086941198Z] libcontainerd: started new containerd process  pid=5082
INFO[2022-12-11T04:11:09.086989169Z] parsed scheme: "unix"                         module=grpc
INFO[2022-12-11T04:11:09.087014427Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2022-12-11T04:11:09.087045386Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2022-12-11T04:11:09.087075143Z] ClientConn switching balancer to "pick_first"  module=grpc
WARN[0000] containerd config version `1` has been deprecated and will be removed in containerd v2.0, please switch to version `2`, see https://github.com/containerd/containerd/blob/main/docs/PLUGINS.md#version-header
INFO[2022-12-11T04:11:09.111311679Z] starting containerd                           revision=a05d175400b1145e5e6a735a6710579d181e7fb0 version=1.6.12
INFO[2022-12-11T04:11:09.123235446Z] loading plugin "io.containerd.content.v1.content"...  type=io.containerd.content.v1
INFO[2022-12-11T04:11:09.123379851Z] loading plugin "io.containerd.snapshotter.v1.aufs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123551588Z] skip loading plugin "io.containerd.snapshotter.v1.aufs"...  error="aufs is not supported (modprobe aufs failed: exec: \"modprobe\": executable file not found in $PATH \"\"): skip plugin" type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123594400Z] loading plugin "io.containerd.snapshotter.v1.btrfs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123813437Z] skip loading plugin "io.containerd.snapshotter.v1.btrfs"...  error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs (overlay) must be a btrfs filesystem to be used with the btrfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123843744Z] loading plugin "io.containerd.snapshotter.v1.devmapper"...  type=io.containerd.snapshotter.v1
WARN[2022-12-11T04:11:09.123877829Z] failed to load plugin io.containerd.snapshotter.v1.devmapper  error="devmapper not configured"
INFO[2022-12-11T04:11:09.123902577Z] loading plugin "io.containerd.snapshotter.v1.native"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123943695Z] loading plugin "io.containerd.snapshotter.v1.overlayfs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.124044467Z] loading plugin "io.containerd.snapshotter.v1.zfs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.124271960Z] skip loading plugin "io.containerd.snapshotter.v1.zfs"...  error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.124311505Z] loading plugin "io.containerd.metadata.v1.bolt"...  type=io.containerd.metadata.v1
WARN[2022-12-11T04:11:09.124344629Z] could not use snapshotter devmapper in metadata plugin  error="devmapper not configured"
INFO[2022-12-11T04:11:09.124370588Z] metadata content store policy set             policy=shared
INFO[2022-12-11T04:11:09.124478724Z] loading plugin "io.containerd.differ.v1.walking"...  type=io.containerd.differ.v1
INFO[2022-12-11T04:11:09.124525022Z] loading plugin "io.containerd.event.v1.exchange"...  type=io.containerd.event.v1
INFO[2022-12-11T04:11:09.124555250Z] loading plugin "io.containerd.gc.v1.scheduler"...  type=io.containerd.gc.v1
INFO[2022-12-11T04:11:09.124615985Z] loading plugin "io.containerd.service.v1.introspection-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124685808Z] loading plugin "io.containerd.service.v1.containers-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124717539Z] loading plugin "io.containerd.service.v1.content-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124737517Z] loading plugin "io.containerd.service.v1.diff-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124771001Z] loading plugin "io.containerd.service.v1.images-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124811598Z] loading plugin "io.containerd.service.v1.leases-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124847637Z] loading plugin "io.containerd.service.v1.namespaces-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124878826Z] loading plugin "io.containerd.service.v1.snapshots-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124908202Z] loading plugin "io.containerd.runtime.v1.linux"...  type=io.containerd.runtime.v1
INFO[2022-12-11T04:11:09.124998945Z] loading plugin "io.containerd.runtime.v2.task"...  type=io.containerd.runtime.v2
INFO[2022-12-11T04:11:09.125069299Z] loading plugin "io.containerd.monitor.v1.cgroups"...  type=io.containerd.monitor.v1
INFO[2022-12-11T04:11:09.125419756Z] loading plugin "io.containerd.service.v1.tasks-service"...  type=io.containerd.service.v1
DEBU[2022-12-11T04:11:09.125460905Z] No RDT config file specified, RDT not configured
INFO[2022-12-11T04:11:09.125490351Z] loading plugin "io.containerd.grpc.v1.introspection"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125525187Z] loading plugin "io.containerd.internal.v1.restart"...  type=io.containerd.internal.v1
INFO[2022-12-11T04:11:09.125607123Z] loading plugin "io.containerd.grpc.v1.containers"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125641409Z] loading plugin "io.containerd.grpc.v1.content"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125670845Z] loading plugin "io.containerd.grpc.v1.diff"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125698708Z] loading plugin "io.containerd.grpc.v1.events"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125731540Z] loading plugin "io.containerd.grpc.v1.healthcheck"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125769402Z] loading plugin "io.containerd.grpc.v1.images"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125797887Z] loading plugin "io.containerd.grpc.v1.leases"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125831551Z] loading plugin "io.containerd.grpc.v1.namespaces"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125864313Z] loading plugin "io.containerd.internal.v1.opt"...  type=io.containerd.internal.v1
INFO[2022-12-11T04:11:09.125919709Z] loading plugin "io.containerd.grpc.v1.snapshots"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125951680Z] loading plugin "io.containerd.grpc.v1.tasks"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125978801Z] loading plugin "io.containerd.grpc.v1.version"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.126028927Z] loading plugin "io.containerd.tracing.processor.v1.otlp"...  type=io.containerd.tracing.processor.v1
INFO[2022-12-11T04:11:09.126066589Z] skip loading plugin "io.containerd.tracing.processor.v1.otlp"...  error="no OpenTelemetry endpoint: skip plugin" type=io.containerd.tracing.processor.v1
INFO[2022-12-11T04:11:09.126094872Z] loading plugin "io.containerd.internal.v1.tracing"...  type=io.containerd.internal.v1
ERRO[2022-12-11T04:11:09.126133927Z] failed to initialize a tracing processor "otlp"  error="no OpenTelemetry endpoint: skip plugin"
INFO[2022-12-11T04:11:09.126489334Z] serving...                                    address=/var/run/docker/containerd/containerd-debug.sock
INFO[2022-12-11T04:11:09.126939640Z] serving...                                    address=/var/run/docker/containerd/containerd.sock.ttrpc
INFO[2022-12-11T04:11:09.127060220Z] serving...                                    address=/var/run/docker/containerd/containerd.sock
DEBU[2022-12-11T04:11:09.127105035Z] sd notification                               error="<nil>" notified=false state="READY=1"
INFO[2022-12-11T04:11:09.127249406Z] containerd successfully booted in 0.016919s
DEBU[2022-12-11T04:11:09.130423237Z] Created containerd monitoring client          address=/var/run/docker/containerd/containerd.sock
DEBU[2022-12-11T04:11:09.131826569Z] Started daemon managed containerd
DEBU[2022-12-11T04:11:09.132817863Z] Golang's threads limit set to 172350
INFO[2022-12-11T04:11:09.133276546Z] parsed scheme: "unix"                         module=grpc
INFO[2022-12-11T04:11:09.133311483Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2022-12-11T04:11:09.133332884Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2022-12-11T04:11:09.133355918Z] ClientConn switching balancer to "pick_first"  module=grpc
DEBU[2022-12-11T04:11:09.133390327Z] metrics API listening on /var/run/docker/metrics.sock
INFO[2022-12-11T04:11:09.134727494Z] parsed scheme: "unix"                         module=grpc
INFO[2022-12-11T04:11:09.134768452Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2022-12-11T04:11:09.134804090Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2022-12-11T04:11:09.134828887Z] ClientConn switching balancer to "pick_first"  module=grpc
DEBU[2022-12-11T04:11:09.136599610Z] Using default logging driver json-file
DEBU[2022-12-11T04:11:09.136631100Z] processing event stream                       module=libcontainerd namespace=plugins.moby
DEBU[2022-12-11T04:11:09.136663782Z] [graphdriver] priority list: [btrfs zfs overlay2 fuse-overlayfs aufs overlay devicemapper vfs]
DEBU[2022-12-11T04:11:09.136751510Z] zfs command is not available: exec: "zfs": executable file not found in $PATH  storage-driver=zfs
ERRO[2022-12-11T04:11:09.137867145Z] failed to mount overlay: operation not permitted  storage-driver=overlay2
ERRO[2022-12-11T04:11:09.137929453Z] exec: "fuse-overlayfs": executable file not found in $PATH  storage-driver=fuse-overlayfs
ERRO[2022-12-11T04:11:09.138094297Z] AUFS was not found in /proc/filesystems       storage-driver=aufs
ERRO[2022-12-11T04:11:09.138752311Z] failed to mount overlay: operation not permitted  storage-driver=overlay
WARN[2022-12-11T04:11:09.140326691Z] Unable to setup quota: operation not permitted
DEBU[2022-12-11T04:11:09.140356818Z] Initialized graph driver vfs
DEBU[2022-12-11T04:11:09.140520430Z] No quota support for local volumes in /var/lib/docker/volumes: operation not permitted
WARN[2022-12-11T04:11:09.145493167Z] Your kernel does not support cgroup blkio weight
WARN[2022-12-11T04:11:09.145540136Z] Your kernel does not support cgroup blkio weight_device
WARN[2022-12-11T04:11:09.145546618Z] Your kernel does not support cgroup blkio throttle.read_bps_device
WARN[2022-12-11T04:11:09.145550846Z] Your kernel does not support cgroup blkio throttle.write_bps_device
WARN[2022-12-11T04:11:09.145570524Z] Your kernel does not support cgroup blkio throttle.read_iops_device
WARN[2022-12-11T04:11:09.145590302Z] Your kernel does not support cgroup blkio throttle.write_iops_device
DEBU[2022-12-11T04:11:09.145756468Z] Max Concurrent Downloads: 3
DEBU[2022-12-11T04:11:09.145781566Z] Max Concurrent Uploads: 5
DEBU[2022-12-11T04:11:09.145786886Z] Max Download Attempts: 5
INFO[2022-12-11T04:11:09.145805472Z] Loading containers: start.
DEBU[2022-12-11T04:11:09.145871698Z] Option Experimental: false
DEBU[2022-12-11T04:11:09.145896815Z] Option DefaultDriver: bridge
DEBU[2022-12-11T04:11:09.145916112Z] Option DefaultNetwork: bridge
DEBU[2022-12-11T04:11:09.145936591Z] Network Control Plane MTU: 1500
DEBU[2022-12-11T04:11:09.146037693Z] processing event stream                       module=libcontainerd namespace=moby
ERRO[2022-12-11T04:11:09.147450956Z] failed to set to initial namespace, net:[4026533620], initns fd 14: operation not permitted
INFO[2022-12-11T04:11:09.147624286Z] Default bridge (docker0) is assigned with an IP address 172.18.0.0/16. Daemon option --bip can be used to set a preferred IP address
DEBU[2022-12-11T04:11:09.147666476Z] Allocating IPv4 pools for network bridge (290e2ac13ff4d994a6dc424aae0de3fc2b3dbd47ac2d70daf202fe32a8c8a933)
DEBU[2022-12-11T04:11:09.147696063Z] RequestPool(LocalDefault, 172.18.0.0/16, , map[], false)
DEBU[2022-12-11T04:11:09.147747761Z] RequestAddress(LocalDefault/172.18.0.0/16, <nil>, map[RequestAddressType:com.docker.network.gateway])
DEBU[2022-12-11T04:11:09.147795652Z] Request address PoolID:172.18.0.0/16 App: ipam/default/data, ID: LocalDefault/172.18.0.0/16, DBIndex: 0x0, Bits: 65536, Unselected: 65534, Sequence: (0x80000000, 1)->(0x0, 2046)->(0x1, 1)->end Curr:0 Serial:false PrefAddress:<nil>
ERRO[2022-12-11T04:11:09.147858973Z] failed to set to initial namespace, net:[4026533620], initns fd 14: operation not permitted
DEBU[2022-12-11T04:11:09.147914869Z] Did not find any interface with name docker0: Link not found
DEBU[2022-12-11T04:11:09.148010572Z] Setting bridge mac address to 02:42:e2:0a:5b:d3
DEBU[2022-12-11T04:11:09.148053373Z] Failed to create bridge docker0 via netlink. Trying ioctl
DEBU[2022-12-11T04:11:09.148099591Z] releasing IPv4 pools from network bridge (290e2ac13ff4d994a6dc424aae0de3fc2b3dbd47ac2d70daf202fe32a8c8a933)
DEBU[2022-12-11T04:11:09.148126242Z] ReleaseAddress(LocalDefault/172.18.0.0/16, 172.18.0.1)
DEBU[2022-12-11T04:11:09.148213228Z] Released address PoolID:LocalDefault/172.18.0.0/16, Address:172.18.0.1 Sequence:App: ipam/default/data, ID: LocalDefault/172.18.0.0/16, DBIndex: 0x0, Bits: 65536, Unselected: 65533, Sequence: (0xc0000000, 1)->(0x0, 2046)->(0x1, 1)->end Curr:2
DEBU[2022-12-11T04:11:09.148240490Z] ReleasePool(LocalDefault/172.18.0.0/16)
DEBU[2022-12-11T04:11:09.148254947Z] daemon configured with a 15 seconds minimum shutdown timeout
DEBU[2022-12-11T04:11:09.148274815Z] start clean shutdown of all containers with a 15 seconds timeout...
DEBU[2022-12-11T04:11:09.148324430Z] found 0 orphan layers
DEBU[2022-12-11T04:11:09.148765069Z] Cleaning up old mountid : start.
INFO[2022-12-11T04:11:09.148953131Z] stopping event stream following graceful shutdown  error="<nil>" module=libcontainerd namespace=moby
DEBU[2022-12-11T04:11:09.149076141Z] Cleaning up old mountid : done.
INFO[2022-12-11T04:11:09.149405639Z] stopping event stream following graceful shutdown  error="context canceled" module=libcontainerd namespace=plugins.moby
INFO[2022-12-11T04:11:09.149442914Z] stopping healthcheck following graceful shutdown  module=libcontainerd
DEBU[2022-12-11T04:11:09.149602629Z] received signal                               signal=terminated
DEBU[2022-12-11T04:11:09.149688012Z] sd notification                               error="<nil>" notified=false state="STOPPING=1"
WARN[2022-12-11T04:11:10.150011723Z] grpc: addrConn.createTransport failed to connect to {unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}. Err :connection error: desc = "transport: Error while dialing dial unix:///var/run/docker/containerd/containerd.sock: timeout". Reconnecting...  module=grpc
failed to start daemon: Error initializing network controller: Error creating default "bridge" network: operation not permitted
</code>```

and when i try running something like

```<code>sudo docker run -v /var/run/docker.sock:/var/run/docker.sock docker
</code>```

i get docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

Body:
I'm trying to set up a dev-container in VS code that is able to run docker-compose and spin up some containers. I'm using Windows, so using wsl2 (and have docker desktop installed). I am able to install docker in the dev-container and it runs, but am unable to start up dockerd. I've checked a lot of different articles/questions on the internet, but haven't been able to figure it out.

This is what my container is based on in the dev-container Dockerfile:

ARG VARIANT="3.10-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
RUN curl -fsSL https://get.docker.com | sh

I try running

sudo dockerd --iptables=false --debug

and i get

INFO[2022-12-11T04:11:09.085898954Z] Starting up
DEBU[2022-12-11T04:11:09.086390079Z] Listener created for HTTP on unix (/var/run/docker.sock)
DEBU[2022-12-11T04:11:09.086417341Z] Containerd not running, starting daemon managed containerd
INFO[2022-12-11T04:11:09.086941198Z] libcontainerd: started new containerd process  pid=5082
INFO[2022-12-11T04:11:09.086989169Z] parsed scheme: "unix"                         module=grpc
INFO[2022-12-11T04:11:09.087014427Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2022-12-11T04:11:09.087045386Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2022-12-11T04:11:09.087075143Z] ClientConn switching balancer to "pick_first"  module=grpc
WARN[0000] containerd config version `1` has been deprecated and will be removed in containerd v2.0, please switch to version `2`, see https://github.com/containerd/containerd/blob/main/docs/PLUGINS.md#version-header
INFO[2022-12-11T04:11:09.111311679Z] starting containerd                           revision=a05d175400b1145e5e6a735a6710579d181e7fb0 version=1.6.12
INFO[2022-12-11T04:11:09.123235446Z] loading plugin "io.containerd.content.v1.content"...  type=io.containerd.content.v1
INFO[2022-12-11T04:11:09.123379851Z] loading plugin "io.containerd.snapshotter.v1.aufs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123551588Z] skip loading plugin "io.containerd.snapshotter.v1.aufs"...  error="aufs is not supported (modprobe aufs failed: exec: \"modprobe\": executable file not found in $PATH \"\"): skip plugin" type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123594400Z] loading plugin "io.containerd.snapshotter.v1.btrfs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123813437Z] skip loading plugin "io.containerd.snapshotter.v1.btrfs"...  error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.btrfs (overlay) must be a btrfs filesystem to be used with the btrfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123843744Z] loading plugin "io.containerd.snapshotter.v1.devmapper"...  type=io.containerd.snapshotter.v1
WARN[2022-12-11T04:11:09.123877829Z] failed to load plugin io.containerd.snapshotter.v1.devmapper  error="devmapper not configured"
INFO[2022-12-11T04:11:09.123902577Z] loading plugin "io.containerd.snapshotter.v1.native"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.123943695Z] loading plugin "io.containerd.snapshotter.v1.overlayfs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.124044467Z] loading plugin "io.containerd.snapshotter.v1.zfs"...  type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.124271960Z] skip loading plugin "io.containerd.snapshotter.v1.zfs"...  error="path /var/lib/docker/containerd/daemon/io.containerd.snapshotter.v1.zfs must be a zfs filesystem to be used with the zfs snapshotter: skip plugin" type=io.containerd.snapshotter.v1
INFO[2022-12-11T04:11:09.124311505Z] loading plugin "io.containerd.metadata.v1.bolt"...  type=io.containerd.metadata.v1
WARN[2022-12-11T04:11:09.124344629Z] could not use snapshotter devmapper in metadata plugin  error="devmapper not configured"
INFO[2022-12-11T04:11:09.124370588Z] metadata content store policy set             policy=shared
INFO[2022-12-11T04:11:09.124478724Z] loading plugin "io.containerd.differ.v1.walking"...  type=io.containerd.differ.v1
INFO[2022-12-11T04:11:09.124525022Z] loading plugin "io.containerd.event.v1.exchange"...  type=io.containerd.event.v1
INFO[2022-12-11T04:11:09.124555250Z] loading plugin "io.containerd.gc.v1.scheduler"...  type=io.containerd.gc.v1
INFO[2022-12-11T04:11:09.124615985Z] loading plugin "io.containerd.service.v1.introspection-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124685808Z] loading plugin "io.containerd.service.v1.containers-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124717539Z] loading plugin "io.containerd.service.v1.content-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124737517Z] loading plugin "io.containerd.service.v1.diff-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124771001Z] loading plugin "io.containerd.service.v1.images-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124811598Z] loading plugin "io.containerd.service.v1.leases-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124847637Z] loading plugin "io.containerd.service.v1.namespaces-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124878826Z] loading plugin "io.containerd.service.v1.snapshots-service"...  type=io.containerd.service.v1
INFO[2022-12-11T04:11:09.124908202Z] loading plugin "io.containerd.runtime.v1.linux"...  type=io.containerd.runtime.v1
INFO[2022-12-11T04:11:09.124998945Z] loading plugin "io.containerd.runtime.v2.task"...  type=io.containerd.runtime.v2
INFO[2022-12-11T04:11:09.125069299Z] loading plugin "io.containerd.monitor.v1.cgroups"...  type=io.containerd.monitor.v1
INFO[2022-12-11T04:11:09.125419756Z] loading plugin "io.containerd.service.v1.tasks-service"...  type=io.containerd.service.v1
DEBU[2022-12-11T04:11:09.125460905Z] No RDT config file specified, RDT not configured
INFO[2022-12-11T04:11:09.125490351Z] loading plugin "io.containerd.grpc.v1.introspection"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125525187Z] loading plugin "io.containerd.internal.v1.restart"...  type=io.containerd.internal.v1
INFO[2022-12-11T04:11:09.125607123Z] loading plugin "io.containerd.grpc.v1.containers"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125641409Z] loading plugin "io.containerd.grpc.v1.content"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125670845Z] loading plugin "io.containerd.grpc.v1.diff"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125698708Z] loading plugin "io.containerd.grpc.v1.events"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125731540Z] loading plugin "io.containerd.grpc.v1.healthcheck"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125769402Z] loading plugin "io.containerd.grpc.v1.images"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125797887Z] loading plugin "io.containerd.grpc.v1.leases"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125831551Z] loading plugin "io.containerd.grpc.v1.namespaces"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125864313Z] loading plugin "io.containerd.internal.v1.opt"...  type=io.containerd.internal.v1
INFO[2022-12-11T04:11:09.125919709Z] loading plugin "io.containerd.grpc.v1.snapshots"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125951680Z] loading plugin "io.containerd.grpc.v1.tasks"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.125978801Z] loading plugin "io.containerd.grpc.v1.version"...  type=io.containerd.grpc.v1
INFO[2022-12-11T04:11:09.126028927Z] loading plugin "io.containerd.tracing.processor.v1.otlp"...  type=io.containerd.tracing.processor.v1
INFO[2022-12-11T04:11:09.126066589Z] skip loading plugin "io.containerd.tracing.processor.v1.otlp"...  error="no OpenTelemetry endpoint: skip plugin" type=io.containerd.tracing.processor.v1
INFO[2022-12-11T04:11:09.126094872Z] loading plugin "io.containerd.internal.v1.tracing"...  type=io.containerd.internal.v1
ERRO[2022-12-11T04:11:09.126133927Z] failed to initialize a tracing processor "otlp"  error="no OpenTelemetry endpoint: skip plugin"
INFO[2022-12-11T04:11:09.126489334Z] serving...                                    address=/var/run/docker/containerd/containerd-debug.sock
INFO[2022-12-11T04:11:09.126939640Z] serving...                                    address=/var/run/docker/containerd/containerd.sock.ttrpc
INFO[2022-12-11T04:11:09.127060220Z] serving...                                    address=/var/run/docker/containerd/containerd.sock
DEBU[2022-12-11T04:11:09.127105035Z] sd notification                               error="<nil>" notified=false state="READY=1"
INFO[2022-12-11T04:11:09.127249406Z] containerd successfully booted in 0.016919s
DEBU[2022-12-11T04:11:09.130423237Z] Created containerd monitoring client          address=/var/run/docker/containerd/containerd.sock
DEBU[2022-12-11T04:11:09.131826569Z] Started daemon managed containerd
DEBU[2022-12-11T04:11:09.132817863Z] Golang's threads limit set to 172350
INFO[2022-12-11T04:11:09.133276546Z] parsed scheme: "unix"                         module=grpc
INFO[2022-12-11T04:11:09.133311483Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2022-12-11T04:11:09.133332884Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2022-12-11T04:11:09.133355918Z] ClientConn switching balancer to "pick_first"  module=grpc
DEBU[2022-12-11T04:11:09.133390327Z] metrics API listening on /var/run/docker/metrics.sock
INFO[2022-12-11T04:11:09.134727494Z] parsed scheme: "unix"                         module=grpc
INFO[2022-12-11T04:11:09.134768452Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2022-12-11T04:11:09.134804090Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2022-12-11T04:11:09.134828887Z] ClientConn switching balancer to "pick_first"  module=grpc
DEBU[2022-12-11T04:11:09.136599610Z] Using default logging driver json-file
DEBU[2022-12-11T04:11:09.136631100Z] processing event stream                       module=libcontainerd namespace=plugins.moby
DEBU[2022-12-11T04:11:09.136663782Z] [graphdriver] priority list: [btrfs zfs overlay2 fuse-overlayfs aufs overlay devicemapper vfs]
DEBU[2022-12-11T04:11:09.136751510Z] zfs command is not available: exec: "zfs": executable file not found in $PATH  storage-driver=zfs
ERRO[2022-12-11T04:11:09.137867145Z] failed to mount overlay: operation not permitted  storage-driver=overlay2
ERRO[2022-12-11T04:11:09.137929453Z] exec: "fuse-overlayfs": executable file not found in $PATH  storage-driver=fuse-overlayfs
ERRO[2022-12-11T04:11:09.138094297Z] AUFS was not found in /proc/filesystems       storage-driver=aufs
ERRO[2022-12-11T04:11:09.138752311Z] failed to mount overlay: operation not permitted  storage-driver=overlay
WARN[2022-12-11T04:11:09.140326691Z] Unable to setup quota: operation not permitted
DEBU[2022-12-11T04:11:09.140356818Z] Initialized graph driver vfs
DEBU[2022-12-11T04:11:09.140520430Z] No quota support for local volumes in /var/lib/docker/volumes: operation not permitted
WARN[2022-12-11T04:11:09.145493167Z] Your kernel does not support cgroup blkio weight
WARN[2022-12-11T04:11:09.145540136Z] Your kernel does not support cgroup blkio weight_device
WARN[2022-12-11T04:11:09.145546618Z] Your kernel does not support cgroup blkio throttle.read_bps_device
WARN[2022-12-11T04:11:09.145550846Z] Your kernel does not support cgroup blkio throttle.write_bps_device
WARN[2022-12-11T04:11:09.145570524Z] Your kernel does not support cgroup blkio throttle.read_iops_device
WARN[2022-12-11T04:11:09.145590302Z] Your kernel does not support cgroup blkio throttle.write_iops_device
DEBU[2022-12-11T04:11:09.145756468Z] Max Concurrent Downloads: 3
DEBU[2022-12-11T04:11:09.145781566Z] Max Concurrent Uploads: 5
DEBU[2022-12-11T04:11:09.145786886Z] Max Download Attempts: 5
INFO[2022-12-11T04:11:09.145805472Z] Loading containers: start.
DEBU[2022-12-11T04:11:09.145871698Z] Option Experimental: false
DEBU[2022-12-11T04:11:09.145896815Z] Option DefaultDriver: bridge
DEBU[2022-12-11T04:11:09.145916112Z] Option DefaultNetwork: bridge
DEBU[2022-12-11T04:11:09.145936591Z] Network Control Plane MTU: 1500
DEBU[2022-12-11T04:11:09.146037693Z] processing event stream                       module=libcontainerd namespace=moby
ERRO[2022-12-11T04:11:09.147450956Z] failed to set to initial namespace, net:[4026533620], initns fd 14: operation not permitted
INFO[2022-12-11T04:11:09.147624286Z] Default bridge (docker0) is assigned with an IP address 172.18.0.0/16. Daemon option --bip can be used to set a preferred IP address
DEBU[2022-12-11T04:11:09.147666476Z] Allocating IPv4 pools for network bridge (290e2ac13ff4d994a6dc424aae0de3fc2b3dbd47ac2d70daf202fe32a8c8a933)
DEBU[2022-12-11T04:11:09.147696063Z] RequestPool(LocalDefault, 172.18.0.0/16, , map[], false)
DEBU[2022-12-11T04:11:09.147747761Z] RequestAddress(LocalDefault/172.18.0.0/16, <nil>, map[RequestAddressType:com.docker.network.gateway])
DEBU[2022-12-11T04:11:09.147795652Z] Request address PoolID:172.18.0.0/16 App: ipam/default/data, ID: LocalDefault/172.18.0.0/16, DBIndex: 0x0, Bits: 65536, Unselected: 65534, Sequence: (0x80000000, 1)->(0x0, 2046)->(0x1, 1)->end Curr:0 Serial:false PrefAddress:<nil>
ERRO[2022-12-11T04:11:09.147858973Z] failed to set to initial namespace, net:[4026533620], initns fd 14: operation not permitted
DEBU[2022-12-11T04:11:09.147914869Z] Did not find any interface with name docker0: Link not found
DEBU[2022-12-11T04:11:09.148010572Z] Setting bridge mac address to 02:42:e2:0a:5b:d3
DEBU[2022-12-11T04:11:09.148053373Z] Failed to create bridge docker0 via netlink. Trying ioctl
DEBU[2022-12-11T04:11:09.148099591Z] releasing IPv4 pools from network bridge (290e2ac13ff4d994a6dc424aae0de3fc2b3dbd47ac2d70daf202fe32a8c8a933)
DEBU[2022-12-11T04:11:09.148126242Z] ReleaseAddress(LocalDefault/172.18.0.0/16, 172.18.0.1)
DEBU[2022-12-11T04:11:09.148213228Z] Released address PoolID:LocalDefault/172.18.0.0/16, Address:172.18.0.1 Sequence:App: ipam/default/data, ID: LocalDefault/172.18.0.0/16, DBIndex: 0x0, Bits: 65536, Unselected: 65533, Sequence: (0xc0000000, 1)->(0x0, 2046)->(0x1, 1)->end Curr:2
DEBU[2022-12-11T04:11:09.148240490Z] ReleasePool(LocalDefault/172.18.0.0/16)
DEBU[2022-12-11T04:11:09.148254947Z] daemon configured with a 15 seconds minimum shutdown timeout
DEBU[2022-12-11T04:11:09.148274815Z] start clean shutdown of all containers with a 15 seconds timeout...
DEBU[2022-12-11T04:11:09.148324430Z] found 0 orphan layers
DEBU[2022-12-11T04:11:09.148765069Z] Cleaning up old mountid : start.
INFO[2022-12-11T04:11:09.148953131Z] stopping event stream following graceful shutdown  error="<nil>" module=libcontainerd namespace=moby
DEBU[2022-12-11T04:11:09.149076141Z] Cleaning up old mountid : done.
INFO[2022-12-11T04:11:09.149405639Z] stopping event stream following graceful shutdown  error="context canceled" module=libcontainerd namespace=plugins.moby
INFO[2022-12-11T04:11:09.149442914Z] stopping healthcheck following graceful shutdown  module=libcontainerd
DEBU[2022-12-11T04:11:09.149602629Z] received signal                               signal=terminated
DEBU[2022-12-11T04:11:09.149688012Z] sd notification                               error="<nil>" notified=false state="STOPPING=1"
WARN[2022-12-11T04:11:10.150011723Z] grpc: addrConn.createTransport failed to connect to {unix:///var/run/docker/containerd/containerd.sock  <nil> 0 <nil>}. Err :connection error: desc = "transport: Error while dialing dial unix:///var/run/docker/containerd/containerd.sock: timeout". Reconnecting...  module=grpc
failed to start daemon: Error initializing network controller: Error creating default "bridge" network: operation not permitted

and when i try running something like

sudo docker run -v /var/run/docker.sock:/var/run/docker.sock docker

i get docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.


来源: stackexchange

问:
How would you build this component? Flutter Widget Design (Custom Range Slider)
More of  a flexible question, But  I've been looking at this and either don't know enough about flutter (custom drag detectors etc) but the best I have is a range slider (with some sort of overlay that handles the white dots) and then a container that uses math to determine where to clip the vertical bars. However I'm not sure exactly how I'd pull that off

So I'm curious how would you guys pull it off? Custom containers and clips with gesture detectors? Etc. At least from there I'd have an idea as to what method I need to be researching. A starting point as such

Thanks!

Images:

ContentLicense: CC BY-SA 4.0


问:
LDA topic modeling in R : error : Each row of the input matrix needs to contain at least one non-zero entry
```<code>news_nov_lda<-LDA(news_nov_dtm2, k=18, seed=1234)

Error in LDA(news_nov_dtm2, k = 18, seed = 1234) :
  Each row of the input matrix needs to contain at least one non-zero entry
</code>```
```<code>So I tried

</code>```

raw.sum=apply(news_nov_dtm2, 1, FUN = sum)
news_nov_dtm2=table[raw.sum!=0,]

Error in table[raw.sum != 0, ] :
object of type 'closure' is not subsettable

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

Help....

Body:
news_nov_lda<-LDA(news_nov_dtm2, k=18, seed=1234)

Error in LDA(news_nov_dtm2, k = 18, seed = 1234) :
  Each row of the input matrix needs to contain at least one non-zero entry

So I tried

raw.sum=apply(news_nov_dtm2, 1, FUN = sum)
news_nov_dtm2=table[raw.sum!=0,]

Error in table[raw.sum != 0, ] :
object of type 'closure' is not subsettable

Help....


问:
is there a way to know which slider is centered on react slick slider?
I am using react slick slider to implement a design where a centered div will have a different design and other divs will have a general design. To achieve this, I decided to use react slick slider. React slick slider have a default setting which is centerMode. I want to know which item from my data index is centered also I want to fire an event when an item is centered so that I can customize my design based on that.
I tried to know the way by searching on google but didn't get much information.</p>


问:
Getting undefined value when sending data to server side
index.html:

```<code>//display the searched laptop
function searchProducts(){
    let search = document.getElementById("laptopSearched").value;
    console.log("Search_Value " + search);

    const formData = new FormData();

    formData.append('mySearch', search);

    //Create request object
    let request = new XMLHttpRequest();

    //Set up request with HTTP method and URL
    request.open("POST", "/laptops");

    //Send request
    request.send(formData);

}
</code>```

server.js

```<code> app.post('/laptops', function(request, response){
   //get laptop searched by user
   let laptopBrand = request.body.mySearch;
   console.log(laptopBrand);
 });
</code>```

When request.body.mySearch is read on the server side, an undefined value is returned. How  should this problem be solved please?

Body:
index.html:

//display the searched laptop
function searchProducts(){
    let search = document.getElementById("laptopSearched").value;
    console.log("Search_Value " + search);

    const formData = new FormData();

    formData.append('mySearch', search);

    //Create request object
    let request = new XMLHttpRequest();

    //Set up request with HTTP method and URL
    request.open("POST", "/laptops");

    //Send request
    request.send(formData);

}

server.js

 app.post('/laptops', function(request, response){
   //get laptop searched by user
   let laptopBrand = request.body.mySearch;
   console.log(laptopBrand);
 });

When request.body.mySearch is read on the server side, an undefined value is returned. How  should this problem be solved please?


问:
How to dynamically get view's origin in swiftui
Background

Using SwiftUI, I want to implement tutorial(Coach marks) functionalities for some view( like button, text, image and so on) which was defined without specifying origin and sizes

for modifier frame. especially such functionalities will be asked for several difference screen.

My Test Code

1. Definition of PreferenceKey

```<code>struct MyPreferenceKey: PreferenceKey {
    static var defaultValue: CGRect = .zero
    static func reduce(value: inout CGRect, nextValue: () -> CGRect) {
        value = nextValue()
    }
}
</code>```

main view

```<code>struct ContentView: View {

    @State var rating : Int = 3
    var body: some View {
        GeometryReader { geometry in
            let origin = geometry.frame(in: .global).origin
            let size = geometry.frame(in: .global).size
            VStack {

                HStack{
                    Text("Test1")   // for testing following target,just add some view hierachy
                        .padding()
                        .background(Color.yellow)
                    VStack{
                        Text("test2")
                            .padding()
                            .background(Color.purple)
                        Text("")   // here is my target, i want to get the origin of this view
                            .frame(width: 100, height: 200)   // just for having spece to show value of frame
                            .background(Color.green)
                            .overlay(
                                GeometryReader { proxy in
                                    let frm = proxy.frame(in: .global)
                                    let size = proxy.size
                                    Color.clear.preference(key: MyPreferenceKey.self,value: proxy.frame(in: .global))
                                    Text(verbatim: "X=\(String(format: "%.2f",  frm.midX)) y=\(String(format: "%.2f",  frm.midY) ) width=\(String(format: "%.2f",  frm.width)) height=\(String(format: "%.2f",  frm.height))")

                                }

                            )
                    }
                }
                .onPreferenceChange(MyPreferenceKey.self){
                    print("\($0)")
                }

            }
            .frame(width: 200, height: 300, alignment: .center)
        }

    }
}
</code>```

3. Ran result (Xcode)

4.Ran result (Log)

(89.83333333333331, 127.16666666666669, 100.0, 200.0)

5. Problem

the view with green background says it's origin.x is 139, but logs printed above is 89 in modifier onPreferenceChange.

My Question:

how can i get real origin.x with 139 using like modifier onPreferenceChange.

is there a way to get value  shown by above Text view

thanks.

Body:
Background

Using SwiftUI, I want to implement tutorial(Coach marks) functionalities for some view( like button, text, image and so on) which was defined without specifying origin and sizes

for modifier frame. especially such functionalities will be asked for several difference screen.

My Test Code

1. Definition of PreferenceKey

struct MyPreferenceKey: PreferenceKey {
    static var defaultValue: CGRect = .zero
    static func reduce(value: inout CGRect, nextValue: () -> CGRect) {
        value = nextValue()
    }
}

main view

struct ContentView: View {

    @State var rating : Int = 3
    var body: some View {
        GeometryReader { geometry in
            let origin = geometry.frame(in: .global).origin
            let size = geometry.frame(in: .global).size
            VStack {

                HStack{
                    Text("Test1")   // for testing following target,just add some view hierachy
                        .padding()
                        .background(Color.yellow)
                    VStack{
                        Text("test2")
                            .padding()
                            .background(Color.purple)
                        Text("")   // here is my target, i want to get the origin of this view
                            .frame(width: 100, height: 200)   // just for having spece to show value of frame
                            .background(Color.green)
                            .overlay(
                                GeometryReader { proxy in
                                    let frm = proxy.frame(in: .global)
                                    let size = proxy.size
                                    Color.clear.preference(key: MyPreferenceKey.self,value: proxy.frame(in: .global))
                                    Text(verbatim: "X=\(String(format: "%.2f",  frm.midX)) y=\(String(format: "%.2f",  frm.midY) ) width=\(String(format: "%.2f",  frm.width)) height=\(String(format: "%.2f",  frm.height))")

                                }

                            )
                    }
                }
                .onPreferenceChange(MyPreferenceKey.self){
                    print("\($0)")
                }

            }
            .frame(width: 200, height: 300, alignment: .center)
        }

    }
}

3. Ran result (Xcode)

4.Ran result (Log)

(89.83333333333331, 127.16666666666669, 100.0, 200.0)

5. Problem

the view with green background says it's origin.x is 139, but logs printed above is 89 in modifier onPreferenceChange.

My Question:

how can i get real origin.x with 139 using like modifier onPreferenceChange.

is there a way to get value  shown by above Text view

thanks.


问:
How can I call a method from another project in Java using Remote Method Invocation (RMI)?
I am using IntelliJ as my IDE and the code below runs alright if they are in the same src folder. However, what I want is to call the sayHello() method in another project. Is that possible? I thought this is possible since this is what RMI enables, but am I wrong?

I tried to create another project that contains a Main java class and has the same code as the Client Test Drive below, hoping to call the sayHello() method by utilizing Naming.lookup() but it doesn't work! If I try to run it, I was given a java.rmi.UnmarshalException: error unmarshalling return; exception. What am I missing?

How can I call the sayHello() method "remotely"?

Remote Interface:

```<code>package Remote;

import java.rmi.*;

public interface HelloRemote extends Remote {
    String sayHello() throws RemoteException;
}
</code>```

Remote Implementation

```<code>package Remote;

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class HelloRemoteImpl extends UnicastRemoteObject implements HelloRemote{
    public HelloRemoteImpl() throws RemoteException {};

    @Override
    public String sayHello() throws RemoteException {
        return "Server says, \"Hello!\"";
    }

    public static void main(String[] args) {
        try {
            // 2.3 register the service
            HelloRemote service = new HelloRemoteImpl();
            final int PORT = 1888;
            Registry registry = LocateRegistry.createRegistry(PORT);
            registry.rebind("hello", service);
            System.out.println("Service running on PORT: " + PORT);

        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}
</code>```

Client Test Drive

```<code>package Remote;

import java.rmi.Naming;

public class SayHelloTest {
    public static void main(String[] args) {
        try {
            HelloRemote service = (HelloRemote) Naming.lookup("rmi://127.0.0.1:1888/hello");
            String helloStr = service.sayHello();

            System.out.println(helloStr);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
</code>```

Body:
I am using IntelliJ as my IDE and the code below runs alright if they are in the same src folder. However, what I want is to call the sayHello() method in another project. Is that possible? I thought this is possible since this is what RMI enables, but am I wrong?

I tried to create another project that contains a Main java class and has the same code as the Client Test Drive below, hoping to call the sayHello() method by utilizing Naming.lookup() but it doesn't work! If I try to run it, I was given a java.rmi.UnmarshalException: error unmarshalling return; exception. What am I missing?

How can I call the sayHello() method "remotely"?

Remote Interface:

package Remote;

import java.rmi.*;

public interface HelloRemote extends Remote {
    String sayHello() throws RemoteException;
}

Remote Implementation

package Remote;

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class HelloRemoteImpl extends UnicastRemoteObject implements HelloRemote{
    public HelloRemoteImpl() throws RemoteException {};

    @Override
    public String sayHello() throws RemoteException {
        return "Server says, \"Hello!\"";
    }

    public static void main(String[] args) {
        try {
            // 2.3 register the service
            HelloRemote service = new HelloRemoteImpl();
            final int PORT = 1888;
            Registry registry = LocateRegistry.createRegistry(PORT);
            registry.rebind("hello", service);
            System.out.println("Service running on PORT: " + PORT);

        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Client Test Drive

package Remote;

import java.rmi.Naming;

public class SayHelloTest {
    public static void main(String[] args) {
        try {
            HelloRemote service = (HelloRemote) Naming.lookup("rmi://127.0.0.1:1888/hello");
            String helloStr = service.sayHello();

            System.out.println(helloStr);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


问:
IntelliJ IDEA not recognizing classes specified in Maven dependencies
import com.app.abc.*;

abc is being displayed in red color.

verified the .m2/repository. dependency is downloaded.
tried reload of project... deleted all dependencies frm .m2 and downloaded again.. Still does not help

even tried mvn -U idea:idea

Also tried

```<code>**Right Clicking the pom.xml in Intellij-idea -> Maven - Reload Project.**
</code>```

Tried File > Invalidate Caches / Restart...

Classes from the dependency are being shown in a list of recommendation by Intellij. But the import statement is causing the error

Body:
import com.app.abc.*;

abc is being displayed in red color.

verified the .m2/repository. dependency is downloaded.
tried reload of project... deleted all dependencies frm .m2 and downloaded again.. Still does not help

even tried mvn -U idea:idea

Also tried

**Right Clicking the pom.xml in Intellij-idea -> Maven - Reload Project.**

Tried File > Invalidate Caches / Restart...

Classes from the dependency are being shown in a list of recommendation by Intellij. But the import statement is causing the error


问:
Bot scheduled messages using Cron have multiple-minute delay
I've been learning how to make Discord bots recently and have been experimenting with scheduled messages. Currently, I have 8 or so messages scheduled to send throughout the week. Some send at a certain time every single day, while some send at a specific time only on the weekends, etc.

Every few weeks or so, however, the messages start sending one minute later than they're supposed to. It started with just sending one minute late, so I adjusted the time in the job to one minute later, but the delay just keeps getting worse. Now the messages are sending 7 minutes later than they're supposed to according to the time I originally set in the job.

I'm very much an amateur, and I'm not sure what might be causing this.

The only thing I have been able to come up with to remedy the problem is adjusting the time in the job, but that's definitely not an ideal solution. It works for a little while, but then the message just delays even more.

The issue still persists even after I've reset the bot, refreshed the js files, etc. as I've been working on other bot functions.

Is there a way to reset those Cron tasks specifically, so they're running on time again. Is the reason just because I have other stuff going on in the command file where those jobs are started? If so, how could I remedy that besides moving it to a separate file?


问:
.NET Framework and .NET 6 compatibility (Entity Framework)
I have a solution with several projects that use .NET Framework 4.7.2. One of the projects contains all of my Entity Framework models and the DbContext (EF v6.4.4). It also uses the ASPNet.Identity.EntityFramework (v2.2.3) extensions.

The projects contains an API layer, common layer (shared DTO models, helper functions, etc), WebJob project, and a Unit Test project.

I need to add in an Azure Function project to process messages from a service bus queue (which receives messages from our ERP system) and update our front facing e-commerce web app.

I need to get with the times and get more familiar with .NET Core / Standard project types. My issue is that the Azure Function project is using .NET 6.0. I want to reference my Entity Framework project.

I have been reading that with later version of .NET Core / Standard, there is "more" compatibility between those and .NET Framework projects.

I was able to reference everything in my Azure Function project and get it to compile with not much issue. However, when I go to do anything with the Entity Framework (read from the DB or write), I get an exception like this:

System.Private.CoreLib: Exception while executing function: InboundFunctions. EntityFramework: The type initializer for 'MethodCallTranslator' threw an exception. System.Private.CoreLib: Value cannot be null. (Parameter 'key').

After digging some more, I seem to have an issue with the Microsoft.AspNet.Identity.EntityFramework package. I had to include this in my AZ function project to satisfy the implementation of the IdentityDbContext. According to VS, this is the library that is throwing a warning about compatibility issues.

At the moment, I am not sure how to resolve this. Would it be easier to make a new DbContext for just the .NET Core stuff or is there a better approach? I don't need any of the Identity stuff in my Azure functions project - it's really only used in my API layer.

Thank you for your help!


问:
Cast string to int64 is not supported
I have problem using subclass keras Api. First I read data from TF record as following

```<code>train_ds = tf.data.TFRecordDataset(['./data.tfrecord'])
val_ds = tf.data.TFRecordDataset(['./data_validate.tfrecord'])
train_ds = train_ds.cache().prefetch(buffer_size=AUTOTUNE)
val_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE)

feature_description = {
    'label': tf.io.FixedLenFeature([], tf.int64, default_value=0),
    'feature1': tf.io.FixedLenFeature([], tf.string, default_value=''),
    'feature2':tf.io.FixedLenFeature([], tf.string, default_value='')
    }

def _parse_function(example_proto):
  example = tf.io.parse_single_example(example_proto, feature_description)
  return {'feature1': example['feature1'], 'feature2': example['feature2']}, example['label']

train_ds = train_ds.map(_parse_function).batch(256)
val_ds = val_ds.map(_parse_function).batch(256)
</code>```

Second

I generated my Model as following

```<code>class VanillaModel(tf.keras.Model):

    def __init__(self, number_of_classes):
        super(VanillaModel, self).__init__()
        self.number_of_classes=number_of_classes
        max_tokens = 100_000
        sequence_length = 1042
        embedding_dim = 64

        embedding = "https://tfhub.dev/google/nnlm-en-dim128-with-normalization/2"
        self.feature2_embedding = hub.KerasLayer(embedding, input_shape=[],
                           dtype=tf.string, name="embedding", trainable=True)

        def custom_standardization(input_data):
            lowercase = tf.strings.lower(input_data)
            stripped_html = tf.strings.regex_replace(
                lowercase, r'<[^<>]*>', ' ')

            return tf.strings.regex_replace(stripped_html,
                                            '[%s]' % re.escape(string.punctuation), '')

        self.feature1_embedding = tf.keras.Sequential([
            feature1_lookup,
            Embedding(max_tokens, output_dim= 32, mask_zero=True),
            GlobalAveragePooling1D()
        ])

        self.hidden_layer_1 = Dense(embedding_dim, activation='relu', name="hidden_layer_1")
        self.hidden_layer_2 = Dense(embedding_dim//2, activation='relu', name="hidden_layer_2")
        self.drop_out_1 = Dropout(rate=0.15, name='drop_out_1')
        self.hidden_layer_3 = Dense(embedding_dim//2, activation='relu',name="hidden_layer_3")
        self.output_layer = Dense(number_of_classes, activation='sigmoid', name="output_layer")

    def call(self, inputs):
        x = tf.concat([
            self.feature1_embedding(inputs["feature1"]),
            self.feature2_embedding(inputs["feature2"])
        ], axis=1)

        x = self.hidden_layer_1(x)
        x = self.hidden_layer_2(x)
        x = self.drop_out_1(x)
        x = self.hidden_layer_3(x)
        output=self.output_layer(x)
        return output
</code>```

Finally

I call Model to train it as following and pass dataset to model.fit:

```<code>tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir="logs")
steps_per_epoch = 85
model = ProblemTypeModel(number_of_classes)
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(
                  from_logits=False),
              metrics=['accuracy'])
history = model.fit(
    train_ds,
    validation_data=val_ds,
    epochs=30,
    steps_per_epoch=steps_per_epoch,
    callbacks=[tensorboard_callback])
</code>```

however I receive this Error Cast string to int64 is not supported

```<code>"name": "UnimplementedError",
    "message": "Graph execution error:\n\nDetected at node 'vanilla_model_22/sequential_45/Cast' defined at (most recent call last):\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\runpy.py\", line 196, in _run_module_as_main\n
    return _run_code(code, main_globals, None,\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\runpy.py\", line 86, in _run_code\n      exec(code, run_globals)\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\ipykernel_launcher.py\", line 17, in <module>\n      app.launch_new_instance()\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\traitlets\\config\\application.py\", line 965, in launch_instance\n      app.start()\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 712, in start\n      self.io_loop.start()\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 199, in start\n
    self.asyncio_loop.run_forever()
.
.
.
.
tensor = tf.cast(tensor, dtype=ref_input.dtype)\nNode: 'problem_type_model_22/sequential_45/Cast'\nCast string to int64 is not supported\n\t [[{{node vanilla_model_22/sequential_45/Cast}}]] [Op:__inference_train_function_32172]
</code>```

my understanding that need to parse my dataset to tuple of features, label which that what i am doing in _parse_function, also when i added print statement in cell function o found out that it works just fine for first two examples and it errors out after that. i don't know why tensorflow throw Cast string to int64 is not supported exception. i would appreciate your all help if you could spot where is error in my code. thank you in advance to take time to look at my post.

tensorflow version: 2.8.3

Title: Cast string to int64 is not supported

Body:
I have problem using subclass keras Api. First I read data from TF record as following

train_ds = tf.data.TFRecordDataset(['./data.tfrecord'])
val_ds = tf.data.TFRecordDataset(['./data_validate.tfrecord'])
train_ds = train_ds.cache().prefetch(buffer_size=AUTOTUNE)
val_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE)

feature_description = {
    'label': tf.io.FixedLenFeature([], tf.int64, default_value=0),
    'feature1': tf.io.FixedLenFeature([], tf.string, default_value=''),
    'feature2':tf.io.FixedLenFeature([], tf.string, default_value='')
    }

def _parse_function(example_proto):
  example = tf.io.parse_single_example(example_proto, feature_description)
  return {'feature1': example['feature1'], 'feature2': example['feature2']}, example['label']

train_ds = train_ds.map(_parse_function).batch(256)
val_ds = val_ds.map(_parse_function).batch(256)

Second

I generated my Model as following

class VanillaModel(tf.keras.Model):

    def __init__(self, number_of_classes):
        super(VanillaModel, self).__init__()
        self.number_of_classes=number_of_classes
        max_tokens = 100_000
        sequence_length = 1042
        embedding_dim = 64

        embedding = "https://tfhub.dev/google/nnlm-en-dim128-with-normalization/2"
        self.feature2_embedding = hub.KerasLayer(embedding, input_shape=[],
                           dtype=tf.string, name="embedding", trainable=True)

        def custom_standardization(input_data):
            lowercase = tf.strings.lower(input_data)
            stripped_html = tf.strings.regex_replace(
                lowercase, r'<[^<>]*>', ' ')

            return tf.strings.regex_replace(stripped_html,
                                            '[%s]' % re.escape(string.punctuation), '')

        self.feature1_embedding = tf.keras.Sequential([
            feature1_lookup,
            Embedding(max_tokens, output_dim= 32, mask_zero=True),
            GlobalAveragePooling1D()
        ])

        self.hidden_layer_1 = Dense(embedding_dim, activation='relu', name="hidden_layer_1")
        self.hidden_layer_2 = Dense(embedding_dim//2, activation='relu', name="hidden_layer_2")
        self.drop_out_1 = Dropout(rate=0.15, name='drop_out_1')
        self.hidden_layer_3 = Dense(embedding_dim//2, activation='relu',name="hidden_layer_3")
        self.output_layer = Dense(number_of_classes, activation='sigmoid', name="output_layer")

    def call(self, inputs):
        x = tf.concat([
            self.feature1_embedding(inputs["feature1"]),
            self.feature2_embedding(inputs["feature2"])
        ], axis=1)

        x = self.hidden_layer_1(x)
        x = self.hidden_layer_2(x)
        x = self.drop_out_1(x)
        x = self.hidden_layer_3(x)
        output=self.output_layer(x)
        return output

Finally

I call Model to train it as following and pass dataset to model.fit:

tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir="logs")
steps_per_epoch = 85
model = ProblemTypeModel(number_of_classes)
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(
                  from_logits=False),
              metrics=['accuracy'])
history = model.fit(
    train_ds,
    validation_data=val_ds,
    epochs=30,
    steps_per_epoch=steps_per_epoch,
    callbacks=[tensorboard_callback])

however I receive this Error Cast string to int64 is not supported

"name": "UnimplementedError",
    "message": "Graph execution error:\n\nDetected at node 'vanilla_model_22/sequential_45/Cast' defined at (most recent call last):\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\runpy.py\", line 196, in _run_module_as_main\n
    return _run_code(code, main_globals, None,\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\runpy.py\", line 86, in _run_code\n      exec(code, run_globals)\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\ipykernel_launcher.py\", line 17, in <module>\n      app.launch_new_instance()\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\traitlets\\config\\application.py\", line 965, in launch_instance\n      app.start()\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\ipykernel\\kernelapp.py\", line 712, in start\n      self.io_loop.start()\n
    File \"c:\\Users\\fakeuser\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\tornado\\platform\\asyncio.py\", line 199, in start\n
    self.asyncio_loop.run_forever()
.
.
.
.
tensor = tf.cast(tensor, dtype=ref_input.dtype)\nNode: 'problem_type_model_22/sequential_45/Cast'\nCast string to int64 is not supported\n\t [[{{node vanilla_model_22/sequential_45/Cast}}]] [Op:__inference_train_function_32172]

my understanding that need to parse my dataset to tuple of features, label which that what i am doing in _parse_function, also when i added print statement in cell function o found out that it works just fine for first two examples and it errors out after that. i don't know why tensorflow throw Cast string to int64 is not supported exception. i would appreciate your all help if you could spot where is error in my code. thank you in advance to take time to look at my post.

tensorflow version: 2.8.3


问:
Appending lists to my iterative algorithm is appending the wrong list
It is my first question on stack overflow and python is not my native language. Please forgive me for any confusions.

I am finding the positions of the sun and earth in my iterative algorithm below using euler's method. I am running into an issue in the bottom of my code. My original array declarations (positions and velocities) are a list of lists. If you read below, I'm having trouble appending these updated lists to my arrays (positions_list and velocities_list), which is to store the history of these updates.

```<code>G = 6.67e-11
Ms = 1.99e30
Me = 5.972e24
AU = 1.496e11

positions = [[0,0], [1.0167*AU,0]]
velocities = [[0,0], [0,29290]]
masses = [Ms, Me]

day_sec = 24*60*60
dt = day_sec*1

num_Iterations = 10
num_planets = 2

positions_list = []
velocities_list = []

for i in range(3):
    forces = []

    for j in range(num_planets): #calculate at planet j
        fx = 0
        fy = 0

        for k in range(num_planets): #calculate pairs

            if j != k:
                rx = positions[j][0] - positions[k][0]
                ry = positions[j][1] - positions[k][1]

                r = (rx**2 + ry**2)**0.5
                f = (G * masses[j] * masses[k]) / (r**2)

                fx += f * (rx / r)
                fy += f * (ry / r)

        forces.append([fx, fy])

    for j in range(num_planets):
        positions[j][0] += velocities[j][0] * dt
        positions[j][1] += velocities[j][1] * dt
        velocities[j][0] += forces[j][0] * dt / masses[j]
        velocities[j][1] += forces[j][1] * dt / masses[j]

   print(positions.copy())
   positions_list.append(positions.copy())
</code>```

An output of print(positions.copy()) is...

```<code>[[0, 0], [152098320000.0, 2530656000]]
[[-128.53585292903838, 0.0], [152141150935.58752, 5061312000.0]]
[[-385.5542028593587, -2.137729081631383], [152226795027.40958, 7592680337.721441]]
</code>```

However, my last line of code positions_list.append(positions.copy()) is...

```<code>[[[-385.5542028593587, -2.137729081631383],
  [152226795027.40958, 7592680337.721441]],
 [[-385.5542028593587, -2.137729081631383],
  [152226795027.40958, 7592680337.721441]],
 [[-385.5542028593587, -2.137729081631383],
  [152226795027.40958, 7592680337.721441]]]
</code>```

It essentially appends the last list made in the code. I want it to append each list separately, storing all lists over the iteration. No matter how long the iteration is, it will only store the last list made however many iterations the loop is.

Therefore, my desired output of positions_list is...

```<code>[[[0, 0], [152098320000.0, 2530656000]],
[[-128.53585292903838, 0.0], [152141150935.58752, 5061312000.0]],
[[-385.5542028593587, -2.137729081631383], [152226795027.40958, 7592680337.721441]]]
</code>```

Body:
It is my first question on stack overflow and python is not my native language. Please forgive me for any confusions.

I am finding the positions of the sun and earth in my iterative algorithm below using euler's method. I am running into an issue in the bottom of my code. My original array declarations (positions and velocities) are a list of lists. If you read below, I'm having trouble appending these updated lists to my arrays (positions_list and velocities_list), which is to store the history of these updates.

G = 6.67e-11
Ms = 1.99e30
Me = 5.972e24
AU = 1.496e11

positions = [[0,0], [1.0167*AU,0]]
velocities = [[0,0], [0,29290]]
masses = [Ms, Me]

day_sec = 24*60*60
dt = day_sec*1

num_Iterations = 10
num_planets = 2

positions_list = []
velocities_list = []

for i in range(3):
    forces = []

    for j in range(num_planets): #calculate at planet j
        fx = 0
        fy = 0

        for k in range(num_planets): #calculate pairs

            if j != k:
                rx = positions[j][0] - positions[k][0]
                ry = positions[j][1] - positions[k][1]

                r = (rx**2 + ry**2)**0.5
                f = (G * masses[j] * masses[k]) / (r**2)

                fx += f * (rx / r)
                fy += f * (ry / r)

        forces.append([fx, fy])

    for j in range(num_planets):
        positions[j][0] += velocities[j][0] * dt
        positions[j][1] += velocities[j][1] * dt
        velocities[j][0] += forces[j][0] * dt / masses[j]
        velocities[j][1] += forces[j][1] * dt / masses[j]

   print(positions.copy())
   positions_list.append(positions.copy())

An output of print(positions.copy()) is...

[[0, 0], [152098320000.0, 2530656000]]
[[-128.53585292903838, 0.0], [152141150935.58752, 5061312000.0]]
[[-385.5542028593587, -2.137729081631383], [152226795027.40958, 7592680337.721441]]

However, my last line of code positions_list.append(positions.copy()) is...

[[[-385.5542028593587, -2.137729081631383],
  [152226795027.40958, 7592680337.721441]],
 [[-385.5542028593587, -2.137729081631383],
  [152226795027.40958, 7592680337.721441]],
 [[-385.5542028593587, -2.137729081631383],
  [152226795027.40958, 7592680337.721441]]]

It essentially appends the last list made in the code. I want it to append each list separately, storing all lists over the iteration. No matter how long the iteration is, it will only store the last list made however many iterations the loop is.

Therefore, my desired output of positions_list is...

[[[0, 0], [152098320000.0, 2530656000]],
[[-128.53585292903838, 0.0], [152141150935.58752, 5061312000.0]],
[[-385.5542028593587, -2.137729081631383], [152226795027.40958, 7592680337.721441]]]


问:
C++ Left Center Right Dice Game (Game Loop and connecting vectors/arrays to classes/header files)
So i have to code the dice game LCR for a final prject but am having some trouble. First off, I know the code is sloppy and really redundant, that's why im looking for help. I couldn't figure out how to connect the 'chips' int vector and 'name' array into the player.h file. I basically need help writing methods for the chip passing to make the code less redundant. But another problem of mine is having the game loop until just one person has chips. Thanks for any help or advice.

```<code>
LeftCenterRight.cpp

#include <iostream>
#include <string>
#include <time.h>
#include "Dice.h"
#include "Player.h"
#include <vector>
#include <algorithm>

using namespace std;

void Player::gameRules()
{
    cout << ("\n-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n\n");
    cout << ("Left Center Right is a multiplayer dice game");
    cout << ("With a minimum of three players.");
    cout << ("Dice containing letters L, C, R along\n"
        "with dots on the remaining side are rolled each turn");
    cout << ("\n-----Each Player starts with three chips-----\n");
    cout << (">> For each L rolled, the player must pass one chip to the player to their left\n"
        ">> For each R rolled, the player must pass one chip to the player to their right\n"
        ">> For each C rolled, the player must pass a chip into the center pot (out of play)\n"
        ">> Dots are neutral and require no action");
    cout << ("If a player has three or more chips, he/she rolls all three dice\n"
        "If a player only has two chips, he/she rolles onlt two dice\n"
        "If a player only has one chip, he/she rolls only one die\n"
        "If a player is out of chips, he/she is still in the game,\n"
        "\tbut does not roll any dice and passes their turn"
        "\n\n >>> The last player with chips is the winner <<<");
    cout << ("\n\n-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n");
};

int main()
{
    int result = 0;
    int currPlayer = 1;
    srand((unsigned)time(NULL));

    int numPlayers;
    cout << "How many players are playing? (Please enter 3 or more): " << endl;
    cin >> numPlayers;

    if (numPlayers <= 2)
    {
        while (numPlayers <= 2)
        {
            cout << "More players needed.";
            cout << "How many players are player?: ";
            cin >> numPlayers;
        }
    }

    std::string* names = new string[numPlayers]; // getting names and index is seat number
    for (int i = 0; i < numPlayers; i++)
    {
        cout << "Please enter your name player " << i+1 << endl;
        cin >> names[i];
        std::string playerName = names[i];

    }

    vector<int>chips[1]; // intial 3 chips
    for (int i = 0; i < numPlayers; i++)
    {
        int InitialChips = 3;
        chips->push_back(InitialChips);
    }

    Player::gameRules();

    int sum = 0;
    for (int i = 0; i < chips->size(); i++)
    {
        int num = chips->at(i);
        sum+=num;
    }

    int thePot = 0;
    int i = 0;
    while (sum > 0)
    {
        if ( i >=4 )
        {
            i = 0;
        }
        string currPlayer = names[i];
        int currSeat = i;
        cout << "It's " << currPlayer << "'s Turn!" << endl;
        cout << "[1] Roll Dice      [2] Quit      :";
        int choice;
        cin >> choice;
        if (choice == 1)
        {
            if (chips->at(currSeat) == 0)
            {
                break;
            }
            if (chips->at(currSeat) >= 3)
            {
                for (int k = 0; k <= 3; k++)
                {
                    int outcome = Dice::rollDice();
                    if (outcome == 1)
                    {
                        int currChips = chips->at(i);
                        chips->at(i) = (currChips - 1);
                        cout << ">> -1 chip to " << names[i] << endl;
                        cout << ">> " << names[i] << " now has " << chips->at(i) << " chip(s)" << endl;

                        if (i == 0)
                        {
                            int j = (numPlayers - 1);
                            int currChips2 = (chips->at(j));
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;
                        }
                        else
                        {
                            int j = i - 1;
                            int currChips2 = (chips->at(j));
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;

                        }

                    }
                    if (outcome == 2)
                    {
                        int currChips = chips->at(i);
                        chips->at(i) = (currChips - 1);
                        cout << ">> -1 chip to " << names[i] << endl;
                        cout << ">> " << names[i] << " now has " << chips->at(i) << " chip(s)" << endl;

                        if (i == chips->size())
                        {
                            int j = chips->at(0);
                            int currChips2 = chips->at(0);
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;

                        }
                        else
                        {
                            int j = i + 1;
                            int currChips2 = (chips->at(j));
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;

                        }

                    }
                    if (outcome == 3)
                    {
                        thePot++;
                        cout << ">> +1 chip to the Center Pot" << endl;
                        cout << "There are now " << thePot << " chip(s) in the Center Pot " << endl;
                        int currChips = chips->at(i);
                        chips->at(i) = (currChips - 1);
                        cout << ">> -1 chip to " << names[i] << endl;
                        cout << ">> " << names[i] << " now has " << chips->at(i) << " chip(s)" << endl;
                        break;

                    }
                    else if ((outcome == 4) || (outcome == 5) || (outcome == 6))
                    {
                        break;

                    }

                }
            }
// ^^basically copied and pasted most of the while loop for the other two numbers of dice to roll^^

// had redundant code for if the player had 2 chips, to roll two dice only ^^

// also redundant code for only one chip, to roll one die. ^^

            }

        }
        else if (choice == 2)
        {
            break;
        }
        else
        {
            cout << ">> Input Error";
            cout << "[1] Roll Dice     [2] Quit";
            cin >> choice;
        }

        i++;

    }
    return 0;
}
</code>```

Dice.h

```<code>#pragma once

using namespace std;

class Dice
{
public:
    static int rollDice();
    static int diceOutcome;
};

int Dice::rollDice()
{
    int diceOutcome;
    diceOutcome = (rand() % 6) + 1;

    switch (diceOutcome)
    {
    default:
        cout << "Error, retry";
    case 1:
        if (diceOutcome == 1)
        {
            cout << "               --- " << endl;
            cout << "You rolled a  | L |     Move 1 chip left." << endl;
            cout << "               --- " << endl;
            return 1;
        }
        break;
    case 2:
        if (diceOutcome == 2)
        {
            cout << "               --- " << endl;
            cout << "You rolled a  | R |     Move 1 chip right." << endl;
            cout << "               --- " << endl;
            return 2;
        }
        break;
    case 3:
        if (diceOutcome == 3)
        {
            cout << "               --- " << endl;
            cout << "You rolled a  | C |     Move 1 chip to the center." << endl;
            cout << "               --- " << endl;
            return 3;
        }
        break;
    case 4:
        if (diceOutcome == 4)
        cout << "               --- " << endl;
        cout << "You rolled a  | * |     No action needed." << endl;
        cout << "               --- " << endl;
        return 0;
        break;
    case 5:
        if (diceOutcome == 5)
        cout << "               --- " << endl;
        cout << "You rolled a  | * |     No action needed." << endl;
        cout << "               --- " << endl;
        return 0;
        break;
    case 6:
        if (diceOutcome == 6)
        cout << "               --- " << endl;
        cout << "You rolled a  | * |     No action needed." << endl;
        cout << "               --- " << endl;
        return 0;
        break;
    }
}

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

To be fair, I'm quite new to programming, but I have been working on this project for days and kept running into conatiner problems and storing the name and chip values independently. So i've tried a lot of different things, probably not correctly though so I'm open to anything.

Body:
So i have to code the dice game LCR for a final prject but am having some trouble. First off, I know the code is sloppy and really redundant, that's why im looking for help. I couldn't figure out how to connect the 'chips' int vector and 'name' array into the player.h file. I basically need help writing methods for the chip passing to make the code less redundant. But another problem of mine is having the game loop until just one person has chips. Thanks for any help or advice.

LeftCenterRight.cpp

#include <iostream>
#include <string>
#include <time.h>
#include "Dice.h"
#include "Player.h"
#include <vector>
#include <algorithm>

using namespace std;

void Player::gameRules()
{
    cout << ("\n-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n\n");
    cout << ("Left Center Right is a multiplayer dice game");
    cout << ("With a minimum of three players.");
    cout << ("Dice containing letters L, C, R along\n"
        "with dots on the remaining side are rolled each turn");
    cout << ("\n-----Each Player starts with three chips-----\n");
    cout << (">> For each L rolled, the player must pass one chip to the player to their left\n"
        ">> For each R rolled, the player must pass one chip to the player to their right\n"
        ">> For each C rolled, the player must pass a chip into the center pot (out of play)\n"
        ">> Dots are neutral and require no action");
    cout << ("If a player has three or more chips, he/she rolls all three dice\n"
        "If a player only has two chips, he/she rolles onlt two dice\n"
        "If a player only has one chip, he/she rolls only one die\n"
        "If a player is out of chips, he/she is still in the game,\n"
        "\tbut does not roll any dice and passes their turn"
        "\n\n >>> The last player with chips is the winner <<<");
    cout << ("\n\n-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\n");
};

int main()
{
    int result = 0;
    int currPlayer = 1;
    srand((unsigned)time(NULL));

    int numPlayers;
    cout << "How many players are playing? (Please enter 3 or more): " << endl;
    cin >> numPlayers;

    if (numPlayers <= 2)
    {
        while (numPlayers <= 2)
        {
            cout << "More players needed.";
            cout << "How many players are player?: ";
            cin >> numPlayers;
        }
    }

    std::string* names = new string[numPlayers]; // getting names and index is seat number
    for (int i = 0; i < numPlayers; i++)
    {
        cout << "Please enter your name player " << i+1 << endl;
        cin >> names[i];
        std::string playerName = names[i];

    }

    vector<int>chips[1]; // intial 3 chips
    for (int i = 0; i < numPlayers; i++)
    {
        int InitialChips = 3;
        chips->push_back(InitialChips);
    }

    Player::gameRules();

    int sum = 0;
    for (int i = 0; i < chips->size(); i++)
    {
        int num = chips->at(i);
        sum+=num;
    }

    int thePot = 0;
    int i = 0;
    while (sum > 0)
    {
        if ( i >=4 )
        {
            i = 0;
        }
        string currPlayer = names[i];
        int currSeat = i;
        cout << "It's " << currPlayer << "'s Turn!" << endl;
        cout << "[1] Roll Dice      [2] Quit      :";
        int choice;
        cin >> choice;
        if (choice == 1)
        {
            if (chips->at(currSeat) == 0)
            {
                break;
            }
            if (chips->at(currSeat) >= 3)
            {
                for (int k = 0; k <= 3; k++)
                {
                    int outcome = Dice::rollDice();
                    if (outcome == 1)
                    {
                        int currChips = chips->at(i);
                        chips->at(i) = (currChips - 1);
                        cout << ">> -1 chip to " << names[i] << endl;
                        cout << ">> " << names[i] << " now has " << chips->at(i) << " chip(s)" << endl;

                        if (i == 0)
                        {
                            int j = (numPlayers - 1);
                            int currChips2 = (chips->at(j));
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;
                        }
                        else
                        {
                            int j = i - 1;
                            int currChips2 = (chips->at(j));
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;

                        }

                    }
                    if (outcome == 2)
                    {
                        int currChips = chips->at(i);
                        chips->at(i) = (currChips - 1);
                        cout << ">> -1 chip to " << names[i] << endl;
                        cout << ">> " << names[i] << " now has " << chips->at(i) << " chip(s)" << endl;

                        if (i == chips->size())
                        {
                            int j = chips->at(0);
                            int currChips2 = chips->at(0);
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;

                        }
                        else
                        {
                            int j = i + 1;
                            int currChips2 = (chips->at(j));
                            chips->at(j) = (currChips2 + 1);
                            cout << ">> +1 chip to " << names[j] << endl;
                            cout << ">> " << names[j] << " now has " << chips->at(j) << " chip(s)" << endl;
                            break;

                        }

                    }
                    if (outcome == 3)
                    {
                        thePot++;
                        cout << ">> +1 chip to the Center Pot" << endl;
                        cout << "There are now " << thePot << " chip(s) in the Center Pot " << endl;
                        int currChips = chips->at(i);
                        chips->at(i) = (currChips - 1);
                        cout << ">> -1 chip to " << names[i] << endl;
                        cout << ">> " << names[i] << " now has " << chips->at(i) << " chip(s)" << endl;
                        break;

                    }
                    else if ((outcome == 4) || (outcome == 5) || (outcome == 6))
                    {
                        break;

                    }

                }
            }
// ^^basically copied and pasted most of the while loop for the other two numbers of dice to roll^^

// had redundant code for if the player had 2 chips, to roll two dice only ^^

// also redundant code for only one chip, to roll one die. ^^

            }

        }
        else if (choice == 2)
        {
            break;
        }
        else
        {
            cout << ">> Input Error";
            cout << "[1] Roll Dice     [2] Quit";
            cin >> choice;
        }

        i++;

    }
    return 0;
}

Dice.h

#pragma once

using namespace std;

class Dice
{
public:
    static int rollDice();
    static int diceOutcome;
};

int Dice::rollDice()
{
    int diceOutcome;
    diceOutcome = (rand() % 6) + 1;

    switch (diceOutcome)
    {
    default:
        cout << "Error, retry";
    case 1:
        if (diceOutcome == 1)
        {
            cout << "               --- " << endl;
            cout << "You rolled a  | L |     Move 1 chip left." << endl;
            cout << "               --- " << endl;
            return 1;
        }
        break;
    case 2:
        if (diceOutcome == 2)
        {
            cout << "               --- " << endl;
            cout << "You rolled a  | R |     Move 1 chip right." << endl;
            cout << "               --- " << endl;
            return 2;
        }
        break;
    case 3:
        if (diceOutcome == 3)
        {
            cout << "               --- " << endl;
            cout << "You rolled a  | C |     Move 1 chip to the center." << endl;
            cout << "               --- " << endl;
            return 3;
        }
        break;
    case 4:
        if (diceOutcome == 4)
        cout << "               --- " << endl;
        cout << "You rolled a  | * |     No action needed." << endl;
        cout << "               --- " << endl;
        return 0;
        break;
    case 5:
        if (diceOutcome == 5)
        cout << "               --- " << endl;
        cout << "You rolled a  | * |     No action needed." << endl;
        cout << "               --- " << endl;
        return 0;
        break;
    case 6:
        if (diceOutcome == 6)
        cout << "               --- " << endl;
        cout << "You rolled a  | * |     No action needed." << endl;
        cout << "               --- " << endl;
        return 0;
        break;
    }
}

To be fair, I'm quite new to programming, but I have been working on this project for days and kept running into conatiner problems and storing the name and chip values independently. So i've tried a lot of different things, probably not correctly though so I'm open to anything.


问:
How to use mutate function while excluding certain rows
So I am trying to create percentages to display on a plot.

Here is my dataset:

```<code>how_often_ByYear <- structure(list(Var1 = structure(c(1L, 2L, 3L, 1L, 2L, 3L), levels = c("A few times a year",
"Never been", "Once or twice"), class = "factor"), Var2 = structure(c(1L,
1L, 1L, 2L, 2L, 2L), levels = c("Year 1", "Year 2"), class = "factor"),
    Freq = c(0, 122, 47, 1, 117, 50), percent = c(0, 72, 28,
    1, 69, 30)), class = "data.frame", row.names = c(NA, -6L))
</code>```

And here is my code:

```<code>how_often_ByYear <- Visitor_Data_ByYear %>%
  dplyr::select(How_often_have_you_visited_us, Year) #selects column for question 16
#mutate_all(funs(gsub("[[:punct:]]", "", .))) #removes annoying symbols
how_often_ByYear <- table(how_often_ByYear$How_often_have_you_visited_us, how_often_ByYear$Year)
how_often_ByYear <- as.data.frame(how_often_ByYear)
how_often_ByYear <- how_often_ByYear %>%
  mutate(percent = Freq/sum(Freq)*100) %>%
  mutate_if(is.numeric, round, 0)
View(how_often_ByYear)
</code>```

right now, the numbers include both year 1 and year 2, so my percentages add up to around 50 percent. How do I separate the percentages for each year so that I can report on both?

Thanks in advance for your help.

Body:
So I am trying to create percentages to display on a plot.

Here is my dataset:

how_often_ByYear <- structure(list(Var1 = structure(c(1L, 2L, 3L, 1L, 2L, 3L), levels = c("A few times a year",
"Never been", "Once or twice"), class = "factor"), Var2 = structure(c(1L,
1L, 1L, 2L, 2L, 2L), levels = c("Year 1", "Year 2"), class = "factor"),
    Freq = c(0, 122, 47, 1, 117, 50), percent = c(0, 72, 28,
    1, 69, 30)), class = "data.frame", row.names = c(NA, -6L))

And here is my code:

how_often_ByYear <- Visitor_Data_ByYear %>%
  dplyr::select(How_often_have_you_visited_us, Year) #selects column for question 16
#mutate_all(funs(gsub("[[:punct:]]", "", .))) #removes annoying symbols
how_often_ByYear <- table(how_often_ByYear$How_often_have_you_visited_us, how_often_ByYear$Year)
how_often_ByYear <- as.data.frame(how_often_ByYear)
how_often_ByYear <- how_often_ByYear %>%
  mutate(percent = Freq/sum(Freq)*100) %>%
  mutate_if(is.numeric, round, 0)
View(how_often_ByYear)

right now, the numbers include both year 1 and year 2, so my percentages add up to around 50 percent. How do I separate the percentages for each year so that I can report on both?

Thanks in advance for your help.