这是我正在使用的图像.
我把它命名了 posgres_test
如果我单独运行图像
docker run -i -t -v="test_volume:/var/lib/postgresql" -p 5432:5432 posgres_test
Run Code Online (Sandbox Code Playgroud)
我可以访问它
psql -h 192.168.99.100 -p 5432 -U pguser -W pgdb
Run Code Online (Sandbox Code Playgroud)
或者我可以使用我的golang应用程序访问它
// host is set to postgres
db, err := sql.Open("postgres", "postgres://pguser:pguser@postgres:5432/pgdb")
// table test_db is manually created.
rows, err := db.Query("SELECT name FROM test_db WHERE)
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用 docker compose
docker-compose.yml
version: "2"
services:
postgres:
image: my_image/postgresql:9.3
volumes:
- test_volume:/var/lib/postgresql
ports:
- "5432:5432"
web:
image: my-golang-app4
ports:
- "8080:8080"
volumes:
test_volume: {}
Run Code Online (Sandbox Code Playgroud)
我得到以下内容
pguser@pgdb ERROR: relation "test_db" …Run Code Online (Sandbox Code Playgroud) 我正在使用intellij 14和scala 2.11.6一起使用home brew和symlink进行安装
ln -s /usr/local/Cellar/scala/2.11.6/libexec/src /usr/local/Cellar/scala/2.11.6/src
ln -s /usr/local/Cellar/scala/2.11.6/libexec/lib /usr/local/Cellar/scala/2.11.6/lib
mkdir -p /usr/local/Cellar/scala/2.11.6/doc/scala-devel-docs
ln -s /usr/local/Cellar/scala/2.11.6/share/doc/scala /usr/local/Cellar/scala/2.11.6/doc/scala-devel-docs/api
Run Code Online (Sandbox Code Playgroud)
我试过运行一个简单的hello世界,但遇到了以下问题.
Error:scalac: Multiple 'scala-library*.jar' files (scala-library.jar, scala-library.jar, scala-library.jar) in Scala compiler classpath in Scala SDK scala-sdk-2.11.6
Run Code Online (Sandbox Code Playgroud)
编辑:
所以我检查全局库上的编译器类路径,显然有多个scal-library.jar
file:///usr/local/Cellar/scala/2.11.6/idea/lib/scala-library.jar
file:///usr/local/Cellar/scala/2.11.6/lib/scala-library.jar
file:///usr/local/Cellar/scala/2.11.6/libexec/lib/scala-library.jar
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么?
这是我的模板
<input (keyup)="onKey($event)">
Run Code Online (Sandbox Code Playgroud)
这是我的打字稿文件
onKey(event:any) {
console.log(typeof event);
}
Run Code Online (Sandbox Code Playgroud)
该console.log输出object但在现实中它应该是KeyboardEvent.
是否有通用的方法来查找事件类型?
使用django.conf.urls.patterns而不仅仅是网址列表是否有好处?
例如,有什么区别
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
]
Run Code Online (Sandbox Code Playgroud)
VS
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)))
Run Code Online (Sandbox Code Playgroud) 我正在尝试将django连接到docker redis容器
这是我的docker文件
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y redis-server
EXPOSE 6379
ENTRYPOINT ["/usr/bin/redis-server"]
Run Code Online (Sandbox Code Playgroud)
这是结果 docker ps -a
4f7eaeb2761b /redis "/usr/bin/redis-serve" 16 hours ago Up 16 hours 6379/tcp redis
Run Code Online (Sandbox Code Playgroud)
这是一个快速的健全性检查,redis在docker容器内工作
docker exec -ti redis bash
root@4f7eaeb2761b:/# redis-cli ping
PONG
root@4f7eaeb2761b:/# redis-cli
127.0.0.1:6379> exit
Run Code Online (Sandbox Code Playgroud)
这是我的Django settings.py
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': 'localhost:6379',
},
}
Run Code Online (Sandbox Code Playgroud)
这是我的看法
from django.shortcuts import render
from django.template import loader
from django.http import HttpResponse
from django.views.decorators.cache import cache_page
@cache_page(60 * 15)
def …Run Code Online (Sandbox Code Playgroud) 这是一个去游乐场的链接
package main
import "fmt"
import "math"
func main() {
fmt.Println("Hello, playground")
fmt.Println(math.MaxUint32)
}
Run Code Online (Sandbox Code Playgroud)
上面的代码似乎导致了
constant 4294967295 overflows int
Run Code Online (Sandbox Code Playgroud)
会fmt.Println自动将每个数字转换为int吗?
在官方的angular2教程中,它包含以下代码
getHeroes(): Promise<Hero[]> {
return Promise.resolve(HEROES);
}
ngOnInit(): void {
this.route.params
.switchMap((params: Params) => this.heroService.getHero(+params['id']))
.subscribe(hero => this.hero = hero);
console.log(this.route.params);
console.log(this.route.params
.switchMap((params: Params) => this.heroService.getHero(+params['id'])));
}
Run Code Online (Sandbox Code Playgroud)
现在我们知道this.route.params返回一个observable,同时
this.heroService.getHero(+params['id'])返回一个promise
这是签名 rxjs switchmap
switchMap(project: function: Observable, resultSelector: function(outerValue, innerValue, outerIndex, innerIndex): any): Observable
Run Code Online (Sandbox Code Playgroud)
我们看到第一个参数采用发出可观察的函数.
但是在上面的例子中,我们实际上传递了一个发出promise的函数.
它们是否相互兼容?
此外还有控制台
console.log(this.route.params
.switchMap((params: Params) => this.heroService.getHero(+params['id'])));
Run Code Online (Sandbox Code Playgroud)
输出
AnonymousSubject {_isScalar: false, observers: Array[0], closed: false, isStopped: false, hasError: false…}
Run Code Online (Sandbox Code Playgroud)
不应该_isScalar设置为true,因为函数输出一个承诺?
这是我的postgres版本 postgresql/9.4.1
这是我的游戏版本 addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")
这是我的 libraryDependencies
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test,
"postgresql" % "postgresql" % "9.1-901-1.jdbc4"
)
Run Code Online (Sandbox Code Playgroud)
更改版本9.4-1201-jdbc41给出sbt.ResolveException: unresolved dependency: postgresql#postgresql;9.4-1201-jdbc41: not found
这是我的application.conf
db.default.driver=org.postgresql.Driver
# I tried the following combination
#db.default.url="postgres://user:pass@localhost/20160210_scala_play"
# And
db.default.url="jdbc:postgresql://localhost/20160210_scala_play"
db.default.user="user"
db.default.password="pass"
Run Code Online (Sandbox Code Playgroud)
所有结果都是
`Cannot connect to database`
Run Code Online (Sandbox Code Playgroud)
我证实了这一点
psql \list
Run Code Online (Sandbox Code Playgroud)
确实包含
20160210_scala_play
Run Code Online (Sandbox Code Playgroud)
同 user=user password=password
有人可以指点我的方向吗?
我试图从以下回购中了解这个快速排序代码
object QuickSort {
@inline final def limit: Int = 16
final def sort[@sp A:Order:ClassTag](data:Array[A]): Unit = qsort(data, 0, data.length - 1)
final def qsort[@sp A](data:Array[A], left: Int, right: Int)(implicit o:Order[A], ct:ClassTag[A]): Unit = {
if (right - left < limit) return InsertionSort.sort(data, left, right + 1)
val pivot = left + (right - left) / 2
val next = partition(data, left, right, pivot)
qsort(data, left, next - 1)
qsort(data, next + 1, right)
}
final def partition[@sp …Run Code Online (Sandbox Code Playgroud) 考虑以下btoa输出
btoa(99999999999999999999)
"MTAwMDAwMDAwMDAwMDAwMDAwMDAw"
btoa(99999999999999999998)
"MTAwMDAwMDAwMDAwMDAwMDAwMDAw"
btoa("99999999999999999998")
"OTk5OTk5OTk5OTk5OTk5OTk5OTg="
btoa("99999999999999999999")
"OTk5OTk5OTk5OTk5OTk5OTk5OTk="
Run Code Online (Sandbox Code Playgroud)
我们看到btoa无法编码20位数的唯一哈希,int但能够编码20位数string.为什么是这样?
我最初的猜测是,既然btoa是基础,64它只能编码低于基数的东西64,但为什么它能够编码20位string呢?
而且btoa似乎不能编码int少于9223372036854775807a2^63
btoa(9223372036854775302)
"OTIyMzM3MjAzNjg1NDc3NjAwMA=="
btoa(9223372036854775303)
"OTIyMzM3MjAzNjg1NDc3NjAwMA=="
Run Code Online (Sandbox Code Playgroud) 传递给intent构造函数时this和之间有什么区别ActivityClass.this
例如,给定2个活动:ActivityOne和ActivityTwo
以下不起作用(编译错误)
@Override
public void onClick(View v) {
Intent intent = null;
Log.i(TAG, this.toString());
Log.i(TAG, ActivityOne.this.toString());
intent = new Intent(this, ActivityTwo.class);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
这虽然有效
@Override
public void onClick(View v) {
Intent intent = null;
Log.i(TAG, this.toString());
Log.i(TAG, ActivityOne.this.toString());
intent = new Intent(ActivityOnethis, ActivityTwo.class);
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
日志中的日志信息是
activitylab.ActivityOne$1@41fc5818
activitylab.ActivityOne@41fa2948
Run Code Online (Sandbox Code Playgroud)
虽然它们不同,但传递活动的常见答案通常是使用this,我不是为什么我遇到这个问题
我有两行(或可能更多)输入行,我希望程序接受。例如。
1 2 3 4
5 6 7 8
Run Code Online (Sandbox Code Playgroud)
根据官方文件,
for scanner.Scan() {
}
Run Code Online (Sandbox Code Playgroud)
会导致对无限行进行扫描,直到达到EOF或错误为止,是否还有其他函数会接受两行输入呢?
请考虑以下代码
val sc = new java.util.Scanner (System.in)
while (sc.hasNext()) {
var temp = sc.nextLine()
println(temp.nonEmpty)
println (temp)
}
Run Code Online (Sandbox Code Playgroud)
每当我按enter空行时,程序只是等待下一个输入发生,并且不执行内部语句
例如
input:
<enter>
<enter>
1
Run Code Online (Sandbox Code Playgroud)
原因
output:
<space>
false
<space>
false
1
true
Run Code Online (Sandbox Code Playgroud)
我试图让用户输入行列表,并退出空行
例如.
1 2 3 4
5 6 7 8
<enter> // -> will exit
Run Code Online (Sandbox Code Playgroud)
我怎么做到这一点?