小编Gqq*_*big的帖子

没有提示,将图像保存到硬盘?

我用twitter.有些人的推文包含照片,我想保存它们.

我检查了ifttt,其中twitter不是触发器.因此,ifttt无法帮助我做到这一点.

一个想法可能是使用JavaScript.我使用Firefox并安装了Greasemonkey.我可以写一个在twitter网站上运行的Greasemonkey脚本(JavaScript).点击"转发"链接或我的脚本添加的其他按钮后,我的脚本会检查推文的内容,找到照片的网址,然后将其保存到我的磁盘中.

一个问题是如何保存图像.我搜索了互联网.一些使用win.document.execCommand("SaveAs"),它将显示"另存为"窗口.现在窗口显示,为什么不直接单击图像并选择手动保存?所以我不喜欢这种方法.

有什么建议?

javascript greasemonkey filesystem-access userscripts tampermonkey

7
推荐指数
2
解决办法
5873
查看次数

Python3.3:.format(),带有unicode format_spec

我有datetime对象,我的用户提供自己的格式字符串,以他们喜欢的方式格式化时间.

我发现的一种方法是使用'{:...}'.format(mydatetime).

lt = time.localtime(time.time())
d = datetime. datetime.fromtimestamp(time.mktime(lt))
print(userString.format(datetime=d))
Run Code Online (Sandbox Code Playgroud)

英语用户可以提供'{datetime:%B %d, %Y}'格式为2013年12月24日.

中国用户可以提供'{datetime:%Y?%m?%d?}'(YYYYMMDD格式,年=年,月=月,日=日).

但是在执行时'{datetime:%Y?%m?%d?}'.format(datetime=d),Python会引发UnicodeEncodingError: 'locale'编解码器无法编码位置2中的字符'\ u5e74':非法字节序列

我知道有一个解决方法,我可以告诉我的中国用户给格式字符串'{datetime:%Y}?{datime:%m}?{datetime:%d}?',但不能在format_spec中unicode字符显示?如何解决这个问题呢?

我正在使用Windows.

谢谢

python unicode character-encoding python-3.x

7
推荐指数
1
解决办法
697
查看次数

在关键服务器上(数十亿个文件名)对字符串进行内存约束的外部排序,并对重复项进行组合和计数

我们的服务器生成{c521c143-2a23-42ef-89d1-557915e2323a}-sign.xml日志文件夹中的文件.第一部分是GUID; 第二部分是名称模板.

我想计算具有相同名称模板的文件数.例如,我们有

{c521c143-2a23-42ef-89d1-557915e2323a}-sign.xml
{aa3718d1-98e2-4559-bab0-1c69f04eb7ec}-hero.xml
{0c7a50dc-972e-4062-a60c-062a51c7b32c}-sign.xml
Run Code Online (Sandbox Code Playgroud)

结果应该是

sign.xml,2
hero.xml,1
Run Code Online (Sandbox Code Playgroud)

可能的名称模板的总种类是未知的,可能超过int.MaxValue.

服务器上的文件总数未知,可能超过int.MaxValue.

要求:

最终结果应按名称模板排序.

该工具将运行的服务器是超级关键的.在运行工具之前,我们应该能够告诉内存使用情况(MB)和生成的临时文件数(如果有),并且不知道日志文件夹的任何特征.

我们使用C#语言.

我的想法:

  • 对于前5000个文件,计算出现次数,将结果写入Group1.txt.
  • 对于第二个5000个文件,计算出现次数,将结果写入Group2.txt.
  • 重复,直到处理完所有文件.现在我们有一堆组文件.

然后我合并所有这些组文件.

   Group1.txt     Group2.txt   Group3.txt     Group4.txt   
       \            /            \                /
       Group1-2.txt                Group3-4.txt
                  \                 /
                    Group1-4.txt
Run Code Online (Sandbox Code Playgroud)

Group1-4.txt 是最后的结果.

我和我朋友之间的分歧是我们如何计算事件的数量.

我建议使用字典.文件名模板是关键.设m为分区大小.(在这个例子中它是5000.)然后时间复杂度O(m),空间复杂度O(m).

我的朋友建议对名称模板进行排序,然后在一次传递中对事件进行计数,因为相同的名称模板现在都在一起.时间复杂度O(m log m),空间复杂度O(m).

我们无法说服对方.你们看到这两种方法有什么问题吗?

c# sorting algorithm dictionary large-data

7
推荐指数
2
解决办法
1854
查看次数

如何在ASP.NET中使用标记声明对象

假设我们有一个Person班级:

