小编chr*_*ris的帖子

Javascript承诺不等待解决

我认为我对承诺有一个很好的理解,直到我遇到一个简化的代码片段问题.我的印象是console.log调用会输出first second third,而是导致second third first.

有人可以解释为什么第二和第三个承诺能够继续而不等待第一个承诺.

var Q = require('q');

(function() {

  var Obj = function() {

    function first() {
      var deferred = Q.defer();

      setTimeout(function() {
        console.log('in the first')
        deferred.resolve();
      }, 200);

      return deferred.promise;
    }

    function second() {
      return Q.fcall(function() {
        console.log('in the second');
      })
    }

    function third() {
      return Q.fcall(function() {
        console.log('in the third');
      })
    }

    return {
      first:  first,
      second: second,
      third:  third
    }
  };

  var obj = Obj();
  obj.first()
    .then(obj.second())
    .then(obj.third());

}());
Run Code Online (Sandbox Code Playgroud)

javascript promise

5
推荐指数
1
解决办法
2800
查看次数

有没有人去过Pragmatic Studio iPhone课程,如果有的话,值得吗?

我正在考虑去实用的工作室iphone课程,但由于价格而有点警惕.我目前从事合同工作,因此没有一家公司会为我支付课程费用,当然除了我的.

旅行,食品,酒店和货币转换后,课程可达3500多个.

这值得么?

iphone

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

需要获得服务以回复活动

我需要创建一个活动来启动监视用户位置的服务,并且在某个区域内允许调用Activity更新其视图以通知用户.

由于有几种不同的方式来处理服务,我有点困惑的是哪一种对我的情况是正确的.

使用startService()stopService()方法:从我的理解,我不能直接回到起始活动.在谷歌文档中有一个示例显示如何通过PendingIntent将BroadcastReceiver传递给服务并调用它,但我不认为允许我更新正在运行的活动的视图...或者它会吗?

绑定服务:从文档看来,这将允许服务和活动之间的双向通信,但也提到绑定服务不会无限期地在后台运行.现在我不需要甚至不想让服务无限期地运行,但在最糟糕的情况下,我可能需要它在bg中运行至少一两个小时而不会被杀死.

第三个(可能不是那么好)选项:在活动的线程中运行位置服务,这将使实时视图更新变得容易,然后在onPause事件中,停止活动中的位置服务并将其交给服务通过startService()并使用通知服务在输入定义的区域时提醒用户.

任何建议将不胜感激.

  1. 如果您希望服务返回结果,则启动服务的客户端可以为广播创建PendingIntent(使用getBroadcast())并将其传递给启动服务的Intent中的服务.然后,该服务可以使用广播来传递结果.

  2. 绑定服务通常仅在其服务于另一个应用程序组件时才存在,并且不会无限期地在后台运行.

android android-service

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

Gulp有两个相互冲突的任务

我有javascript和css文件,我使用gulp-rev lib [1]的分叉回购,它们都重命名文件并更新html文件中的文件引用.

不幸的是,两个任务之间存在争用条件,导致样式表引用md5命名文件或js文件获胜.

我试图使用promises和回调(见下文)来允许同步任务,但从来都不是css和js md5引用.

sindresorhus的lib只重命名文件并且不修复链接,所以是否有更好的方法来修复html链接,或者使用forked插件他们的方式去(有一些我缺少的修复)?

gulp.task('rev', ['rev-js'] );
gulp.task('rev-js', ['rev-css'], function(cb) {
  var context = rev.Context();
  gulp.src(['./build/public/js/woddy.js', './build/public/js/angular.js', './build/public/js/components.js'])
    .pipe(rev(context))
    .pipe(gulp.dest('./build/public/js'));
  gulp.src('./build/public/app.html')
    .pipe(context.replace(/src="js\/(\w+\.js)"/g, 'src="js/{{$1}}"'))
    .pipe(gulp.dest('./build/public'));
});
gulp.task('rev-css', function() {
  var context = rev.Context();
  gulp.src('./build/public/styles/woddy.css')
    .pipe(rev(context))
    .pipe(gulp.dest('./build/public/styles'));
  gulp.src('./build/public/app.html')
    .pipe(context.replace(/href="styles\/(\w+\.css)"/g, 'href="styles/{{$1}}"'))
    .pipe(gulp.dest('./build/public'));
});
Run Code Online (Sandbox Code Playgroud)
  1. https://github.com/dtinth/gulp-rev

javascript node.js gulp

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

google api redirect_uri_mismatch 错误

