我有一个函数,其中一个参数为numpy.ndarray.它是可变的,所以它不能被lru_cache缓存.
有没有现成的解决方案?
我使用https://graph.microsoft.com/beta/me/photo/ $ value API来获取outlook用户的个人资料图片.我得到了一个关于在rest-client中运行上述API的图像.API的内容类型是"image/jpg"
但是,在Node.js中,API的响应如下:
????\u0000\u0010JFIF\u0000\u0001\u0001\u0000\u0000\u0001\u0000\u0001\u0000\u0000??\u0000?\u0000\u0005\u0005\u0005\u0005\u0005\u0005\u0006\u0006\u0006\u0006\b\t\b\t\b\f\u000b\n\n\u000b\f\u0012\r\u000e\r\u000e\r\u0012\u001b\u0011\u0014\u0011\u0011\u0014\u0011\u001b\u0018\u001d\u0018\u0016\u0018\u001d\u0018+"\u001e\u001e"+2*(*2<66<LHLdd?\u
Run Code Online (Sandbox Code Playgroud)
我用'fs'来创建一个图像文件.代码如下:
const options = {
url: "https://graph.microsoft.com/beta/me/photo/$value",
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${locals.access_token}`,
'Content-type': 'image/jpg',
}
};
request(options, (err, res, body) => {
if(err){
reject(err);
}
console.log(res);
const fs = require('fs');
const data = new Buffer(body).toString("base64");
// const data = new Buffer(body);
fs.writeFileSync('profile.jpg', data, (err) => {
if (err) {
console.log("There was an error writing the image")
}
else {
console.log("The file is written successfully");
}
});
});
Run Code Online (Sandbox Code Playgroud)
文件写入成功,但.jpg …
我正在创建一个数据库来存储有关我网站用户的信息(我正在使用stuts2,因此使用Java EE技术).对于数据库,我将制作一个DBManager.我应该在这里应用单例模式还是将所有方法设为静态?
我将使用此DBManager来添加,删除和更新用户配置文件等基本内容.除此之外,我将用于所有其他查询目的,例如,查明用户名是否已经存在,并让所有用户出于管理目的和类似的东西.
我的问题
问候
shahensha
PS数据库比这大.这里我只讨论我将用于存储用户信息的表.
我一直在寻找解决方案,但我找不到答案.
我创建了一个图片上传表单.它使用ajaxform插件运行.但它仍然没有上传到目录.error_log说
move_uploaded_file()无法将文件从[tmp]移动到[dir].
然后在前端显示上传完成.但是当调用文件时,它不存在.
HTML代码:
<div class="imgupload hidden">
<form id="profpicform" action="" method="post" enctype="multipart/form-data">
<input type="file" size="60" name="profpic">
<input type="submit" value="Submit File">
</form>
<div class="imguploadStatus">
<div class="imguploadProgress">
<div class="imguploadProgressBar"></div>
<div class="imguploadProgressPercent">0%</div>
</div>
<div class="imguploadMsg"></div>
</div>
<div class="imgpreview"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
var options = {
beforeSend: function()
{
$(".imguploadProgress").show();
$(".imguploadProgressBar").width('0%');
$(".imguploadMsg").html("");
$(".imguploadProgressPercent").html("0%");
},
uploadProgress: function(event, position, total, percentComplete)
{
$(".imguploadProgressBar").width(percentComplete+'%');
$(".imguploadProgressPercent").html(percentComplete+'%');
},
success: function()
{
$(".imguploadProgressBar").width('100%');
$(".imguploadProgressPercent").html('100%');
},
complete: function(response)
{
alert('Complecion');
},
error: function()
{
$(".imguploadMsg").html("<font color='red'> ERROR: unable to upload files</font>"); …Run Code Online (Sandbox Code Playgroud) 我select2用来选择和ajax加载数据,如何在初始选择后更改状态时替换旧数据.
我的加载代码:
$('.datetimepicker').on("changeDate", function() {
//refresh selectbox ??
doctor_id = $(".select2-doctors").val();
clinic_id = $(".select2-clinics").val();
date = $('.datetimepicker').datepicker('getFormattedDate');
$.ajax({
url: '/admin/appointments/time_slots',
type: 'GET',
dataType: 'json',
data: {doctor_id: doctor_id, clinic_id: clinic_id, date: date}
})
.done(function(data) {
console.log("success");
console.log(data);
$('.select2-slot').select2({
data: data.slots
});
})
.always(function() {
console.log("complete");
});
});
Run Code Online (Sandbox Code Playgroud) 我有一个任务,我需要在Python中找到包含超过65个素数的最低Collatz序列.
例如,19的Collatz序列是:
19,58,29,88,44,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1
该序列包含7个素数.
我还需要使用memoization,因此它不必运行"年"来找到它.我找到了Collatz序列记忆的代码,但是当我只需要素数时,我无法弄清楚如何让它工作.
这是我发现的Collatz记忆代码:
lookup = {}
def countTerms(n):
if n not in lookup:
if n == 1:
lookup[n] = 1
elif not n % 2:
lookup[n] = countTerms(n / 2)[0] + 1
else:
lookup[n] = countTerms(n*3 + 1)[0] + 1
return lookup[n], n
Run Code Online (Sandbox Code Playgroud)
这是我的素数测试员:
def is_prime(a):
for i in xrange(2,a):
if a%i==0:
#print a, " is not a prime number"
return False
if a==1:
return False
else:
return True
Run Code Online (Sandbox Code Playgroud) 有我的docker-compose.yml
version: '2'
services:
web:
image: nginx:latest
ports:
- "8018:80"
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/default.conf
- /private/var/log/nginx:/var/log/nginx
- /private/var/run/php7-fpm.sock:/var/run/php7-fpm.sock
networks:
- code-network
php:
image: php:fpm
volumes:
- ./code:/code
- ./php-fpm.conf:/usr/local/etc/php-fpm.conf
- ./www.conf:/usr/local/etc/php-fpm.d/www.conf
- /private/var/run/php7-fpm.sock:/var/run/php7-fpm.sock
networks:
- code-network
networks:
code-network:
driver: bridge
Run Code Online (Sandbox Code Playgroud)
在site.conf中,我这样写,fastcgi_pass unix:/var/run/php7-fpm.sock;我还将监听地址更改为listen = /var/run/php7-fpm.sockwww.conf。在我的MAC中,在文件夹/ private / var / run中以模式666运行了一个名为php7-fpm.sock的文件。
运行之后docker-compose up -d,容器运行成功。但是当我访问http:// localhost:8018时,它返回了502。检查了nginx错误日志后,我发现了这一点
2017/11/01 13:08:39 [错误] 6#6:* 1连接()到Unix:/var/run/php7-fpm.sock在连接到上游时失败(111:连接被拒绝),客户端:172.18 .0.1,服务器:本地主机,请求:“ GET / HTTP / 1.1”,上游:“ fastcgi:// unix:/var/run/php7-fpm.sock:”,主机:“ localhost:8018”
顺便说一句,在尝试使用unix套接字模式之前。我以tcp / ip模式成功访问了http:// …
我正在尝试根据国家/地区名称在ImageView中设置国家/地区标志.
我遵循以下惯例:国家标志图像始终存储在 drawable/flag_country_name
例如; drawable/flag_india,drawable/flag_south_africa
我到目前为止编写的代码是
imageFlagRight.setImageResource(getFlagResource("India"));
private int getFlagResource(String teamName) {
if(teamName.equals("India")){
return R.drawable.flag_india;
}
if(teamName.equals("Srilanka")){
return R.drawable.flag_srilanka;
}
if(teamName.equals("New Zealand")){
return R.drawable.flag_new_zealand;
}
if(teamName.equals("Pakistan")){
return R.drawable.flag_pakistan;
}
if(teamName.equals("Srilanka")){
return R.drawable.flag_srilanka;
}
if(teamName.equals("South Africa")){
return R.drawable.flag_south_africa;
}
if(teamName.equals("Austalia")){
return R.drawable.flag_australia;
}
return R.drawable.flag_default;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常.
现在我想添加更多的县和旗帜.有没有办法减少代码行?喜欢
return R.drawable.flag+underscorise(teamName);
我已经开始学习 C++。我读到只能在运行之前设置数组的大小,并且可以在运行时设置动态数组。所以我期待这会失败,但它没有:
#include <iostream>
int main() {
using namespace std;
int size;
cout << "enter array size:";
cin >> size;
int i, score[size], max; //array size set to variable doesn't fail
cout << endl << "enter scores:\n";
cin >> score[0];
max = score[0];
for (i = 1; i < size; i++)
{
cin >> score[i];
if (score[i] > max)
max = score[i];
}
cout << "the highest score is " << max << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是最近的 C++ 编译器中的新功能吗?它是否意识到我需要一个动态数组并创建它?
我一般在类定义之上使用关键字"use".像这样:
<?php
namespace suites\plugins\content\agpaypal;
use \Codeception\Util\Fixtures;
use \Codeception\Verify;
use \Codeception\Specify;
class agpaypalTest extends \Codeception\Test\Unit
{
protected $tester;
...
Run Code Online (Sandbox Code Playgroud)
但是现在我意识到,我必须将特性指定的行放入类定义中.像这样:
<?php
namespace suites\plugins\content\agpaypal;
use \Codeception\Util\Fixtures;
use \Codeception\Verify;
class agpaypalTest extends \Codeception\Test\Unit
{
use \Codeception\Specify;
protected $tester;
...
Run Code Online (Sandbox Code Playgroud)
我认为这是因为包\ Codeception\Specify; 是一种特质.但我不明白为什么我设置行use\Codeception\Specify时不能重用这个特性; 在课前定义?
如果有人能指出我的提示或解释,我会很高兴向我解释我应该在哪里使用关键词"使用"最好的.