我正在尝试进行扑克模拟并获得有关扑克桌的以下数据
player[0].score == player[1].score,他们并列)我不知道每个玩家应该赢得多少,而不需要创建副圈并为每个玩家分配玩家.
例如,
player[0].contributed = 100
player[1].contributed = 80
player[2].contributed = 20
Run Code Online (Sandbox Code Playgroud)
player[0].score = 10
player[1].score = 2
player[2].score = 10
Run Code Online (Sandbox Code Playgroud)
total_pot = 200;
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我首先需要返回player[0]20并将其从锅中取出吗?
然后,因为player[0]并且player[2]已经并列第一名并且player[1]已经输了,所以应该将底池划分为:
player[0].received = 170
player[1].received = 0
player[2].received = 30
Run Code Online (Sandbox Code Playgroud)
然后,如果player[1]赢了,应该将底池划分为:
player[0].received = 20
player[1].received = 180
player[2].received = 0
Run Code Online (Sandbox Code Playgroud) 我正在构建一个跨平台的移动应用程序(使用Xamarian工具,MonoTouch/MonoDroid).我正在尝试通过身份验证工作流程,并遇到了绊脚石.我已经搜遍了一个明确的答案,但还没有找到它.
以下是我当前设置的概述.
我有一个内置在nodejs的网站.我使用passport.js在网站上进行oAuth登录.这很好用,用户可以使用Twitter或Facebook登录我的网站.
现在我想将这个相同的登录功能扩展到我的移动客户端.
我看到2个选项
将app id和app secret嵌入移动客户端,并通过移动应用程序直接向FB或Twitter发出oAuth调用
代理oAuth通过我现有的nodejs Web服务器调用(保留服务器上的密钥)
选项2似乎是首选方式(因为它避免了在移动应用程序中"运送"秘密).
我的代理方法主要是工作.
http://mysever/auth/twitter这是我的问题:
这是困扰我的最后一步.在我的服务器上完成握手后,我在服务器上获得了所需的用户信息,并需要将其发送回移动客户端应用程序
我无法弄清楚WebView控件中的任何方式来获取响应对象并获取cookie或标头值(例如)(对于Android和iOS来说这似乎是正确的).我不认为它是特定于平台的.我想我正试图做一些移动平台上的WebView小部件不支持的东西.这让我觉得我错过了一些明显的东西.
我唯一想到的是让我的网络服务器将移动客户端浏览器"重定向"到在查询字符串中包含用户信息的虚假URL.像myapp:// info?userid = 1234之类的东西
然后在移动应用程序中,我可以劫持URL加载并获取此URL并获取我需要的数据.然后,我可以存储此userinfo,关闭WebView控件并转到我的移动应用程序中的本机屏幕,并在任何后续REST调用中将userinfo用户命名为我的nodejs服务器,以识别用户.
由于多种原因,这是大规模的kludgy.其中最大的一点是,网址是通过未加密的网络发送的,并且所有数据都是纯文本的.
必须有更好的方法将数据从Web服务器返回到移动客户端?
或者我做错了吗?
我正在对OAuth身份验证问题(invalid_grant)进行故障排除,其中两个可能原因之一是服务器的时钟与NTP不同步.我确保服务器的时钟是同步的.
nodejs是否实例化自己的时钟或引用系统时钟?
我希望它会引用系统时钟.我只是问,因为重启nodejs暂时修复了问题(invalid_grant),我想排除时间同步.
我正在开发一个将部署到Heroku的Web应用程序.
我选择使用Node.js堆栈,因为我厌倦了"传统"的Web框架.我在Express.js上设计应用程序.与Django或Grails相比,我发现它非常高效和直观.
因此,Web应用程序将为访客和经过身份验证的用户提供功能.当应用程序部署到Heroku(一个云平台服务)时,由于Heroku的负载平衡器和实践,应用程序不能在服务器内部存储任何内部状态.事实上,在分布式环境中拥有内部状态也是糟糕的设计.
我的本地开发设置有一个Redis实例(用于存储会话)和一个MongoDB实例(用于存储用户数据,例如Facebook用户详细信息).我使用Passport.js和passport-facebook来处理身份验证.目前,我只实施了Facebook身份验证,至少在本地工作正常.
问题是我不确定也没有读过Express/Passport如何神奇地填充req.user对象.我对此有点怀疑,感觉就像是存储在服务器的内存中.
passport.serializeUser(function(user, done) {
console.log(
"This outputs a complete" +
"User Profile object when the user logs in.",
user);
done(null, user);
});
passport.deserializeUser(function(obj, done) {
console.log(
"And this too, but I'm afraid that" +
"obj comes from memory.",
obj);
done(null, obj);
});
Run Code Online (Sandbox Code Playgroud)
Passport.js文档并没有很好地说明这一点.我的猜测是serializeUser()从Facebook获取用户,但是deserializeUser()从内存中获取它?
如果是这样,它是一个解决方案将原始用户数据转储到serializeUser()中的Mongo数据库,然后从deserializeUser()中获取它吗?
这个身份验证工作正常,我得到一个重定向:
server.post(authPostRoute, passport.authenticate(
'local'
, { successRedirect: '/', failureRedirect: '/login' }
));
Run Code Online (Sandbox Code Playgroud)
调用回调后,此身份验证会挂起:
server.post(authPostRoute, passport.authenticate(
'local'
, function(){ console.log('Hitting the callback'); console.log(arguments)}
));
Run Code Online (Sandbox Code Playgroud)
这记录了以下内容:
{ '0': null,
'1':
{ id: [Getter/Setter],
firstName: [Getter/Setter],
lastName: [Getter/Setter],
email: [Getter/Setter],
addedOn: [Getter/Setter],
active: [Getter/Setter],
password: [Getter/Setter] },
'2': undefined }
Run Code Online (Sandbox Code Playgroud)
但是在整个文档(http://passportjs.org/guide/authenticate/)中,它看起来好像是通过req和res传递的,但显然不是.然后是调用回调的代码:
node_modules \护照\ LIB \中间件\ authenticate.js
strategy.success = function(user, info) {
if (callback) {
return callback(null, user, info);
}
Run Code Online (Sandbox Code Playgroud)
不传递这些参数.我究竟做错了什么?
我想用CURL测试我的node.js + express + passport.js测试应用程序(RESTful).我的代码:
var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
// Define the strategy to be used by PassportJS
passport.use(new LocalStrategy(
function(username, password, done) {
if (username === "admin" && password === "admin") // stupid example
return done(null, {name: "admin"});
return done(null, false, { message: 'Incorrect username.' });
}
));
// Serialized and deserialized methods when got from session
passport.serializeUser(function(user, done) …Run Code Online (Sandbox Code Playgroud) 关于该主题的每个问题都 解释了如何删除 HTML5视频元素的控件.
videoElement.removeAttribute('controls');
Run Code Online (Sandbox Code Playgroud)
但浏览器,Firefox和Chrome有一种方法可以隐藏控件,这使得它们在光标不移动且视频正在播放时消失.如果您移动光标或视频停止播放,它们会再次出现.
<video controls><source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"></video>Run Code Online (Sandbox Code Playgroud)
视频测试文件:http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
如果您播放上述视频,并在不移动光标的情况下单独播放,则控件将消失.如果再次移动光标,它们将再次出现.他们也会在暂停或视频整理时出现.
非常像流行的原生或桌面视频播放器.
这就是我要的.我希望隐藏控件的方式与他们在视频播放时自动隐藏的方式相同,并且光标没有移动一段时间.
有没有办法实现这一点,而无需完全删除控件?
我正在尝试使用Express框架进行Node的第一步.我试图使用Passport实现一个微小的身份验证示例.但是,我无法使其发挥作用; 我一直收到错误:Error: failed to serialize user into session.
我安装了node-inspector来试着看看发生了什么.显然,我的序列化函数被调用,并按done(null, 0)预期执行.我试过看看Passport代码,但我无法理解问题是什么.这几乎是我第一次尝试Node应用程序,所以我不熟悉代码.有人能给我一个暗示吗?谢谢.
var express = require('express');
var jade = require('jade');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var app = express();
/*
* Settings
*/
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: 'cat in the bag' }));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(
function(username, password, done) {
done(null, { id: 0, username: 'juancito' });
}
));
passport.serializeUser(function(user, done) {
done(null, user.id);
});
passport.deserializeUser(function(id, …Run Code Online (Sandbox Code Playgroud) 我有两个nodejs服务器(web-server,socket-server),它们通过socket.io相互连接.在Web服务上,我使用express.js和passport.js作为身份验证中间件.
这是我的网络服务器配置:
var express = require('express'),
mongo = require('mongodb'),
io = require('socket.io'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
MongoStore = require('connect-mongo')(express);
app.configure(function () {
app.use(express.cookieParser());
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(express.session({
secret: 'keyboard cat',
store: new MongoStore({
db: 'MyDatabase'
})
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(__dirname + '/htdocs'));
});
Run Code Online (Sandbox Code Playgroud)
当我使用connect-mongo时,它会为每个http请求创建一个新会话.
此元素使用登录请求创建:
{
"_id" : "UCnXade6Bk6ofOZ+jiEgzyH8",
"session" : "{\"cookie\":{\"originalMaxAge\":31536000000,\"expires\":\"2014-03-07T13:07:45.703Z\",\"httpOnly\":true,\"path\":\"/\"},\"passport\":{\"user\":\"50cae08806e31ea2e5634e3f\"}}",
"expires" : new Date("7.3.2014 19:07:45")
}
Run Code Online (Sandbox Code Playgroud)
每当我按F5或接受套接字时,此元素就会创建.
{
"_id" : "JhypbYFtj1CGOK/ylMhG8+Yk",
"session" : "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{}}",
"expires" : new Date("21.3.2013 19:03:38")
}
Run Code Online (Sandbox Code Playgroud)
当web-server采用套接字连接时,connect-mongo会创建新会话.每分钟大约有50个新文档.
可能是什么原因?
UPDATE
在更新页面的情况下,帮助提示添加app.use(express.favicon()). …
我收到此错误,我无法弄清楚为什么?
错误号:1052
where子句中的列'id'不明确
SELECT `leads`.*,
`customers`.`id` AS customers_id,
`customers`.`name` AS customers_name,
`customers`.`company` AS customers_company,
`customers`.`email` AS customers_email,
`customers`.`phone` AS customers_phone,
`customers`.`created_at` AS customers_created_at,
`customers`.`updated_at` AS customers_updated_at,
`customers`.`ip_address` AS customers_ip_addressFROM (`leads`)
JOIN `customers` ON `customers`.`id` = `leads`.`customer_id`
WHERE `id` = '3'
AND `leads`.`id` = '1'LIMIT 1
Run Code Online (Sandbox Code Playgroud)
文件名:/home/www/REMOVED/models/lead.php
行号:12
该函数如下所示:
function get($id)
{
$this->db->select('leads.*, customers.id AS customers_id, customers.name AS customers_name, customers.company AS customers_company, customers.email AS customers_email, customers.phone AS customers_phone, customers.created_at AS customers_created_at, customers.updated_at AS customers_updated_at, customers.ip_address AS customers_ip_address');
$this->db->where('leads.id', '1');
$this->db->from('leads');
$this->db->join('customers', …Run Code Online (Sandbox Code Playgroud) passport.js ×7
node.js ×6
express ×5
mongodb ×2
oauth ×2
algorithm ×1
codeigniter ×1
curl ×1
git-bash ×1
heroku ×1
html5 ×1
javascript ×1
mysql ×1
poker ×1
redis ×1
video ×1
xamarin.ios ×1