小编Ben*_*Ben的帖子

Firebase 生态系统 - 安全性和成本

在 Firebase 生态系统中,例如在 Cloud-Firestore 中,财务成本高度依赖于文档读取等因素。

  • 有什么东西可以保护我们免受敌对者直接向我们的 Firestore 发送大量读取请求(绕过我们的应用程序)以提高我们的成本

  • Firebase 平台是否以某种方式识别并过滤掉它,或者如果这发生在我们身上,我们是否只需要付费?

说明:假设我们的 Firestore 安全规则是这样的,即任何人都可以执行某些读取请求 ( allow read;)。例如,考虑一个 HackerNews 类型的应用程序,其中任何人都可以列出帖子(无需身份验证)

firebase google-cloud-firestore

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

打字稿枚举,接口和映射

在TypeScript中,在数组或类似数据结构中,如何在将字符串映射到ID的同时确保只允许特定范围的ID?

这是我想做的。这很好。但是,我想知道是否有更简洁的方法来实现这一目标?

enum ETypeId {
    alpha  = "a",
    beta   = "b",
    gamma  = "g"
}

interface IType {
    id:     ETypeId,
    title:  string,
}

myTypes: IType[] = [
    { id: ETypeId.alpha, title: "Alpha" },
    { id: ETypeId.beta,  title: "Beta"  },
    { id: ETypeId.gamma, title: "Gamma" }
];
Run Code Online (Sandbox Code Playgroud)

就目前而言,我必须执行以下操作才能从id到达title

function getTypeForTypeId( typeId: ETypeId ): IType {
    return myTypes.find( type => type.id == typeId );
}
Run Code Online (Sandbox Code Playgroud)

我是否可以使用其他数据结构,使上面的某些代码更简洁,还是已经足够好了?


说明:

  • "a" 是什么存储在我的数据库中
  • ETypeId.alpha 是我在代码中访问它的方式
  • "Alpha" 显示给用户的是什么。

typescript

5
推荐指数
2
解决办法
9367
查看次数

角编译在ng serve上失败,但在随后的保存成功

在Angular 5中,我注意到ng serveVisual Studio Code中的命令具有以下奇怪行为,导致第一次编译与后续编译的结果不同。

  • 假设我们有一个简单的TypeScript错误,例如 [ts] Property 'x' does not exist on type 'y'.
  • 当我键入ng serve并按Enter键时,控制台将显示TypeScript错误,然后显示消息webpack: Failed to compile
  • 但是,如果忽略此错误,请打开另一个文件,然后直接单击CTRL + S,则会忽略TypeScript错误,并显示以下消息:webpack: Compiled successfully

这是我一段时间以来注意到的。第一次编译应用程序时,如果出现TypeScript错误,它将失败。但是,在由后续保存触发的编译中,尽管存在这些错误,该应用程序仍可以成功编译。

为什么会这样?有没有解决的办法,或者这是预期的行为?

typescript visual-studio-code angular-cli angular angular5

5
推荐指数
0
解决办法
204
查看次数

在 React 中动态加载 Markdown 文件

我使用markdown-to-jsx在我的 React 组件中呈现Markdown

我的问题是我想动态加载降价文件,而不是用import. 场景是这发生在文章详细信息页面上,即我articleId从路由参数中获取,然后基于该 ID,我想加载相应的降价文件,例如article-123.md.

这是我到目前为止所拥有的。如何动态加载 md 文件?

import React, { Component } from 'react'
import Markdown from 'markdown-to-jsx';
import articleMd from './article-123.md'

class Article extends Component {
  constructor(props) {
    super(props)
    this.state = { md: '' }
  }

  componentWillMount() {
    fetch(articleMd)
      .then((res) => res.text())
      .then((md) => {
        this.setState({ md })
      })
  }

  render() {
    return (
      <div className="article">
        <Markdown children={this.state.md}/>
      </div>
    )
  }
}

export default Article
Run Code Online (Sandbox Code Playgroud)

这可以正常工作,但是如果我import …

markdown reactjs

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

嵌入新的黑色YouTube播放器

如何将新的黑色YouTube播放器嵌入我的网站(刚推出的那个)?

在此输入图像描述

我之前已经问过这个问题了,但是因为没有人在投票和关闭之前没有打算真正阅读这个问题而关闭了.不,我没有问如何嵌入播放器的V2或V3,我问的是刚推出的新版本.

