我想在我的ubuntu v16.4 LTS上安装你,但我收到这个错误:
npm WARN deprecated npmconf@2.1.2: this package has been reintegrated into npm and is now out of date with respect to npm
npm ERR! Linux 4.4.0-22-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "yo"
npm ERR! node v6.2.0
npm ERR! npm v3.9.0
npm ERR! path /usr/local/lib/node_modules/yo/lib/cli.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/yo/lib/cli.js'
npm ERR! enoent ENOENT: no such file or directory, …Run Code Online (Sandbox Code Playgroud) 我试图解决这个问题:编写一个函数,找到字符串中最长运行的从零开始的索引.运行是相同字符的连续序列.如果有多个具有相同长度的运行,则返回第一个的索引.
例如,IndexOfLongestRun("abbcccddddcccbba")应该返回6,因为最长的运行是dddd,它首先出现在索引6上.
按照我的所作所为:
private static int IndexOfLongestRun(string str)
{
char[] array1 = str.ToCharArray();
//Array.Sort(array1);
Comparer comparer = new Comparer();
int counter =1;
int maxCount = 0;
int idenxOf = 0;
for (int i =0; i<array1.Length-1 ; i++)
{
if (comparer.Compare(array1[i],array1[i+1]) == 0)
{
counter++;
}
else {
if(maxCount < counter)
{
maxCount = counter;
idenxOf = i - counter + 1;
}
counter = 1;
}
}
return idenxOf ;
}
}
public class Comparer : IComparer<char>
{
public int …Run Code Online (Sandbox Code Playgroud) 我试图使用以下代码将zip文件从asp.net web api返回给客户端:
private byte[] CreateZip(string data)
{
using (var ms = new MemoryStream())
{
using (var ar = new ZipArchive(ms, ZipArchiveMode.Create, true))
{
var file = archive.CreateEntry("file.html");
using (var entryStream = file.Open())
using (var sw = new StreamWriter(entryStream))
{
sw .Write(value);
}
}
return memoryStream.ToArray();
}
}
public HttpResponseMessage Post([FromBody] string data)
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(CreateZip(data));
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip, application/octet-stream");
return result;
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我收到以下错误:
ExceptionMessage":"值'application/zip,application/octet-stream'的格式无效."
这是JS代码:
$.ajax({
type: "POST",
url: url,
data: …Run Code Online (Sandbox Code Playgroud) 我试图拒绝公众使用node express以下代码查看特殊目录中的文件:
app.use(express.static(path.join(__dirname, 'partials')));
app.all('/partials/*', function (req,res, next) {
res.status(403).send(
{
message: 'Access Forbidden'
});
next();
});
Run Code Online (Sandbox Code Playgroud)
如果我路由到localhost/partials,我收到消息'Access Forbidden'但不是如果我路由到localhost/partials/files.html
有什么建议?
我试图找出如何创建一个包含不同扩展名的文件的zip存档,例如.txt文件,.html文件
如果我这样做:
using (var zipArchive = new ZipArchive(memory, ZipArchiveMode.Create, true))
{
var file1= zipArchive .CreateEntry("file1.html");
var file2= zipArchive .CreateEntry("file2.txt");
using (var entryStream = file1.Open())
using (var sw = new StreamWriter(entryStream))
{
streamWriter.Write("testing testinsg steing");
}
using (var entryStream = file2.Open())
using (var sw = new StreamWriter(entryStream))
{
sw.Write("xyxyxyxyxyxy");
}
}
Run Code Online (Sandbox Code Playgroud)
创建模式中的条目只能写入一次,并且一次只能打开一个条目.
我怎么解决这个问题?