小编Dav*_*ter的帖子

自定义推送通知的iOS权限对话框

当iOS应用程序首次尝试注册推送通知时,系统会弹出一个权限对话框,要求用户获得接收推送通知的权限.是否可以自定义此对话框的文本,以解释为什么要搜索这些权限?

push-notification apple-push-notifications ios ios-permissions

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

如果已经配置了Vagrant VM,请避免重新配置

我正在尝试获取一个shell配置程序,以避免重新配置VM实例(如果它之前已经这样做过).

考虑以下Vagrantfile:

Vagrant::Config.run do |config|
  config.vm.define :minimal do |config|
    # Base image
    config.vm.box = "lucid32"
    config.vm.box_url = "http://files.vagrantup.com/lucid32.box"

    config.vm.provision :shell, :inline => "mkdir /tmp/foobar"
  end
end
Run Code Online (Sandbox Code Playgroud)

如果您运行vagrant up minimal,它将创建该框并最初进行配置.如果你然后运行vagrant provision minimal它将尝试重新配置该框但会失败(因为/ tmp/foobar目录已经存在).

有没有办法让Vagrant记住它过去是否配置了一台机器并避免以后重置它?

更多上下文:如果我运行vagrant up minimal,重新启动我的主机,然后vagrant up minimal再次运行,它将尝试重新配置该框并失败.这种情况经常发生,因为VirtualBox经常在我的主机上引起内核恐慌.

vagrant

17
推荐指数
3
解决办法
9500
查看次数

Can I get TypeScript to reveal what type it has determined for an expression?

I have some code like the following where I want to determine what type TypeScript has inferred for an expression:

var timer = window.setTimeout(...);
/* QUESTION: What is the inferred type of "timer" here? */
Run Code Online (Sandbox Code Playgroud)

When I use the mypy typechecker for Python, I can insert the special expression reveal_type(my_expression) into code to have the typechecker print a fake error containing the inferred type for expression my_expression.

Is there a way I can ask the TypeScript tsc type-checker for …

typescript

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

Agda:将一行标准输入读取为String而不是Costring

我正在尝试编写一个简单的程序,从标准输入读取一行,将其反转,然后打印反转的字符串.

不幸的是,本机getLine函数读取Costring; 我只能扭转Strings; 并且没有任何功能需要Costringa String.

如何修改此程序进行编译?

module EchoInputReverse where

-- Agda standard library 0.7
open import Data.List using (reverse)
open import Data.String
open import Foreign.Haskell using (Unit)
open import IO.Primitive

postulate
  getLine : IO Costring

