小编Pet*_*rns的帖子

我什么时候应该使用mmap进行文件访问?

POSIX环境提供至少两种访问文件的方法.有标准的系统调用open(),read(),write(),和朋友,但也有使用的选项mmap(),将文件映射到虚拟内存.

何时优先使用一个而不是另一个?它们各自的优势是什么,包括两个接口?

c file-io posix mmap

263
推荐指数
6
解决办法
10万
查看次数

使用querySelector查找Polymer模板内的嵌套元素将返回null

我正在尝试在新元素(tabs-list)中使用paper-tabs但是在打印选项卡之后我不能使用querySelector来更改所选的.

元素代码(没有样式):

<link rel="import" href="../components/polymer/polymer.html">
<link rel="import" href="../sprint-service/sprint-service.html">
<link rel="import" href="../components/paper-tabs/paper-tabs.html">

<polymer-element name="tab-list" attributes="show">
  <template>
    <sprint-service id="service" sprints="{{sprints}}"></sprint-service>   
    <paper-tabs selected="all" valueattr="name" self-end>
      <paper-tab name="all">ALL</paper-tab>
      <template repeat="{{sprint in sprints}}">
        <paper-tab name="{{sprint.id}}">{{sprint.id}}</paper-tab>
      </template>
    </paper-tabs>
  </template>
  <script>
    Polymer('tab-list', {
      ready: function() {
        var tabs = document.querySelector('paper-tabs');
        tabs.addEventListener('core-select', function() {
          list.show = tabs.selected;
        }) 
      } 
    });
  </script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)

Index.html代码(whitout样式):

<!doctype html>
<html>

<head>
  <title>unquote</title>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <script src="../components/platform-dev/platform.js"></script>
  <link rel="import" href="../components/font-roboto/roboto.html">
  <link rel="import"
    href="../components/core-header-panel/core-header-panel.html">
  <link rel="import"
    href="../components/core-toolbar/core-toolbar.html">
  <link rel="import" href="tab-list.html"> …
Run Code Online (Sandbox Code Playgroud)

javascript shadow-dom polymer

20
推荐指数
1
解决办法
3万
查看次数

有效地获取排序列表的排序总和

您有一个升序的数字列表,您可以想到的最有效的算法是获取该列表中每两个数字的总和的升序列表.结果列表中的重复项无关紧要,如果您愿意,可以删除它们或避免使用它们.

要清楚,我对算法很感兴趣.您可以随意使用您喜欢的任何语言和范例发布代码.

language-agnostic algorithm

18
推荐指数
1
解决办法
1687
查看次数

你如何在Git项目的文件中包含当前的提交ID?

我有一个开源静态JavaScript + HTML应用程序,它现在部署在三个不同的地方,一个在我的本地机器上,一个在内部服务器上,一个在稳定的外部服务器上.

我希望能够立即告诉哪个版本部署在哪个地方,并且我希望bug报告者可以轻松访问他们报告错误的版本.

理想情况下,作为提交过程的一部分,我希望使用提交的哈希值来编写文件.当然,根据我对Git的了解,这是不可能的,因为将计算的哈希作为提交中文件的一部分包含在内会改变该提交的计算哈希值.

另一方面,我可以将构建它作为构建过程的一部分.我目前没有构建过程,如果可能的话,我想避免添加一个步骤.

最干净的方法是什么?

git

17
推荐指数
2
解决办法
9157
查看次数

如何使用聚合物将HTML注入模板

我正在使用polymer-jsonp来执行JSONP请求,但响应有时包含html.

例如,假设post.content是"<strong>Foo</strong> bar",我如何"Foo"以粗体显示{{post.content}} ?

<polymer-element name="feed-element" attributes="">
  <template>
    <template repeat="{{post in posts.feed.entry}}">
      <p>{{post.content}}</p>
    </template>
    <polymer-jsonp url="url" response="{{posts}}"></polymer-jsonp>
  </template>
  <script>
    Polymer('feed-element', {
      created: function() { },
      attached: function() { },
      detached: function() { },
      attributeChanged: function(attrName, oldVal, newVal) { }
    });
  </script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)

javascript json polymer

14
推荐指数
2
解决办法
1万
查看次数

node.js中无法捕获的错误

所以我正在尝试编写一个简单的TCP套接字服务器,向所有连接的客户端广播信息.因此,当用户连接时,它们会被添加到客户端列表中,当流发出关闭事件时,它们将从客户端列表中删除.

这很有效,除了有时我在用户断开连接时发送消息.

我已经试过包装stream.write()在一个try/catch块,但没有运气.似乎错误是无法捕获的.

error-handling tcp node.js

11
推荐指数
2
解决办法
4961
查看次数

流视频如何工作?

所以我有一些.flv格式的视频,我希望人们能够从我的网站上查看,而无法下载它们.到目前为止,Flowplayer似乎是真正的Flash播放器的最佳选择.

然而,我一直在研究这个视频流媒体的东西,因为它应该使视频非常快速地查看并允许寻找视频的中间,等等.我需要使它工作,我需要有一些特殊的服务器软件呢?如何使用我将用于显示视频的javascript/PHP代码与此软件集成?

谢谢.

javascript video streaming flv progressive-download

6
推荐指数
1
解决办法
2575
查看次数

使用Jasmine进行单元测试:testE的spyOn()看不到beforeEach()中的代码

一般来说是单元测试的新手,特别是Jasmine.

我在beforeEach()回调中设置了一个变量,但它似乎不适用于第二次测试.它应该在其上下文中的每个测试之前触发初始化的东西,对吧?我确定我的spyOn()电话应该受到责备,但我不知道如何解决这个问题.

注释解释了传递并失败:

describe("Test suite for my library", function () {
  var html,
      body,
      play,
...

  // custom matcher...
  beforeEach(function () {
    this.addMatchers({
      toBeInstanceOf : function (constructr) {
        return this.actual instanceof constructr;
      });
    });
  });

  describe("Within the Button object", function () {

    beforeEach(function () {
      play = new Button("play", false);
    });

    describe("play", function () {

      // This test passes, as expected...
      it("should be an instance of the Button object", function () {
        expect(play).toBeInstanceOf(Button);
      }); …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing jasmine

4
推荐指数
2
解决办法
6831
查看次数

从元素外部调用 LitElement 方法

我有一个简单的 LitElement 组件,如下所示:

class MyElement extends LitElement {

  constructor() {
    super();
  }

  customMethod(data) {
    // do something with the passed parameter
  }

  render() { 
    return html`<div id="element"></div>`;
  }
}

customElements.define('my-element', MyElement);
Run Code Online (Sandbox Code Playgroud)

我希望能够从我的元素外部调用该 customMethod。

例如,如果我将元素添加到网页,如下所示:

<my-element></my-element>
Run Code Online (Sandbox Code Playgroud)

然后我希望能够向页面添加一些 JavaScript 并调用该 customMethod。

我试过:

var element = document.getElementById('element');

element.shadowRoot.customMethod('example data');
Run Code Online (Sandbox Code Playgroud)

但它声称它不可用...我如何调用 LitElement 实例上的方法?

lit-element

2
推荐指数
1
解决办法
2745
查看次数