我很难理解Angular中的依赖注入.所以我的问题是,任何人都可以解释哪些"类型",如控制器,工厂,提供商等,我们可以注入其他类型,包括相同"类型"的其他实例?
我实际上正在寻找的是这个表充满了y/n.对于具有相同行/列的单元格,这意味着将一个"类型"的值注入另一个具有相同"类型"的另一个"类型"
+----------------+----------+------------+-----------+---------+--------+----------+---------+-------+
| Can we inject? | Constant | Controller | Directive | Factory | Filter | Provider | Service | Value |
+----------------+----------+------------+-----------+---------+--------+----------+---------+-------+
| Constant | | | | | | | | |
| Controller | | | | | | | | |
| Directive | | | | | | | | |
| Factory | | | | | | | | |
| Filter | | | | | | | | | …Run Code Online (Sandbox Code Playgroud) 我想匹配像一个正则表达式/(a).(b)(c.)d/使用"aabccde",并获得以下信息反馈:
"a" at index = 0
"b" at index = 2
"cc" at index = 3
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?String.match返回匹配列表和完整匹配开始的索引,而不是每个捕获的索引.
编辑:一个不适用于普通indexOf的测试用例
regex: /(a).(.)/
string: "aaa"
expected result: "a" at 0, "a" at 2
Run Code Online (Sandbox Code Playgroud)
注意:问题类似于Javascript Regex:如何查找每个子表达式的索引?,但我不能修改正则表达式,使每个子表达式成为一个捕获组.
我有这样的文字:
foo bar
`which which`
Run Code Online (Sandbox Code Playgroud)
如果我使用heredoc这样做,我得到一个空白文件:
? ~ echo <<EOT > out
heredoc> foo bar
heredoc> `which which`
heredoc> EOT
? ~ cat out
? ~
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
对不起,我打算做cat.问题是它将它写入文件:which: shell built-in command,即评估反推.没有评估,任何方式做到这一点?
有了cat,我明白了
? ~ cat <<EOT > out
heredoc> foo bar
heredoc> `which which`
heredoc> EOT
? ~ cat out
foo bar
which: shell built-in command
? ~
Run Code Online (Sandbox Code Playgroud)
我不想which which被评估.
而不是做
d3.select("body").append("svg")
Run Code Online (Sandbox Code Playgroud)
,大多数d3.js的例子,我想创建一个元素,而不是立即将它附加到身体或任何东西.
有点像$('<div/>')jQuery.
我怎样才能做到这一点?
我找到了亚瑟惠特尼这件神奇的作品 - http://www.jsoftware.com/jwiki/Essays/Incunabulum
它汇编了一些警告
$ gcc-4.7 incuna.c -o incuna.o
incuna.c: In function 'ma':
incuna.c:8:15: warning: incompatible implicit declaration of built-in function 'malloc' [enabled by default]
incuna.c: In function 'pi':
incuna.c:26:7: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]
incuna.c: In function 'nl':
incuna.c:26:24: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]
incuna.c: In function 'pr':
incuna.c:28:10: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]
incuna.c: In function 'ex':
incuna.c:35:36: warning: assignment …Run Code Online (Sandbox Code Playgroud) 我正在尝试自定义这个 oh-my-zsh主题.
我在其中找到了这段代码,显然打印了dir名称(如果我错了,请纠正我).
# Dir: current working directory
prompt_dir() {
prompt_segment blue black '%~'
}
Run Code Online (Sandbox Code Playgroud)
和prompt_segment定义为
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1 …Run Code Online (Sandbox Code Playgroud) 我想检查多行文本是否与输入匹配。grep接近,但我找不到方法将其解释为纯文本而不是正则表达式。
仅使用Unix实用程序怎么做?
(注:我读过像其他的问题这个,但我一直没能想出解决办法).
我写了这个语法:
start = call
ident = [a-z]+
spaces = [ ]+
call = f:ident spaces g:(call / ident) {
return f + "(" + g + ")";
}
Run Code Online (Sandbox Code Playgroud)
有了这个输入
a b c d
Run Code Online (Sandbox Code Playgroud)
它返回
"a(b(c(d)))"
Run Code Online (Sandbox Code Playgroud)
而且我要
"a(b)(c)(d)"
Run Code Online (Sandbox Code Playgroud)
我认为这个左递归规则可以给我这样的东西,但是PEG.js不支持左递归.
call = f:(call / ident) spaces g:ident {
return f + "(" + g + ")";
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下如何消除左递归?
PS:你可以在在线PEG.js演示中测试这个
这是计算2的1000次幂的代码.
#include <stdio.h>
int main() {
double multiply = 1;
int i;
for(i = 1; i <= 1000; i++) {
multiply *= 2;
}
printf("%lf\n", multiply);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
和我的系统上的输出,以及ideone
10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
Run Code Online (Sandbox Code Playgroud)
这是正确的答案:
irb(main):001:0> 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 == 2 ** 1000
=> true
Run Code Online (Sandbox Code Playgroud) Ruby有Ruby Spec.
APL有什么(开源)接近这个吗?至少预期的投入和产出清单?或者某种APL语言的核心规范?
Angular.js如何处理事件绑定,例如"ng-click"?
如果我使用Chrome Dev Tools检查DOM中的HTML输出,我只会看到2个类添加到具有"ng-click"指令的元素,"ng-scope"和"ng-binding".Angular如何绑定到DOM来拦截这些?它是否附加到最顶层的元素,并将内存映射事件中的大对象保存到它们注册的DOM元素,并使用事件冒泡?或者是其他东西?
这是我的代码:
#include <stdio.h>
typedef struct node_struct {
int data;
struct node_struct *next;
} node;
void push(node *top, int data) {
node *new_node = (node*) malloc(sizeof(node));
new_node->data = data;
new_node->next = top;
top = new_node;
}
int main() {
node *top = (node*) malloc(sizeof(node));
top->data = 1;
printf("Set data of top node to: %d\n", top->data);
push(top, 2);
printf("Pushed 2 to top, top->next->data = %d\n", top->next->data);
}
Run Code Online (Sandbox Code Playgroud)
程序段错误在第3行最后一行(push(top, 2);),我想在线top = new_node;
我只是在学习C(现在指针).
我做错了什么?
(我对汇编语言几乎一无所知)。
我正在尝试遵循本教程。
问题在于他的编译器和我的测试设置(Linux 32位上的gcc)产生了完全不同的输出,并且比我的主要设置(OSX 64位上的clang)产生的输出要少得多。
这是我的输出 int main() {}
Linux 32位上的gcc
$ cat blank.c
int main() {}
$ gcc -S blank.c
$ cat blank.s
.file "blank.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
popl %ebp
.cfi_def_cfa 4, 4
.cfi_restore 5
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
Run Code Online (Sandbox Code Playgroud)
Mac OSX 64位上的叮当声
$ cat blank.c
int main() {}
$ clang …Run Code Online (Sandbox Code Playgroud)