我正在尝试让 google plus 身份验证适用于网络应用程序,但不断收到 redirect_uri_mismatch 错误。我已经检查并重新检查我在代码和谷歌开发设置中是否有匹配的重定向 URL。

我已经标记了发生故障的位置 -> ** CRASHES HERE

任何帮助,将不胜感激。

js绑定

window.gplusSigninCallback = function(authResult) {
  if (!authResult.code) {
    return;
  }

  request
    .post('/api/users')
    .send({ code: authResult.code })
    .end(function(err, res) {
      dom('#signinButton').remove();
    });
};
Run Code Online (Sandbox Code Playgroud)

谷歌+组件

<span id="signinButton">
  <span class="g-signin"
    data-scope="https://www.googleapis.com/auth/plus.login"
    data-clientid="{clientId}"
    data-redirecturi="postmessage"
    data-accesstype="offline"
    data-cookiepolicy="single_host_origin"
    data-callback="gplusSigninCallback">
  </span>
</span>
Run Code Online (Sandbox Code Playgroud)

发布/用户

使用来自https://github.com/google/google-api-nodejs-client/blob/master/examples/oauth2.js 的代码

'use strict';

const router    = require('express').Router();
const User      = require('../models/user');

const GoogleCreds   = require('../config/google_api_credentials').web;
const googleapis    = require('googleapis');
const OAuth2Client  = googleapis.OAuth2Client;

module.exports = router;

/**
 * …
Run Code Online (Sandbox Code Playgroud)

javascript node.js google-api-js-client

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

使用httputil.ReverseProxy时,mux.Vars为空

我试图一起使用gorilla mux和httputil.ReverseProxy,但是当试图获取mux.Vars时它是空的.根据https://golang.org/src/net/http/httputil/reverseproxy.go?s=2744:2819#L93,似乎http.Request指针是原始请求的浅表副本,它应该仍然有效.

有任何想法吗?

https://play.golang.org/p/JpjNvEMIFB

package main

import (
    "github.com/gorilla/mux"
    "log"
    "net/http"
    "net/http/httputil"
    "net/url"
)

type route struct {
    match string
    base  string
}

var routes = []route{
    // proxy http://localhost:3000/api/foo/bar => https://api.bar.com/5/foo/bar
    route{match: "/api/{path}", base: "https://api.bar.com/5"},
    route{match: "/sales/{path}", base: "https://sales.bar.com/3"},
}

func NewProxy(r *route) http.Handler {
    director := func(req *http.Request) {
        out, _ := url.Parse(r.base)

        req.URL.Scheme = out.Scheme
        req.URL.Host = out.Host
        req.URL.Path = out.Path + "/" + mux.Vars(req)["path"] // mux Vars are empty here
    }
    return &httputil.ReverseProxy{Director: director} …
Run Code Online (Sandbox Code Playgroud)

go gorilla

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

自定义获取线输入功能

我正在阅读K&R的书,我有点卡住了.

以下是什么问题?

void getInput(int* output) {
   int c, i;
   for(i=0; (c = getchar()) != '\n'; i++)
     output[i] = c; // printf("%c", c) prints the c value as expected
   output[++i] = '\0';
}
Run Code Online (Sandbox Code Playgroud)

当我运行程序时,它永远不会离开循环而我必须Ctrl+C退出.但是,如果我用第五行替换printf("%c", c);,它会在输入并创建新行后打印出所有输入.

c kernighan-and-ritchie buffer-overflow

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

未能以隐含意图启动活动

我有点困惑为什么隐式意图调用失败.尝试启动意图时,我不断收到以下错误:

    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://org.chrisolsen.crossfit.providers.WorkoutProvider/workouts typ=vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout }
Run Code Online (Sandbox Code Playgroud)

AndroidManifest

    <activity android:name=".activities.WorkoutsActivity" 
        android:label="@string/title_workouts" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <data android:mimeType="vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout"/>
        </intent-filter>
    </activity> 

    <provider 
      android:name=".providers.WorkoutProvider"
      android:authorities="org.chrisolsen.crossfit.providers.WorkoutProvider" />    
Run Code Online (Sandbox Code Playgroud)

通话活动(仪表板)

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(WorkoutProvider.CONTENT_URI, "vnd.android.cursor.dir/vnd.chrisolsen.crossfit.workout");
    startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

被称为活动(锻炼).它没有在这里

    Uri uri = getIntent().getData();
    ...
Run Code Online (Sandbox Code Playgroud)

它似乎应该很简单,但我很困惑为什么它说没有找到任何活动.

有任何想法吗?

android android-intent

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