我正在做一些前端实验,我想有一个非常基本的网络服务器来快速启动项目并提供文件(一个index.html文件+一些css/js/img文件).所以我正在尝试使用node.js和express,我已经玩了两次,但是这次我不想使用渲染引擎,因为我只有一个静态文件,这个代码我得到了html文件但不是资产(错误404):
var express = require('express'),
app = express.createServer();
app.configure(function(){
app.use(express.static(__dirname + '/static'));
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.listen(3000);
Run Code Online (Sandbox Code Playgroud)
是否有一种简单的方法(如果可能,在一个文件中)或Express需要使用视图和渲染引擎?
我有大量的文件和解析器.我要做的是剥离所有非utf-8符号并将数据放入mongodb.目前我有这样的代码.
with open(fname, "r") as fp:
for line in fp:
line = line.strip()
line = line.decode('utf-8', 'ignore')
line = line.encode('utf-8', 'ignore')
Run Code Online (Sandbox Code Playgroud)
不知怎的,我仍然得到一个错误
bson.errors.InvalidStringData: strings in documents must be valid UTF-8:
1/b62010montecassianomcir\xe2\x86\x90ta0\xe2\x86\x90008923304320733/290066010401040101506055soccorin
Run Code Online (Sandbox Code Playgroud)
我不明白.有一些简单的方法吗?
UPD:似乎Python和Mongo不同意Utf-8 Valid字符串的定义.
我有一个这样的对象:
Object1.prototype = {
isInit: false,
Get : function (){}
}
Run Code Online (Sandbox Code Playgroud)
现在我想添加一个带有一个参数的构造函数.我该怎么做?
首先,问题是"编写一个Java程序,使用三元运算符找到三个最小的数字."
这是我的代码:
class questionNine
{
public static void main(String args[])
{
int x = 1, y = 2, z = 3;
int smallestNum;
smallestNum = (x<y && x<z) ? x : (y<x && y<z) ? y : (z<y && z<x) ? z;
System.out.println(smallestNum + " is the smallest of the three numbers.");
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在三元运算符中使用多个条件,但这不起作用.几天我不在,所以我不确定该做什么,老师的电话已关闭.有帮助吗?
我在与我通常使用的计算机不同的计算机上运行我的节点应用程序时遇到问题。经过大量的故障排除:
我收到的错误消息是:
Error: ENOENT: no such file or directory, scandir '.../node_modules/node-sass/vendor'
Run Code Online (Sandbox Code Playgroud)
我正在阅读的帖子建议我运行sudo npm install -g node-sass,这给了我以下错误:
Error: EACCES: permission denied, mkdir '...nvm/versions/node/v8.9.0/lib/node_modules/node-sass/build'
Run Code Online (Sandbox Code Playgroud)
然后我尝试运行,sudo npm rebuild node-sass但收到相同的错误消息:
Error: EACCES: permission denied, mkdir '.../node_modules/node-sass/build'
Run Code Online (Sandbox Code Playgroud)
然后我跑了,sudo npm install -g node-sass --unsafe-perm=true --allow-root但它也没有用:
ENOENT: no such file or directory, scandir '.../node_modules/node-sass/vendor'
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?为什么 node-sass 不工作?为什么 sudo 不能正常工作?
我正在使用python并尝试在我的计算机和站点之间刮取HTTP流量,其中包括所有传入和传出请求,响应,如图像和外部呼叫等.
我试图在我的hit_site功能中找到网络流量,但我找不到这些信息.
hit_site("http://www.google.com")
def hit_site(url):
print url
r = requests.get(url,stream = True)
print r.headers
print r.encoding
print r.status_code
print r.json()
print requests.get(url,stream=True)
print r.request.headers
print r.response.headers
for line in r.iter_lines():
print line
data = r.text
soup = BeautifulSoup(data)
return soup
Run Code Online (Sandbox Code Playgroud)
我想要捕获的信息类型的示例如下(我使用fiddler2来获取此信息.所有这些以及更多来自访问groupon.com):
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
6 200 HTTP www.groupon.com / 23,236 private, max-age=0, no-cache, no-store, must-revalidate text/html; charset=utf-8 chrome:6080
7 200 HTTP www.groupon.com /homepage-assets/styles-6fca4e9f48.css 6,766 public, max-age=31369910 text/css; charset=UTF-8 chrome:6080
8 …Run Code Online (Sandbox Code Playgroud) 我正在使用离子标签.一些选项卡是从数据库生成的(没有图标的选项卡)
现在当我添加一个新标签并刷新数组时,我应该得到3个动态标签.相反,我有5个(前2个和前2个具有最新创建的选项卡)尽管数组正确有3个对象.
[对象,对象,对象]
所以这里的相关代码(tabs组件有一个监听选项卡创建的事件):
// tabs.ts
import { Component } from '@angular/core';
import { Events } from 'ionic-angular';
import { DatabaseService } from "../../providers/database.service";
import { ItemsPage } from '../items/items';
import { ContactPage } from '../contact/contact';
import { HomePage } from '../home/home';
import { CategoryPage } from '../category/category';
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
categories: any = [];
tab1Root = HomePage;
tab2Root = CategoryPage;
tab3Root = ItemsPage;
tab4Root = ContactPage;
constructor(public databaseService: DatabaseService, public events: Events) {
this.events.subscribe('category:created', …Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我将每个项目的密钥和一个电子邮件地址保存在一个表中,并使用所述密钥检索要从原始表中获取的对象.我可以看到rawList当我在console.log中时项目被放入数组中,但是函数this.cartList在它有任何内容之前返回,因此视图不会接收任何数据.我怎样才能让它在返回之前this.cartList等待rawList满满?
ionViewWillEnter() {
var user = firebase.auth().currentUser;
this.cartData.getCart().on('value', snapshot => {
let rawList = [];
snapshot.forEach(snap => {
if (user.email == snap.val().email) {
var desiredItem = this.goodsData.findGoodById(snap.val().key);
desiredItem.once("value")
.then(function(snapshot2) {
rawList.push(snapshot2);
});
return false
}
});
console.log(rawList);
this.cartList = rawList;
});
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试将this.cartList = rawList放在许多不同的位置(之前return false,甚至在.then语句内部,但这并没有解决问题.
javascript callback firebase firebase-realtime-database angular
我正在创建一个Stripe支付系统,并且很难使这个集成代码正常运行.代码是从这里拉出来的.我想要做的是创建一个数据库引用到用户的特定用户ID(uid),因为createStripeCharge等待write event发生类似的事情/stripe_customers/XCXaweADowefj/charges/QC123XYZ.我不确定,但也许我的问题是我错误地引用了客户.如果您对我如何正确使用此功能有任何想法或反馈,我非常感谢!
触发器(这会导致云功能工作):
payByStripe(amount,email,userId, token): firebase.database.Reference {
return firebase.database().ref(`/stripe_customers/${userId}/charges/`).push({
amount:amount,
email:email,
token:token
});
}
Run Code Online (Sandbox Code Playgroud)
云功能:
exports.createStripeCharge = functions.database.ref('/stripe_customers/{userId}/charges/{id}').onWrite(event => {
const val = event.data.val();
if (val === null || val.id || val.error) return null;
return admin.database().ref(`/stripe_customers/${event.params.userId}/customer_id`).once('value').then(snapshot => {
return snapshot.val();
}).then(customer => {
const amount = val.amount;
const idempotency_key = event.params.id;
let charge = {amount, currency, customer};
if (val.source !== null) charge.source = val.source;
return stripe.charges.create(charge, {idempotency_key});
}).then(response …Run Code Online (Sandbox Code Playgroud)