{-# COMPILED getLine getLine #-}

main : IO Unit
main = 
  getLine >>= (? s ? 
  -- NOTE: Need a (toString : Costring ? String) here. Or some other strategy.
  return (toCostring (fromList (reverse (toList (toString …
Run Code Online (Sandbox Code Playgroud)

io agda

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

使用 --noEmit 时使用 TypeScript 进行增量编译?

我想使用 TypeScript 的--incremental模式使其在重复运行时更快。但是我的tsconfig.json设置"noEmit": true是因为我目前只使用 TypeScript 进行类型检查而不是代码生成。

如果我运行tsc --incremental --outDir ~/tmp/typescript --noEmit它似乎不会输出tsconfig.tsbuildinfo文件,因此实际上不会在重复运行时进行增量编译。

我想我实际上可以启用发射和运行,tsc --incremental --outDir ~/tmp/typescript --noEmit false但它不仅生成而且生成tsconfig.tsbuildinfo一堆我不需要的 JS 文件,这并不理想。

有没有办法可以运行tsc --incremental --noEmit,实际增量编译,只生成tsconfig.tsbuildinfo增量编译需要的文件?

typescript

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

使用AppleScript检查应用程序是否存在

此代码不适用于不存在的应用程序,因为它会提示用户查找"FooApp"(我不想与用户交互):

get exists application "FooApp"
Run Code Online (Sandbox Code Playgroud)

此代码仅适用于进程名称与其应用程序名称匹配的应用程序,该应用程序名称涵盖大多数应用程序,

tell application "System Events"
    get exists application process "FooApp"
end tell
Run Code Online (Sandbox Code Playgroud)

(例如在我的机器上"OmniGraffle Professional"是一个进程名称,但相应的应用程序名称是"OmniGraffle Professional 4".)

applescript

5
推荐指数
2
解决办法
8502
查看次数

使用 TypeScript 自动检测 .js 文件中的类型定义时出现问题

TypeScript 被记录为从已安装的 npm 模块自动检测类型定义。

例如,jQuery 的类型定义可以很好地自动检测:

$ npm install typescript @types/jquery
$ echo '$("body").text("Hello");' > index.js
$ node_modules/.bin/tsc --allowJs --checkJs --noEmit index.js
# (no errors)
Run Code Online (Sandbox Code Playgroud)

维埃

然而,Vue 的类型定义不会自动检测,至少在 JS 中使用时是这样:

$ npm install typescript git+ssh://git@github.com/vuejs/vue.git#ab50e8e1da2f4f944af683252481728485fedf16
$ echo 'new Vue({ el: "body", template: "Hello" });' > index.js
$ node_modules/.bin/tsc --allowJs --checkJs --noEmit index.js
index.js:1:5 - error TS2304: Cannot find name 'Vue'.

1 new Vue({ el: "body", template: "Hello" });
      ~~~
Found 1 error.
Run Code Online (Sandbox Code Playgroud)

解决方法:如果我明确包含node_modules/vue/types/umd.d.ts为源文件,那么它就会开始工作:

$ node_modules/.bin/tsc --allowJs --checkJs --noEmit …
Run Code Online (Sandbox Code Playgroud)

typescript

5
推荐指数
0
解决办法
308
查看次数

从hGetContents中检测惰性字符串中的I/O异常?

hGetContents返回一个惰性String对象,该对象可用于纯函数代码以从文件句柄中读取.如果在读取此延迟字符串时发生I/O异常,则会以静默方式关闭基础文件句柄,并且不会向延迟字符串添加其他字符.

如何检测此I/O异常?

作为一个具体的例子,考虑以下程序:

import System.IO    -- for stdin

lengthOfFirstLine :: String -> Int
lengthOfFirstLine "" = 0
lengthOfFirstLine s  = (length . head . lines) s

main :: IO ()
main = do
    lazyStdin <- hGetContents stdin
    print (lengthOfFirstLine lazyStdin)
Run Code Online (Sandbox Code Playgroud)

如果在读取文件的第一行时发生异常,则此程序将打印字符数,直到发生I/O异常.相反,我希望程序崩溃并使用适当的I/O异常.如何修改此程序以具有该行为?

编辑:仔细检查hGetContents实现后,似乎不会忽略I/O异常,而是通过调用纯函数代码冒泡到触发评估的任何IO代码,然后有机会处理它.(我以前没有意识到纯函数代码会引发异常.)因此,这个问题是一个误解.

旁白:如果通过经验验证这种特殊行为,那将是最好的.不幸的是,很难模拟低级I/O错误.

error-handling haskell

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

FB.getLoginStatus总是返回status ='unknown'

如果我登录到facebook.com,我希望调用FB.getLoginStatus将返回status ='not_authorized'.相反,它返回status ='unknown',即使我为'force'参数传递true也是如此.

如果我调用FB.login,然后调用FB.getLoginStatus,我得到status ='connected'.说得通.

如果我调用FB.login,重新加载页面,然后调用FB.getLoginStatus,我得到status ='unknown'.没有意义.如果我添加'true'作为第二个参数(即力),我仍然得到status ='unknown'.(在这种情况下,我希望status ='not_authorized'.)

似乎没有办法在实践中获得status ='not_authorized'.

难道我做错了什么?这是FB.getLoginStatus或其文档中的错误吗?

这是一个最小的测试页面:http: //pastebin.com/NqiBXni2

语境:

我正在编写一个网站小部件,显示公共Facebook页面的帖子.(这可以在不通过app访问令牌提示用户的情况下访问.)每个帖子都有一个"赞"/"不同"链接.为了确定是否显示"喜欢"或"不喜欢",我需要知道浏览用户的Facebook ID是什么,以便我可以检查它是否在帖子的喜欢列表中.

javascript facebook-javascript-sdk facebook-login

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