小编Mad*_*uja的帖子

提交后的gitignore

我有一个在Github上托管的git存储库.提交许多文件后,我意识到我需要创建.gitignore和排除.exe,.obj文件.

但是,它会自动从存储库中删除这些提交的文件吗?有没有办法强制这样做?

git github gitignore

190
推荐指数
5
解决办法
9万
查看次数

访问Google API - GoogleAccountCredential.usingOAuth2与GoogleAuthUtil.getToken()

最近,我一直在使用Android上的Google API,特别是Google Analytics,AdSense和Tasks API.

我见过Google提供的一些示例,他们使用此语句获取GoogleAccountCredential对象

https://code.google.com/p/google-api-java-client/source/browse/tasks-android-sample/src/main/java/com/google/api/services/samples/tasks/android/ TasksSample.java?repo=samples

credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(TasksScopes.TASKS));

但是,如果我查看以下文档:
http://developer.android.com/google/auth/http-auth.html
http://developer.android.com/google/play-services/auth.html

他们都提到了下面用于获取令牌的方法:
token = GoogleAuthUtil.getToken(mActivity, mEmail, mScope);

我很困惑在哪种场景中使用哪一个以及为什么.我一直在使用Method no.1成功而无需在首选项中保留令牌(我猜这是由GoogleAccountCredential自动完成的)

  1. 任何人都可以告诉我为什么有人会使用第一种方法而不是第二种方法?

  2. 如何在第一种方法中访问身份验证令牌?

android google-api oauth-2.0 google-api-java-client

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

如何在没有线程的情况下在Javascript中实现Promise

最近,我已经看到Promise的概念在AngularJS和JQuery中实现.

我已经在下面的代码中看到了Java中的Futures的实现,但是这需要在语言/平台中存在线程池的概念.但是,Javascript中没有这样的线程概念.如何实现Javascript中的Promise?

public class Futures1 {

    private static final ExecutorService pool = Executors
            .newFixedThreadPool(10);

    public static void main(String[] args) {

        Future<String> contentsFuture = null;
        try {
            contentsFuture = startDownloading(new URL("http://www.example.com"));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        // other computation
        try {
            final String contents = contentsFuture.get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

    }

    public static Future<String> startDownloading(final URL url) {
        return pool.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                try (InputStream input = url.openStream()) …
Run Code Online (Sandbox Code Playgroud)

javascript jquery promise

36
推荐指数
2
解决办法
1万
查看次数

在正则表达式中捕获组

我正在探索在Regex中捕获组,我对它缺乏文档感到困惑.对于前者,任何人都可以告诉我两个正则表达式之间的区别:

/(?:madhur)?/
Run Code Online (Sandbox Code Playgroud)

/(madhur)?/
Run Code Online (Sandbox Code Playgroud)

按照我的意见,?在第二个建议madhur在字符串中匹配零或一次.

第一个与第二个有什么不同?

javascript regex

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

将HTTP REST API用于聊天应用程序是否可以?

我们正在Android中构建聊天应用程序.我们正在考虑使用HTTP REST API发送出站邮件.与使用WebSockets或XMPP(这似乎更像是转移聊天消息的事实标准)相比,想知道它是一个好方法还是有任何缺点?

我能想到的一些优点/缺点是:
+ HTTP端点很容易在服务器端水平扩展(这是一个主要问题)
+与HTTP相比,Websockets的学习曲线更陡峭
- 与websockets相比,HTTP消息的负载更大

根据这份文件,似乎Facebook最初使用AJAX来处理聊天消息:

https://www.erlang-factory.com/upload/presentations/31/EugeneLetuchy-ErlangatFacebook.pdf

android chat xmpp

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

ArrayList按Id检索对象

假设我有一个ArrayList<Account>非常简单的自定义对象.例如:

class Account
{
public String Name;
public Integer Id;
}
Run Code Online (Sandbox Code Playgroud)

我想Account根据Id应用程序的许多部分中的参数检索特定对象.最好的办法是什么?

我想扩展,ArrayList但我相信必须有更好的方法.

java collections arraylist

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

用Java [没有Node.js]的React.js服务器端渲染

我们在纯JSP/JQuery中有一个应用程序,我们试图将其转移到ReactJs以实现可维护性.我看到的ReactJs的一个好处是服务器端渲染.但是,我所看到的服务器端渲染的所有示例都将Node.js用作服务器端.我们目前正在使用Tomcat,而不是仅仅为了服务器端渲染而部署node.js.

我考虑过几个替代方案,比如使用Nashorn(http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/)

但是,Nashorn似乎没有准备好生产.

是否有人在生产中在Tomcat上部署了React.js和服务器端渲染?

java tomcat node.js reactjs

14
推荐指数
1
解决办法
7220
查看次数

ValueError:invalid\x escape

python -c 'print "\x90" * 348 + "\x31\xc0\x83\xec\x01\x88\x04\x24\x68\x62\x61\x73\x68\x68\x62\x69\x6e\x2f\x8\xec\x01\xc6\x04\x24\x2f\x89\xe6\x50\x56\xb0\x0b\x89\xf3\x89\xe1\x31\xd2\xcd\x80\xb0\x01\x31\xdb\xcd\x80" + "\x30\xd1\xff\xff" * 35'
ValueError: invalid \x escape
Run Code Online (Sandbox Code Playgroud)

知道是什么导致了这个错误吗?

python

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

如何优化Tomcat for Feed pull

我们有一个移动应用程序,向用户提供Feed.feed tom API是在tomcat上实现的,它并行调用不同的数据源,如Couchbase,MYSQL来呈现内容.简单的代码如下:

Future<List<CardDTO>> pnrFuture = null;
Future<List<CardDTO>> newsFuture = null;

ExecutionContext ec = ExecutionContexts.fromExecutorService(executor);

final List<CardDTO> combinedDTOs = new ArrayList<CardDTO>();

// Array list of futures 
List<Future<List<CardDTO>>> futures = new ArrayList<Future<List<CardDTO>>>();

futures.add(future(new PNRFuture(pnrService, userId), ec)); 
futures.add(future(new NewsFuture(newsService, userId), ec)); 
futures.add(future(new SettingsFuture(userPreferenceManager, userId), ec)); 

Future<Iterable<List<CardDTO>>> futuresSequence = sequence(futures, ec); 

// combine the cards 
Future<List<CardDTO>> futureSum =  futuresSequence.map( 
        new Mapper<Iterable<List<CardDTO>>, List<CardDTO>>() {
            @Override 
            public List<CardDTO> apply(Iterable<List<CardDTO>> allDTOs) { 
                for (List<CardDTO> cardDTOs : allDTOs) {
                    if (cardDTOs != null) {
                        combinedDTOs.addAll(cardDTOs);
                    } 
                } …
Run Code Online (Sandbox Code Playgroud)

java tomcat akka

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

Spring mongodb获取保存后插入项目的ID

我正在使用Spring MongoDb.

我使用insert方法创建各种实体:http: //docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoOperations.html#insert-java.lang.Object -

但是,所有方法都返回void.我需要返回ObjectId插入的文档.

获得它的最佳方法是什么?

mongodb spring-mongo

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