小编Ewa*_*ine的帖子

你能否,或者你应该在Redux的初始状态下使用localStorage?

例如...

export const user = (state = {
  id: localStorage.getItem('id'),
  name: localStorage.getItem('name'),
  loggedInAt: null
}, action) => {
    case types.LOGIN:
      localStorage.setItem('name', action.payload.user.name);
      localStorage.setItem('id', action.payload.user.id);
      return { ...state, ...action.payload.user }

    default:
      return {  ...state, loggedInAt: Date.now() }
}
Run Code Online (Sandbox Code Playgroud)

这是我正在做的缩小版本,默认按照预期从localStorage返回状态.但是,一旦刷新页面,我的应用程序状态实际上是空白的.

javascript flux ecmascript-6 reactjs redux

22
推荐指数
1
解决办法
8405
查看次数

在Docker容器中安装OpenCV

我正在尝试Dockerise一个依赖于OpenCV的Python应用程序.我尝试了几种不同的方法,但是ImportError: No module named cv2当我尝试运行应用程序时,我一直在......

这是我目前的Dockerfile.

FROM python:2.7

MAINTAINER Ewan Valentine <ewan@theladbible.com>

RUN mkdir -p /usr/src/app 
WORKDIR /usr/src/app 

# Various Python and C/build deps
RUN apt-get update && apt-get install -y \ 
    wget \
    build-essential \ 
    cmake \ 
    git \
    pkg-config \
    python-dev \ 
    python-opencv \ 
    libopencv-dev \ 
    libav-tools  \ 
    libjpeg-dev \ 
    libpng-dev \ 
    libtiff-dev \ 
    libjasper-dev \ 
    libgtk2.0-dev \ 
    python-numpy \ 
    python-pycurl \ 
    libatlas-base-dev \
    gfortran \
    webp \ 
    python-opencv 

# Install Open CV - Warning, this …
Run Code Online (Sandbox Code Playgroud)

python opencv docker

19
推荐指数
2
解决办法
2万
查看次数

我无法从draft-js获取html输出?

我一直在玩Facebook的draft-js,但我实际上无法弄清楚如何获得编辑器的html输出.以下示例中的console.log输出一些_map属性,但它们似乎不包含我的实际内容?

class ContentContainer extends React.Component {
      constructor(props) {
        super(props);
        this.state = {
          value: '',
          editorState: EditorState.createEmpty()
        };
        this.onChange = (editorState) => this.setState({editorState});
        this.createContent = this.createContent.bind(this);
      }

      createContent() {
        console.log(this.state.editorState.getCurrentContent());
      }

      render() {
        const {editorState} = this.state;
        const { content } = this.props;
        return (
          <Template>
            <br /><br /><br />
            <ContentList content={content} />
            <div className="content__editor">
              <Editor editorState={editorState} onChange={this.onChange} ref="content"/>
            </div>
            <FormButton text="Create" onClick={this.createContent.bind(this)} />
          </Template>
        );
      }
    }
Run Code Online (Sandbox Code Playgroud)

javascript reactjs draftjs

18
推荐指数
3
解决办法
2万
查看次数

你如何在Golangs Gorm做UUID?

我有以下型号......

type User struct {
    ID        string  `sql:"type:uuid;primary_key;default:uuid_generate_v4()"`
    FirstName string `form:"first_name" json:"first_name,omitempty"`
    LastName  string `form:"last_name" json:"last_name,omitempty"`
    Password  string `form:"password" json:"password" bindind:"required"`
    Email     string `gorm:"type:varchar(110);unique_index" form:"email" json:"email,omitempty" binding:"required"`
    Location  string `form:"location" json:"location,omitempty"`
    Avatar    string `form:"avatar" json:"avatar,omitempty"`
    BgImg     string `form:"bg_img" json:"bg_img,omitempty"`
    CreatedAt time.Time
    UpdatedAt time.Time
    DeletedAt time.Time
}
Run Code Online (Sandbox Code Playgroud)

我尝试了几种不同的方式,但这种方式会抛出(pq: relation "users" does not exist).我没有相关的模型,它只是一个模型.

我试过用...

func (user *User) BeforeCreate(scope *gorm.Scope) error {
    scope.SetColumn("ID", uuid.NewV4())
    return nil
}
Run Code Online (Sandbox Code Playgroud)

随着一个uuid lib,但也没有运气.

postgresql go go-gorm

9
推荐指数
5
解决办法
5793
查看次数

从bson结构转换protoc生成的结构的最佳方法是什么?

我在Golang中编写了一个RESTful API,它也有一个gRPC api.API连接到MongoDB数据库,并使用结构来映射实体.我也有一个.proto定义,它与我用于MongoDB的结构类似.

我只是想知道是否有一种方法可以共享或重新使用.proto定义的MongoDB调用代码.我注意到strucs protoc生成的每个字段都有json标签,但显然没有bson标签等.

我有类似......

// Menu -
type Menu struct {
    ID          bson.ObjectId      `json:"id" bson"_id"`
    Name        string             `json:"name" bson:"name"`
    Description string             `json:"description" bson:"description"`
    Mixers      []mixers.Mixer     `json:"mixers" bson:"mixers"`
    Sections    []sections.Section `json:"sections" bson:"sections"`
}
Run Code Online (Sandbox Code Playgroud)

但后来我也有protoc生成的代码......

type Menu struct {
    Id          string     `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
    Name        string     `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
    Description string     `protobuf:"bytes,3,opt,name=description" json:"description,omitempty"`
    Mixers      []*Mixer   `protobuf:"bytes,4,rep,name=mixers" json:"mixers,omitempty"`
    Sections    []*Section `protobuf:"bytes,5,rep,name=sections" json:"sections,omitempty"`
}
Run Code Online (Sandbox Code Playgroud)

