我不确定为什么,但我的会话每次请求都被删除了.
这是我的代码
require 'rubygems'
require 'sinatra'
require 'sinatra/base'
require 'haml'
require 'facebook_oauth'
class MyClass < Sinatra::Base
set :logging, true
set :sessions, true
get "/auth/facebook_callback" do
// Do some facebook login which is fine
access_token = facebookClient.authorize(:code => params[:code])
session[:access_token] = access_token.token
session[:user] = facebookClient.me.info['name']
session[:id] = facebookClient.me.info["id"]
#print session by "pp session" I can still see all the sessions
redirect '/'
end
get '/' do
#print all the sessions again. And I can't see anything. The session_id is also different …Run Code Online (Sandbox Code Playgroud) 我正在尝试用Capybara测试一个简单的文件上传.这是我的Gemfile.lock
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
Run Code Online (Sandbox Code Playgroud)
我的selenium-webdriver版本是2.18.这是我的web_steps文件(它是生成的):
When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
with_scope(selector) do
attach_file(field, path)
end
end
Run Code Online (Sandbox Code Playgroud)
这是我上传文件的功能:
Then I attach the file "features/resources/empty.file" to "file" within "#uploadForm"
Run Code Online (Sandbox Code Playgroud)
实际上它在线路上运行正常和绿色,但输入没有拾取任何文件,因此测试失败,因为没有选择文件.
这是我的表格:
%form#uploadForm{:action => "/upload", :method => "POST", :enctype => "multipart/form-data"}
%input{:type => "file", :name => "file", :id => "file"}
Run Code Online (Sandbox Code Playgroud)
这是非常基本的,但我不确定为什么它不起作用.
我被困了好几个小时,这是因为我是Jasmine和Angularjs的新手.基本上,我有这个控制器.
angular.module('toadlane.controllers', []).
controller('MainController', function($scope, $http, SomeService) {
var promise = SomeService.getObjects();
promise.then(function(data) {
if(data.length > 0) {
$scope.objs = data;
} else {
$scope.message = "Please come back soon";
}
});
});
Run Code Online (Sandbox Code Playgroud)
如何写一个Jasmine测试来模拟SomeService来存根data并模拟是否有数据scope的长度不应该是0,如果data是[],则消息应该是"请尽快回来".
'use strict';
describe('controllers', function () {
var scope, someService;
beforeEach(module('services'));
beforeEach(module('controllers'));
beforeEach(inject(function (SomeService) {
someService = SomeService;
var callback = jasmine.createSpy();
someService.getObjs().then(callback);
}));
it('should return some objs', inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
expect($controller('MainController', {$scope: scope, SomeService : someService})).toBeTruthy(); …Run Code Online (Sandbox Code Playgroud) 我要导入到iGraph的文本文件中有一个Twitter关注者列表。
这是我的清单样本
393795446 18215973
393795446 582203919
393795446 190709835
393795446 1093090866
393795446 157780872
393795446 1580109739
393795446 3301748909
393795446 1536791610
393795446 106170345
393795446 9409752
Run Code Online (Sandbox Code Playgroud)
这就是我导入的方式
from igraph import *
twitter_igraph = Graph.Read_Edgelist('twitter_edgelist.txt', directed=True)
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误。
---------------------------------------------------------------------------
InternalError Traceback (most recent call last)
<ipython-input-10-d808f2237fa8> in <module>()
----> 1 twitter_igraph = Graph.Read_Edgelist('twitter_edgelist.txt', directed=True)
InternalError: Error at type_indexededgelist.c:369: cannot add negative number of vertices, Invalid value
Run Code Online (Sandbox Code Playgroud)
我不确定为什么要说负数。我检查了文件,它没有任何负数或ID。
我想将域列入白名单,我将此列表作为
(domain1.com|domain2.com)
但是,它仍然会匹配到
ci.domain1.com
https://regex101.com/r/A2IOJE/1/
我在 node.js 中编写代码
这是代码
new RegExp('(domain1.com|domain2.com)', 'igm').test('ci.domain1.com');
Run Code Online (Sandbox Code Playgroud) 这是一个非常新手的问题,但我不知道如何存根.
我必须模拟一个像这样返回Class的方法.
public Class<? extends SomeClass> getAClass();
Run Code Online (Sandbox Code Playgroud)
如果我做这样的事情
when(this.someInstance.getAClass())
.thenReturn(SomeClassThatExtendsSomeClass.class);
Run Code Online (Sandbox Code Playgroud)
我收到编译错误.
The method thenReturn(Class<capture#1-of ? extends SomeClass>) in the type OngoingStubbing<Class<capture#1-of ? extends SomeClass>> is not applicable for the arguments (Class<SomeClassThatExtendsSomeClass>)
Run Code Online (Sandbox Code Playgroud) 我正在阅读关于promises的博客文章,我发现这个代码我不确定它是如何工作的?
function getPost(id) {
return $.getJSON('/posts/'+ id).then(function(data, status, xhr) {
return data;
});
}
Run Code Online (Sandbox Code Playgroud)
当我尝试这个功能时,它总是会给我一个默认的承诺$.getJSON但第二个return data;意思是什么?
谢谢
我正在学习RxJs,这很酷.我正在尝试创建一个Ajax调用是间隔的页面,因此数据将每5秒刷新一次.所以我以为我会这样做.
var ajax = new Promise(function(resolve) {
return resolve('test');
});
var source1 = Rx.Observable.interval(5000)
.map(function(i) {
return Rx.Observable.fromPromise(ajax);
});
source1.subscribe(function(res) {
res.subscribe(function(pro) {
console.log(pro);
})
});
Run Code Online (Sandbox Code Playgroud)
然而,事实上我需要做两件事subscribe让我觉得我可能在这里做错了.我不确定我是否正朝着正确的方向前进?
我想要的是每5秒钟取一次的承诺流.
这是我的jsfiddle
我们正在尝试复制这个 ES 插件https://github.com/MLnick/elasticsearch-vector-scoring。原因是 AWS ES 不允许安装任何自定义插件。该插件只是做点积和余弦相似度,所以我猜想在painless脚本中复制它应该很简单。看起来groovy脚本在 5.0 中已被弃用。
这是插件的源代码。
/**
* @param params index that a scored are placed in this parameter. Initialize them here.
*/
@SuppressWarnings("unchecked")
private PayloadVectorScoreScript(Map<String, Object> params) {
params.entrySet();
// get field to score
field = (String) params.get("field");
// get query vector
vector = (List<Double>) params.get("vector");
// cosine flag
Object cosineParam = params.get("cosine");
if (cosineParam != null) {
cosine = (boolean) cosineParam;
}
if (field == null || vector == …Run Code Online (Sandbox Code Playgroud) 我有这个命令,我想从输出中总结所有数字.
该命令看起来像这样
$(hadoop fs -ls -R /reports/dt=2018-08-27 | grep _stats.json | awk '{print $NF}' | xargs hadoop fs -cat | jq '.duration')
Run Code Online (Sandbox Code Playgroud)
所以它会列出所有的文件夹/reports/dt=2018-08-27,并只获得_stats.json和传递,通过jq从hadoop -cat和只得到.duration从JSON.最后我得到了这样的结果.
1211789 1211789 373585 495379 1211789
Run Code Online (Sandbox Code Playgroud)
但我希望命令将所有这些数字加在一起成为 4504331