我有一个Points类型的多维点列表.
我已经实现了sort.Sort界面,现在可以排序了y value.
例如
type Points []*Point
func (points Points) Len() int {
return len(points)
}
func (points Points) Less(i, j int) bool {
return points[i].y < points[j].y
}
func (points Points) Swap(i, j int) {
points[i], points[j] = points[j], points[i]
}
type Point struct {
x int
y int
country_id int
}
Run Code Online (Sandbox Code Playgroud)
现在我想用x value而不是来分类我的观点y value.
我的想法是使用带有全局标志的if语句(可以在排序之前打开或关闭):
func (points Points) Less(i, j int) bool {
if SORT_BY_X {
return points[i].x < points[j].x …Run Code Online (Sandbox Code Playgroud) 我必须手动传递overlayRef,有没有更好的方法将它包含在带有DI的组件构造函数中?
服务代码:
display() {
const overlayRef = this.overlay.create({
positionStrategy: this.overlay.position().global().top(),
});
const portal = new ComponentPortal(ErrorsListBottomSheetComponent);
this.ref = overlayRef.attach<ErrorsListBottomSheetComponent>(portal);
this.ref.instance.overlayRef = overlayRef;
overlayRef.backdropClick().subscribe(() => {
overlayRef.detach();
});
}
Run Code Online (Sandbox Code Playgroud)
组件代码:
export class ErrorsListBottomSheetComponent implements OnInit {
overlayRef: OverlayRef; -- REMOVE THIS--
constructor(
-- ADD SOMETHING HERE --
) {}
close() {
if (this.overlayRef) {
this.overlayRef.detach();
}
}
Run Code Online (Sandbox Code Playgroud)
更好的是,是否有类似的叠加
<button mat-dialog-close>close</button>
Run Code Online (Sandbox Code Playgroud)
代替
<button (click)="close()">close</button>
Run Code Online (Sandbox Code Playgroud) 我的eval()电话是相当密集的,需要大约一秒钟来生成每个解决方案.
因此,生成每个段落元素(然后我附加到dom - document.getElementById('project_euler_solutions').appendChild(p); )需要大约一秒钟.
因此,我希望每个段落在网页上显示大约一秒钟.(所以大约40秒后我会有40段说).
但是,当我单击按钮时,40秒内没有任何操作,然后所有解决方案立即出现.
为什么在更新dom之前等待所有人完成?
我认为每个段落一旦附加到dom就会出现
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.6.2.min.js"></script>
<script src="/statics/project_euler.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
for (var i in window) {
if (i.slice(0,5) == "solve") {
var p = document.createElement('p');
p.innerHTML = "running: " + i;
document.getElementById('project_euler_solutions').appendChild(p);
var p = document.createElement('p');
p.innerHTML = "Solution: " + eval(i + "()");
document.getElementById('project_euler_solutions').appendChild(p);
}
}
});
});
</script>
</head>
<body>
<div id="project_euler_solutions"><button>Calculate solutions</button></button></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) my_list = [1, 2]
def f():
print my_list
yield 11
print my_list
yield 22
print my_list
my_list[:] = f()
print "finally ",
print my_list
Run Code Online (Sandbox Code Playgroud)
输出:
[1, 2]
[1, 2]
[1, 2]
finally [11, 22]
Run Code Online (Sandbox Code Playgroud)
我的期望是:
[1, 2]
[11, 2]
[11, 22]
finally [11, 22]
Run Code Online (Sandbox Code Playgroud)
有人曾告诉我切片分配到位.显然不是.是否有一种优雅的方式来实现它?
我正在做一些图遍历.在每个点上,我保存了一个可以探索的其他可能选项的生成器.后来,我探索了一些这些生成器,但它不起作用.
这是一个简化的示例,您可以在其中看到所有生成器中的"node"变量都设置为3.(因此生成器指向"node"变量,但"node"变量在生成器消耗之前发生变化.
在我的特定情况下,我可以存储一些指针并添加如何处理这些指针以重新创建生成器的逻辑 - 但这是一个丑陋的解决方案.
有一个简单的方法吗?
node_size = {1:1, 2:2, 3:1, 4:3}
iters = []
for node in range(1,4):
it = (1 + node_size[node]+j for j in xrange(3))
#it = iter(list(it)) #remove comment to get correct result but very slow.
iters.append(it)
for iter_ in iters:
print list(iter_)
"""
Correct Output
[2, 3, 4]
[3, 4, 5]
[2, 3, 4]
"""
"""
Actual Output:
[2, 3, 4]
[2, 3, 4]
[2, 3, 4]
"""
Run Code Online (Sandbox Code Playgroud) 我想ng build --prod与WebStorm 一起运行,但是似乎只能这样做ng build并且错过了该--prod命令。
我想在WebStorm中而不是在终端中运行它。
注意:如果我添加--prod到Arguments,它将无法正常工作:
/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run build --scripts-prepend-node-path=auto --prod
> cosmoline@0.0.0 build /Users/robertking/go/src/gitlab.com/cosmoline_client
> ng build
Run Code Online (Sandbox Code Playgroud) 在他们使用的文档中MAT_DIALOG_DATA在他们用来与组件共享数据的
但是,为什么不直接去ref.componentInstance.myInput = my_value
将数据传递给组件与设置组件实例输入之间有什么区别?我还没有发现直接在组件上设置值的任何限制。
当我运行以下hellow world程序(使用GAE Launcher)时,它可以工作:
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
Run Code Online (Sandbox Code Playgroud)
但是如果我去终端我无法导入webapp2:
C:\Users\Robert>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import webapp2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named webapp2
>>>
Run Code Online (Sandbox Code Playgroud)
我的IDE也没有为webapp2对象提供自动完成功能.
看到GAE Launcher使用与我在终端中使用的相同的python版本,我对导入必须如何在GAE启动器中工作感到困惑.
我是jQuery的新手并注意到有人去了:
var $this = $(this);
Run Code Online (Sandbox Code Playgroud)
为什么这样?是为了节省打字吗?它有助于提高性能吗?这是相当标准的做法吗?
我也开始做以下事情:
var minus_button = $('#minus_button');
Run Code Online (Sandbox Code Playgroud)
这应该是发var $minus_button = $('#minus_button');信号它是一个jquery对象吗?
我阅读了http://docs.jquery.com/JQuery_Core_Style_Guidelines但找不到任何建议.
当用户单击登录按钮时,将调用登录功能:
login: function() {
ref.auth.$authWithOAuthPopup('facebook').then(user.setUser).catch(function(error) {
console.error('Authentication failed: ', error);
});
}
Run Code Online (Sandbox Code Playgroud)
我使用登录按钮来避免弹出窗口阻止程序.
现在,每当用户访问我的网站或刷新页面时,他们都必须单击登录.如果他们之前已经登录过,有没有办法自动/立即登录?这样,如果立即登录失败,我只能提供登录按钮.
与测试 mat-dialog 类似,测试 cdk 覆盖的好方法是什么?
服务调用示例:
openNotifications(origin: HTMLElement) {
this.refreshNotifications()
.subscribe();
const overlayRef = this.overlay.create({
positionStrategy: this.overlay.position().flexibleConnectedTo(origin).withPositions([
{
originX: 'center',
originY: 'bottom',
overlayX: 'center',
overlayY: 'top',
}
]),
hasBackdrop: true,
});
const portal = new ComponentPortal(NotificationsDropdownComponent);
overlayRef.attach(portal);
overlayRef.backdropClick().subscribe(() => {
overlayRef.detach();
this.refreshNotificationCount().subscribe();
});
}
Run Code Online (Sandbox Code Playgroud) 使用Angular-gettext,我们从html中提取带注释的字符串,如下所示Gruntfile.js:
grunt.initConfig({
nggettext_extract: {
pot: {
files: {
'po/template.pot': ['src/views/*.html']
}
},
},
})
Run Code Online (Sandbox Code Playgroud)
是否有可能从javascript文件中提取字符串?
我有一个案例,我正在从angularjs控制器生成字符串:
<textarea ng-model="generatedCSV"></textarea>
Run Code Online (Sandbox Code Playgroud)
CSV的标题行是:
"Full Name", "Email"
Run Code Online (Sandbox Code Playgroud)
哪些需要翻译成其他语言.
使用angular-gettext有一个很好的方法吗?
我emit.next(1)迷路了,我希望我的订户能够获得这个价值.我的订阅者直到发射已经发生之后才能订阅.
这个答案建议发布并连接RxJs:如何在我们订阅之前获取值?但我不知道如何让它工作:
console.log('make emit')
let emit = new Subject<number>();
console.log('make obs')
let obs = emit.asObservable()
console.log('emit 1')
emit.next(1)
console.log('subscribe')
obs.subscribe((v)=>console.log(v,'!'))
console.log('emit 2')
emit.next(2)
console.log('set timeout 1000 to emit')
setTimeout(()=>emit.next(3),1000)
console.log('done')
Run Code Online (Sandbox Code Playgroud)
输出:
make emit
main.bundle.js:1561 make obs
main.bundle.js:1563 emit 1
main.bundle.js:1565 subscribe
main.bundle.js:1567 emit 2
main.bundle.js:1566 2 "!"
main.bundle.js:1569 set timeout 1000 to emit
main.bundle.js:1571 done
main.bundle.js:1566 3 "!"
Run Code Online (Sandbox Code Playgroud)
它应该记录 1 "!"
angular ×4
javascript ×3
python ×3
angular-cdk ×2
angularjs ×2
jquery ×2
angular-cli ×1
angularfire ×1
dom ×1
firebase ×1
generator ×1
gettext ×1
go ×1
import ×1
jasmine ×1
list ×1
npm ×1
observable ×1
po ×1
rxjs ×1
scope ×1
slice ×1
sorting ×1
struct ×1
translation ×1
webstorm ×1