public class Person
{
  public string FamilyName {get;set;}
  public string GivenName {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

并且有一个控件以某种方式显示人员列表的信息.这是aspx的伪代码:

<uc1:EmployeesViewer runat="server">
  <Employees>
    <Person>
      <GivenName>John</GivenName>
      <FamilyName>Kerry</GivenName>
    </Person>
    <Person>
      <GivenName>Jack</GivenName>  
      <FamilyName>Lew</GivenName>
    </Person>
  <Employees>
</uc1:EmployeesViewer>
Run Code Online (Sandbox Code Playgroud)

EmployeesViewer.EmployeesList<Person>属性的类型[PersistenceMode(PersistenceMode.InnerProperty)].

但是Visual Studio不会编译它.是否可以Person使用标记声明对象?

c# asp.net webforms

7
推荐指数
1
解决办法
1069
查看次数

BroadcastChannel 是否在同一页面上工作?

我的网页有

var bc = new BroadcastChannel('Consumer');

bc.onmessage = function(event) {
  alert("a");
}

bc.postMessage("hello");
Run Code Online (Sandbox Code Playgroud)

它广播一条消息,页面也需要接收相同的消息。

但是它不起作用。我错过了什么吗?

javascript

6
推荐指数
2
解决办法
1749
查看次数

如何使PerspectiveTransform工作?

我只是想重现这里发布的结果.

我将源重写为EmguCV表单.

    Image<Bgr, byte> image = new Image<Bgr, byte>(@"B:\perspective.png");

    CvInvoke.cvShowImage("Hello World!", image);

    float[,] scrp = { { 43, 18 }, { 280,40}, {19,223 }, { 304,200} };
    float[,] dstp = { { 0,0}, { 320,0}, { 0,240 }, { 320,240 } };
    float[,] homog = new float[3, 3];


    Matrix<float> c1 = new Matrix<float>(scrp);
    Matrix<float> c2 = new Matrix<float>(dstp);
    Matrix<float> homogm = new Matrix<float>(homog);


    CvInvoke.cvFindHomography(c1.Ptr, c2.Ptr, homogm.Ptr, Emgu.CV.CvEnum.HOMOGRAPHY_METHOD.DEFAULT, 0, IntPtr.Zero);
    CvInvoke.cvGetPerspectiveTransform(c1, c2, homogm);

    Image<Bgr, byte> newImage = …
Run Code Online (Sandbox Code Playgroud)

c# opencv image-processing emgucv perspective

5
推荐指数
1
解决办法
7780
查看次数

为什么我不必逃避等号?

例如:

"1+1=2".replace(/=/,"aa");
"1+1=2".replace(/\=/,"aa");
Run Code Online (Sandbox Code Playgroud)

返回相同的结果。

这是否意味着我不必在 JavaScript 中转义“=”(等号)?我记得我总是必须在 Java 和 .NET 中转义等号。

我试图从https://www.ecma-international.org/ecma-262/7.0/index.html找到一些信息,但没有想出任何东西。

任何人都可以帮我找到规范是否谈到转义等号?

javascript regex

5
推荐指数
1
解决办法
2647
查看次数

为什么我可以在没有runat = server的情况下从服务器端访问HTML元素?

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        myTr.Visible = false;
        mySpan.Visible = false;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <table runat="server">
            <tr id="myTr">
                <td>Hello</td>
                <td><span id="mySpan">World</span></td>
            </tr>
            <tr>
                <td>Hi</td>
                <td>Bye</td>
            </tr>
        </table>
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

请注意myTr,mySpan 两者都没有runat = server,但编译器只会出错mySpan.Visible = false.

在此输入图像描述

为什么编译器报告错误myTr.Visible = false

asp.net

5
推荐指数
1
解决办法
340
查看次数

如何搜索整个代码块

我的文件有

.settings {
}


.field {
    margin-bottom: 1em;
}
Run Code Online (Sandbox Code Playgroud)

我想知道什么时候

.settings {
}
Run Code Online (Sandbox Code Playgroud)

成立了.

我知道如果我想搜索一行代码,我会这样做git log -S".settings {".

但在这里我想搜索

.settings {
}
Run Code Online (Sandbox Code Playgroud)

作为一个整体,我试过了

git log -S".settings {\r}" confirm.less.css
git log -S".settings {\n}" confirm.less.css
git log -S".settings {\r\n}" confirm.less.css
Run Code Online (Sandbox Code Playgroud)

但所有人都没有后退.

如何搜索包含新行字符的整个代码块

git

5
推荐指数
1
解决办法
146
查看次数

从控制器获取 JsonOptions

我在 Startup 类中设置了缩进 JSON,但是如何从控制器中检索格式值?

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc()
                .AddWebApiConventions()
                .AddJsonOptions(options=> options.SerializerSettings.Formatting=Newtonsoft.Json.Formatting.Indented);
    }

}


public class HomeController : Controller
{
    public bool GetIsIndented()
    {
        bool isIndented = ????
        return isIndented;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-2.0

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