我开始使用Yeoman工作流程,但我似乎无法完全理解index.html文件中usemin任务的"备用搜索路径".例如,使用'yo angular'命令生成了2个块:
<!-- build:js scripts/modules.js -->
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<!-- endbuild -->
Run Code Online (Sandbox Code Playgroud)
与
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/directives/multiselect.js"></script>
<!-- endbuild -->
Run Code Online (Sandbox Code Playgroud)
为什么第二个具有{.tmp,app}"备用搜索路径"(这是什么意思)?提前致谢.
我有一个关于"Effective Java"中涵盖的"Builder Pattern"的问题.我们需要一种.build()方法来正确实现模式吗?例如,假设我们有以下类:
public class CoffeeDrink {
private int numEspressoShots;
private short milkType;
private boolean withWhip;
private CoffeeDrink() {
}
public static CoffeeDrink buildNewDrink() {
return new CoffeeDrink();
}
public CoffeeDrink withEspresso(int n) {
this.numEspressoShots = n;
return this;
}
public CoffeeDrink withMilkType(shot t) {
this.milkType = t;
return this;
}
public CoffeeDrink withWhip() {
this.withWhip = true;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我们如何使用它:
CoffeeDrink c = CoffeeDrink.buildNewDrink()
.withEspresso(2)
.withMilkType(2)
.withWhip();
Run Code Online (Sandbox Code Playgroud)
如果我没有静态内部Builder类,这仍然有效吗?我猜其中一个优点是,CoffeeDrink在.build()调用该方法之前,它不会创建新对象,但我仍在创建一个Builder …
我正在编写一个与Google Places API集成的简单Express API,并尝试将地方照片发送到客户端,但无法让它工作.Google Places API的响应如下所示:

响应对象还包含一个headers属性.我试过像这样发回图像:
router.get('/photo/:photoRef', function (req, res) {
var params = {
maxwidth: 400,
photoreference: req.params.photoRef,
key: key
};
var url = baseUrl + 'photo?' + querystring.stringify(params);
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.type(response.headers['content-type']);
res.send(response.body);
}
});
});
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.我得到以下图像:

任何帮助将不胜感激.
所以我想学习在C#中使用'async'和'await'的基础知识,但我不确定我在这里做错了什么.我期待以下输出:
Calling DoDownload
DoDownload done
[...output here...]
Run Code Online (Sandbox Code Playgroud)
但我没有得到下载的输出,我也期望"完成",但这需要一段时间.不应该立即输出吗?另外,我似乎也无法获得字符串结果.这是我的代码:
namespace AsyncTest
{
class Program
{
static void Main(string[] args)
{
Debug.WriteLine("Calling DoDownload");
DoDownloadAsync();
Debug.WriteLine("DoDownload done");
}
private static async void DoDownloadAsync()
{
WebClient w = new WebClient();
string txt = await w.DownloadStringTaskAsync("http://www.google.com/");
Debug.WriteLine(txt);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的裸骨Node.js应用程序看起来像这样(基本上我经常调用一个Web服务,并将数据推送到客户端)大约一天后,即使添加了emitter.setMaxListeners,我也会得到以下运行错误( 0).我很确定我的代码没有任何内存泄漏.有什么建议?
/*
* Server setup
*/
var querystring = require('querystring');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
var eyes = require('eyes');
var http = require('http');
var app = http.createServer(handler);
var io = require('socket.io').listen(app);
var emitter = new (require('events').EventEmitter);
emitter.setMaxListeners(0);
io.set('log level', 0);
app.listen(8080);
function handler(req, res){
res.writeHead(200, {'Content-Type':'text/html'});
res.end('Test');
}
/*
* Global data object
*/
var xmlData= '';
var cache = [];
/*
* web service info
*/
var postData = querystring.stringify({
'index' : '',
'type' …Run Code Online (Sandbox Code Playgroud) 我正在使用 iisnode 运行我的 node.js 应用程序。然而,大约一个小时后,node.exe 进程停止运行(我需要它运行,因为我有一个 setInterval() 方法,每隔几秒钟从数据库中提取数据)。有什么建议吗?
另外,如果我使用 process.env.PORT 设置我的服务器,我如何在客户端使用 socket.io 连接到它?我明白我必须使用
io.configure(function () {
io.set("transports", ["xhr-polling"]); // no websockets
io.set("polling duration", 10);
io.set("log level", 1); // no debug msg
});
Run Code Online (Sandbox Code Playgroud) 我有以下基本的WPF应用程序,我希望在文本框中显示内容.但是,当我单击按钮时,UI线程似乎正在阻塞.我不确定我做错了什么,因为我从Pluralsight课程的练习文件中抓取了这段代码.
XAML和代码:
<Window x:Class="AsyncFetch.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button
x:Name="getButton"
HorizontalAlignment="Left"
Width="75"
Content="_Get Data"
Click="getButton_Click"
/>
<TextBox
x:Name="dataTextBox"
Margin="4"
Grid.Row="1"
/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
代码:
namespace AsyncFetch
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void getButton_Click(object sender, RoutedEventArgs e)
{
WebClient w = new WebClient();
string txt = await w.DownloadStringTaskAsync("http://www.google.com");
dataTextBox.Text = txt;
} …Run Code Online (Sandbox Code Playgroud) 我有以下示例
我似乎无法弄清楚为什么x标度对我不起作用(获取我的cx值的NaN).以下是我的代码的摘录:
var parse = d3.time.format("%Y").parse;
var data = [
{ year: "2008", number : 3},
{ year: "2009", number : 10},
{ year: "2010", number : 17},
{ year: "2011", number : 23},
{ year: "2012", number : 34},
{ year: "2013", number : 50}
];
for (var i = 0; i < data.length; i++) {
var d = data[i];
d.year = parse(d.year);
};
var yearScale = d3.time.scale()
.domain(d3.extent(data, function (d) { return d.year;}))
.range(50, window.innerWidth - 50); …Run Code Online (Sandbox Code Playgroud) 我使用grunt简单地连接和缩小我的CSS文件(不使用SASS).有没有像我可以使用的源地图?我想查看生产网站并使用Chrome Dev工具进行检查,但请告诉我原始的CSS文件.这是我的咕噜文件:
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
removeModuleCss: {
src:["App/**/module.css"]
}
},
cssmin: {
module: {
files: {
'App/styles/module.css': ['App/**/*.css']
}
}
},
concat: {
module: {
src: 'App/styles/**/*.css',
dest: 'App/styles/module.css'
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('css', ['clean', 'concat']);
grunt.registerTask('cssmin', ['clean', 'cssmin']);
};
Run Code Online (Sandbox Code Playgroud) 因此,我正在开发一个 Node.js 应用程序,它将每隔x几秒轮询一次 Google Analytics api。我已经设置了一个“服务帐户”,并将p12密钥转换为.pem文件。初始设置看起来像这样:
var authClient = new google.auth.JWT(authData.serviceEmail, authData.keyFile, null, authData.scope, '');
authClient.authorize(function(err, tokens) {
if (err) {
winston.log('error', 'Error authorizing with GA', {error: err});
return;
}
setInterval(function() {
analytics.data.realtime.get({
'auth': authClient,
...
}, function (err, body) {
// getting 401 error here
})
}, 20000);
});
Run Code Online (Sandbox Code Playgroud)
我没有意识到初始代币的有效期为 1 小时;但是我收到的令牌如下所示:
{
access_token: ...,
token_type: 'Bearer',
expiry_date: NaN,
refresh_token: 'jwt-placeholder
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,一旦收到该401 invalidCredentials错误,我是否只需重新授权即可获取新的访问令牌以便能够从 Google Analytics 进行轮询?我是 JWT 的新手,这似乎会授权太多次。这有限制吗?
作为参考,我正在使用Google …
google-analytics google-api node.js jwt google-api-nodejs-client
node.js ×4
async-await ×2
c# ×2
gruntjs ×2
javascript ×2
builder ×1
c#-5.0 ×1
d3.js ×1
express ×1
google-api ×1
iisnode ×1
java ×1
jwt ×1
source-maps ×1
wpf ×1
yeoman ×1