PS:我是新人所以我不知道是否有人会重新打开我的另一个问题,或者它是否会永久关闭.随意删除其中一个问题,只要对方保持打开状态即可.

编辑:如果你不知道我在说什么,请阅读:http://newsinabox.net/1630/youtube-launched-cosmic-panda.html

youtube video-player

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

将网格内的数字转换为相应的x,y坐标

给定以下网格中的数字(从1到36),如何确定网格中的坐标(x,y)?

 |  0  1  2  3  4  5  6  7  8
------------------------------
0|  1  2  3  4  5  6  7  8  9
1| 10 11 12 13 14 15 16 17 18
2| 19 20 21 22 23 24 25 26 27
3| 28 29 30 31 32 33 34 35 36
Run Code Online (Sandbox Code Playgroud)

即我想要获得的是以下内容:

 |     0     1     2        8
------------------------------
0| (0,0) (1,0) (2,0) ... (8,0)
1| (0,1) (1,1) (2,1) ... (8,1)
2| (0,2) (1,2) (2,2) ... (8,2)
3| (0,3) (1,3) …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm grid

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

更改精灵使用的png

在cocos2d-x中,如何更改精灵使用的png?

以下作品,但似乎有点长,我想知道是否有一个替代方案,阻止我不得不打电话new

// create sprite with original png
m_pSpr = CCSprite::create( "1.png" );
m_pSpr->setPosition( ccp( 100, 100 ) );
this->addChild( m_pSpr );

// now change the png that is used by the sprite

// new image from png file
CCImage* img = new CCImage();
img->initWithImageFile( "2.png", CCImage::kFmtPng );

// new texture from image
CCTexture2D* tex = new CCTexture2D();
tex->initWithImage( img );

// finally change texture of sprite
m_pSpr->setTexture( tex );
Run Code Online (Sandbox Code Playgroud)

cocos2d-iphone cocos2d-x

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

Express/Mongoose app的结构

我应该如何构建我的express/mongoose应用程序,以便我可以使用我的模式,模型,路由以及在命中这些路由时调用的函数?

server.js

// setup
var express = require("express");
var app = express();
var mongoose = require("mongoose");
app.db = mongoose.connect( 'mydb' ) );

// this is the bit I am not sure about
var UserSchema =  require( './modules/users/schema' )( app, mongoose );
var routes = require( './modules/users/routes' )( app, mongoose, UserSchema );

// listen
app.listen( 3000 );
Run Code Online (Sandbox Code Playgroud)

模块/用户/ schema.js

exports = module.exports = function( app, mongoose ) 
{
    var UserSchema = mongoose.Schema(
    {
        username: { type: String, required: true },
        password: …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose node.js express

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

隐藏继承成员警告

在以下 Unity/C# 代码中,该collider变量会产生以下警告

警告 CS0108“Controller2D.collider”隐藏继承成员“Component.collider”。如果打算隐藏,请使用 new 关键字。

这是什么意思以及如何解决它?


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// require that our object has a box-collider-2d component
[RequireComponent(typeof(BoxCollider2D))]

// controller-2D script
public class Controller2D : MonoBehaviour {

    // stores a reference to our object's box-collider-2d component
    BoxCollider2D collider; // the warning occurs here

    // ...
}
Run Code Online (Sandbox Code Playgroud)

c# inheritance unity-game-engine

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

使用 React 和 Axios 从 Express API 下载文件

当使用带有 Express API 的 React 客户端时,React 客户端如何下载 Express API 发送的文件?

问题:

  • 如果我在浏览器栏中输入网址并按 Enter 键,则文件下载成功。
  • 但是,如果我使用 Axios 在 React 应用程序中调用相同的 url,则该文件不会下载。

快递服务器

// Route handler for /api/files/testfile
const getFile = async (req, res, next) => {

    // File
    const fileName = 'file.csv';
    const filePath = path.join(__dirname, '/../../public/', fileName);

    // File options
     const options = {
        headers: {
            'x-timestamp': Date.now(),
            'x-sent': true,
            'content-disposition': "attachment; filename=" + fileName, // gets ignored
            'content-type': "text/csv"
        }
    }

    try {
        res.download(
            filePath,
            fileName,
            options
        );
        console.log("File …
Run Code Online (Sandbox Code Playgroud)

javascript express reactjs axios

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