小编A-S*_*ani的帖子

HTML5 JS / 本地数据库

我正在寻找一种在本地存储数据的方法,无论是 sqlite 数据库类型还是在文件中...

我见过 webSql、file Api、localstorage ......

我的限制是:

  • 即使清除缓存后数据也不会过期(因此没有本地存储)
  • 读/写
  • 无需网络服务器即可访问(没有 http:// 而是 file://)
  • 使用 HTML5 或 JS 进行操作
  • 可选:使用 Firefox

是否可以 ?

html javascript database

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

如何仅使用javascript切换/切换div的类

我希望a div切换其类(切换)onclick,然后再次恢复原始类onclick

我的代码是:

 function myfunc() {
    //the code over here
 }
Run Code Online (Sandbox Code Playgroud)
.normal { 
  width:25%;
  height:25%;
  background: #f00;
}

.active { 
  width:100%;
  height:100%;
  background: #f00;
}

#div{}
Run Code Online (Sandbox Code Playgroud)
<body>
  <div id="div" onclick="myfunc()">click here</div>
</body>
Run Code Online (Sandbox Code Playgroud)

html javascript class onclick toggle

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

按位移位,无符号字符

任何人都可以详细解释这完成了什么?我试图学习c并且很难绕过它.

void tonet_short(uint8_t *p, unsigned short s) {
  p[0] = (s >> 8) & 0xff;
  p[1] = s & 0xff;
}

void tonet_long(uint8_t *p, unsigned long l)
{
  p[0] = (l >> 24) & 0xff;
  p[1] = (l >> 16) & 0xff;
  p[2] = (l >> 8) & 0xff;
  p[3] = l & 0xff;
}
Run Code Online (Sandbox Code Playgroud)

c c++ bitwise-and

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

在for循环中创建新线程并传递参数

考虑以下代码:

for(int i = 0; i < 10; i ++)
{
    new Thread(() => Test(i)).Start();
}
Run Code Online (Sandbox Code Playgroud)

Test(int i)函数:

public void Test(int i)
{
    Console.WriteLine("=== Test " + i);
}
Run Code Online (Sandbox Code Playgroud)

实际输出:

===测试3
===测试4
===测试4
===测试5
===测试5
===测试5
===测试9
===测试9
===测试9
===测试10

你可以看到一些数字丢失了,其他一些数据被复制了.

预期产量:

我希望以随机顺序看到所有数字.

我应该锁定任何变量/方法吗?我怎样才能解决这个问题?

c# parallel-processing multithreading

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

模拟方法以返回某些参数并为所有其他参数抛出异常

Moq用来模拟一个方法:

public class DbService : IDbService
{
    public Record GetRecord(Guid Id)
    {
        // Returns the record if exists.
        // Throws exception if record not found.
    }
}
Run Code Online (Sandbox Code Playgroud)

我想模拟一下,如果我传递这三个 guid,它会返回记录,并且所有其他 Guid 都会抛出异常。

Guid id = Guid.NewGuid();
Guid id2 = Guid.NewGuid();
Guid id3 = Guid.NwGuid();

var mock = new Mock<IDbService>();
mock.Setup(t => t.GetRecord(id)).Returns(record1);
mock.Setup(t => t.GetRecord(id2)).Returns(record2);
mock.Setup(t => t.GetRecord(id3)).Returns(record3);
// Throw exception for all other guids...
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

c# moq

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

Express.Static不适用于子目录

Express.static适用于根目录中的任何视图,但是在添加子目录时会中断。

app.use(express.static(path.join(__dirname, 'public')));
Run Code Online (Sandbox Code Playgroud)

作品:

//Homepage
router.get('/', isAuthenticated, function (req, res, next) {
    res.render('index.hbs', {user: req.user, message:req.flash('message')});      //add add'l data {title:'Express', addlData:'SomeData', layout:'layout'}
});
Run Code Online (Sandbox Code Playgroud)

不起作用:

//Organization Profile
router.get('/orgprofile/:username', function(req,res,next){
    User.findOne({username:req.params.username}, function(err,docs){
        res.render('orgprofile.hbs',{orgdetails:docs});
    });
});
Run Code Online (Sandbox Code Playgroud)

我猜__dirname更改为get发出请求的目录,但我只想对所有静态请求使用根(/ public)目录。

javascript node.js express

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

Identity.GetUserId()如何找到用户ID?

如何User.Identity.GetUserId()找到当前用户的ID?

它是从Cookies中找到用户ID,还是查询数据库?还是其他方法?

问题

由于某种原因,当我将有效值添加到Http请求标头并将请求发送到控制器的端点时,User.Identity.GetUserId()返回:nullBearer Token

// MVC Controller Action Method

[Authorize]
public HttpResponseMessage(UserInfoViewModel model)
{
    // Request passes the Authorization filter since a valid oauth token 
    // is attached to the request header.

    string userId = User.Identity.GetUserId();

    // However, userId is null!

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

asp.net asp.net-mvc asp.net-identity

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

Windows 10 Store:您无法提交预编译的.NET Native包

我正在尝试将基于Cordova的Windows 10(通用Windows)的应用程序发布到现有的Windows Phone 8.1商店记录中.

通过Store生成应用程序包 - 创建应用程序包后,我得到了19 MB的文件命名CordovaApp.Windows10_1.3.2.0_x86_x64_arm.appxbundle.然后我将此文件上传到App Packages并获取.

CordovaApp.Windows10_1.3.2.0_x86_x64_arm.appxbundle 18.9 MB

Package acceptance validation error: You cannot submit pre-compiled .NET Native packages. Please upload the Store appxupload file and try again.

我正在使用Visual Studio 2015 Update 2请注意,我已经尝试过

  • 启动新的App记录并上传Windows10程序包
  • 删除引用项目和上传包
  • 右键单击项目Store - Create App Packages
  • 项目 - 商店 - 创建应用包

cordova windows-store-apps visual-studio-cordova windows-10 windows-10-universal

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

用于测量重载运算符和成员函数的时间的函数

描述


是否可以编写一个可用于测量运算符时间的函数以及其他类似函数:

// pass an operator as an argument
measureTime(MyClass::operator*, lhs, rhs);

// Pass a function as an argument
measureTime(MyFunction(arg1, arg2));

// or
measureTime(MyFunction, arg1, arg2);

// or other signatures ...
Run Code Online (Sandbox Code Playgroud)

我遇到了一个函数模板来执行此操作:

template<typename F, typename... Args>
double measureTime(F func, Args&&... args){
    auto t1 = high_resolution_clock::now();
    func(std::forward<Args>(args)...);
    return high_resolution_clock::now() - t1;
}
Run Code Online (Sandbox Code Playgroud)

不确定如何使用它(或编写新函数)来测量重载运算符的时间.

问题


  • 最好的方法是什么(如果可能的话)?
  • 如果不可能,还有其他选择吗?


我正在编写一个用于大整数运算的库,我正在使用不同的算法,并希望在传递不同长度的整数时测量(和比较)它们的时间(并查看它们的行为)...

这是我班级的一部分:

class bigint {
   public:
      int compare(const bigint& other) const;
      bigint operator*(const bigint& rhs) const;
      bigint& operator++();
      bigint otherAlgorithms(const bigint& other) const;
      // …
Run Code Online (Sandbox Code Playgroud)

c++

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

如何通过Kotlin中的函数返回Firestore数据库中的列表?

我正在为朋友构建一个应用程序,我使用的是Firestore.我想要的是显示最喜欢的地方列表,但由于某种原因,列表总是空的.

在此输入图像描述

我无法从Firestore获取数据.这是我的代码:

fun getListOfPlaces() : List<String> {
    val places = ArrayList<String>()
    placesRef.get().addOnCompleteListener { task ->
        if (task.isSuccessful) {
            for (document in task.result) {
                val name = document.data["name"].toString()
                places.add(name)
            }
        }
    }
    return list;
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试打印,请在onCreate函数中说明列表的大小,大小始终为0.

Log.d("TAG", getListOfPlaces().size().toString()); // Is 0 !!!
Run Code Online (Sandbox Code Playgroud)

我可以确认Firebase已成功安装.如果您需要我的其他信息,请告诉我.我错过了什么?谢谢!

kotlin firebase google-cloud-firestore

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