目前我不得不根据我正在做的事情在两个结构之间进行转换.这很乏味,而且我可能会受到相当大的性能影响.那么是否有更好的方法在两者之间进行转换,或者为两个任务重新使用其中一个?

go mongodb mgo grpc

7
推荐指数
1
解决办法
2781
查看次数

我如何在golang中将uint64转换为uint?

我有以下功能:

func (rc ResizeController) Resize(c *gin.Context) {

    height := c.Query("height")
    width := c.Query("width")
    filepath := c.Query("file")

    h, err := strconv.ParseUint(height, 10, 32)
    w, err := strconv.ParseUint(width, 10, 32)

    file, err := os.Open("./test_images/" + filepath)

    if err != nil {
        log.Fatal(err)
    }

    image, err := jpeg.Decode(file)

    if err != nil {
        log.Fatal(err)
    }

    m := resize.Resize(1000, 100, image, resize.Lanczos3)

    buf := new(bytes.Buffer)
    jpeg.Encode(buf, m, nil)
    response := buf.Bytes()

    c.Data(200, "image/jpeg", response)
}
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

controllers/resize_controller.go:41: cannot use h (type uint64) as type …
Run Code Online (Sandbox Code Playgroud)

go

5
推荐指数
1
解决办法
8848
查看次数

将Redux状态传递给组件时的最佳实践

我正在与其他几个开发人员一起开展React + Redux项目,我们无法就最佳实践在哪些方面传递状态和行动达成一致.

我的方法是拥有一个"容器"或"提供者"组件,它是父组件,所有必需的状态和操作都映射到状态并传递给子组件,从而创建单一的事实来源.然而,缺点是,你必须记住在每个子组件中传递操作和值,这可能很难遵循.

另一种开发人员方法是mapStateToProps在堆栈中的任何位置使用需要它的每个组件.因此,如果三个或四个级别的子组件需要某个状态,他将在该组件上使用mapStateToProps.他还会直接使用import关键字导入动作创建者,而不是将其称为道具.我不喜欢这种方法,因为您可能会多次注入状态,并且无法在一个地方快速切换您的状态或操作.

我可以看到这两种方法都有它们的优点和后备,所以我只是想知道是否有一个明确的最佳实践,在何时何地将状态/动作注入到一堆React组件中.

javascript reactjs redux

5
推荐指数
1
解决办法
1222
查看次数

检查输入时出错:预期density_Dense1_input具有x尺寸。但是得到了形状为y,z的数组

一般来说,我对Tensorflowjs和Tensorflow还是很陌生。我有一些数据,容量使用率超出100%,因此数字介于0和100之间,并且每天有5个小时记录这些容量。所以我有一个5天的矩阵,其中100%中包含5个百分比。

我有以下模型:

const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [5, 5] }));
model.compile({ loss: 'binaryCrossentropy', optimizer: 'sgd' });

// Input data
// Array of days, and their capacity used out of 
// 100% for 5 hour period
const xs = tf.tensor([
  [11, 23, 34, 45, 96],
  [12, 23, 43, 56, 23],
  [12, 23, 56, 67, 56],
  [13, 34, 56, 45, 67],
  [12, 23, 54, 56, 78]
]);

// Labels
const ys = tf.tensor([[1], [2], [3], [4], [5]]);

// Train the …
Run Code Online (Sandbox Code Playgroud)

javascript tensorflow tensorflow.js

5
推荐指数
1
解决办法
971
查看次数

无法连接到Kubernetes群集中的mongodb服务

我在Google Cloud上有一个Kubernetes集群,我有一个数据库服务,它在mongodb部署之前运行.我还有一系列微服务,它们正在尝试连接到该数据存储区.

但是,他们似乎无法找到主持人.

apiVersion: v1
kind: Service
metadata:
 labels:
   name: mongo
 name: mongo
spec:
 ports:
 - port: 27017
   targetPort: 27017
 selector:
   name: mongo
Run Code Online (Sandbox Code Playgroud)

这是我的mongo部署......

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mongo-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: mongo
    spec:
      containers:
      - image: mongo:latest
        name: mongo
        ports:
        - name: mongo
          containerPort: 27017
          hostPort: 27017
        volumeMounts:
          - name: mongo-persistent-storage
            mountPath: /data/db
      volumes:
        - name: mongo-persistent-storage
          gcePersistentDisk:
            pdName: mongo-disk
            fsType: ext4
Run Code Online (Sandbox Code Playgroud)

以及我的一项服务的例子......

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: bandzest-artists
spec:
  replicas: 1 …
Run Code Online (Sandbox Code Playgroud)

mongodb google-cloud-platform kubernetes

4
推荐指数
1
解决办法
6178
查看次数

Redis没有在Laravel 5.1中接收广播事件

我有以下事件:

<?php

namespace SixtyFiveContrib\Events;

use Auth;

use SixtyFiveContrib\Events\Event;
use SixtyFiveContrib\Models\Notification;

use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

/**
 * NotificationEvent 
 *
 */
class NotificationEvent extends Event implements ShouldBroadcast
{
    use SerializesModels;

    public $notification;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Notification $notification)
    {
        $this->notification = $notification;
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['feed', 'updates'];
    }

    public function broadcastWith()
    {
        return …
Run Code Online (Sandbox Code Playgroud)

redis socket.io laravel laravel-5

3
推荐指数
1
解决办法
2197
查看次数