小编Sof*_*mur的帖子

OCaml中模块的构造函数的范围

我已经定义了以下接口和模块:

module type TYPE =
  sig
    type t
  end

module Type = (struct
  type t =
    | TBot
    | T of int
    | TTop
end: TYPE)
Run Code Online (Sandbox Code Playgroud)

现在我意识到如果我在外面写Type.T 5,编译器会给我错误Error: Unbound constructor Type.T.如果我删除签名并保留模块,则错误将消失.

1)所以我的第一个问题是,如何更改签名以便我可以在外部使用构造函数?

2)一种方法是如下明确定义构造函数,你认为它是一种传统方式吗?我现在可以看到的一个缺点是它不允许构造TBotTTop.

module type TYPE =
  sig
    type t
    val make : int -> t
  end

module Type = (struct
  ...
  let make (i: int) : t =
      T i
end: TYPE)
Run Code Online (Sandbox Code Playgroud)

3)是否总是需要让外部能够在模块内部构造一个值?

constructor ocaml module

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

函数中的变量

我看到以下代码......第一次调用(next-num)return 1,第二次返回2.

(define next-num
  (let ((num 0))
    (lambda () (set! num (+ num 1)) num)))

(next-num)   ; 1
(next-num)   ; 2
Run Code Online (Sandbox Code Playgroud)

我无法理解的是... num是由let内部创建的next-num,它是一种局部变量...方案如何知道每次next-num被调用,值num都没有被删除let ((num 0)); 方案如何知道num每当next-num调用它时它总是相同的?

它似乎num是本地的和静态的......我们如何定义局部变量,而不是静态变量?

scheme closures scope racket

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

使用多个可单击的行显示文本

我有一张桌子.对于某些元素,我想要产生一种效果,当我们鼠标悬停(或点击)一个元素时,它旁边会出现一个文本,文本可能有几行,有些行可以点击.

例如,在以下代码生成的表格中,当我们鼠标悬停时30,会出现一个文本

<table style="width:100%">
  <tr>
    <th>First Name</th>
    <th>Points</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td><span title="monday: 10; tuesday: 10; wednesday: 10">30</span></td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

JSBin

不过,我想出现的文字是monday: 10,tuesday: 10wednesday: 10一行行.我们可以点击例如,monday: 10打开页面或移动到页面的另一部分.title不允许这样做.

有谁知道如何实现这一点?我们可以使用JavaScript,CSS ......

(*此主题没有解释如何在出现的文本中插入链接*)

html javascript css jquery

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

作为匿名用户进行身份验证

我想重现 plunker 如何管理匿名帐户。

Plunker 可以识别匿名用户。例如,我们可以将一个 plunker 保存为anonym然后freeze它。因此,

  1. 只有同一用户(在清除浏览器历史记录之前)才能完全访问此插件(例如,保存修改、解冻)。

  2. 如果同一用户在另一个浏览器中打开它或其他用户打开同一链接,他们不能进行save任何修改;他们必须fork这样做。

在我的网站中,我使用管理命名用户local的策略。passport.js例如,

router.post('/login', function (req, res, next) {
    if (!req.body.username || !req.body.password)
        return res.status(400).json({ message: 'Please fill out all fields' });

    passport.authenticate('local', function (err, user, info) {
        if (err) return next(err);
        if (user) res.json({ token: user.generateJWT() });
        else return res.status(401).json(info);
    })(req, res, next);
});
Run Code Online (Sandbox Code Playgroud)

我使用 alocalStorage来存储令牌。例如,

