小编Alx*_*Alx的帖子

Handler vs AsyncTask vs Thread

我稍微感到困惑之间的差异Handlers,AsyncTaskThreads在Android中.我在stackoverflow中阅读了很多博客和问题.

Handler是后台线程,提供您与UI进行通信.例如,更新进度条应该通过Handler.使用处理程序可以获得优势MessagingQueues,因此,如果要计划消息或更新多个UI元素或具有重复任务.

AsyncTask类似的,实际上它们使用Handler但不在UI线程中运行,因此它对于获取数据很有用,例如获取Web服务.稍后您可以与UI进行交互.

Thread然而,无法与UI交互,提供更多"基本"线程,你错过了所有的抽象AsyncTask.

但是,我想在服务中运行套接字连接.应该在处理程序或线程中运行,还是在AsyncTask?根本不需要UI交互.它在我使用的性能方面有所不同吗?

与此同时,文件已得到重大改进.

multithreading android android-asynctask android-handler

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

使用passport.js在node.js中进行身份验证后重定向到上一页

我正在尝试使用node.js,express和passport.js建立登录机制.登录本身工作得非常好,会话与redis很好地存储,但是在提示进行身份验证之前,我确实遇到了将用户重定向到他开始的地方的麻烦.

例如,用户跟随链接http://localhost:3000/hidden然后被重定向到http://localhost:3000/login但我希望他再次被重定向回http://localhost:3000/hidden.

这样做的目的是,如果用户随机访问他需要首先登录的页面,他将被重定向到提供其凭据的/ login站点,然后被重定向回他之前尝试访问的站点.

这是我的登录帖子

app.post('/login', function (req, res, next) {
    passport.authenticate('local', function (err, user, info) {
        if (err) {
            return next(err)
        } else if (!user) { 
            console.log('message: ' + info.message);
            return res.redirect('/login') 
        } else {
            req.logIn(user, function (err) {
                if (err) {
                    return next(err);
                }
                return next(); // <-? Is this line right?
            });
        }
    })(req, res, next);
});
Run Code Online (Sandbox Code Playgroud)

在这里我的ensureAuthenticated方法

function ensureAuthenticated (req, res, next) {
  if (req.isAuthenticated()) { 
      return next();
  }
  res.redirect('/login'); …
Run Code Online (Sandbox Code Playgroud)

authentication redirect node.js express passport.js

92
推荐指数
5
解决办法
7万
查看次数

如何使用jade模板将块附加到父级

我正在尝试使用jade模板创建模块化布局.我想将一个来自子节点的脚本块添加到其父节点父节点中.我不太确定它是否可能.

这是我的结构

layout.jade

head.jade

index.jade

users.jade

layout.jade:doctype html #html include head

    body
        block content
Run Code Online (Sandbox Code Playgroud)

head.jade:

head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
    block scripts
Run Code Online (Sandbox Code Playgroud)

index.jade:

extends layout

block content
    h1 Hello

    include users
Run Code Online (Sandbox Code Playgroud)

users.jade

block append scripts
    script(src='/javascripts/user.js')  

ul
    each user, i in users
        li(class=i+"-"+user) #{user} 
Run Code Online (Sandbox Code Playgroud)

我想要的html输出应该是:

<!DOCTYPE html>
<html id="html">
    <head>
        <title>Index</title>
        <link href="/stylesheets/style.css" rel="stylesheet">
        <script src="/javascripts/user.js">  <!--// append this from user.jade into head.jade //-->
    </head>
    <body>

        <h1>Hello bob</h1>
        <li class="0-user1">user1</li>
Run Code Online (Sandbox Code Playgroud)

inheritance append include node.js pug

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

通过 Microsoft Graph 检查目录邀请的兑换状态

我正在邀请用户使用 Microsoft Graph REST API 作为成员添加到我的 Active Directory。

curl -X POST \
  https://graph.microsoft.com/v1.0/invitations \
  -H 'authorization: Bearer ey...Jg' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
  "invitedUserEmailAddress": "userInvite@hotmail.com",
  "inviteRedirectUrl": "https://example.com/afterInvite",
  "sendInvitationMessage": false,
  "invitedUserType":"Member"
}'
Run Code Online (Sandbox Code Playgroud)

我确实收到了带有状态字段的正确响应:

"status": "待接受",

这当然是正确的,因为用户刚刚被邀请。有没有办法查看用户是否已兑换邀请?

多谢

azure-active-directory microsoft-graph-api

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

Node.js产生多个进程

我对我的node.js应用程序有些困惑。据我所知,node.js在单个进程中运行。但是,如果我通过调用应用程序node app.js并使用htop监视它来启动应用程序,则可以看到4个子进程正在运行,我希望只有一个子进程可以运行。

在此处输入图片说明

app.js

var express = require('express'),
    routes = require('./routes'),

    objects = require('./objects'),

    http = require('http'),
    path = require('path'),

    pinLayout = objects.pinlayout,

    // utils
    util = require('util'),
    wiringPi = require('wiring-pi'),
    winston = require('winston'),
    async = require('async');


