小编toy*_*toy的帖子

Android内存指南中的"避免依赖注入框架"是否也适用于Dagger?

所以我在Android文章中遇到了关于内存性能的最佳实践.

http://developer.android.com/training/articles/memory.html

他们说

避免依赖注入框架

使用依赖注入框架(如Guice或RoboGuice)可能很有吸引力,因为它们可以简化您编写的代码并提供对测试和其他配置更改有用的自适应环境.但是,这些框架倾向于通过扫描代码进行注释来执行大量进程初始化,这可能需要将大量代码映射到RAM中,即使您不需要它也是如此.这些映射页面被分配到干净的内存中,因此Android可以删除它们,但是直到页面长时间留在内存中才会发生这种情况.

但他们声称快速的Dagger呢?不确定我应该去哪一个?

performance android dependency-injection dagger

60
推荐指数
2
解决办法
8074
查看次数

茉莉花模拟窗口对象

我如何模拟窗口对象?我正在做firefox扩展,我想用jasmine进行javascript测试.

在我的JavaScript中我有


function submit() {
...
var url = window.arguments[0];
...
}

显然,我必须在jasmine中模拟window.arguments [0],因为如果不从window.openDialog传递任何参数,该对象就不存在

这是我试图用"with"嘲笑它


it("should submit to server", function() {

        var localContext = {
            "window": {
                arguments: ["http://localhost"]
            }

        }

        with(localContext);

但是我仍然得到这个错误TypeError:无法读取未定义的属性'0',就像测试运行时一样window.arguments [0]被真实窗口消除了,因为如果我做的话

window.arguments[0]

在测试中,它正确打印出"http:// localhost".但是当涉及到submit()方法时,它会显示window.argument未定义的错误.

javascript mocking jasmine

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

如何使用git-svn只检查主干而不是分支和标签?

我正在开发一个Java遗留项目,它有20个模块相互连接.因此,每个模块都有自己的分支和标记.结构是这样的:


/projects
   .svn
   - module1
       .svn
       -trunk
       -branch
       -tag
   - module2
       .svn
       -trunk
       -branch
       -tag

projects文件夹大约30 GB,几乎不可能用于git-svn clone签出所有模块,但这是因为它计算所有分支和标签.

是否可以只克隆项目中继,以便我可以开始在本地提交?

svn git git-svn

42
推荐指数
3
解决办法
3万
查看次数

谷歌地图HTML5点击获取lat,很长

我正在尝试构建一个移动HTML5网络应用,用户可以点击地图从谷歌地图获取纬度/经度.有代码示例吗?我尝试使用谷歌搜索,但只找到一些网站,但没有源代码示例.

这是因为我将首先使用HTML5地理位置来显示当前位置,但如果它不准确,那么用户可以自己指定.

非常感谢.

javascript html5 google-maps

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

如何为nodejs运行像pm2这样的python脚本

我用过pm2我的Node.js脚本,我喜欢它.
现在我有一个python脚本,它收集EC2上的流数据.有时脚本会爆炸,我希望进程管理器像pm2一样重启.

对于python,是否有与pm2相同的东西?我一直在四处搜寻,找不到任何东西.

这是我的错误

  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 430, in filter
    self._start(async)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 346, in _start
    self._run()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/streaming.py", line 286, in _run
    raise exception
AttributeError: 'NoneType' object has no attribute 'strip'
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:90:
Run Code Online (Sandbox Code Playgroud)

这是一个简单的数据收集脚本

class StdOutListener(StreamListener):

    def on_data(self, data):
        mydata = json.loads(data)
        db.raw_tweets.insert_one(mydata)
        return True

    def on_error(self, status):
        mydata = json.loads(status)
        db.error_tweets.insert_one(mydata)


if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter Streaming API
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream …
Run Code Online (Sandbox Code Playgroud)

python ubuntu process-management node.js python-2.7

22
推荐指数
6
解决办法
3万
查看次数

如何在Jasmine中编写FileReader测试?

我正在努力使这个测试工作,但我无法理解如何使用FileReader编写测试.这是我的代码


function Uploader(file) {
    this.file = file;
}

Uploader.prototype =  (function() {

    function upload_file(file, file_contents) {
        var file_data = new FormData()
        file_data.append('filename', file.name)
        file_data.append('mimetype', file.type)
        file_data.append('data', file_contents)
        file_data.append('size', file.size)

        $.ajax({
            url: "/upload/file",
            type: "POST",
            data: file_contents,            
            contentType: file.type,
            success: function(){

                // $("#thumbnail").attr("src", "/upload/thumbnail");    

            },
            error: function(){
                alert("Failed");
            },
            xhr: function() {
                myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){
                    myXhr.upload.addEventListener('progress',showProgress, false);
                } else {
                    console.log("Upload progress is not supported.");
                }
                return myXhr;
            }
        });
    }

    return {
        upload : function() {
            var self = …
Run Code Online (Sandbox Code Playgroud)

javascript html5 unit-testing jasmine

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

RandomForestRegressor中的连续不受支持错误

我只是想做一个简单的RandomForestRegressor示例.但在测试准确性时,我得到了这个错误

/Users/noppanit/anaconda/lib/python2.7/site-packages/sklearn/metrics/classification.pyc
Run Code Online (Sandbox Code Playgroud)

in accuracy_score(y_true,y_pred,normalize,sample_weight)177 178#计算每种可能表示的准确性 - > 179 y_type,y_true,y_pred = _check_targets(y_true,y_pred)180如果y_type.startswith('multilabel'):181 differing_labels = count_nonzero(y_true - y_pred,axis = 1)

/Users/noppanit/anaconda/lib/python2.7/site-packages/sklearn/metrics/classification.pyc
Run Code Online (Sandbox Code Playgroud)

in _check_targets(y_true,y_pred)90 if(y_type不在["binary","multiclass","multilabel-indicator",91"multilabel-sequences"]):---> 92引发ValueError("{0}是不支持".format(y_type)"93 94如果["binary","multiclass"]中的y_type:

ValueError: continuous is not supported
Run Code Online (Sandbox Code Playgroud)

这是数据的样本.我无法显示真实数据.

target, func_1, func_2, func_2, ... func_200
float, float, float, float, ... float
Run Code Online (Sandbox Code Playgroud)

这是我的代码.

import pandas as pd
import numpy as np
from sklearn.preprocessing import Imputer
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor, ExtraTreesRegressor, GradientBoostingRegressor
from sklearn.cross_validation import train_test_split
from sklearn.metrics import accuracy_score
from sklearn import tree

train = pd.read_csv('data.txt', sep='\t')

labels = …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas random-forest scikit-learn

14
推荐指数
2
解决办法
3万
查看次数

如何使用shell脚本检查存在桶?

我安装了awscli.我只是不确定如何在shell脚本中执行此操作.

当我运行命令aws s3 ls s3://bucket它会给我这样的东西

调用ListObjects操作时发生客户端错误(NoSuchBucket):指定的存储桶不存在

这意味着存储桶不存在.所以我想从shell脚本运行它并检查是否grep找到它.但我的命令不起作用.

if [ $(aws s3 ls "s3://$S3_BUCKET" | grep 'NoSuchBucket' &> /dev/null) == 0 ] 
then
    echo "$S3_BUCKET doesn\'t exist please check again"
    exit
fi
Run Code Online (Sandbox Code Playgroud)

它只是给了我这个

backup.sh:20:[:0:意外的运算符

更新

我改变了脚本

echo "S3_BUCKET=$S3_BUCKET"
if aws s3 ls "s3://$S3_BUCKET" | grep -q 'AllAccessDisabled'    
then
    echo "$S3_BUCKET doesn\'t exist please check again"
    exit
fi
Run Code Online (Sandbox Code Playgroud)

这是我得到的输出

A client error (AllAccessDisabled) occurred when calling the ListObjects operation: All access to this object has been …
Run Code Online (Sandbox Code Playgroud)

bash shell ubuntu amazon-s3

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

如何使用Jasmine测试XMLHttpRequest

如何在没有jQuery的情况下测试XMLHttpRequest或纯Javascript AJAX上的onreadystatechange?我这样做是因为我正在开发Firefox扩展.我想我必须使用间谍,但无法弄清楚因为我的ajax不会返回任何东西.


    submit : function() {
        var url = window.arguments[0];
        var request = new XMLHttpRequest();
        request.open("POST", 'http://'+this.host+'/doSomething', true);
        request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        request.send("param="+param+"&emotions="+this.getParams());
        request.onreadystatechange = function() {
            if(this.readyState == 4) {
                // alert(this.responseText);
            }
        };

    }

javascript ajax jasmine

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

Makefile with source get error`没有这样的文件或目录`

我有一个非常简单Makefile的方法source来设置ENV变量.但如果我从中调用它,它就不起作用Makefile

我收到这个错误

make dev
source ./bin/authenticate.sh
make: source: No such file or directory
make: *** [dev] Error 1
Run Code Online (Sandbox Code Playgroud)

该脚本存在.

如果我在命令行中运行它,它的工作原理.

source ./bin/authenticate.sh
Works!
Run Code Online (Sandbox Code Playgroud)

这是我的 Makefile

test:
    pytest -s

dev:
    source ./bin/authenticate.sh
Run Code Online (Sandbox Code Playgroud)

我正在使用OSX.我不确定这是否会有所作为.

macos makefile

12
推荐指数
1
解决办法
2608
查看次数