auth.logIn = function (user) {
    return $http.post('/login', user).success(function (token) { …
Run Code Online (Sandbox Code Playgroud)

authentication local-storage angular-local-storage passport.js

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

检查Office.js是否在Office客户端之外加载

如果我们office.js在Office客户端外部加载引用网页,则会收到警告:Office.js is loaded outside of Office client

此信息很有用。

有人知道我的代码中是否有API可以检查该API?

编辑1:

我会解释一下我的情况以及为什么问这个问题。我正在使用angularjs制作应用程序,可以将其作为网页加载到浏览器中,也可以作为加载项加载到Office中。我意识到,我们不应该做的<body ng-app="myApp">angular.bootstrap(document, ['myApp'])在一起,否则控制器将执行两次。因此,我决定不编写<body ng-app="myApp">并且始终angular.bootstrap在两种情况下都使用(即网页和加载项)。

所以对于一个网页,我可以这样写:

$(document).ready(function () {
    angular.bootstrap(document, ['myApp'])  
})

app = angular.module('myApp', ['ui.router', 'ui.bootstrap'])
...
Run Code Online (Sandbox Code Playgroud)

因此,对于网页,我需要在angular.bootstrapinside 中编写Office.initialize代码,并在插件的情况下共享其他代码:

Office.initialize = function (reason) {
    $(document).ready(function () {
        angular.bootstrap(document, ['myApp'])
    });
}

app = angular.module('myApp', ['ui.router', 'ui.bootstrap'])
// share the same code
Run Code Online (Sandbox Code Playgroud)

但是,如果我按以下方式将这两种情况写在一起,则它适用于网页,而我给出了错误:ng:btstrpd应用程序已经使用此Element引导加载项

$(document).ready(function () {
    angular.bootstrap(document, ['myApp'])
    console.log("bootstrapped …
Run Code Online (Sandbox Code Playgroud)

ms-office office-js

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

摩纳哥编辑的高度

我想制作一个非常简单的摩纳哥编辑器:JSBin:

<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <style>
        .me {
          height: 100vh;
        }
    </style>
</head>
<body>
    <div class="me" id="container"></div>
    <script src="https://www.matrixlead.com/monaco-editor/min/vs/loader.js"></script>
    <script>
        require.config({ paths: { 'vs': 'https://www.matrixlead.com/monaco-editor/min/vs' }})

        require(["vs/editor/editor.main"], function () {
          var editor = monaco.editor.create(document.getElementById('container'), {
            value: 'function x() {\n\tconsole.log("Hello world!");\n}',
            language: 'javascript',
            minimap: { enabled: false },
            scrollBeyondLastLine: false
          });
        });
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我在Chrome中看到它并向上和向下滚动时,整个窗口都有一个滚动条.这似乎是因为编辑器的高度大于窗口的高度.我只是不想看到任何滚动条.有谁知道如何实现这一目标?

编辑1: Safari 10.1.2中的截图height: calc(100% - 24px)

在此输入图像描述

解:

在答案的帮助下,这是适合我的解决方案:

1)我们需要在一个独立的html文件而不是JSBin中测试它

2)关键是使用 overflow: hidden

3)因此,下面的代码在向上和向下滚动时不会创建任何滚动条,当代码很长时,底部没有隐藏的行:

<html>
    <style>
    body {
        overflow: …
Run Code Online (Sandbox Code Playgroud)

javascript css height monaco-editor

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

错误:听EACCES 0.0.0.0:443

我试图在我的MacOS上运行NodeJS的Web项目.

之后npm install,npm start返回错误

events.js:183
  throw er; // Unhandled 'error' event
  ^

Error: listen EACCES 0.0.0.0:443
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at Server.setupListenHandle [as _listen2] (net.js:1334:19)
    at listenInCluster (net.js:1392:12)
    at Server.listen (net.js:1476:7)
    at Object.<anonymous> (/Users/softtimur/Startup/PRODSERVER/tmp/WeCard/models/www:36:8)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Run Code Online (Sandbox Code Playgroud)

我的Mac上没有运行其他网站.

有谁知道什么是错的?我需要在Mac上配置一些东西吗?

编辑1:

sudo npm start 回报

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: listen …
Run Code Online (Sandbox Code Playgroud)

node.js express

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

我们如何将 Docusaurus 网站链接到数据库?

我正在用Docusaurus V2建立一个网站。

由于 Docusaurus 网站基本上是一个 React 应用程序,我想知道我们如何向网站添加身份验证系统。

是否有将 Docusaurus 网站链接到数据库、后端或调用 API 的指南或示例?

docusaurus

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

不在悬停消息中显示marker.message和marker.code

我正在使用 Monaco Editor 来制作我自己的 IDE。我使用了provideHover某些类型的代码。

我意识到悬停窗口显示了几个文本。一类文本来源于内容;一类文本来源于内容;另一种文本由marker.messagemarker.code( https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.imarker.html ) 组成。

有谁知道是否可以不显示这些由marker.message和组成的文本marker.code

在此输入图像描述

PS:代码provideHover

public async provideHover(model: monaco.editor.ITextModel, position: monaco.Position, token: CancellationToken): Promise<monaco.languages.Hover | undefined> {
    let marker = monaco.editor.getModelMarkers({}).find(marker => { // https://microsoft.github.io/monaco-editor/api/modules/monaco.editor.html#getmodelmarkers
        let markerStart = new monaco.Position(marker.startLineNumber, marker.startColumn);
        let markerEnd = new monaco.Position(marker.endLineNumber, marker.endColumn);
        if (markerStart.isBeforeOrEqual(position) && position.isBeforeOrEqual(markerEnd)) return marker;
        return null;
    });

    if (marker != null) {
        if (marker.code == "113") {
            return {
                contents: [{ …
Run Code Online (Sandbox Code Playgroud)

monaco-editor

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

打开多个 VSCode 窗口时在 2 个 VSCode 窗口之间切换的快捷方式

我使用的是 Mac。

我打开了几个 VSCode 窗口。

我只想在 2 个(上次查看的)窗口之间切换。有谁知道这样做的键盘快捷键是什么?

我尝试了 command + `,但它一一浏览了所有打开的 VSCode 窗口。选项+选项卡也是如此。

我尝试了 control + w,它也会浏览所有打开的 VSCode 窗口,除非您使用向上和向下键进行选择。

有人可以帮忙吗?

keyboard-shortcuts visual-studio-code

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