// Logger - winston
var log = new(winston.Logger)({
    transports: [
        new(winston.transports.Console)({
            colorize: true,
            timestamp: true
        }),
        new(winston.transports.File)({
            filename: './log/app.log'
        })
    ]
});

// WiringPi
wiringPi.setup('gpio');

var app = express();

// all environments
app.set('port', process.env.PORT || 3001);
app.set('views', __dirname + '/views');
app.set('view engine', …
Run Code Online (Sandbox Code Playgroud)

javascript process node.js nodemon

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

使用angular.js输入类型时间

根据文档输入[时间]:https://docs.angularjs.org/api/ng/input/input%5Btime%5D

它应该足以使用输入类型时间并将其绑定到日期对象,但它不能像我期望的那样工作.

<input ng-model="time" type="time" placeholder="HH:mm" min="08:00" max="17:00" required >
Run Code Online (Sandbox Code Playgroud)

$scope.time = new Date();
Run Code Online (Sandbox Code Playgroud)

结果我想在输入字段中看到HH:mm.

这是一个可以玩的小提琴:

http://jsfiddle.net/U3pVM/7314/

time html5 angularjs

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

为什么建议使用纱线云构建器?

查看 Google Cloud Build 的纱线构建器的源代码,我想知道为什么建议使用构建器而不是指定入口点。

https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/yarn

基本上

steps
  - name: 'gcr.io/cloud-builders/yarn'
    args:
      - install
Run Code Online (Sandbox Code Playgroud)

steps:
  - name: node:10
    entrypoint: yarn
    args:
      - install
Run Code Online (Sandbox Code Playgroud)

是否因为云构建器已在 Google Cloud 容器注册表中注册,因此从 Google Cloud 构建中读取速度更快?

google-cloud-build

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

将背景应用于离子侧菜单

我正在使用ionic和angular.js,并且想知道如何在侧边菜单中正确应用背景样式.我确实有一个模糊的背景图像和内容框悬停在背景图像上方.我的意图是打开左侧或右侧菜单时,背景保持固定,只有内容移动.

左侧截图显示了我到目前为止的结果.backgroundimage附加到菜单的每个内容视图,否则将底层内容设置为透明.右侧屏幕截图是一个简单的html模型,用于说明最终结果.

有人有什么建议吗?

插图

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>
    <link href="css/style.css" rel="stylesheet">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
  </head>
  <body ng-app="starter" animation="slide-left-right-ios7">
    <ion-header-bar align-title="left" class="bar-positive">
  <div class="buttons">
    <button class="button" ng-click="doSomething()">Left Button</button>
  </div>
  <h1 class="title">Title!</h1>
  <div class="buttons">
    <button class="button">Right Button</button>
  </div>
</ion-header-bar>

    <ion-side-menus class="sideMenus">

      <ion-side-menu-content class="custom">
        <h1>bdafs1</h1>   
      </ion-side-menu-content>

      <ion-side-menu side="left" …
Run Code Online (Sandbox Code Playgroud)

html javascript css angularjs ionic-framework

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

如何正确使用CALLER_IS_SYNCADAPTER

不知怎的,我不明白查询参数CALLER_IS_SYNCADAPTER的工作概念.其默认值为false,如果设置,则不会自动设置DIRTY标志.那它究竟意味着什么呢?根据我的理解,联系人的每次更改都会导致将脏标志设置为1.在同步适配器完成作业后,使用插入/更新/删除CALLER_IS_SYNCADAPTER,插入/更新和删除的记录的脏标志应为0 , 是对的吗?

但是,如果我使用该可选参数调用查询,则条目将保留为标志1.

还有什么我必须做的,或者我理解它应该如何运作错误?或者有什么东西告诉系统同步已成功完成设置标志?

有没有人有进一步阅读的样本或建议?

android android-syncadapter

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

是否需要通过https://apps.dev.microsoft.com注册新的应用程序?

我是否必须通过https://apps.dev.microsoft.com向我的MS帐户注册一个新应用程序

- 要么 -

我可以在Azure Active Directory中添加一个新的应用程序吗?

我想使用OAuth2隐式流程来使用Microsoft Graph单点登录.我通过Active Directory中的Azure门户创建了一个新应用程序,在清单中启用了隐式流程 "oauth2AllowImplicitFlow": true,启用了多租户环境.目标是为个人和组织帐户启用单点登录,基本上每个人都拥有MS帐户.要验证和请求新令牌,我使用的是公共端点:

public const string AuthorizationEndPoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";

public const string TokenEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误消息:

https://login.live.com/err.srf?lc=1033#error=unauthorized_client&error_description=The+client+does+not+exist.+If+you+are+the+application+developer%2c+configure+a +新+应用+通过在+ HTTPS +的+应用+管理+网站+://apps.dev.microsoft.com/.&state=ABC...EFG

在Azure门户中,我确实看到失败的登录以及以下消息.

FAILURE REASON The application named X was not found in the tenant named Y. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the …
Run Code Online (Sandbox Code Playgroud)

azure azure-active-directory microsoft-graph

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