我的webapp在ios safari私密浏览中有javascript错误:
JavaScript的:错误
未定义
QUOTA_EXCEEDED_ERR:DOM例外22:尝试向存储添加内容......
我的代码:
localStorage.setItem('test',1)
Run Code Online (Sandbox Code Playgroud) 我想检查两个结构是否相等,但有一些问题:
package main
import (
"fmt"
"reflect"
)
type T struct {
X int
Y string
Z []int
M map[string]int
}
func main() {
t1 := T{
X: 1,
Y: "lei",
Z: []int{1, 2, 3},
M: map[string]int{
"a": 1,
"b": 2,
},
}
t2 := T{
X: 1,
Y: "lei",
Z: []int{1, 2, 3},
M: map[string]int{
"a": 1,
"b": 2,
},
}
fmt.Println(t2 == t1)
//error - invalid operation: t2 == t1 (struct containing []int cannot be compared)
fmt.Println(reflect.ValueOf(t2) == …Run Code Online (Sandbox Code Playgroud) 我有一个websocket服务.这是有错误的:"太多打开的文件",但我已经设置了系统配置:
/etc/security/limits.conf
* soft nofile 65000
* hard nofile 65000
/etc/sysctl.conf
net.ipv4.ip_local_port_range = 1024 65000
ulimit -n
//output 6500
Run Code Online (Sandbox Code Playgroud)
所以我认为我的系统配置正确.
我的服务由主管管理,可能是主管限制?
检查过程由主管开始:
cat /proc/815/limits
Max open files 1024 4096 files
Run Code Online (Sandbox Code Playgroud)
检查过程手册启动:
cat /proc/900/limits
Max open files 65000 65000 files
Run Code Online (Sandbox Code Playgroud)
原因是使用主管管理服务.如果我重新启动supervisor并重新启动子进程,那么当启动系统管理程序自动启动时,它是"max open files"ok(65000)但错误(1024).
可能是主管启动级别太高而系统配置在主管启动时不起作用?
编辑:
系统:ubuntu 12.04 64bit
这不是主管问题,系统重启后所有进程自动启动都没有使用系统配置(最大打开文件= 1024),但重新启动它没问题.
更新
也许问题是:
现在的问题是,如何设置全局nofile限制,因为我不想在我需要的每个upstart脚本中设置nofile限制.
我的代码从远程URL获取文件并在浏览器中下载文件:
func Index(w http.ResponseWriter, r *http.Request) {
url := "http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png"
...
resp, err := client.Get(url)
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(len(body))
//download the file in browser
}
func main() {
http.HandleFunc("/", Index)
err := http.ListenAndServe(":8000", nil)
if err != nil {
fmt.Println(err)
}
}
Run Code Online (Sandbox Code Playgroud)
代码:http://play.golang.org/p/x-EyR2zFjv
获取文件是可以的,但如何在浏览器中下载?
谢谢.
我知道一次插入多个数据的效率更高:
INSERT INTO test(n1, n2, n3)
VALUES(v1, v2, v3),(v4, v5, v6),(v7, v8, v9);
Run Code Online (Sandbox Code Playgroud)
如何在golang中做到这一点?
data := []map[string]string{
{"v1":"1", "v2":"1", "v3":"1"},
{"v1":"2", "v2":"2", "v3":"2"},
{"v1":"3", "v2":"3", "v3":"3"},
}
//I do not want to do it
for _, v := range data {
sqlStr := "INSERT INTO test(n1, n2, n3) VALUES(?, ?, ?)"
stmt, _ := db.Prepare(sqlStr)
res, _ := stmt.Exec(v["v1"], v["v2"], v["v3"])
}
Run Code Online (Sandbox Code Playgroud)
使用字符串拼接,但它并不好.db.Prepare更安全吧?
sqlStr := "INSERT INTO test(n1, n2, n3) VALUES"
for k, v := range data {
if k …Run Code Online (Sandbox Code Playgroud) 某些函数可以对字符串或[]字节进行排序:
"bcad" to "abcd"
or
[]byte("bcad") to []byte("abcd")
Run Code Online (Sandbox Code Playgroud)
字符串只有字母.
如果是字母和数字?
我找到了排序包但不是想要的功能.
谢谢.
我想返回大于或等于整数除法的最小整数值.所以我用过math.ceil,但无法获得我想要的价值.
package main
import (
"fmt"
"math"
)
func main() {
var pagesize int = 10
var length int = 43
d := float64(length / pagesize)
page := int(math.Ceil(d))
fmt.Println(page)
// output 4 not 5
}
Run Code Online (Sandbox Code Playgroud)
http://golang.org/pkg/math/#Ceil
http://play.golang.org/p/asHta1HkO_
怎么了?谢谢.
一个带有三个子模板的布局模板.
的layout.html
<html>
<body>
{{template "tags"}}
{{template "content"}}
{{template "comment"}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
tags.html
{{define "tags"}}
<div>
{{.Name}}
<div>
{{end}}
Run Code Online (Sandbox Code Playgroud)
content.html
{{define "content"}}
<div>
<p>{{.Title}}</p>
<p>{{.Content}}</p>
</div>
{{end}}
Run Code Online (Sandbox Code Playgroud)
comment.html
{{define "tags"}}
<div>
{{.Note}}
</div>
{{end}}
Run Code Online (Sandbox Code Playgroud)
type Tags struct {
Id int
Name string
}
type Content struct {
Id int
Title string
Content string
}
type Comment struct {
Id int
Note string
}
func main() {
tags := &Tags{"Id":1, "Name":"golang"}
Content := &Content{"Id":9, "Title":"Hello", "Content":"World!"}
Comment := &Comment{"Id":2, "Note":"Good …Run Code Online (Sandbox Code Playgroud) 我使用了aws sdk(https://github.com/aws/aws-sdk-php).
码
$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => $key,
'Body' => $file,
'ACL' => 'public-read',
));
Run Code Online (Sandbox Code Playgroud)
它运作良好,但我有一个问题:
谢谢.
我使用php Yii框架并运行功能测试.我已经安装了PHPUnit_Story
pear install phpunit/PHPUnit_Story
Run Code Online (Sandbox Code Playgroud)
而扩展就在那里
/usr/share/php/PHPUnit/Extensions/Story
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
PHP Warning: include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory in /var/www/yii/framework/YiiBase.php on line 427
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:581
PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:132
PHP 4. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/bin/phpunit/phpunit/TextUI/Command.php:179
PHP 5. PHPUnit_TextUI_ResultPrinter->printResult() phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php:425
PHP 6. PHPUnit_TextUI_ResultPrinter->printFailures() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:177
PHP 7. PHPUnit_TextUI_ResultPrinter->printDefects() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:322
PHP 8. PHPUnit_TextUI_ResultPrinter->printDefect() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:243
PHP 9. PHPUnit_TextUI_ResultPrinter->printDefectTrace() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:254
PHP 10. PHPUnit_Util_Filter::getFilteredStacktrace() phar:///usr/bin/phpunit/phpunit/TextUI/ResultPrinter.php:290
PHP 11. PHPUnit_Util_Blacklist->isBlacklisted() phar:///usr/bin/phpunit/phpunit/Util/Filter.php:105
PHP 12. PHPUnit_Util_Blacklist->initialize() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:74
PHP 13. class_exists() phar:///usr/bin/phpunit/phpunit/Util/Blacklist.php:110 …Run Code Online (Sandbox Code Playgroud) go ×6
php ×2
amazon-s3 ×1
byte ×1
ceil ×1
go-reflect ×1
html5 ×1
javascript ×1
linux ×1
linux-kernel ×1
phpunit ×1
sorting ×1
string ×1
ubuntu ×1
unit-testing ×1
upstart ×1