小编Dor*_*ori的帖子

如何保持div一定比例,但给它一个最大尺寸?

我试图保持div元素的特定比例(比如1:2),但保持宽度小于200px.

到目前为止我得到了什么:

div {
    width: 100%;
    height: 0;
    padding-bottom: 50%;
    max-width: 200px;
}
Run Code Online (Sandbox Code Playgroud)

它不起作用 - 如果我展开窗口,宽度停止扩展200px但高度不断增长!

我试过设置box-sizing: border-boxmax-height: 100px,但既不工作.

我该怎么办?

这是一个小提琴:http://jsfiddle.net/WVu3s/

html css

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

使用Firebase时,GoogleSignIn会标记为内部版本,不应从应用中访问

我正在尝试在我的Android应用中检索已登录用户的联系人电子邮件列表.从这里的教程开始,以下行:

mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
Run Code Online (Sandbox Code Playgroud)

导致Android Studio错误"GoogleSignIn被标记为内部,不应从应用访问".

该项目编译,但当我尝试登录时,logcat输出:

W/GooglePlayServicesUtil: Google Play services out of date.  Requires 12210000 but found 11947470
Run Code Online (Sandbox Code Playgroud)

我的app/gradle.build包含:

dependencies {
    ...
    implementation 'com.google.android.gms:play-services-auth:12.0.0'
    implementation 'com.google.firebase:firebase-core:12.0.0'
    implementation 'com.google.firebase:firebase-firestore:12.0.0'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

当我对Firebase发表评论时:

dependencies {
    ...
    implementation 'com.google.android.gms:play-services-auth:12.0.0'
    //implementation 'com.google.firebase:firebase-core:12.0.0'
    //implementation 'com.google.firebase:firebase-firestore:12.0.0'
}
//apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

我没有收到错误并成功登录.

我想将Firestorm集成到我的应用程序中,是否需要重新设计登录过程?如果是这样,怎么样?

重现,这是我的MainActivity.通过编译Firebase,Log.w调用输出signInResult:failed code=12500:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    static final int RC_SIGN_IN = 1000; …
Run Code Online (Sandbox Code Playgroud)

android firebase google-signin

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

有条件地在c ++中强制执行模板类型

我有一个类模板,需要能够通过从Compare我拥有的类派生的比较对象来比较两个对象:

template<typename T>
class Container {
public:
    template<typename A, typename B>
    class Compare {
    public:
        virtual bool eq(const A&, const B&) const = 0;
    };
Run Code Online (Sandbox Code Playgroud)

我提供了一个默认的比较对象,假设type T有运算符==:

    template<typename A, typename B>
    class Default : public Compare<A,B> {
    public:
        bool eq(const A& a, const B& b) const { return a==b; }
    };
private:
    Compare<T,T>* comparison_object;
    bool uses_default;
    Container() : comparison_object(new Default<T,T>()), uses_default(true) {}
    Container(Compare<T,T>& cmp) : comparison_object(&cmp), uses_default(false) {}
    ~Container() { if(uses_default) delete comparison_object; }
}; …
Run Code Online (Sandbox Code Playgroud)

c++ templates

6
推荐指数
1
解决办法
142
查看次数

Mypy 认为 @classmethod @property 是可调用的

Mypy 似乎无法理解属性不是类的可调用方法:

from abc import abstractmethod
from typing import Type


class A:
    pass


class B:
    @abstractmethod
    @property
    @classmethod
    def other_type(cls) -> Type[A]:
        pass

    @classmethod
    def __init_subclass__(cls, **kwargs):
        assert issubclass(cls.other_type, A)
Run Code Online (Sandbox Code Playgroud)

在上面的示例上运行 mypy 会导致以下错误:

error: Argument 1 to "issubclass" has incompatible type "Callable[[], Type[A]]"; expected "type"  [arg-type]
Run Code Online (Sandbox Code Playgroud)

如果没有 ,我如何强制执行正确的类型# type: ignore[arg-type]?我正在使用 mypy 版本 0.782 和 python 3.7

(注意:我正在使用该--check-untyped-defs标志运行 mypy,因此 mypy 应该扫描该__init_subclass__方法)。

python callable mypy

6
推荐指数
0
解决办法
974
查看次数

Node JS Firestore事务中的多个文档读取

我要执行一个事务,该事务需要使用这些文档的先前值来更新两个文档。

为了解决这个问题,我正在尝试将100个令牌从一个应用程序用户转移到另一个应用程序用户。此操作必须是原子性的,以保持DB的数据完整性,因此在服务器端虽然可以使用admin.firestore().runTransaction

据我了解,runTransaction需要在执行写入操作之前执行所有读取操作,那么在更新数据之前如何读取两个用户的余额?

这是我到目前为止的内容:

db = admin.firestore();
const user1Ref = db.collection('users').doc(user1Id);
const user2Ref = db.collection('users').doc(user2Id);
transaction = db.runTransaction(t => {
    return t.get(user1Ref).then(user1Snap => {
        const user1Balance = user1Snap.data().balance;
        // Somehow get the second user's balance (user2Balance)
        t.update(user1Ref , {balance: user1Balance - 100});
        t.update(user2Ref , {balance: user2Balance + 100});
        return Promise.resolve('Transferred 100 tokens from ' + user1Id + ' to ' + user2Id);
    });
}).then(result => {
    console.log('Transaction success', result);
});
Run Code Online (Sandbox Code Playgroud)

node.js firebase firebase-admin google-cloud-firestore

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

PHP - 使用静态属性序列化类

当用户登录我的站点时,我创建了一个我的User类的实例,获取一些与用户相关的数据并将该对象存储在SESSION.

我从数据库中获取的一些数据应该在整个会话期间保持不变,并且我希望可以从其他对象访问数据.我更喜欢使用User::$static_value_in_class,以$_SESSION['static_value_in_session']从另一个对象中使用值的时候,但我愿意劝说.

问题是,当我将User实例序列化为SESSION,然后加载不同的页面时,不会记住这些值.

类定义:

class User {
    public $name;
    public static $allowed_actions;
    public function __construct($username, $password) {
        // Validate credentials, etc.
        self::$allowed_actions = get_allowed_actions_for_this_user($this);
    }   
}
class Blog {
    public static function write($text) {
        if (in_array(USER_MAY_WRITE_BLOG, User::$allowed_actions)) {
            // Write blog entry
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

login.php中:

$user = new User($_POST['username'], $_POST['password']);
if (successful_login($user)) {
    $_SESSION['user'] = $user;
    header('Location: index.php');
}
Run Code Online (Sandbox Code Playgroud)

index.php文件:

if (!isset($_SESSION['user'])) {
    header('Location: login.php');
}
Blog::write("I'm …
Run Code Online (Sandbox Code Playgroud)

php serialization static class

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